index.js 491 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458
  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 (-1 !== e.indexOf(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. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  91. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  92. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  93. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  94. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  95. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  96. ConstructorIsAsync: "Constructor can't be an async function.",
  97. ConstructorIsGenerator: "Constructor can't be a generator.",
  98. DeclarationMissingInitializer: ({
  99. kind
  100. }) => `Missing initializer in ${kind} declaration.`,
  101. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  102. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  103. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  104. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  105. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  106. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  107. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  108. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  109. DeletePrivateField: "Deleting a private field is not allowed.",
  110. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  111. DuplicateConstructor: "Duplicate constructor in the same class.",
  112. DuplicateDefaultExport: "Only one default export allowed per module.",
  113. DuplicateExport: ({
  114. exportName
  115. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  116. DuplicateProto: "Redefinition of __proto__ property.",
  117. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  118. DynamicImportPhaseRequiresImportExpressions: ({
  119. phase
  120. }) => `'import.${phase}(...)' can only be parsed when using the 'createImportExpressions' option.`,
  121. ElementAfterRest: "Rest element must be last element.",
  122. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  123. ExportBindingIsString: ({
  124. localName,
  125. exportName
  126. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  127. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  128. ForInOfLoopInitializer: ({
  129. type
  130. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  131. ForInUsing: "For-in loop may not start with 'using' declaration.",
  132. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  133. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  134. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  135. IllegalBreakContinue: ({
  136. type
  137. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  138. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  139. IllegalReturn: "'return' outside of function.",
  140. 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.",
  141. ImportBindingIsString: ({
  142. importName
  143. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  144. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  145. ImportCallNotNewExpression: "Cannot use new with import(...).",
  146. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  147. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  148. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  149. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  150. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  151. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  152. InvalidCodePoint: "Code point out of bounds.",
  153. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  154. InvalidDecimal: "Invalid decimal.",
  155. InvalidDigit: ({
  156. radix
  157. }) => `Expected number in radix ${radix}.`,
  158. InvalidEscapeSequence: "Bad character escape sequence.",
  159. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  160. InvalidEscapedReservedWord: ({
  161. reservedWord
  162. }) => `Escape sequence in keyword ${reservedWord}.`,
  163. InvalidIdentifier: ({
  164. identifierName
  165. }) => `Invalid identifier ${identifierName}.`,
  166. InvalidLhs: ({
  167. ancestor
  168. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  169. InvalidLhsBinding: ({
  170. ancestor
  171. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  172. InvalidLhsOptionalChaining: ({
  173. ancestor
  174. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  175. InvalidNumber: "Invalid number.",
  176. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  177. InvalidOrUnexpectedToken: ({
  178. unexpected
  179. }) => `Unexpected character '${unexpected}'.`,
  180. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  181. InvalidPrivateFieldResolution: ({
  182. identifierName
  183. }) => `Private name #${identifierName} is not defined.`,
  184. InvalidPropertyBindingPattern: "Binding member expression.",
  185. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  186. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  187. LabelRedeclaration: ({
  188. labelName
  189. }) => `Label '${labelName}' is already declared.`,
  190. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  191. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  192. MalformedRegExpFlags: "Invalid regular expression flag.",
  193. MissingClassName: "A class name is required.",
  194. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  195. MissingSemicolon: "Missing semicolon.",
  196. MissingPlugin: ({
  197. missingPlugin
  198. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  199. MissingOneOfPlugins: ({
  200. missingPlugin
  201. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  202. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  203. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  204. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  205. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  206. ModuleAttributesWithDuplicateKeys: ({
  207. key
  208. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  209. ModuleExportNameHasLoneSurrogate: ({
  210. surrogateCharCode
  211. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  212. ModuleExportUndefined: ({
  213. localName
  214. }) => `Export '${localName}' is not defined.`,
  215. MultipleDefaultsInSwitch: "Multiple default clauses.",
  216. NewlineAfterThrow: "Illegal newline after throw.",
  217. NoCatchOrFinally: "Missing catch or finally clause.",
  218. NumberIdentifier: "Identifier directly after number.",
  219. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  220. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  221. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  222. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  223. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  224. ParamDupe: "Argument name clash.",
  225. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  226. PatternHasMethod: "Object pattern can't contain methods.",
  227. PrivateInExpectedIn: ({
  228. identifierName
  229. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  230. PrivateNameRedeclaration: ({
  231. identifierName
  232. }) => `Duplicate private name #${identifierName}.`,
  233. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  234. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  235. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  236. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  237. RestTrailingComma: "Unexpected trailing comma after rest element.",
  238. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  239. 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.",
  240. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  241. StaticPrototype: "Classes may not have static property named prototype.",
  242. 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?",
  243. SuperPrivateField: "Private fields can't be accessed on super.",
  244. TrailingDecorator: "Decorators must be attached to a class element.",
  245. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  246. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  247. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  248. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  249. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  250. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  251. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  252. UnexpectedKeyword: ({
  253. keyword
  254. }) => `Unexpected keyword '${keyword}'.`,
  255. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  256. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  257. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  258. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  259. UnexpectedPrivateField: "Unexpected private name.",
  260. UnexpectedReservedWord: ({
  261. reservedWord
  262. }) => `Unexpected reserved word '${reservedWord}'.`,
  263. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  264. UnexpectedToken: ({
  265. expected,
  266. unexpected
  267. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  268. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  269. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  270. UnsupportedBind: "Binding should be performed on object property.",
  271. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  272. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  273. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  274. UnsupportedMetaProperty: ({
  275. target,
  276. onlyValidPropertyName
  277. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  278. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  279. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  280. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  281. UnterminatedComment: "Unterminated comment.",
  282. UnterminatedRegExp: "Unterminated regular expression.",
  283. UnterminatedString: "Unterminated string constant.",
  284. UnterminatedTemplate: "Unterminated template.",
  285. UsingDeclarationExport: "Using declaration cannot be exported.",
  286. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  287. VarRedeclaration: ({
  288. identifierName
  289. }) => `Identifier '${identifierName}' has already been declared.`,
  290. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  291. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  292. YieldNotInGeneratorFunction: "'yield' is only allowed within generator functions.",
  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 = Object.assign({
  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. }, {
  323. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  324. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  325. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  326. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  327. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  328. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  329. });
  330. const _excluded = ["message"];
  331. function defineHidden(obj, key, value) {
  332. Object.defineProperty(obj, key, {
  333. enumerable: false,
  334. configurable: true,
  335. value
  336. });
  337. }
  338. function toParseErrorConstructor({
  339. toMessage,
  340. code,
  341. reasonCode,
  342. syntaxPlugin
  343. }) {
  344. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  345. {
  346. const oldReasonCodes = {
  347. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  348. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  349. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  350. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  351. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  352. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  353. };
  354. if (oldReasonCodes[reasonCode]) {
  355. reasonCode = oldReasonCodes[reasonCode];
  356. }
  357. }
  358. return function constructor(loc, details) {
  359. const error = new SyntaxError();
  360. error.code = code;
  361. error.reasonCode = reasonCode;
  362. error.loc = loc;
  363. error.pos = loc.index;
  364. error.syntaxPlugin = syntaxPlugin;
  365. if (hasMissingPlugin) {
  366. error.missingPlugin = details.missingPlugin;
  367. }
  368. defineHidden(error, "clone", function clone(overrides = {}) {
  369. var _overrides$loc;
  370. const {
  371. line,
  372. column,
  373. index
  374. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  375. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  376. });
  377. defineHidden(error, "details", details);
  378. Object.defineProperty(error, "message", {
  379. configurable: true,
  380. get() {
  381. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  382. this.message = message;
  383. return message;
  384. },
  385. set(value) {
  386. Object.defineProperty(this, "message", {
  387. value,
  388. writable: true
  389. });
  390. }
  391. });
  392. return error;
  393. };
  394. }
  395. function ParseErrorEnum(argument, syntaxPlugin) {
  396. if (Array.isArray(argument)) {
  397. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  398. }
  399. const ParseErrorConstructors = {};
  400. for (const reasonCode of Object.keys(argument)) {
  401. const template = argument[reasonCode];
  402. const _ref = typeof template === "string" ? {
  403. message: () => template
  404. } : typeof template === "function" ? {
  405. message: template
  406. } : template,
  407. {
  408. message
  409. } = _ref,
  410. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  411. const toMessage = typeof message === "string" ? () => message : message;
  412. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  413. code: "BABEL_PARSER_SYNTAX_ERROR",
  414. reasonCode,
  415. toMessage
  416. }, syntaxPlugin ? {
  417. syntaxPlugin
  418. } : {}, rest));
  419. }
  420. return ParseErrorConstructors;
  421. }
  422. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  423. function createDefaultOptions() {
  424. return {
  425. sourceType: "script",
  426. sourceFilename: undefined,
  427. startIndex: 0,
  428. startColumn: 0,
  429. startLine: 1,
  430. allowAwaitOutsideFunction: false,
  431. allowReturnOutsideFunction: false,
  432. allowNewTargetOutsideFunction: false,
  433. allowImportExportEverywhere: false,
  434. allowSuperOutsideMethod: false,
  435. allowUndeclaredExports: false,
  436. allowYieldOutsideFunction: false,
  437. plugins: [],
  438. strictMode: null,
  439. ranges: false,
  440. tokens: false,
  441. createImportExpressions: false,
  442. createParenthesizedExpressions: false,
  443. errorRecovery: false,
  444. attachComment: true,
  445. annexB: true
  446. };
  447. }
  448. function getOptions(opts) {
  449. const options = createDefaultOptions();
  450. if (opts == null) {
  451. return options;
  452. }
  453. if (opts.annexB != null && opts.annexB !== false) {
  454. throw new Error("The `annexB` option can only be set to `false`.");
  455. }
  456. for (const key of Object.keys(options)) {
  457. if (opts[key] != null) options[key] = opts[key];
  458. }
  459. if (options.startLine === 1) {
  460. if (opts.startIndex == null && options.startColumn > 0) {
  461. options.startIndex = options.startColumn;
  462. } else if (opts.startColumn == null && options.startIndex > 0) {
  463. options.startColumn = options.startIndex;
  464. }
  465. } else if (opts.startColumn == null || opts.startIndex == null) {
  466. if (opts.startIndex != null) {
  467. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  468. }
  469. }
  470. return options;
  471. }
  472. const {
  473. defineProperty
  474. } = Object;
  475. const toUnenumerable = (object, key) => {
  476. if (object) {
  477. defineProperty(object, key, {
  478. enumerable: false,
  479. value: object[key]
  480. });
  481. }
  482. };
  483. function toESTreeLocation(node) {
  484. toUnenumerable(node.loc.start, "index");
  485. toUnenumerable(node.loc.end, "index");
  486. return node;
  487. }
  488. var estree = superClass => class ESTreeParserMixin extends superClass {
  489. parse() {
  490. const file = toESTreeLocation(super.parse());
  491. if (this.optionFlags & 256) {
  492. file.tokens = file.tokens.map(toESTreeLocation);
  493. }
  494. return file;
  495. }
  496. parseRegExpLiteral({
  497. pattern,
  498. flags
  499. }) {
  500. let regex = null;
  501. try {
  502. regex = new RegExp(pattern, flags);
  503. } catch (_) {}
  504. const node = this.estreeParseLiteral(regex);
  505. node.regex = {
  506. pattern,
  507. flags
  508. };
  509. return node;
  510. }
  511. parseBigIntLiteral(value) {
  512. let bigInt;
  513. try {
  514. bigInt = BigInt(value);
  515. } catch (_unused) {
  516. bigInt = null;
  517. }
  518. const node = this.estreeParseLiteral(bigInt);
  519. node.bigint = String(node.value || value);
  520. return node;
  521. }
  522. parseDecimalLiteral(value) {
  523. const decimal = null;
  524. const node = this.estreeParseLiteral(decimal);
  525. node.decimal = String(node.value || value);
  526. return node;
  527. }
  528. estreeParseLiteral(value) {
  529. return this.parseLiteral(value, "Literal");
  530. }
  531. parseStringLiteral(value) {
  532. return this.estreeParseLiteral(value);
  533. }
  534. parseNumericLiteral(value) {
  535. return this.estreeParseLiteral(value);
  536. }
  537. parseNullLiteral() {
  538. return this.estreeParseLiteral(null);
  539. }
  540. parseBooleanLiteral(value) {
  541. return this.estreeParseLiteral(value);
  542. }
  543. estreeParseChainExpression(node, endLoc) {
  544. const chain = this.startNodeAtNode(node);
  545. chain.expression = node;
  546. return this.finishNodeAt(chain, "ChainExpression", endLoc);
  547. }
  548. directiveToStmt(directive) {
  549. const expression = directive.value;
  550. delete directive.value;
  551. this.castNodeTo(expression, "Literal");
  552. expression.raw = expression.extra.raw;
  553. expression.value = expression.extra.expressionValue;
  554. const stmt = this.castNodeTo(directive, "ExpressionStatement");
  555. stmt.expression = expression;
  556. stmt.directive = expression.extra.rawValue;
  557. delete expression.extra;
  558. return stmt;
  559. }
  560. fillOptionalPropertiesForTSESLint(node) {}
  561. cloneEstreeStringLiteral(node) {
  562. const {
  563. start,
  564. end,
  565. loc,
  566. range,
  567. raw,
  568. value
  569. } = node;
  570. const cloned = Object.create(node.constructor.prototype);
  571. cloned.type = "Literal";
  572. cloned.start = start;
  573. cloned.end = end;
  574. cloned.loc = loc;
  575. cloned.range = range;
  576. cloned.raw = raw;
  577. cloned.value = value;
  578. return cloned;
  579. }
  580. initFunction(node, isAsync) {
  581. super.initFunction(node, isAsync);
  582. node.expression = false;
  583. }
  584. checkDeclaration(node) {
  585. if (node != null && this.isObjectProperty(node)) {
  586. this.checkDeclaration(node.value);
  587. } else {
  588. super.checkDeclaration(node);
  589. }
  590. }
  591. getObjectOrClassMethodParams(method) {
  592. return method.value.params;
  593. }
  594. isValidDirective(stmt) {
  595. var _stmt$expression$extr;
  596. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  597. }
  598. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  599. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  600. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  601. node.body = directiveStatements.concat(node.body);
  602. delete node.directives;
  603. }
  604. parsePrivateName() {
  605. const node = super.parsePrivateName();
  606. {
  607. if (!this.getPluginOption("estree", "classFeatures")) {
  608. return node;
  609. }
  610. }
  611. return this.convertPrivateNameToPrivateIdentifier(node);
  612. }
  613. convertPrivateNameToPrivateIdentifier(node) {
  614. const name = super.getPrivateNameSV(node);
  615. node = node;
  616. delete node.id;
  617. node.name = name;
  618. return this.castNodeTo(node, "PrivateIdentifier");
  619. }
  620. isPrivateName(node) {
  621. {
  622. if (!this.getPluginOption("estree", "classFeatures")) {
  623. return super.isPrivateName(node);
  624. }
  625. }
  626. return node.type === "PrivateIdentifier";
  627. }
  628. getPrivateNameSV(node) {
  629. {
  630. if (!this.getPluginOption("estree", "classFeatures")) {
  631. return super.getPrivateNameSV(node);
  632. }
  633. }
  634. return node.name;
  635. }
  636. parseLiteral(value, type) {
  637. const node = super.parseLiteral(value, type);
  638. node.raw = node.extra.raw;
  639. delete node.extra;
  640. return node;
  641. }
  642. parseFunctionBody(node, allowExpression, isMethod = false) {
  643. super.parseFunctionBody(node, allowExpression, isMethod);
  644. node.expression = node.body.type !== "BlockStatement";
  645. }
  646. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  647. let funcNode = this.startNode();
  648. funcNode.kind = node.kind;
  649. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  650. delete funcNode.kind;
  651. const {
  652. typeParameters
  653. } = node;
  654. if (typeParameters) {
  655. delete node.typeParameters;
  656. funcNode.typeParameters = typeParameters;
  657. this.resetStartLocationFromNode(funcNode, typeParameters);
  658. }
  659. const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
  660. node.value = valueNode;
  661. if (type === "ClassPrivateMethod") {
  662. node.computed = false;
  663. }
  664. if (type === "ObjectMethod") {
  665. if (node.kind === "method") {
  666. node.kind = "init";
  667. }
  668. node.shorthand = false;
  669. return this.finishNode(node, "Property");
  670. } else {
  671. return this.finishNode(node, "MethodDefinition");
  672. }
  673. }
  674. nameIsConstructor(key) {
  675. if (key.type === "Literal") return key.value === "constructor";
  676. return super.nameIsConstructor(key);
  677. }
  678. parseClassProperty(...args) {
  679. const propertyNode = super.parseClassProperty(...args);
  680. {
  681. if (!this.getPluginOption("estree", "classFeatures")) {
  682. return propertyNode;
  683. }
  684. }
  685. {
  686. this.castNodeTo(propertyNode, "PropertyDefinition");
  687. }
  688. return propertyNode;
  689. }
  690. parseClassPrivateProperty(...args) {
  691. const propertyNode = super.parseClassPrivateProperty(...args);
  692. {
  693. if (!this.getPluginOption("estree", "classFeatures")) {
  694. return propertyNode;
  695. }
  696. }
  697. {
  698. this.castNodeTo(propertyNode, "PropertyDefinition");
  699. }
  700. propertyNode.computed = false;
  701. return propertyNode;
  702. }
  703. parseClassAccessorProperty(node) {
  704. const accessorPropertyNode = super.parseClassAccessorProperty(node);
  705. {
  706. if (!this.getPluginOption("estree", "classFeatures")) {
  707. return accessorPropertyNode;
  708. }
  709. }
  710. if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
  711. delete accessorPropertyNode.abstract;
  712. this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
  713. } else {
  714. this.castNodeTo(accessorPropertyNode, "AccessorProperty");
  715. }
  716. return accessorPropertyNode;
  717. }
  718. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  719. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  720. if (node) {
  721. node.kind = "init";
  722. this.castNodeTo(node, "Property");
  723. }
  724. return node;
  725. }
  726. finishObjectProperty(node) {
  727. node.kind = "init";
  728. return this.finishNode(node, "Property");
  729. }
  730. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  731. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  732. }
  733. isAssignable(node, isBinding) {
  734. if (node != null && this.isObjectProperty(node)) {
  735. return this.isAssignable(node.value, isBinding);
  736. }
  737. return super.isAssignable(node, isBinding);
  738. }
  739. toAssignable(node, isLHS = false) {
  740. if (node != null && this.isObjectProperty(node)) {
  741. const {
  742. key,
  743. value
  744. } = node;
  745. if (this.isPrivateName(key)) {
  746. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  747. }
  748. this.toAssignable(value, isLHS);
  749. } else {
  750. super.toAssignable(node, isLHS);
  751. }
  752. }
  753. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  754. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  755. this.raise(Errors.PatternHasAccessor, prop.key);
  756. } else if (prop.type === "Property" && prop.method) {
  757. this.raise(Errors.PatternHasMethod, prop.key);
  758. } else {
  759. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  760. }
  761. }
  762. finishCallExpression(unfinished, optional) {
  763. const node = super.finishCallExpression(unfinished, optional);
  764. if (node.callee.type === "Import") {
  765. var _ref, _ref2;
  766. this.castNodeTo(node, "ImportExpression");
  767. node.source = node.arguments[0];
  768. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  769. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  770. delete node.arguments;
  771. delete node.callee;
  772. } else if (node.type === "OptionalCallExpression") {
  773. this.castNodeTo(node, "CallExpression");
  774. } else {
  775. node.optional = false;
  776. }
  777. return node;
  778. }
  779. toReferencedArguments(node) {
  780. if (node.type === "ImportExpression") {
  781. return;
  782. }
  783. super.toReferencedArguments(node);
  784. }
  785. parseExport(unfinished, decorators) {
  786. const exportStartLoc = this.state.lastTokStartLoc;
  787. const node = super.parseExport(unfinished, decorators);
  788. switch (node.type) {
  789. case "ExportAllDeclaration":
  790. node.exported = null;
  791. break;
  792. case "ExportNamedDeclaration":
  793. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  794. this.castNodeTo(node, "ExportAllDeclaration");
  795. node.exported = node.specifiers[0].exported;
  796. delete node.specifiers;
  797. }
  798. case "ExportDefaultDeclaration":
  799. {
  800. var _declaration$decorato;
  801. const {
  802. declaration
  803. } = node;
  804. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  805. this.resetStartLocation(node, exportStartLoc);
  806. }
  807. }
  808. break;
  809. }
  810. return node;
  811. }
  812. stopParseSubscript(base, state) {
  813. const node = super.stopParseSubscript(base, state);
  814. if (state.optionalChainMember) {
  815. return this.estreeParseChainExpression(node, base.loc.end);
  816. }
  817. return node;
  818. }
  819. parseMember(base, startLoc, state, computed, optional) {
  820. const node = super.parseMember(base, startLoc, state, computed, optional);
  821. if (node.type === "OptionalMemberExpression") {
  822. this.castNodeTo(node, "MemberExpression");
  823. } else {
  824. node.optional = false;
  825. }
  826. return node;
  827. }
  828. isOptionalMemberExpression(node) {
  829. if (node.type === "ChainExpression") {
  830. return node.expression.type === "MemberExpression";
  831. }
  832. return super.isOptionalMemberExpression(node);
  833. }
  834. hasPropertyAsPrivateName(node) {
  835. if (node.type === "ChainExpression") {
  836. node = node.expression;
  837. }
  838. return super.hasPropertyAsPrivateName(node);
  839. }
  840. isObjectProperty(node) {
  841. return node.type === "Property" && node.kind === "init" && !node.method;
  842. }
  843. isObjectMethod(node) {
  844. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  845. }
  846. castNodeTo(node, type) {
  847. const result = super.castNodeTo(node, type);
  848. this.fillOptionalPropertiesForTSESLint(result);
  849. return result;
  850. }
  851. cloneIdentifier(node) {
  852. const cloned = super.cloneIdentifier(node);
  853. this.fillOptionalPropertiesForTSESLint(cloned);
  854. return cloned;
  855. }
  856. cloneStringLiteral(node) {
  857. if (node.type === "Literal") {
  858. return this.cloneEstreeStringLiteral(node);
  859. }
  860. return super.cloneStringLiteral(node);
  861. }
  862. finishNodeAt(node, type, endLoc) {
  863. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  864. }
  865. finishNode(node, type) {
  866. const result = super.finishNode(node, type);
  867. this.fillOptionalPropertiesForTSESLint(result);
  868. return result;
  869. }
  870. resetStartLocation(node, startLoc) {
  871. super.resetStartLocation(node, startLoc);
  872. toESTreeLocation(node);
  873. }
  874. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  875. super.resetEndLocation(node, endLoc);
  876. toESTreeLocation(node);
  877. }
  878. };
  879. class TokContext {
  880. constructor(token, preserveSpace) {
  881. this.token = void 0;
  882. this.preserveSpace = void 0;
  883. this.token = token;
  884. this.preserveSpace = !!preserveSpace;
  885. }
  886. }
  887. const types = {
  888. brace: new TokContext("{"),
  889. j_oTag: new TokContext("<tag"),
  890. j_cTag: new TokContext("</tag"),
  891. j_expr: new TokContext("<tag>...</tag>", true)
  892. };
  893. {
  894. types.template = new TokContext("`", true);
  895. }
  896. const beforeExpr = true;
  897. const startsExpr = true;
  898. const isLoop = true;
  899. const isAssign = true;
  900. const prefix = true;
  901. const postfix = true;
  902. class ExportedTokenType {
  903. constructor(label, conf = {}) {
  904. this.label = void 0;
  905. this.keyword = void 0;
  906. this.beforeExpr = void 0;
  907. this.startsExpr = void 0;
  908. this.rightAssociative = void 0;
  909. this.isLoop = void 0;
  910. this.isAssign = void 0;
  911. this.prefix = void 0;
  912. this.postfix = void 0;
  913. this.binop = void 0;
  914. this.label = label;
  915. this.keyword = conf.keyword;
  916. this.beforeExpr = !!conf.beforeExpr;
  917. this.startsExpr = !!conf.startsExpr;
  918. this.rightAssociative = !!conf.rightAssociative;
  919. this.isLoop = !!conf.isLoop;
  920. this.isAssign = !!conf.isAssign;
  921. this.prefix = !!conf.prefix;
  922. this.postfix = !!conf.postfix;
  923. this.binop = conf.binop != null ? conf.binop : null;
  924. {
  925. this.updateContext = null;
  926. }
  927. }
  928. }
  929. const keywords$1 = new Map();
  930. function createKeyword(name, options = {}) {
  931. options.keyword = name;
  932. const token = createToken(name, options);
  933. keywords$1.set(name, token);
  934. return token;
  935. }
  936. function createBinop(name, binop) {
  937. return createToken(name, {
  938. beforeExpr,
  939. binop
  940. });
  941. }
  942. let tokenTypeCounter = -1;
  943. const tokenTypes = [];
  944. const tokenLabels = [];
  945. const tokenBinops = [];
  946. const tokenBeforeExprs = [];
  947. const tokenStartsExprs = [];
  948. const tokenPrefixes = [];
  949. function createToken(name, options = {}) {
  950. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  951. ++tokenTypeCounter;
  952. tokenLabels.push(name);
  953. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  954. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  955. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  956. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  957. tokenTypes.push(new ExportedTokenType(name, options));
  958. return tokenTypeCounter;
  959. }
  960. function createKeywordLike(name, options = {}) {
  961. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  962. ++tokenTypeCounter;
  963. keywords$1.set(name, tokenTypeCounter);
  964. tokenLabels.push(name);
  965. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  966. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  967. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  968. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  969. tokenTypes.push(new ExportedTokenType("name", options));
  970. return tokenTypeCounter;
  971. }
  972. const tt = {
  973. bracketL: createToken("[", {
  974. beforeExpr,
  975. startsExpr
  976. }),
  977. bracketHashL: createToken("#[", {
  978. beforeExpr,
  979. startsExpr
  980. }),
  981. bracketBarL: createToken("[|", {
  982. beforeExpr,
  983. startsExpr
  984. }),
  985. bracketR: createToken("]"),
  986. bracketBarR: createToken("|]"),
  987. braceL: createToken("{", {
  988. beforeExpr,
  989. startsExpr
  990. }),
  991. braceBarL: createToken("{|", {
  992. beforeExpr,
  993. startsExpr
  994. }),
  995. braceHashL: createToken("#{", {
  996. beforeExpr,
  997. startsExpr
  998. }),
  999. braceR: createToken("}"),
  1000. braceBarR: createToken("|}"),
  1001. parenL: createToken("(", {
  1002. beforeExpr,
  1003. startsExpr
  1004. }),
  1005. parenR: createToken(")"),
  1006. comma: createToken(",", {
  1007. beforeExpr
  1008. }),
  1009. semi: createToken(";", {
  1010. beforeExpr
  1011. }),
  1012. colon: createToken(":", {
  1013. beforeExpr
  1014. }),
  1015. doubleColon: createToken("::", {
  1016. beforeExpr
  1017. }),
  1018. dot: createToken("."),
  1019. question: createToken("?", {
  1020. beforeExpr
  1021. }),
  1022. questionDot: createToken("?."),
  1023. arrow: createToken("=>", {
  1024. beforeExpr
  1025. }),
  1026. template: createToken("template"),
  1027. ellipsis: createToken("...", {
  1028. beforeExpr
  1029. }),
  1030. backQuote: createToken("`", {
  1031. startsExpr
  1032. }),
  1033. dollarBraceL: createToken("${", {
  1034. beforeExpr,
  1035. startsExpr
  1036. }),
  1037. templateTail: createToken("...`", {
  1038. startsExpr
  1039. }),
  1040. templateNonTail: createToken("...${", {
  1041. beforeExpr,
  1042. startsExpr
  1043. }),
  1044. at: createToken("@"),
  1045. hash: createToken("#", {
  1046. startsExpr
  1047. }),
  1048. interpreterDirective: createToken("#!..."),
  1049. eq: createToken("=", {
  1050. beforeExpr,
  1051. isAssign
  1052. }),
  1053. assign: createToken("_=", {
  1054. beforeExpr,
  1055. isAssign
  1056. }),
  1057. slashAssign: createToken("_=", {
  1058. beforeExpr,
  1059. isAssign
  1060. }),
  1061. xorAssign: createToken("_=", {
  1062. beforeExpr,
  1063. isAssign
  1064. }),
  1065. moduloAssign: createToken("_=", {
  1066. beforeExpr,
  1067. isAssign
  1068. }),
  1069. incDec: createToken("++/--", {
  1070. prefix,
  1071. postfix,
  1072. startsExpr
  1073. }),
  1074. bang: createToken("!", {
  1075. beforeExpr,
  1076. prefix,
  1077. startsExpr
  1078. }),
  1079. tilde: createToken("~", {
  1080. beforeExpr,
  1081. prefix,
  1082. startsExpr
  1083. }),
  1084. doubleCaret: createToken("^^", {
  1085. startsExpr
  1086. }),
  1087. doubleAt: createToken("@@", {
  1088. startsExpr
  1089. }),
  1090. pipeline: createBinop("|>", 0),
  1091. nullishCoalescing: createBinop("??", 1),
  1092. logicalOR: createBinop("||", 1),
  1093. logicalAND: createBinop("&&", 2),
  1094. bitwiseOR: createBinop("|", 3),
  1095. bitwiseXOR: createBinop("^", 4),
  1096. bitwiseAND: createBinop("&", 5),
  1097. equality: createBinop("==/!=/===/!==", 6),
  1098. lt: createBinop("</>/<=/>=", 7),
  1099. gt: createBinop("</>/<=/>=", 7),
  1100. relational: createBinop("</>/<=/>=", 7),
  1101. bitShift: createBinop("<</>>/>>>", 8),
  1102. bitShiftL: createBinop("<</>>/>>>", 8),
  1103. bitShiftR: createBinop("<</>>/>>>", 8),
  1104. plusMin: createToken("+/-", {
  1105. beforeExpr,
  1106. binop: 9,
  1107. prefix,
  1108. startsExpr
  1109. }),
  1110. modulo: createToken("%", {
  1111. binop: 10,
  1112. startsExpr
  1113. }),
  1114. star: createToken("*", {
  1115. binop: 10
  1116. }),
  1117. slash: createBinop("/", 10),
  1118. exponent: createToken("**", {
  1119. beforeExpr,
  1120. binop: 11,
  1121. rightAssociative: true
  1122. }),
  1123. _in: createKeyword("in", {
  1124. beforeExpr,
  1125. binop: 7
  1126. }),
  1127. _instanceof: createKeyword("instanceof", {
  1128. beforeExpr,
  1129. binop: 7
  1130. }),
  1131. _break: createKeyword("break"),
  1132. _case: createKeyword("case", {
  1133. beforeExpr
  1134. }),
  1135. _catch: createKeyword("catch"),
  1136. _continue: createKeyword("continue"),
  1137. _debugger: createKeyword("debugger"),
  1138. _default: createKeyword("default", {
  1139. beforeExpr
  1140. }),
  1141. _else: createKeyword("else", {
  1142. beforeExpr
  1143. }),
  1144. _finally: createKeyword("finally"),
  1145. _function: createKeyword("function", {
  1146. startsExpr
  1147. }),
  1148. _if: createKeyword("if"),
  1149. _return: createKeyword("return", {
  1150. beforeExpr
  1151. }),
  1152. _switch: createKeyword("switch"),
  1153. _throw: createKeyword("throw", {
  1154. beforeExpr,
  1155. prefix,
  1156. startsExpr
  1157. }),
  1158. _try: createKeyword("try"),
  1159. _var: createKeyword("var"),
  1160. _const: createKeyword("const"),
  1161. _with: createKeyword("with"),
  1162. _new: createKeyword("new", {
  1163. beforeExpr,
  1164. startsExpr
  1165. }),
  1166. _this: createKeyword("this", {
  1167. startsExpr
  1168. }),
  1169. _super: createKeyword("super", {
  1170. startsExpr
  1171. }),
  1172. _class: createKeyword("class", {
  1173. startsExpr
  1174. }),
  1175. _extends: createKeyword("extends", {
  1176. beforeExpr
  1177. }),
  1178. _export: createKeyword("export"),
  1179. _import: createKeyword("import", {
  1180. startsExpr
  1181. }),
  1182. _null: createKeyword("null", {
  1183. startsExpr
  1184. }),
  1185. _true: createKeyword("true", {
  1186. startsExpr
  1187. }),
  1188. _false: createKeyword("false", {
  1189. startsExpr
  1190. }),
  1191. _typeof: createKeyword("typeof", {
  1192. beforeExpr,
  1193. prefix,
  1194. startsExpr
  1195. }),
  1196. _void: createKeyword("void", {
  1197. beforeExpr,
  1198. prefix,
  1199. startsExpr
  1200. }),
  1201. _delete: createKeyword("delete", {
  1202. beforeExpr,
  1203. prefix,
  1204. startsExpr
  1205. }),
  1206. _do: createKeyword("do", {
  1207. isLoop,
  1208. beforeExpr
  1209. }),
  1210. _for: createKeyword("for", {
  1211. isLoop
  1212. }),
  1213. _while: createKeyword("while", {
  1214. isLoop
  1215. }),
  1216. _as: createKeywordLike("as", {
  1217. startsExpr
  1218. }),
  1219. _assert: createKeywordLike("assert", {
  1220. startsExpr
  1221. }),
  1222. _async: createKeywordLike("async", {
  1223. startsExpr
  1224. }),
  1225. _await: createKeywordLike("await", {
  1226. startsExpr
  1227. }),
  1228. _defer: createKeywordLike("defer", {
  1229. startsExpr
  1230. }),
  1231. _from: createKeywordLike("from", {
  1232. startsExpr
  1233. }),
  1234. _get: createKeywordLike("get", {
  1235. startsExpr
  1236. }),
  1237. _let: createKeywordLike("let", {
  1238. startsExpr
  1239. }),
  1240. _meta: createKeywordLike("meta", {
  1241. startsExpr
  1242. }),
  1243. _of: createKeywordLike("of", {
  1244. startsExpr
  1245. }),
  1246. _sent: createKeywordLike("sent", {
  1247. startsExpr
  1248. }),
  1249. _set: createKeywordLike("set", {
  1250. startsExpr
  1251. }),
  1252. _source: createKeywordLike("source", {
  1253. startsExpr
  1254. }),
  1255. _static: createKeywordLike("static", {
  1256. startsExpr
  1257. }),
  1258. _using: createKeywordLike("using", {
  1259. startsExpr
  1260. }),
  1261. _yield: createKeywordLike("yield", {
  1262. startsExpr
  1263. }),
  1264. _asserts: createKeywordLike("asserts", {
  1265. startsExpr
  1266. }),
  1267. _checks: createKeywordLike("checks", {
  1268. startsExpr
  1269. }),
  1270. _exports: createKeywordLike("exports", {
  1271. startsExpr
  1272. }),
  1273. _global: createKeywordLike("global", {
  1274. startsExpr
  1275. }),
  1276. _implements: createKeywordLike("implements", {
  1277. startsExpr
  1278. }),
  1279. _intrinsic: createKeywordLike("intrinsic", {
  1280. startsExpr
  1281. }),
  1282. _infer: createKeywordLike("infer", {
  1283. startsExpr
  1284. }),
  1285. _is: createKeywordLike("is", {
  1286. startsExpr
  1287. }),
  1288. _mixins: createKeywordLike("mixins", {
  1289. startsExpr
  1290. }),
  1291. _proto: createKeywordLike("proto", {
  1292. startsExpr
  1293. }),
  1294. _require: createKeywordLike("require", {
  1295. startsExpr
  1296. }),
  1297. _satisfies: createKeywordLike("satisfies", {
  1298. startsExpr
  1299. }),
  1300. _keyof: createKeywordLike("keyof", {
  1301. startsExpr
  1302. }),
  1303. _readonly: createKeywordLike("readonly", {
  1304. startsExpr
  1305. }),
  1306. _unique: createKeywordLike("unique", {
  1307. startsExpr
  1308. }),
  1309. _abstract: createKeywordLike("abstract", {
  1310. startsExpr
  1311. }),
  1312. _declare: createKeywordLike("declare", {
  1313. startsExpr
  1314. }),
  1315. _enum: createKeywordLike("enum", {
  1316. startsExpr
  1317. }),
  1318. _module: createKeywordLike("module", {
  1319. startsExpr
  1320. }),
  1321. _namespace: createKeywordLike("namespace", {
  1322. startsExpr
  1323. }),
  1324. _interface: createKeywordLike("interface", {
  1325. startsExpr
  1326. }),
  1327. _type: createKeywordLike("type", {
  1328. startsExpr
  1329. }),
  1330. _opaque: createKeywordLike("opaque", {
  1331. startsExpr
  1332. }),
  1333. name: createToken("name", {
  1334. startsExpr
  1335. }),
  1336. placeholder: createToken("%%", {
  1337. startsExpr: true
  1338. }),
  1339. string: createToken("string", {
  1340. startsExpr
  1341. }),
  1342. num: createToken("num", {
  1343. startsExpr
  1344. }),
  1345. bigint: createToken("bigint", {
  1346. startsExpr
  1347. }),
  1348. decimal: createToken("decimal", {
  1349. startsExpr
  1350. }),
  1351. regexp: createToken("regexp", {
  1352. startsExpr
  1353. }),
  1354. privateName: createToken("#name", {
  1355. startsExpr
  1356. }),
  1357. eof: createToken("eof"),
  1358. jsxName: createToken("jsxName"),
  1359. jsxText: createToken("jsxText", {
  1360. beforeExpr: true
  1361. }),
  1362. jsxTagStart: createToken("jsxTagStart", {
  1363. startsExpr: true
  1364. }),
  1365. jsxTagEnd: createToken("jsxTagEnd")
  1366. };
  1367. function tokenIsIdentifier(token) {
  1368. return token >= 93 && token <= 133;
  1369. }
  1370. function tokenKeywordOrIdentifierIsKeyword(token) {
  1371. return token <= 92;
  1372. }
  1373. function tokenIsKeywordOrIdentifier(token) {
  1374. return token >= 58 && token <= 133;
  1375. }
  1376. function tokenIsLiteralPropertyName(token) {
  1377. return token >= 58 && token <= 137;
  1378. }
  1379. function tokenComesBeforeExpression(token) {
  1380. return tokenBeforeExprs[token];
  1381. }
  1382. function tokenCanStartExpression(token) {
  1383. return tokenStartsExprs[token];
  1384. }
  1385. function tokenIsAssignment(token) {
  1386. return token >= 29 && token <= 33;
  1387. }
  1388. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1389. return token >= 129 && token <= 131;
  1390. }
  1391. function tokenIsLoop(token) {
  1392. return token >= 90 && token <= 92;
  1393. }
  1394. function tokenIsKeyword(token) {
  1395. return token >= 58 && token <= 92;
  1396. }
  1397. function tokenIsOperator(token) {
  1398. return token >= 39 && token <= 59;
  1399. }
  1400. function tokenIsPostfix(token) {
  1401. return token === 34;
  1402. }
  1403. function tokenIsPrefix(token) {
  1404. return tokenPrefixes[token];
  1405. }
  1406. function tokenIsTSTypeOperator(token) {
  1407. return token >= 121 && token <= 123;
  1408. }
  1409. function tokenIsTSDeclarationStart(token) {
  1410. return token >= 124 && token <= 130;
  1411. }
  1412. function tokenLabelName(token) {
  1413. return tokenLabels[token];
  1414. }
  1415. function tokenOperatorPrecedence(token) {
  1416. return tokenBinops[token];
  1417. }
  1418. function tokenIsRightAssociative(token) {
  1419. return token === 57;
  1420. }
  1421. function tokenIsTemplate(token) {
  1422. return token >= 24 && token <= 25;
  1423. }
  1424. function getExportedToken(token) {
  1425. return tokenTypes[token];
  1426. }
  1427. {
  1428. tokenTypes[8].updateContext = context => {
  1429. context.pop();
  1430. };
  1431. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1432. context.push(types.brace);
  1433. };
  1434. tokenTypes[22].updateContext = context => {
  1435. if (context[context.length - 1] === types.template) {
  1436. context.pop();
  1437. } else {
  1438. context.push(types.template);
  1439. }
  1440. };
  1441. tokenTypes[143].updateContext = context => {
  1442. context.push(types.j_expr, types.j_oTag);
  1443. };
  1444. }
  1445. 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";
  1446. 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";
  1447. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1448. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1449. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1450. 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];
  1451. 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];
  1452. function isInAstralSet(code, set) {
  1453. let pos = 0x10000;
  1454. for (let i = 0, length = set.length; i < length; i += 2) {
  1455. pos += set[i];
  1456. if (pos > code) return false;
  1457. pos += set[i + 1];
  1458. if (pos >= code) return true;
  1459. }
  1460. return false;
  1461. }
  1462. function isIdentifierStart(code) {
  1463. if (code < 65) return code === 36;
  1464. if (code <= 90) return true;
  1465. if (code < 97) return code === 95;
  1466. if (code <= 122) return true;
  1467. if (code <= 0xffff) {
  1468. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1469. }
  1470. return isInAstralSet(code, astralIdentifierStartCodes);
  1471. }
  1472. function isIdentifierChar(code) {
  1473. if (code < 48) return code === 36;
  1474. if (code < 58) return true;
  1475. if (code < 65) return false;
  1476. if (code <= 90) return true;
  1477. if (code < 97) return code === 95;
  1478. if (code <= 122) return true;
  1479. if (code <= 0xffff) {
  1480. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1481. }
  1482. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1483. }
  1484. const reservedWords = {
  1485. 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"],
  1486. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1487. strictBind: ["eval", "arguments"]
  1488. };
  1489. const keywords = new Set(reservedWords.keyword);
  1490. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1491. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1492. function isReservedWord(word, inModule) {
  1493. return inModule && word === "await" || word === "enum";
  1494. }
  1495. function isStrictReservedWord(word, inModule) {
  1496. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1497. }
  1498. function isStrictBindOnlyReservedWord(word) {
  1499. return reservedWordsStrictBindSet.has(word);
  1500. }
  1501. function isStrictBindReservedWord(word, inModule) {
  1502. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1503. }
  1504. function isKeyword(word) {
  1505. return keywords.has(word);
  1506. }
  1507. function isIteratorStart(current, next, next2) {
  1508. return current === 64 && next === 64 && isIdentifierStart(next2);
  1509. }
  1510. 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"]);
  1511. function canBeReservedWord(word) {
  1512. return reservedWordLikeSet.has(word);
  1513. }
  1514. class Scope {
  1515. constructor(flags) {
  1516. this.flags = 0;
  1517. this.names = new Map();
  1518. this.firstLexicalName = "";
  1519. this.flags = flags;
  1520. }
  1521. }
  1522. class ScopeHandler {
  1523. constructor(parser, inModule) {
  1524. this.parser = void 0;
  1525. this.scopeStack = [];
  1526. this.inModule = void 0;
  1527. this.undefinedExports = new Map();
  1528. this.parser = parser;
  1529. this.inModule = inModule;
  1530. }
  1531. get inTopLevel() {
  1532. return (this.currentScope().flags & 1) > 0;
  1533. }
  1534. get inFunction() {
  1535. return (this.currentVarScopeFlags() & 2) > 0;
  1536. }
  1537. get allowSuper() {
  1538. return (this.currentThisScopeFlags() & 16) > 0;
  1539. }
  1540. get allowDirectSuper() {
  1541. return (this.currentThisScopeFlags() & 32) > 0;
  1542. }
  1543. get inClass() {
  1544. return (this.currentThisScopeFlags() & 64) > 0;
  1545. }
  1546. get inClassAndNotInNonArrowFunction() {
  1547. const flags = this.currentThisScopeFlags();
  1548. return (flags & 64) > 0 && (flags & 2) === 0;
  1549. }
  1550. get inStaticBlock() {
  1551. for (let i = this.scopeStack.length - 1;; i--) {
  1552. const {
  1553. flags
  1554. } = this.scopeStack[i];
  1555. if (flags & 128) {
  1556. return true;
  1557. }
  1558. if (flags & (387 | 64)) {
  1559. return false;
  1560. }
  1561. }
  1562. }
  1563. get inNonArrowFunction() {
  1564. return (this.currentThisScopeFlags() & 2) > 0;
  1565. }
  1566. get treatFunctionsAsVar() {
  1567. return this.treatFunctionsAsVarInScope(this.currentScope());
  1568. }
  1569. createScope(flags) {
  1570. return new Scope(flags);
  1571. }
  1572. enter(flags) {
  1573. this.scopeStack.push(this.createScope(flags));
  1574. }
  1575. exit() {
  1576. const scope = this.scopeStack.pop();
  1577. return scope.flags;
  1578. }
  1579. treatFunctionsAsVarInScope(scope) {
  1580. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1581. }
  1582. declareName(name, bindingType, loc) {
  1583. let scope = this.currentScope();
  1584. if (bindingType & 8 || bindingType & 16) {
  1585. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1586. let type = scope.names.get(name) || 0;
  1587. if (bindingType & 16) {
  1588. type = type | 4;
  1589. } else {
  1590. if (!scope.firstLexicalName) {
  1591. scope.firstLexicalName = name;
  1592. }
  1593. type = type | 2;
  1594. }
  1595. scope.names.set(name, type);
  1596. if (bindingType & 8) {
  1597. this.maybeExportDefined(scope, name);
  1598. }
  1599. } else if (bindingType & 4) {
  1600. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1601. scope = this.scopeStack[i];
  1602. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1603. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1604. this.maybeExportDefined(scope, name);
  1605. if (scope.flags & 387) break;
  1606. }
  1607. }
  1608. if (this.parser.inModule && scope.flags & 1) {
  1609. this.undefinedExports.delete(name);
  1610. }
  1611. }
  1612. maybeExportDefined(scope, name) {
  1613. if (this.parser.inModule && scope.flags & 1) {
  1614. this.undefinedExports.delete(name);
  1615. }
  1616. }
  1617. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1618. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1619. this.parser.raise(Errors.VarRedeclaration, loc, {
  1620. identifierName: name
  1621. });
  1622. }
  1623. }
  1624. isRedeclaredInScope(scope, name, bindingType) {
  1625. if (!(bindingType & 1)) return false;
  1626. if (bindingType & 8) {
  1627. return scope.names.has(name);
  1628. }
  1629. const type = scope.names.get(name);
  1630. if (bindingType & 16) {
  1631. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1632. }
  1633. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1634. }
  1635. checkLocalExport(id) {
  1636. const {
  1637. name
  1638. } = id;
  1639. const topLevelScope = this.scopeStack[0];
  1640. if (!topLevelScope.names.has(name)) {
  1641. this.undefinedExports.set(name, id.loc.start);
  1642. }
  1643. }
  1644. currentScope() {
  1645. return this.scopeStack[this.scopeStack.length - 1];
  1646. }
  1647. currentVarScopeFlags() {
  1648. for (let i = this.scopeStack.length - 1;; i--) {
  1649. const {
  1650. flags
  1651. } = this.scopeStack[i];
  1652. if (flags & 387) {
  1653. return flags;
  1654. }
  1655. }
  1656. }
  1657. currentThisScopeFlags() {
  1658. for (let i = this.scopeStack.length - 1;; i--) {
  1659. const {
  1660. flags
  1661. } = this.scopeStack[i];
  1662. if (flags & (387 | 64) && !(flags & 4)) {
  1663. return flags;
  1664. }
  1665. }
  1666. }
  1667. }
  1668. class FlowScope extends Scope {
  1669. constructor(...args) {
  1670. super(...args);
  1671. this.declareFunctions = new Set();
  1672. }
  1673. }
  1674. class FlowScopeHandler extends ScopeHandler {
  1675. createScope(flags) {
  1676. return new FlowScope(flags);
  1677. }
  1678. declareName(name, bindingType, loc) {
  1679. const scope = this.currentScope();
  1680. if (bindingType & 2048) {
  1681. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1682. this.maybeExportDefined(scope, name);
  1683. scope.declareFunctions.add(name);
  1684. return;
  1685. }
  1686. super.declareName(name, bindingType, loc);
  1687. }
  1688. isRedeclaredInScope(scope, name, bindingType) {
  1689. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1690. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1691. const type = scope.names.get(name);
  1692. return (type & 4) > 0 || (type & 2) > 0;
  1693. }
  1694. return false;
  1695. }
  1696. checkLocalExport(id) {
  1697. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1698. super.checkLocalExport(id);
  1699. }
  1700. }
  1701. }
  1702. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  1703. const FlowErrors = ParseErrorEnum`flow`({
  1704. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  1705. 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.",
  1706. AssignReservedType: ({
  1707. reservedType
  1708. }) => `Cannot overwrite reserved type ${reservedType}.`,
  1709. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  1710. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  1711. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  1712. EnumBooleanMemberNotInitialized: ({
  1713. memberName,
  1714. enumName
  1715. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  1716. EnumDuplicateMemberName: ({
  1717. memberName,
  1718. enumName
  1719. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  1720. EnumInconsistentMemberValues: ({
  1721. enumName
  1722. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  1723. EnumInvalidExplicitType: ({
  1724. invalidEnumType,
  1725. enumName
  1726. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1727. EnumInvalidExplicitTypeUnknownSupplied: ({
  1728. enumName
  1729. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1730. EnumInvalidMemberInitializerPrimaryType: ({
  1731. enumName,
  1732. memberName,
  1733. explicitType
  1734. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  1735. EnumInvalidMemberInitializerSymbolType: ({
  1736. enumName,
  1737. memberName
  1738. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  1739. EnumInvalidMemberInitializerUnknownType: ({
  1740. enumName,
  1741. memberName
  1742. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  1743. EnumInvalidMemberName: ({
  1744. enumName,
  1745. memberName,
  1746. suggestion
  1747. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  1748. EnumNumberMemberNotInitialized: ({
  1749. enumName,
  1750. memberName
  1751. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  1752. EnumStringMemberInconsistentlyInitialized: ({
  1753. enumName
  1754. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  1755. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  1756. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  1757. 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.",
  1758. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  1759. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  1760. InexactVariance: "Explicit inexact syntax cannot have variance.",
  1761. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  1762. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  1763. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  1764. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  1765. PatternIsOptional: Object.assign({
  1766. message: "A binding pattern parameter cannot be optional in an implementation signature."
  1767. }, {
  1768. reasonCode: "OptionalBindingPattern"
  1769. }),
  1770. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  1771. SpreadVariance: "Spread properties cannot have variance.",
  1772. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  1773. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  1774. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  1775. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  1776. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  1777. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  1778. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  1779. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  1780. UnexpectedReservedType: ({
  1781. reservedType
  1782. }) => `Unexpected reserved type ${reservedType}.`,
  1783. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  1784. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  1785. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  1786. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  1787. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  1788. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  1789. UnsupportedDeclareExportKind: ({
  1790. unsupportedExportKind,
  1791. suggestion
  1792. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  1793. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  1794. UnterminatedFlowComment: "Unterminated flow-comment."
  1795. });
  1796. function isEsModuleType(bodyElement) {
  1797. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  1798. }
  1799. function hasTypeImportKind(node) {
  1800. return node.importKind === "type" || node.importKind === "typeof";
  1801. }
  1802. const exportSuggestions = {
  1803. const: "declare export var",
  1804. let: "declare export var",
  1805. type: "export type",
  1806. interface: "export interface"
  1807. };
  1808. function partition(list, test) {
  1809. const list1 = [];
  1810. const list2 = [];
  1811. for (let i = 0; i < list.length; i++) {
  1812. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  1813. }
  1814. return [list1, list2];
  1815. }
  1816. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  1817. var flow = superClass => class FlowParserMixin extends superClass {
  1818. constructor(...args) {
  1819. super(...args);
  1820. this.flowPragma = undefined;
  1821. }
  1822. getScopeHandler() {
  1823. return FlowScopeHandler;
  1824. }
  1825. shouldParseTypes() {
  1826. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  1827. }
  1828. finishToken(type, val) {
  1829. if (type !== 134 && type !== 13 && type !== 28) {
  1830. if (this.flowPragma === undefined) {
  1831. this.flowPragma = null;
  1832. }
  1833. }
  1834. super.finishToken(type, val);
  1835. }
  1836. addComment(comment) {
  1837. if (this.flowPragma === undefined) {
  1838. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  1839. if (!matches) ;else if (matches[1] === "flow") {
  1840. this.flowPragma = "flow";
  1841. } else if (matches[1] === "noflow") {
  1842. this.flowPragma = "noflow";
  1843. } else {
  1844. throw new Error("Unexpected flow pragma");
  1845. }
  1846. }
  1847. super.addComment(comment);
  1848. }
  1849. flowParseTypeInitialiser(tok) {
  1850. const oldInType = this.state.inType;
  1851. this.state.inType = true;
  1852. this.expect(tok || 14);
  1853. const type = this.flowParseType();
  1854. this.state.inType = oldInType;
  1855. return type;
  1856. }
  1857. flowParsePredicate() {
  1858. const node = this.startNode();
  1859. const moduloLoc = this.state.startLoc;
  1860. this.next();
  1861. this.expectContextual(110);
  1862. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  1863. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  1864. }
  1865. if (this.eat(10)) {
  1866. node.value = super.parseExpression();
  1867. this.expect(11);
  1868. return this.finishNode(node, "DeclaredPredicate");
  1869. } else {
  1870. return this.finishNode(node, "InferredPredicate");
  1871. }
  1872. }
  1873. flowParseTypeAndPredicateInitialiser() {
  1874. const oldInType = this.state.inType;
  1875. this.state.inType = true;
  1876. this.expect(14);
  1877. let type = null;
  1878. let predicate = null;
  1879. if (this.match(54)) {
  1880. this.state.inType = oldInType;
  1881. predicate = this.flowParsePredicate();
  1882. } else {
  1883. type = this.flowParseType();
  1884. this.state.inType = oldInType;
  1885. if (this.match(54)) {
  1886. predicate = this.flowParsePredicate();
  1887. }
  1888. }
  1889. return [type, predicate];
  1890. }
  1891. flowParseDeclareClass(node) {
  1892. this.next();
  1893. this.flowParseInterfaceish(node, true);
  1894. return this.finishNode(node, "DeclareClass");
  1895. }
  1896. flowParseDeclareFunction(node) {
  1897. this.next();
  1898. const id = node.id = this.parseIdentifier();
  1899. const typeNode = this.startNode();
  1900. const typeContainer = this.startNode();
  1901. if (this.match(47)) {
  1902. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  1903. } else {
  1904. typeNode.typeParameters = null;
  1905. }
  1906. this.expect(10);
  1907. const tmp = this.flowParseFunctionTypeParams();
  1908. typeNode.params = tmp.params;
  1909. typeNode.rest = tmp.rest;
  1910. typeNode.this = tmp._this;
  1911. this.expect(11);
  1912. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  1913. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  1914. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  1915. this.resetEndLocation(id);
  1916. this.semicolon();
  1917. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  1918. return this.finishNode(node, "DeclareFunction");
  1919. }
  1920. flowParseDeclare(node, insideModule) {
  1921. if (this.match(80)) {
  1922. return this.flowParseDeclareClass(node);
  1923. } else if (this.match(68)) {
  1924. return this.flowParseDeclareFunction(node);
  1925. } else if (this.match(74)) {
  1926. return this.flowParseDeclareVariable(node);
  1927. } else if (this.eatContextual(127)) {
  1928. if (this.match(16)) {
  1929. return this.flowParseDeclareModuleExports(node);
  1930. } else {
  1931. if (insideModule) {
  1932. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  1933. }
  1934. return this.flowParseDeclareModule(node);
  1935. }
  1936. } else if (this.isContextual(130)) {
  1937. return this.flowParseDeclareTypeAlias(node);
  1938. } else if (this.isContextual(131)) {
  1939. return this.flowParseDeclareOpaqueType(node);
  1940. } else if (this.isContextual(129)) {
  1941. return this.flowParseDeclareInterface(node);
  1942. } else if (this.match(82)) {
  1943. return this.flowParseDeclareExportDeclaration(node, insideModule);
  1944. } else {
  1945. this.unexpected();
  1946. }
  1947. }
  1948. flowParseDeclareVariable(node) {
  1949. this.next();
  1950. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  1951. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  1952. this.semicolon();
  1953. return this.finishNode(node, "DeclareVariable");
  1954. }
  1955. flowParseDeclareModule(node) {
  1956. this.scope.enter(0);
  1957. if (this.match(134)) {
  1958. node.id = super.parseExprAtom();
  1959. } else {
  1960. node.id = this.parseIdentifier();
  1961. }
  1962. const bodyNode = node.body = this.startNode();
  1963. const body = bodyNode.body = [];
  1964. this.expect(5);
  1965. while (!this.match(8)) {
  1966. let bodyNode = this.startNode();
  1967. if (this.match(83)) {
  1968. this.next();
  1969. if (!this.isContextual(130) && !this.match(87)) {
  1970. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  1971. }
  1972. super.parseImport(bodyNode);
  1973. } else {
  1974. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  1975. bodyNode = this.flowParseDeclare(bodyNode, true);
  1976. }
  1977. body.push(bodyNode);
  1978. }
  1979. this.scope.exit();
  1980. this.expect(8);
  1981. this.finishNode(bodyNode, "BlockStatement");
  1982. let kind = null;
  1983. let hasModuleExport = false;
  1984. body.forEach(bodyElement => {
  1985. if (isEsModuleType(bodyElement)) {
  1986. if (kind === "CommonJS") {
  1987. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  1988. }
  1989. kind = "ES";
  1990. } else if (bodyElement.type === "DeclareModuleExports") {
  1991. if (hasModuleExport) {
  1992. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  1993. }
  1994. if (kind === "ES") {
  1995. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  1996. }
  1997. kind = "CommonJS";
  1998. hasModuleExport = true;
  1999. }
  2000. });
  2001. node.kind = kind || "CommonJS";
  2002. return this.finishNode(node, "DeclareModule");
  2003. }
  2004. flowParseDeclareExportDeclaration(node, insideModule) {
  2005. this.expect(82);
  2006. if (this.eat(65)) {
  2007. if (this.match(68) || this.match(80)) {
  2008. node.declaration = this.flowParseDeclare(this.startNode());
  2009. } else {
  2010. node.declaration = this.flowParseType();
  2011. this.semicolon();
  2012. }
  2013. node.default = true;
  2014. return this.finishNode(node, "DeclareExportDeclaration");
  2015. } else {
  2016. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  2017. const label = this.state.value;
  2018. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  2019. unsupportedExportKind: label,
  2020. suggestion: exportSuggestions[label]
  2021. });
  2022. }
  2023. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  2024. node.declaration = this.flowParseDeclare(this.startNode());
  2025. node.default = false;
  2026. return this.finishNode(node, "DeclareExportDeclaration");
  2027. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  2028. node = this.parseExport(node, null);
  2029. if (node.type === "ExportNamedDeclaration") {
  2030. node.default = false;
  2031. delete node.exportKind;
  2032. return this.castNodeTo(node, "DeclareExportDeclaration");
  2033. } else {
  2034. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  2035. }
  2036. }
  2037. }
  2038. this.unexpected();
  2039. }
  2040. flowParseDeclareModuleExports(node) {
  2041. this.next();
  2042. this.expectContextual(111);
  2043. node.typeAnnotation = this.flowParseTypeAnnotation();
  2044. this.semicolon();
  2045. return this.finishNode(node, "DeclareModuleExports");
  2046. }
  2047. flowParseDeclareTypeAlias(node) {
  2048. this.next();
  2049. const finished = this.flowParseTypeAlias(node);
  2050. this.castNodeTo(finished, "DeclareTypeAlias");
  2051. return finished;
  2052. }
  2053. flowParseDeclareOpaqueType(node) {
  2054. this.next();
  2055. const finished = this.flowParseOpaqueType(node, true);
  2056. this.castNodeTo(finished, "DeclareOpaqueType");
  2057. return finished;
  2058. }
  2059. flowParseDeclareInterface(node) {
  2060. this.next();
  2061. this.flowParseInterfaceish(node, false);
  2062. return this.finishNode(node, "DeclareInterface");
  2063. }
  2064. flowParseInterfaceish(node, isClass) {
  2065. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  2066. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  2067. if (this.match(47)) {
  2068. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2069. } else {
  2070. node.typeParameters = null;
  2071. }
  2072. node.extends = [];
  2073. if (this.eat(81)) {
  2074. do {
  2075. node.extends.push(this.flowParseInterfaceExtends());
  2076. } while (!isClass && this.eat(12));
  2077. }
  2078. if (isClass) {
  2079. node.implements = [];
  2080. node.mixins = [];
  2081. if (this.eatContextual(117)) {
  2082. do {
  2083. node.mixins.push(this.flowParseInterfaceExtends());
  2084. } while (this.eat(12));
  2085. }
  2086. if (this.eatContextual(113)) {
  2087. do {
  2088. node.implements.push(this.flowParseInterfaceExtends());
  2089. } while (this.eat(12));
  2090. }
  2091. }
  2092. node.body = this.flowParseObjectType({
  2093. allowStatic: isClass,
  2094. allowExact: false,
  2095. allowSpread: false,
  2096. allowProto: isClass,
  2097. allowInexact: false
  2098. });
  2099. }
  2100. flowParseInterfaceExtends() {
  2101. const node = this.startNode();
  2102. node.id = this.flowParseQualifiedTypeIdentifier();
  2103. if (this.match(47)) {
  2104. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2105. } else {
  2106. node.typeParameters = null;
  2107. }
  2108. return this.finishNode(node, "InterfaceExtends");
  2109. }
  2110. flowParseInterface(node) {
  2111. this.flowParseInterfaceish(node, false);
  2112. return this.finishNode(node, "InterfaceDeclaration");
  2113. }
  2114. checkNotUnderscore(word) {
  2115. if (word === "_") {
  2116. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  2117. }
  2118. }
  2119. checkReservedType(word, startLoc, declaration) {
  2120. if (!reservedTypes.has(word)) return;
  2121. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  2122. reservedType: word
  2123. });
  2124. }
  2125. flowParseRestrictedIdentifier(liberal, declaration) {
  2126. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  2127. return this.parseIdentifier(liberal);
  2128. }
  2129. flowParseTypeAlias(node) {
  2130. node.id = this.flowParseRestrictedIdentifier(false, true);
  2131. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2132. if (this.match(47)) {
  2133. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2134. } else {
  2135. node.typeParameters = null;
  2136. }
  2137. node.right = this.flowParseTypeInitialiser(29);
  2138. this.semicolon();
  2139. return this.finishNode(node, "TypeAlias");
  2140. }
  2141. flowParseOpaqueType(node, declare) {
  2142. this.expectContextual(130);
  2143. node.id = this.flowParseRestrictedIdentifier(true, true);
  2144. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2145. if (this.match(47)) {
  2146. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2147. } else {
  2148. node.typeParameters = null;
  2149. }
  2150. node.supertype = null;
  2151. if (this.match(14)) {
  2152. node.supertype = this.flowParseTypeInitialiser(14);
  2153. }
  2154. node.impltype = null;
  2155. if (!declare) {
  2156. node.impltype = this.flowParseTypeInitialiser(29);
  2157. }
  2158. this.semicolon();
  2159. return this.finishNode(node, "OpaqueType");
  2160. }
  2161. flowParseTypeParameter(requireDefault = false) {
  2162. const nodeStartLoc = this.state.startLoc;
  2163. const node = this.startNode();
  2164. const variance = this.flowParseVariance();
  2165. const ident = this.flowParseTypeAnnotatableIdentifier();
  2166. node.name = ident.name;
  2167. node.variance = variance;
  2168. node.bound = ident.typeAnnotation;
  2169. if (this.match(29)) {
  2170. this.eat(29);
  2171. node.default = this.flowParseType();
  2172. } else {
  2173. if (requireDefault) {
  2174. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  2175. }
  2176. }
  2177. return this.finishNode(node, "TypeParameter");
  2178. }
  2179. flowParseTypeParameterDeclaration() {
  2180. const oldInType = this.state.inType;
  2181. const node = this.startNode();
  2182. node.params = [];
  2183. this.state.inType = true;
  2184. if (this.match(47) || this.match(143)) {
  2185. this.next();
  2186. } else {
  2187. this.unexpected();
  2188. }
  2189. let defaultRequired = false;
  2190. do {
  2191. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  2192. node.params.push(typeParameter);
  2193. if (typeParameter.default) {
  2194. defaultRequired = true;
  2195. }
  2196. if (!this.match(48)) {
  2197. this.expect(12);
  2198. }
  2199. } while (!this.match(48));
  2200. this.expect(48);
  2201. this.state.inType = oldInType;
  2202. return this.finishNode(node, "TypeParameterDeclaration");
  2203. }
  2204. flowInTopLevelContext(cb) {
  2205. if (this.curContext() !== types.brace) {
  2206. const oldContext = this.state.context;
  2207. this.state.context = [oldContext[0]];
  2208. try {
  2209. return cb();
  2210. } finally {
  2211. this.state.context = oldContext;
  2212. }
  2213. } else {
  2214. return cb();
  2215. }
  2216. }
  2217. flowParseTypeParameterInstantiationInExpression() {
  2218. if (this.reScan_lt() !== 47) return;
  2219. return this.flowParseTypeParameterInstantiation();
  2220. }
  2221. flowParseTypeParameterInstantiation() {
  2222. const node = this.startNode();
  2223. const oldInType = this.state.inType;
  2224. this.state.inType = true;
  2225. node.params = [];
  2226. this.flowInTopLevelContext(() => {
  2227. this.expect(47);
  2228. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2229. this.state.noAnonFunctionType = false;
  2230. while (!this.match(48)) {
  2231. node.params.push(this.flowParseType());
  2232. if (!this.match(48)) {
  2233. this.expect(12);
  2234. }
  2235. }
  2236. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2237. });
  2238. this.state.inType = oldInType;
  2239. if (!this.state.inType && this.curContext() === types.brace) {
  2240. this.reScan_lt_gt();
  2241. }
  2242. this.expect(48);
  2243. return this.finishNode(node, "TypeParameterInstantiation");
  2244. }
  2245. flowParseTypeParameterInstantiationCallOrNew() {
  2246. if (this.reScan_lt() !== 47) return;
  2247. const node = this.startNode();
  2248. const oldInType = this.state.inType;
  2249. node.params = [];
  2250. this.state.inType = true;
  2251. this.expect(47);
  2252. while (!this.match(48)) {
  2253. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  2254. if (!this.match(48)) {
  2255. this.expect(12);
  2256. }
  2257. }
  2258. this.expect(48);
  2259. this.state.inType = oldInType;
  2260. return this.finishNode(node, "TypeParameterInstantiation");
  2261. }
  2262. flowParseInterfaceType() {
  2263. const node = this.startNode();
  2264. this.expectContextual(129);
  2265. node.extends = [];
  2266. if (this.eat(81)) {
  2267. do {
  2268. node.extends.push(this.flowParseInterfaceExtends());
  2269. } while (this.eat(12));
  2270. }
  2271. node.body = this.flowParseObjectType({
  2272. allowStatic: false,
  2273. allowExact: false,
  2274. allowSpread: false,
  2275. allowProto: false,
  2276. allowInexact: false
  2277. });
  2278. return this.finishNode(node, "InterfaceTypeAnnotation");
  2279. }
  2280. flowParseObjectPropertyKey() {
  2281. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  2282. }
  2283. flowParseObjectTypeIndexer(node, isStatic, variance) {
  2284. node.static = isStatic;
  2285. if (this.lookahead().type === 14) {
  2286. node.id = this.flowParseObjectPropertyKey();
  2287. node.key = this.flowParseTypeInitialiser();
  2288. } else {
  2289. node.id = null;
  2290. node.key = this.flowParseType();
  2291. }
  2292. this.expect(3);
  2293. node.value = this.flowParseTypeInitialiser();
  2294. node.variance = variance;
  2295. return this.finishNode(node, "ObjectTypeIndexer");
  2296. }
  2297. flowParseObjectTypeInternalSlot(node, isStatic) {
  2298. node.static = isStatic;
  2299. node.id = this.flowParseObjectPropertyKey();
  2300. this.expect(3);
  2301. this.expect(3);
  2302. if (this.match(47) || this.match(10)) {
  2303. node.method = true;
  2304. node.optional = false;
  2305. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2306. } else {
  2307. node.method = false;
  2308. if (this.eat(17)) {
  2309. node.optional = true;
  2310. }
  2311. node.value = this.flowParseTypeInitialiser();
  2312. }
  2313. return this.finishNode(node, "ObjectTypeInternalSlot");
  2314. }
  2315. flowParseObjectTypeMethodish(node) {
  2316. node.params = [];
  2317. node.rest = null;
  2318. node.typeParameters = null;
  2319. node.this = null;
  2320. if (this.match(47)) {
  2321. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2322. }
  2323. this.expect(10);
  2324. if (this.match(78)) {
  2325. node.this = this.flowParseFunctionTypeParam(true);
  2326. node.this.name = null;
  2327. if (!this.match(11)) {
  2328. this.expect(12);
  2329. }
  2330. }
  2331. while (!this.match(11) && !this.match(21)) {
  2332. node.params.push(this.flowParseFunctionTypeParam(false));
  2333. if (!this.match(11)) {
  2334. this.expect(12);
  2335. }
  2336. }
  2337. if (this.eat(21)) {
  2338. node.rest = this.flowParseFunctionTypeParam(false);
  2339. }
  2340. this.expect(11);
  2341. node.returnType = this.flowParseTypeInitialiser();
  2342. return this.finishNode(node, "FunctionTypeAnnotation");
  2343. }
  2344. flowParseObjectTypeCallProperty(node, isStatic) {
  2345. const valueNode = this.startNode();
  2346. node.static = isStatic;
  2347. node.value = this.flowParseObjectTypeMethodish(valueNode);
  2348. return this.finishNode(node, "ObjectTypeCallProperty");
  2349. }
  2350. flowParseObjectType({
  2351. allowStatic,
  2352. allowExact,
  2353. allowSpread,
  2354. allowProto,
  2355. allowInexact
  2356. }) {
  2357. const oldInType = this.state.inType;
  2358. this.state.inType = true;
  2359. const nodeStart = this.startNode();
  2360. nodeStart.callProperties = [];
  2361. nodeStart.properties = [];
  2362. nodeStart.indexers = [];
  2363. nodeStart.internalSlots = [];
  2364. let endDelim;
  2365. let exact;
  2366. let inexact = false;
  2367. if (allowExact && this.match(6)) {
  2368. this.expect(6);
  2369. endDelim = 9;
  2370. exact = true;
  2371. } else {
  2372. this.expect(5);
  2373. endDelim = 8;
  2374. exact = false;
  2375. }
  2376. nodeStart.exact = exact;
  2377. while (!this.match(endDelim)) {
  2378. let isStatic = false;
  2379. let protoStartLoc = null;
  2380. let inexactStartLoc = null;
  2381. const node = this.startNode();
  2382. if (allowProto && this.isContextual(118)) {
  2383. const lookahead = this.lookahead();
  2384. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2385. this.next();
  2386. protoStartLoc = this.state.startLoc;
  2387. allowStatic = false;
  2388. }
  2389. }
  2390. if (allowStatic && this.isContextual(106)) {
  2391. const lookahead = this.lookahead();
  2392. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2393. this.next();
  2394. isStatic = true;
  2395. }
  2396. }
  2397. const variance = this.flowParseVariance();
  2398. if (this.eat(0)) {
  2399. if (protoStartLoc != null) {
  2400. this.unexpected(protoStartLoc);
  2401. }
  2402. if (this.eat(0)) {
  2403. if (variance) {
  2404. this.unexpected(variance.loc.start);
  2405. }
  2406. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  2407. } else {
  2408. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  2409. }
  2410. } else if (this.match(10) || this.match(47)) {
  2411. if (protoStartLoc != null) {
  2412. this.unexpected(protoStartLoc);
  2413. }
  2414. if (variance) {
  2415. this.unexpected(variance.loc.start);
  2416. }
  2417. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  2418. } else {
  2419. let kind = "init";
  2420. if (this.isContextual(99) || this.isContextual(104)) {
  2421. const lookahead = this.lookahead();
  2422. if (tokenIsLiteralPropertyName(lookahead.type)) {
  2423. kind = this.state.value;
  2424. this.next();
  2425. }
  2426. }
  2427. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  2428. if (propOrInexact === null) {
  2429. inexact = true;
  2430. inexactStartLoc = this.state.lastTokStartLoc;
  2431. } else {
  2432. nodeStart.properties.push(propOrInexact);
  2433. }
  2434. }
  2435. this.flowObjectTypeSemicolon();
  2436. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  2437. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  2438. }
  2439. }
  2440. this.expect(endDelim);
  2441. if (allowSpread) {
  2442. nodeStart.inexact = inexact;
  2443. }
  2444. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  2445. this.state.inType = oldInType;
  2446. return out;
  2447. }
  2448. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  2449. if (this.eat(21)) {
  2450. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  2451. if (isInexactToken) {
  2452. if (!allowSpread) {
  2453. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  2454. } else if (!allowInexact) {
  2455. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  2456. }
  2457. if (variance) {
  2458. this.raise(FlowErrors.InexactVariance, variance);
  2459. }
  2460. return null;
  2461. }
  2462. if (!allowSpread) {
  2463. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  2464. }
  2465. if (protoStartLoc != null) {
  2466. this.unexpected(protoStartLoc);
  2467. }
  2468. if (variance) {
  2469. this.raise(FlowErrors.SpreadVariance, variance);
  2470. }
  2471. node.argument = this.flowParseType();
  2472. return this.finishNode(node, "ObjectTypeSpreadProperty");
  2473. } else {
  2474. node.key = this.flowParseObjectPropertyKey();
  2475. node.static = isStatic;
  2476. node.proto = protoStartLoc != null;
  2477. node.kind = kind;
  2478. let optional = false;
  2479. if (this.match(47) || this.match(10)) {
  2480. node.method = true;
  2481. if (protoStartLoc != null) {
  2482. this.unexpected(protoStartLoc);
  2483. }
  2484. if (variance) {
  2485. this.unexpected(variance.loc.start);
  2486. }
  2487. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2488. if (kind === "get" || kind === "set") {
  2489. this.flowCheckGetterSetterParams(node);
  2490. }
  2491. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  2492. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  2493. }
  2494. } else {
  2495. if (kind !== "init") this.unexpected();
  2496. node.method = false;
  2497. if (this.eat(17)) {
  2498. optional = true;
  2499. }
  2500. node.value = this.flowParseTypeInitialiser();
  2501. node.variance = variance;
  2502. }
  2503. node.optional = optional;
  2504. return this.finishNode(node, "ObjectTypeProperty");
  2505. }
  2506. }
  2507. flowCheckGetterSetterParams(property) {
  2508. const paramCount = property.kind === "get" ? 0 : 1;
  2509. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  2510. if (property.value.this) {
  2511. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  2512. }
  2513. if (length !== paramCount) {
  2514. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  2515. }
  2516. if (property.kind === "set" && property.value.rest) {
  2517. this.raise(Errors.BadSetterRestParameter, property);
  2518. }
  2519. }
  2520. flowObjectTypeSemicolon() {
  2521. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  2522. this.unexpected();
  2523. }
  2524. }
  2525. flowParseQualifiedTypeIdentifier(startLoc, id) {
  2526. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  2527. let node = id || this.flowParseRestrictedIdentifier(true);
  2528. while (this.eat(16)) {
  2529. const node2 = this.startNodeAt(startLoc);
  2530. node2.qualification = node;
  2531. node2.id = this.flowParseRestrictedIdentifier(true);
  2532. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  2533. }
  2534. return node;
  2535. }
  2536. flowParseGenericType(startLoc, id) {
  2537. const node = this.startNodeAt(startLoc);
  2538. node.typeParameters = null;
  2539. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  2540. if (this.match(47)) {
  2541. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2542. }
  2543. return this.finishNode(node, "GenericTypeAnnotation");
  2544. }
  2545. flowParseTypeofType() {
  2546. const node = this.startNode();
  2547. this.expect(87);
  2548. node.argument = this.flowParsePrimaryType();
  2549. return this.finishNode(node, "TypeofTypeAnnotation");
  2550. }
  2551. flowParseTupleType() {
  2552. const node = this.startNode();
  2553. node.types = [];
  2554. this.expect(0);
  2555. while (this.state.pos < this.length && !this.match(3)) {
  2556. node.types.push(this.flowParseType());
  2557. if (this.match(3)) break;
  2558. this.expect(12);
  2559. }
  2560. this.expect(3);
  2561. return this.finishNode(node, "TupleTypeAnnotation");
  2562. }
  2563. flowParseFunctionTypeParam(first) {
  2564. let name = null;
  2565. let optional = false;
  2566. let typeAnnotation = null;
  2567. const node = this.startNode();
  2568. const lh = this.lookahead();
  2569. const isThis = this.state.type === 78;
  2570. if (lh.type === 14 || lh.type === 17) {
  2571. if (isThis && !first) {
  2572. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  2573. }
  2574. name = this.parseIdentifier(isThis);
  2575. if (this.eat(17)) {
  2576. optional = true;
  2577. if (isThis) {
  2578. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  2579. }
  2580. }
  2581. typeAnnotation = this.flowParseTypeInitialiser();
  2582. } else {
  2583. typeAnnotation = this.flowParseType();
  2584. }
  2585. node.name = name;
  2586. node.optional = optional;
  2587. node.typeAnnotation = typeAnnotation;
  2588. return this.finishNode(node, "FunctionTypeParam");
  2589. }
  2590. reinterpretTypeAsFunctionTypeParam(type) {
  2591. const node = this.startNodeAt(type.loc.start);
  2592. node.name = null;
  2593. node.optional = false;
  2594. node.typeAnnotation = type;
  2595. return this.finishNode(node, "FunctionTypeParam");
  2596. }
  2597. flowParseFunctionTypeParams(params = []) {
  2598. let rest = null;
  2599. let _this = null;
  2600. if (this.match(78)) {
  2601. _this = this.flowParseFunctionTypeParam(true);
  2602. _this.name = null;
  2603. if (!this.match(11)) {
  2604. this.expect(12);
  2605. }
  2606. }
  2607. while (!this.match(11) && !this.match(21)) {
  2608. params.push(this.flowParseFunctionTypeParam(false));
  2609. if (!this.match(11)) {
  2610. this.expect(12);
  2611. }
  2612. }
  2613. if (this.eat(21)) {
  2614. rest = this.flowParseFunctionTypeParam(false);
  2615. }
  2616. return {
  2617. params,
  2618. rest,
  2619. _this
  2620. };
  2621. }
  2622. flowIdentToTypeAnnotation(startLoc, node, id) {
  2623. switch (id.name) {
  2624. case "any":
  2625. return this.finishNode(node, "AnyTypeAnnotation");
  2626. case "bool":
  2627. case "boolean":
  2628. return this.finishNode(node, "BooleanTypeAnnotation");
  2629. case "mixed":
  2630. return this.finishNode(node, "MixedTypeAnnotation");
  2631. case "empty":
  2632. return this.finishNode(node, "EmptyTypeAnnotation");
  2633. case "number":
  2634. return this.finishNode(node, "NumberTypeAnnotation");
  2635. case "string":
  2636. return this.finishNode(node, "StringTypeAnnotation");
  2637. case "symbol":
  2638. return this.finishNode(node, "SymbolTypeAnnotation");
  2639. default:
  2640. this.checkNotUnderscore(id.name);
  2641. return this.flowParseGenericType(startLoc, id);
  2642. }
  2643. }
  2644. flowParsePrimaryType() {
  2645. const startLoc = this.state.startLoc;
  2646. const node = this.startNode();
  2647. let tmp;
  2648. let type;
  2649. let isGroupedType = false;
  2650. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2651. switch (this.state.type) {
  2652. case 5:
  2653. return this.flowParseObjectType({
  2654. allowStatic: false,
  2655. allowExact: false,
  2656. allowSpread: true,
  2657. allowProto: false,
  2658. allowInexact: true
  2659. });
  2660. case 6:
  2661. return this.flowParseObjectType({
  2662. allowStatic: false,
  2663. allowExact: true,
  2664. allowSpread: true,
  2665. allowProto: false,
  2666. allowInexact: false
  2667. });
  2668. case 0:
  2669. this.state.noAnonFunctionType = false;
  2670. type = this.flowParseTupleType();
  2671. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2672. return type;
  2673. case 47:
  2674. {
  2675. const node = this.startNode();
  2676. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2677. this.expect(10);
  2678. tmp = this.flowParseFunctionTypeParams();
  2679. node.params = tmp.params;
  2680. node.rest = tmp.rest;
  2681. node.this = tmp._this;
  2682. this.expect(11);
  2683. this.expect(19);
  2684. node.returnType = this.flowParseType();
  2685. return this.finishNode(node, "FunctionTypeAnnotation");
  2686. }
  2687. case 10:
  2688. {
  2689. const node = this.startNode();
  2690. this.next();
  2691. if (!this.match(11) && !this.match(21)) {
  2692. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  2693. const token = this.lookahead().type;
  2694. isGroupedType = token !== 17 && token !== 14;
  2695. } else {
  2696. isGroupedType = true;
  2697. }
  2698. }
  2699. if (isGroupedType) {
  2700. this.state.noAnonFunctionType = false;
  2701. type = this.flowParseType();
  2702. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2703. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  2704. this.expect(11);
  2705. return type;
  2706. } else {
  2707. this.eat(12);
  2708. }
  2709. }
  2710. if (type) {
  2711. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  2712. } else {
  2713. tmp = this.flowParseFunctionTypeParams();
  2714. }
  2715. node.params = tmp.params;
  2716. node.rest = tmp.rest;
  2717. node.this = tmp._this;
  2718. this.expect(11);
  2719. this.expect(19);
  2720. node.returnType = this.flowParseType();
  2721. node.typeParameters = null;
  2722. return this.finishNode(node, "FunctionTypeAnnotation");
  2723. }
  2724. case 134:
  2725. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  2726. case 85:
  2727. case 86:
  2728. node.value = this.match(85);
  2729. this.next();
  2730. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  2731. case 53:
  2732. if (this.state.value === "-") {
  2733. this.next();
  2734. if (this.match(135)) {
  2735. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  2736. }
  2737. if (this.match(136)) {
  2738. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  2739. }
  2740. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  2741. }
  2742. this.unexpected();
  2743. return;
  2744. case 135:
  2745. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  2746. case 136:
  2747. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  2748. case 88:
  2749. this.next();
  2750. return this.finishNode(node, "VoidTypeAnnotation");
  2751. case 84:
  2752. this.next();
  2753. return this.finishNode(node, "NullLiteralTypeAnnotation");
  2754. case 78:
  2755. this.next();
  2756. return this.finishNode(node, "ThisTypeAnnotation");
  2757. case 55:
  2758. this.next();
  2759. return this.finishNode(node, "ExistsTypeAnnotation");
  2760. case 87:
  2761. return this.flowParseTypeofType();
  2762. default:
  2763. if (tokenIsKeyword(this.state.type)) {
  2764. const label = tokenLabelName(this.state.type);
  2765. this.next();
  2766. return super.createIdentifier(node, label);
  2767. } else if (tokenIsIdentifier(this.state.type)) {
  2768. if (this.isContextual(129)) {
  2769. return this.flowParseInterfaceType();
  2770. }
  2771. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  2772. }
  2773. }
  2774. this.unexpected();
  2775. }
  2776. flowParsePostfixType() {
  2777. const startLoc = this.state.startLoc;
  2778. let type = this.flowParsePrimaryType();
  2779. let seenOptionalIndexedAccess = false;
  2780. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  2781. const node = this.startNodeAt(startLoc);
  2782. const optional = this.eat(18);
  2783. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  2784. this.expect(0);
  2785. if (!optional && this.match(3)) {
  2786. node.elementType = type;
  2787. this.next();
  2788. type = this.finishNode(node, "ArrayTypeAnnotation");
  2789. } else {
  2790. node.objectType = type;
  2791. node.indexType = this.flowParseType();
  2792. this.expect(3);
  2793. if (seenOptionalIndexedAccess) {
  2794. node.optional = optional;
  2795. type = this.finishNode(node, "OptionalIndexedAccessType");
  2796. } else {
  2797. type = this.finishNode(node, "IndexedAccessType");
  2798. }
  2799. }
  2800. }
  2801. return type;
  2802. }
  2803. flowParsePrefixType() {
  2804. const node = this.startNode();
  2805. if (this.eat(17)) {
  2806. node.typeAnnotation = this.flowParsePrefixType();
  2807. return this.finishNode(node, "NullableTypeAnnotation");
  2808. } else {
  2809. return this.flowParsePostfixType();
  2810. }
  2811. }
  2812. flowParseAnonFunctionWithoutParens() {
  2813. const param = this.flowParsePrefixType();
  2814. if (!this.state.noAnonFunctionType && this.eat(19)) {
  2815. const node = this.startNodeAt(param.loc.start);
  2816. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  2817. node.rest = null;
  2818. node.this = null;
  2819. node.returnType = this.flowParseType();
  2820. node.typeParameters = null;
  2821. return this.finishNode(node, "FunctionTypeAnnotation");
  2822. }
  2823. return param;
  2824. }
  2825. flowParseIntersectionType() {
  2826. const node = this.startNode();
  2827. this.eat(45);
  2828. const type = this.flowParseAnonFunctionWithoutParens();
  2829. node.types = [type];
  2830. while (this.eat(45)) {
  2831. node.types.push(this.flowParseAnonFunctionWithoutParens());
  2832. }
  2833. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  2834. }
  2835. flowParseUnionType() {
  2836. const node = this.startNode();
  2837. this.eat(43);
  2838. const type = this.flowParseIntersectionType();
  2839. node.types = [type];
  2840. while (this.eat(43)) {
  2841. node.types.push(this.flowParseIntersectionType());
  2842. }
  2843. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  2844. }
  2845. flowParseType() {
  2846. const oldInType = this.state.inType;
  2847. this.state.inType = true;
  2848. const type = this.flowParseUnionType();
  2849. this.state.inType = oldInType;
  2850. return type;
  2851. }
  2852. flowParseTypeOrImplicitInstantiation() {
  2853. if (this.state.type === 132 && this.state.value === "_") {
  2854. const startLoc = this.state.startLoc;
  2855. const node = this.parseIdentifier();
  2856. return this.flowParseGenericType(startLoc, node);
  2857. } else {
  2858. return this.flowParseType();
  2859. }
  2860. }
  2861. flowParseTypeAnnotation() {
  2862. const node = this.startNode();
  2863. node.typeAnnotation = this.flowParseTypeInitialiser();
  2864. return this.finishNode(node, "TypeAnnotation");
  2865. }
  2866. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  2867. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  2868. if (this.match(14)) {
  2869. ident.typeAnnotation = this.flowParseTypeAnnotation();
  2870. this.resetEndLocation(ident);
  2871. }
  2872. return ident;
  2873. }
  2874. typeCastToParameter(node) {
  2875. node.expression.typeAnnotation = node.typeAnnotation;
  2876. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  2877. return node.expression;
  2878. }
  2879. flowParseVariance() {
  2880. let variance = null;
  2881. if (this.match(53)) {
  2882. variance = this.startNode();
  2883. if (this.state.value === "+") {
  2884. variance.kind = "plus";
  2885. } else {
  2886. variance.kind = "minus";
  2887. }
  2888. this.next();
  2889. return this.finishNode(variance, "Variance");
  2890. }
  2891. return variance;
  2892. }
  2893. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  2894. if (allowExpressionBody) {
  2895. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  2896. return;
  2897. }
  2898. super.parseFunctionBody(node, false, isMethod);
  2899. }
  2900. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  2901. if (this.match(14)) {
  2902. const typeNode = this.startNode();
  2903. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  2904. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  2905. }
  2906. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  2907. }
  2908. parseStatementLike(flags) {
  2909. if (this.state.strict && this.isContextual(129)) {
  2910. const lookahead = this.lookahead();
  2911. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  2912. const node = this.startNode();
  2913. this.next();
  2914. return this.flowParseInterface(node);
  2915. }
  2916. } else if (this.isContextual(126)) {
  2917. const node = this.startNode();
  2918. this.next();
  2919. return this.flowParseEnumDeclaration(node);
  2920. }
  2921. const stmt = super.parseStatementLike(flags);
  2922. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  2923. this.flowPragma = null;
  2924. }
  2925. return stmt;
  2926. }
  2927. parseExpressionStatement(node, expr, decorators) {
  2928. if (expr.type === "Identifier") {
  2929. if (expr.name === "declare") {
  2930. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  2931. return this.flowParseDeclare(node);
  2932. }
  2933. } else if (tokenIsIdentifier(this.state.type)) {
  2934. if (expr.name === "interface") {
  2935. return this.flowParseInterface(node);
  2936. } else if (expr.name === "type") {
  2937. return this.flowParseTypeAlias(node);
  2938. } else if (expr.name === "opaque") {
  2939. return this.flowParseOpaqueType(node, false);
  2940. }
  2941. }
  2942. }
  2943. return super.parseExpressionStatement(node, expr, decorators);
  2944. }
  2945. shouldParseExportDeclaration() {
  2946. const {
  2947. type
  2948. } = this.state;
  2949. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2950. return !this.state.containsEsc;
  2951. }
  2952. return super.shouldParseExportDeclaration();
  2953. }
  2954. isExportDefaultSpecifier() {
  2955. const {
  2956. type
  2957. } = this.state;
  2958. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2959. return this.state.containsEsc;
  2960. }
  2961. return super.isExportDefaultSpecifier();
  2962. }
  2963. parseExportDefaultExpression() {
  2964. if (this.isContextual(126)) {
  2965. const node = this.startNode();
  2966. this.next();
  2967. return this.flowParseEnumDeclaration(node);
  2968. }
  2969. return super.parseExportDefaultExpression();
  2970. }
  2971. parseConditional(expr, startLoc, refExpressionErrors) {
  2972. if (!this.match(17)) return expr;
  2973. if (this.state.maybeInArrowParameters) {
  2974. const nextCh = this.lookaheadCharCode();
  2975. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  2976. this.setOptionalParametersError(refExpressionErrors);
  2977. return expr;
  2978. }
  2979. }
  2980. this.expect(17);
  2981. const state = this.state.clone();
  2982. const originalNoArrowAt = this.state.noArrowAt;
  2983. const node = this.startNodeAt(startLoc);
  2984. let {
  2985. consequent,
  2986. failed
  2987. } = this.tryParseConditionalConsequent();
  2988. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  2989. if (failed || invalid.length > 0) {
  2990. const noArrowAt = [...originalNoArrowAt];
  2991. if (invalid.length > 0) {
  2992. this.state = state;
  2993. this.state.noArrowAt = noArrowAt;
  2994. for (let i = 0; i < invalid.length; i++) {
  2995. noArrowAt.push(invalid[i].start);
  2996. }
  2997. ({
  2998. consequent,
  2999. failed
  3000. } = this.tryParseConditionalConsequent());
  3001. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  3002. }
  3003. if (failed && valid.length > 1) {
  3004. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  3005. }
  3006. if (failed && valid.length === 1) {
  3007. this.state = state;
  3008. noArrowAt.push(valid[0].start);
  3009. this.state.noArrowAt = noArrowAt;
  3010. ({
  3011. consequent,
  3012. failed
  3013. } = this.tryParseConditionalConsequent());
  3014. }
  3015. }
  3016. this.getArrowLikeExpressions(consequent, true);
  3017. this.state.noArrowAt = originalNoArrowAt;
  3018. this.expect(14);
  3019. node.test = expr;
  3020. node.consequent = consequent;
  3021. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  3022. return this.finishNode(node, "ConditionalExpression");
  3023. }
  3024. tryParseConditionalConsequent() {
  3025. this.state.noArrowParamsConversionAt.push(this.state.start);
  3026. const consequent = this.parseMaybeAssignAllowIn();
  3027. const failed = !this.match(14);
  3028. this.state.noArrowParamsConversionAt.pop();
  3029. return {
  3030. consequent,
  3031. failed
  3032. };
  3033. }
  3034. getArrowLikeExpressions(node, disallowInvalid) {
  3035. const stack = [node];
  3036. const arrows = [];
  3037. while (stack.length !== 0) {
  3038. const node = stack.pop();
  3039. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  3040. if (node.typeParameters || !node.returnType) {
  3041. this.finishArrowValidation(node);
  3042. } else {
  3043. arrows.push(node);
  3044. }
  3045. stack.push(node.body);
  3046. } else if (node.type === "ConditionalExpression") {
  3047. stack.push(node.consequent);
  3048. stack.push(node.alternate);
  3049. }
  3050. }
  3051. if (disallowInvalid) {
  3052. arrows.forEach(node => this.finishArrowValidation(node));
  3053. return [arrows, []];
  3054. }
  3055. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  3056. }
  3057. finishArrowValidation(node) {
  3058. var _node$extra;
  3059. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  3060. this.scope.enter(2 | 4);
  3061. super.checkParams(node, false, true);
  3062. this.scope.exit();
  3063. }
  3064. forwardNoArrowParamsConversionAt(node, parse) {
  3065. let result;
  3066. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3067. this.state.noArrowParamsConversionAt.push(this.state.start);
  3068. result = parse();
  3069. this.state.noArrowParamsConversionAt.pop();
  3070. } else {
  3071. result = parse();
  3072. }
  3073. return result;
  3074. }
  3075. parseParenItem(node, startLoc) {
  3076. const newNode = super.parseParenItem(node, startLoc);
  3077. if (this.eat(17)) {
  3078. newNode.optional = true;
  3079. this.resetEndLocation(node);
  3080. }
  3081. if (this.match(14)) {
  3082. const typeCastNode = this.startNodeAt(startLoc);
  3083. typeCastNode.expression = newNode;
  3084. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  3085. return this.finishNode(typeCastNode, "TypeCastExpression");
  3086. }
  3087. return newNode;
  3088. }
  3089. assertModuleNodeAllowed(node) {
  3090. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  3091. return;
  3092. }
  3093. super.assertModuleNodeAllowed(node);
  3094. }
  3095. parseExportDeclaration(node) {
  3096. if (this.isContextual(130)) {
  3097. node.exportKind = "type";
  3098. const declarationNode = this.startNode();
  3099. this.next();
  3100. if (this.match(5)) {
  3101. node.specifiers = this.parseExportSpecifiers(true);
  3102. super.parseExportFrom(node);
  3103. return null;
  3104. } else {
  3105. return this.flowParseTypeAlias(declarationNode);
  3106. }
  3107. } else if (this.isContextual(131)) {
  3108. node.exportKind = "type";
  3109. const declarationNode = this.startNode();
  3110. this.next();
  3111. return this.flowParseOpaqueType(declarationNode, false);
  3112. } else if (this.isContextual(129)) {
  3113. node.exportKind = "type";
  3114. const declarationNode = this.startNode();
  3115. this.next();
  3116. return this.flowParseInterface(declarationNode);
  3117. } else if (this.isContextual(126)) {
  3118. node.exportKind = "value";
  3119. const declarationNode = this.startNode();
  3120. this.next();
  3121. return this.flowParseEnumDeclaration(declarationNode);
  3122. } else {
  3123. return super.parseExportDeclaration(node);
  3124. }
  3125. }
  3126. eatExportStar(node) {
  3127. if (super.eatExportStar(node)) return true;
  3128. if (this.isContextual(130) && this.lookahead().type === 55) {
  3129. node.exportKind = "type";
  3130. this.next();
  3131. this.next();
  3132. return true;
  3133. }
  3134. return false;
  3135. }
  3136. maybeParseExportNamespaceSpecifier(node) {
  3137. const {
  3138. startLoc
  3139. } = this.state;
  3140. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  3141. if (hasNamespace && node.exportKind === "type") {
  3142. this.unexpected(startLoc);
  3143. }
  3144. return hasNamespace;
  3145. }
  3146. parseClassId(node, isStatement, optionalId) {
  3147. super.parseClassId(node, isStatement, optionalId);
  3148. if (this.match(47)) {
  3149. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3150. }
  3151. }
  3152. parseClassMember(classBody, member, state) {
  3153. const {
  3154. startLoc
  3155. } = this.state;
  3156. if (this.isContextual(125)) {
  3157. if (super.parseClassMemberFromModifier(classBody, member)) {
  3158. return;
  3159. }
  3160. member.declare = true;
  3161. }
  3162. super.parseClassMember(classBody, member, state);
  3163. if (member.declare) {
  3164. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  3165. this.raise(FlowErrors.DeclareClassElement, startLoc);
  3166. } else if (member.value) {
  3167. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  3168. }
  3169. }
  3170. }
  3171. isIterator(word) {
  3172. return word === "iterator" || word === "asyncIterator";
  3173. }
  3174. readIterator() {
  3175. const word = super.readWord1();
  3176. const fullWord = "@@" + word;
  3177. if (!this.isIterator(word) || !this.state.inType) {
  3178. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  3179. identifierName: fullWord
  3180. });
  3181. }
  3182. this.finishToken(132, fullWord);
  3183. }
  3184. getTokenFromCode(code) {
  3185. const next = this.input.charCodeAt(this.state.pos + 1);
  3186. if (code === 123 && next === 124) {
  3187. this.finishOp(6, 2);
  3188. } else if (this.state.inType && (code === 62 || code === 60)) {
  3189. this.finishOp(code === 62 ? 48 : 47, 1);
  3190. } else if (this.state.inType && code === 63) {
  3191. if (next === 46) {
  3192. this.finishOp(18, 2);
  3193. } else {
  3194. this.finishOp(17, 1);
  3195. }
  3196. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  3197. this.state.pos += 2;
  3198. this.readIterator();
  3199. } else {
  3200. super.getTokenFromCode(code);
  3201. }
  3202. }
  3203. isAssignable(node, isBinding) {
  3204. if (node.type === "TypeCastExpression") {
  3205. return this.isAssignable(node.expression, isBinding);
  3206. } else {
  3207. return super.isAssignable(node, isBinding);
  3208. }
  3209. }
  3210. toAssignable(node, isLHS = false) {
  3211. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  3212. node.left = this.typeCastToParameter(node.left);
  3213. }
  3214. super.toAssignable(node, isLHS);
  3215. }
  3216. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  3217. for (let i = 0; i < exprList.length; i++) {
  3218. const expr = exprList[i];
  3219. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  3220. exprList[i] = this.typeCastToParameter(expr);
  3221. }
  3222. }
  3223. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  3224. }
  3225. toReferencedList(exprList, isParenthesizedExpr) {
  3226. for (let i = 0; i < exprList.length; i++) {
  3227. var _expr$extra;
  3228. const expr = exprList[i];
  3229. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  3230. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  3231. }
  3232. }
  3233. return exprList;
  3234. }
  3235. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  3236. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  3237. if (canBePattern && !this.state.maybeInArrowParameters) {
  3238. this.toReferencedList(node.elements);
  3239. }
  3240. return node;
  3241. }
  3242. isValidLVal(type, isParenthesized, binding) {
  3243. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  3244. }
  3245. parseClassProperty(node) {
  3246. if (this.match(14)) {
  3247. node.typeAnnotation = this.flowParseTypeAnnotation();
  3248. }
  3249. return super.parseClassProperty(node);
  3250. }
  3251. parseClassPrivateProperty(node) {
  3252. if (this.match(14)) {
  3253. node.typeAnnotation = this.flowParseTypeAnnotation();
  3254. }
  3255. return super.parseClassPrivateProperty(node);
  3256. }
  3257. isClassMethod() {
  3258. return this.match(47) || super.isClassMethod();
  3259. }
  3260. isClassProperty() {
  3261. return this.match(14) || super.isClassProperty();
  3262. }
  3263. isNonstaticConstructor(method) {
  3264. return !this.match(14) && super.isNonstaticConstructor(method);
  3265. }
  3266. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  3267. if (method.variance) {
  3268. this.unexpected(method.variance.loc.start);
  3269. }
  3270. delete method.variance;
  3271. if (this.match(47)) {
  3272. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3273. }
  3274. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  3275. if (method.params && isConstructor) {
  3276. const params = method.params;
  3277. if (params.length > 0 && this.isThisParam(params[0])) {
  3278. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3279. }
  3280. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  3281. const params = method.value.params;
  3282. if (params.length > 0 && this.isThisParam(params[0])) {
  3283. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3284. }
  3285. }
  3286. }
  3287. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  3288. if (method.variance) {
  3289. this.unexpected(method.variance.loc.start);
  3290. }
  3291. delete method.variance;
  3292. if (this.match(47)) {
  3293. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3294. }
  3295. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  3296. }
  3297. parseClassSuper(node) {
  3298. super.parseClassSuper(node);
  3299. if (node.superClass && (this.match(47) || this.match(51))) {
  3300. {
  3301. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  3302. }
  3303. }
  3304. if (this.isContextual(113)) {
  3305. this.next();
  3306. const implemented = node.implements = [];
  3307. do {
  3308. const node = this.startNode();
  3309. node.id = this.flowParseRestrictedIdentifier(true);
  3310. if (this.match(47)) {
  3311. node.typeParameters = this.flowParseTypeParameterInstantiation();
  3312. } else {
  3313. node.typeParameters = null;
  3314. }
  3315. implemented.push(this.finishNode(node, "ClassImplements"));
  3316. } while (this.eat(12));
  3317. }
  3318. }
  3319. checkGetterSetterParams(method) {
  3320. super.checkGetterSetterParams(method);
  3321. const params = this.getObjectOrClassMethodParams(method);
  3322. if (params.length > 0) {
  3323. const param = params[0];
  3324. if (this.isThisParam(param) && method.kind === "get") {
  3325. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  3326. } else if (this.isThisParam(param)) {
  3327. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  3328. }
  3329. }
  3330. }
  3331. parsePropertyNamePrefixOperator(node) {
  3332. node.variance = this.flowParseVariance();
  3333. }
  3334. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  3335. if (prop.variance) {
  3336. this.unexpected(prop.variance.loc.start);
  3337. }
  3338. delete prop.variance;
  3339. let typeParameters;
  3340. if (this.match(47) && !isAccessor) {
  3341. typeParameters = this.flowParseTypeParameterDeclaration();
  3342. if (!this.match(10)) this.unexpected();
  3343. }
  3344. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  3345. if (typeParameters) {
  3346. (result.value || result).typeParameters = typeParameters;
  3347. }
  3348. return result;
  3349. }
  3350. parseFunctionParamType(param) {
  3351. if (this.eat(17)) {
  3352. if (param.type !== "Identifier") {
  3353. this.raise(FlowErrors.PatternIsOptional, param);
  3354. }
  3355. if (this.isThisParam(param)) {
  3356. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  3357. }
  3358. param.optional = true;
  3359. }
  3360. if (this.match(14)) {
  3361. param.typeAnnotation = this.flowParseTypeAnnotation();
  3362. } else if (this.isThisParam(param)) {
  3363. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  3364. }
  3365. if (this.match(29) && this.isThisParam(param)) {
  3366. this.raise(FlowErrors.ThisParamNoDefault, param);
  3367. }
  3368. this.resetEndLocation(param);
  3369. return param;
  3370. }
  3371. parseMaybeDefault(startLoc, left) {
  3372. const node = super.parseMaybeDefault(startLoc, left);
  3373. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  3374. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  3375. }
  3376. return node;
  3377. }
  3378. checkImportReflection(node) {
  3379. super.checkImportReflection(node);
  3380. if (node.module && node.importKind !== "value") {
  3381. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  3382. }
  3383. }
  3384. parseImportSpecifierLocal(node, specifier, type) {
  3385. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  3386. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  3387. }
  3388. isPotentialImportPhase(isExport) {
  3389. if (super.isPotentialImportPhase(isExport)) return true;
  3390. if (this.isContextual(130)) {
  3391. if (!isExport) return true;
  3392. const ch = this.lookaheadCharCode();
  3393. return ch === 123 || ch === 42;
  3394. }
  3395. return !isExport && this.isContextual(87);
  3396. }
  3397. applyImportPhase(node, isExport, phase, loc) {
  3398. super.applyImportPhase(node, isExport, phase, loc);
  3399. if (isExport) {
  3400. if (!phase && this.match(65)) {
  3401. return;
  3402. }
  3403. node.exportKind = phase === "type" ? phase : "value";
  3404. } else {
  3405. if (phase === "type" && this.match(55)) this.unexpected();
  3406. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  3407. }
  3408. }
  3409. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  3410. const firstIdent = specifier.imported;
  3411. let specifierTypeKind = null;
  3412. if (firstIdent.type === "Identifier") {
  3413. if (firstIdent.name === "type") {
  3414. specifierTypeKind = "type";
  3415. } else if (firstIdent.name === "typeof") {
  3416. specifierTypeKind = "typeof";
  3417. }
  3418. }
  3419. let isBinding = false;
  3420. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  3421. const as_ident = this.parseIdentifier(true);
  3422. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  3423. specifier.imported = as_ident;
  3424. specifier.importKind = specifierTypeKind;
  3425. specifier.local = this.cloneIdentifier(as_ident);
  3426. } else {
  3427. specifier.imported = firstIdent;
  3428. specifier.importKind = null;
  3429. specifier.local = this.parseIdentifier();
  3430. }
  3431. } else {
  3432. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  3433. specifier.imported = this.parseIdentifier(true);
  3434. specifier.importKind = specifierTypeKind;
  3435. } else {
  3436. if (importedIsString) {
  3437. throw this.raise(Errors.ImportBindingIsString, specifier, {
  3438. importName: firstIdent.value
  3439. });
  3440. }
  3441. specifier.imported = firstIdent;
  3442. specifier.importKind = null;
  3443. }
  3444. if (this.eatContextual(93)) {
  3445. specifier.local = this.parseIdentifier();
  3446. } else {
  3447. isBinding = true;
  3448. specifier.local = this.cloneIdentifier(specifier.imported);
  3449. }
  3450. }
  3451. const specifierIsTypeImport = hasTypeImportKind(specifier);
  3452. if (isInTypeOnlyImport && specifierIsTypeImport) {
  3453. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  3454. }
  3455. if (isInTypeOnlyImport || specifierIsTypeImport) {
  3456. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  3457. }
  3458. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  3459. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  3460. }
  3461. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  3462. }
  3463. parseBindingAtom() {
  3464. switch (this.state.type) {
  3465. case 78:
  3466. return this.parseIdentifier(true);
  3467. default:
  3468. return super.parseBindingAtom();
  3469. }
  3470. }
  3471. parseFunctionParams(node, isConstructor) {
  3472. const kind = node.kind;
  3473. if (kind !== "get" && kind !== "set" && this.match(47)) {
  3474. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3475. }
  3476. super.parseFunctionParams(node, isConstructor);
  3477. }
  3478. parseVarId(decl, kind) {
  3479. super.parseVarId(decl, kind);
  3480. if (this.match(14)) {
  3481. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  3482. this.resetEndLocation(decl.id);
  3483. }
  3484. }
  3485. parseAsyncArrowFromCallExpression(node, call) {
  3486. if (this.match(14)) {
  3487. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3488. this.state.noAnonFunctionType = true;
  3489. node.returnType = this.flowParseTypeAnnotation();
  3490. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3491. }
  3492. return super.parseAsyncArrowFromCallExpression(node, call);
  3493. }
  3494. shouldParseAsyncArrow() {
  3495. return this.match(14) || super.shouldParseAsyncArrow();
  3496. }
  3497. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  3498. var _jsx;
  3499. let state = null;
  3500. let jsx;
  3501. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  3502. state = this.state.clone();
  3503. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  3504. if (!jsx.error) return jsx.node;
  3505. const {
  3506. context
  3507. } = this.state;
  3508. const currentContext = context[context.length - 1];
  3509. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  3510. context.pop();
  3511. }
  3512. }
  3513. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  3514. var _jsx2, _jsx3;
  3515. state = state || this.state.clone();
  3516. let typeParameters;
  3517. const arrow = this.tryParse(abort => {
  3518. var _arrowExpression$extr;
  3519. typeParameters = this.flowParseTypeParameterDeclaration();
  3520. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  3521. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3522. this.resetStartLocationFromNode(result, typeParameters);
  3523. return result;
  3524. });
  3525. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  3526. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  3527. if (expr.type !== "ArrowFunctionExpression") abort();
  3528. expr.typeParameters = typeParameters;
  3529. this.resetStartLocationFromNode(expr, typeParameters);
  3530. return arrowExpression;
  3531. }, state);
  3532. let arrowExpression = null;
  3533. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  3534. if (!arrow.error && !arrow.aborted) {
  3535. if (arrow.node.async) {
  3536. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  3537. }
  3538. return arrow.node;
  3539. }
  3540. arrowExpression = arrow.node;
  3541. }
  3542. if ((_jsx2 = jsx) != null && _jsx2.node) {
  3543. this.state = jsx.failState;
  3544. return jsx.node;
  3545. }
  3546. if (arrowExpression) {
  3547. this.state = arrow.failState;
  3548. return arrowExpression;
  3549. }
  3550. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  3551. if (arrow.thrown) throw arrow.error;
  3552. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  3553. }
  3554. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3555. }
  3556. parseArrow(node) {
  3557. if (this.match(14)) {
  3558. const result = this.tryParse(() => {
  3559. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3560. this.state.noAnonFunctionType = true;
  3561. const typeNode = this.startNode();
  3562. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  3563. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3564. if (this.canInsertSemicolon()) this.unexpected();
  3565. if (!this.match(19)) this.unexpected();
  3566. return typeNode;
  3567. });
  3568. if (result.thrown) return null;
  3569. if (result.error) this.state = result.failState;
  3570. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  3571. }
  3572. return super.parseArrow(node);
  3573. }
  3574. shouldParseArrow(params) {
  3575. return this.match(14) || super.shouldParseArrow(params);
  3576. }
  3577. setArrowFunctionParameters(node, params) {
  3578. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3579. node.params = params;
  3580. } else {
  3581. super.setArrowFunctionParameters(node, params);
  3582. }
  3583. }
  3584. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  3585. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3586. return;
  3587. }
  3588. for (let i = 0; i < node.params.length; i++) {
  3589. if (this.isThisParam(node.params[i]) && i > 0) {
  3590. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  3591. }
  3592. }
  3593. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  3594. }
  3595. parseParenAndDistinguishExpression(canBeArrow) {
  3596. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  3597. }
  3598. parseSubscripts(base, startLoc, noCalls) {
  3599. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  3600. this.next();
  3601. const node = this.startNodeAt(startLoc);
  3602. node.callee = base;
  3603. node.arguments = super.parseCallExpressionArguments(11);
  3604. base = this.finishNode(node, "CallExpression");
  3605. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  3606. const state = this.state.clone();
  3607. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  3608. if (!arrow.error && !arrow.aborted) return arrow.node;
  3609. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  3610. if (result.node && !result.error) return result.node;
  3611. if (arrow.node) {
  3612. this.state = arrow.failState;
  3613. return arrow.node;
  3614. }
  3615. if (result.node) {
  3616. this.state = result.failState;
  3617. return result.node;
  3618. }
  3619. throw arrow.error || result.error;
  3620. }
  3621. return super.parseSubscripts(base, startLoc, noCalls);
  3622. }
  3623. parseSubscript(base, startLoc, noCalls, subscriptState) {
  3624. if (this.match(18) && this.isLookaheadToken_lt()) {
  3625. subscriptState.optionalChainMember = true;
  3626. if (noCalls) {
  3627. subscriptState.stop = true;
  3628. return base;
  3629. }
  3630. this.next();
  3631. const node = this.startNodeAt(startLoc);
  3632. node.callee = base;
  3633. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  3634. this.expect(10);
  3635. node.arguments = this.parseCallExpressionArguments(11);
  3636. node.optional = true;
  3637. return this.finishCallExpression(node, true);
  3638. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  3639. const node = this.startNodeAt(startLoc);
  3640. node.callee = base;
  3641. const result = this.tryParse(() => {
  3642. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  3643. this.expect(10);
  3644. node.arguments = super.parseCallExpressionArguments(11);
  3645. if (subscriptState.optionalChainMember) {
  3646. node.optional = false;
  3647. }
  3648. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  3649. });
  3650. if (result.node) {
  3651. if (result.error) this.state = result.failState;
  3652. return result.node;
  3653. }
  3654. }
  3655. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  3656. }
  3657. parseNewCallee(node) {
  3658. super.parseNewCallee(node);
  3659. let targs = null;
  3660. if (this.shouldParseTypes() && this.match(47)) {
  3661. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  3662. }
  3663. node.typeArguments = targs;
  3664. }
  3665. parseAsyncArrowWithTypeParameters(startLoc) {
  3666. const node = this.startNodeAt(startLoc);
  3667. this.parseFunctionParams(node, false);
  3668. if (!this.parseArrow(node)) return;
  3669. return super.parseArrowExpression(node, undefined, true);
  3670. }
  3671. readToken_mult_modulo(code) {
  3672. const next = this.input.charCodeAt(this.state.pos + 1);
  3673. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  3674. this.state.hasFlowComment = false;
  3675. this.state.pos += 2;
  3676. this.nextToken();
  3677. return;
  3678. }
  3679. super.readToken_mult_modulo(code);
  3680. }
  3681. readToken_pipe_amp(code) {
  3682. const next = this.input.charCodeAt(this.state.pos + 1);
  3683. if (code === 124 && next === 125) {
  3684. this.finishOp(9, 2);
  3685. return;
  3686. }
  3687. super.readToken_pipe_amp(code);
  3688. }
  3689. parseTopLevel(file, program) {
  3690. const fileNode = super.parseTopLevel(file, program);
  3691. if (this.state.hasFlowComment) {
  3692. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  3693. }
  3694. return fileNode;
  3695. }
  3696. skipBlockComment() {
  3697. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  3698. if (this.state.hasFlowComment) {
  3699. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  3700. }
  3701. this.hasFlowCommentCompletion();
  3702. const commentSkip = this.skipFlowComment();
  3703. if (commentSkip) {
  3704. this.state.pos += commentSkip;
  3705. this.state.hasFlowComment = true;
  3706. }
  3707. return;
  3708. }
  3709. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  3710. }
  3711. skipFlowComment() {
  3712. const {
  3713. pos
  3714. } = this.state;
  3715. let shiftToFirstNonWhiteSpace = 2;
  3716. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  3717. shiftToFirstNonWhiteSpace++;
  3718. }
  3719. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  3720. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  3721. if (ch2 === 58 && ch3 === 58) {
  3722. return shiftToFirstNonWhiteSpace + 2;
  3723. }
  3724. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  3725. return shiftToFirstNonWhiteSpace + 12;
  3726. }
  3727. if (ch2 === 58 && ch3 !== 58) {
  3728. return shiftToFirstNonWhiteSpace;
  3729. }
  3730. return false;
  3731. }
  3732. hasFlowCommentCompletion() {
  3733. const end = this.input.indexOf("*/", this.state.pos);
  3734. if (end === -1) {
  3735. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  3736. }
  3737. }
  3738. flowEnumErrorBooleanMemberNotInitialized(loc, {
  3739. enumName,
  3740. memberName
  3741. }) {
  3742. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  3743. memberName,
  3744. enumName
  3745. });
  3746. }
  3747. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  3748. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  3749. }
  3750. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  3751. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  3752. }
  3753. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  3754. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  3755. }
  3756. flowEnumMemberInit() {
  3757. const startLoc = this.state.startLoc;
  3758. const endOfInit = () => this.match(12) || this.match(8);
  3759. switch (this.state.type) {
  3760. case 135:
  3761. {
  3762. const literal = this.parseNumericLiteral(this.state.value);
  3763. if (endOfInit()) {
  3764. return {
  3765. type: "number",
  3766. loc: literal.loc.start,
  3767. value: literal
  3768. };
  3769. }
  3770. return {
  3771. type: "invalid",
  3772. loc: startLoc
  3773. };
  3774. }
  3775. case 134:
  3776. {
  3777. const literal = this.parseStringLiteral(this.state.value);
  3778. if (endOfInit()) {
  3779. return {
  3780. type: "string",
  3781. loc: literal.loc.start,
  3782. value: literal
  3783. };
  3784. }
  3785. return {
  3786. type: "invalid",
  3787. loc: startLoc
  3788. };
  3789. }
  3790. case 85:
  3791. case 86:
  3792. {
  3793. const literal = this.parseBooleanLiteral(this.match(85));
  3794. if (endOfInit()) {
  3795. return {
  3796. type: "boolean",
  3797. loc: literal.loc.start,
  3798. value: literal
  3799. };
  3800. }
  3801. return {
  3802. type: "invalid",
  3803. loc: startLoc
  3804. };
  3805. }
  3806. default:
  3807. return {
  3808. type: "invalid",
  3809. loc: startLoc
  3810. };
  3811. }
  3812. }
  3813. flowEnumMemberRaw() {
  3814. const loc = this.state.startLoc;
  3815. const id = this.parseIdentifier(true);
  3816. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  3817. type: "none",
  3818. loc
  3819. };
  3820. return {
  3821. id,
  3822. init
  3823. };
  3824. }
  3825. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  3826. const {
  3827. explicitType
  3828. } = context;
  3829. if (explicitType === null) {
  3830. return;
  3831. }
  3832. if (explicitType !== expectedType) {
  3833. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  3834. }
  3835. }
  3836. flowEnumMembers({
  3837. enumName,
  3838. explicitType
  3839. }) {
  3840. const seenNames = new Set();
  3841. const members = {
  3842. booleanMembers: [],
  3843. numberMembers: [],
  3844. stringMembers: [],
  3845. defaultedMembers: []
  3846. };
  3847. let hasUnknownMembers = false;
  3848. while (!this.match(8)) {
  3849. if (this.eat(21)) {
  3850. hasUnknownMembers = true;
  3851. break;
  3852. }
  3853. const memberNode = this.startNode();
  3854. const {
  3855. id,
  3856. init
  3857. } = this.flowEnumMemberRaw();
  3858. const memberName = id.name;
  3859. if (memberName === "") {
  3860. continue;
  3861. }
  3862. if (/^[a-z]/.test(memberName)) {
  3863. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  3864. memberName,
  3865. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  3866. enumName
  3867. });
  3868. }
  3869. if (seenNames.has(memberName)) {
  3870. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  3871. memberName,
  3872. enumName
  3873. });
  3874. }
  3875. seenNames.add(memberName);
  3876. const context = {
  3877. enumName,
  3878. explicitType,
  3879. memberName
  3880. };
  3881. memberNode.id = id;
  3882. switch (init.type) {
  3883. case "boolean":
  3884. {
  3885. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  3886. memberNode.init = init.value;
  3887. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  3888. break;
  3889. }
  3890. case "number":
  3891. {
  3892. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  3893. memberNode.init = init.value;
  3894. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  3895. break;
  3896. }
  3897. case "string":
  3898. {
  3899. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  3900. memberNode.init = init.value;
  3901. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  3902. break;
  3903. }
  3904. case "invalid":
  3905. {
  3906. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  3907. }
  3908. case "none":
  3909. {
  3910. switch (explicitType) {
  3911. case "boolean":
  3912. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  3913. break;
  3914. case "number":
  3915. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  3916. break;
  3917. default:
  3918. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  3919. }
  3920. }
  3921. }
  3922. if (!this.match(8)) {
  3923. this.expect(12);
  3924. }
  3925. }
  3926. return {
  3927. members,
  3928. hasUnknownMembers
  3929. };
  3930. }
  3931. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  3932. enumName
  3933. }) {
  3934. if (initializedMembers.length === 0) {
  3935. return defaultedMembers;
  3936. } else if (defaultedMembers.length === 0) {
  3937. return initializedMembers;
  3938. } else if (defaultedMembers.length > initializedMembers.length) {
  3939. for (const member of initializedMembers) {
  3940. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3941. enumName
  3942. });
  3943. }
  3944. return defaultedMembers;
  3945. } else {
  3946. for (const member of defaultedMembers) {
  3947. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3948. enumName
  3949. });
  3950. }
  3951. return initializedMembers;
  3952. }
  3953. }
  3954. flowEnumParseExplicitType({
  3955. enumName
  3956. }) {
  3957. if (!this.eatContextual(102)) return null;
  3958. if (!tokenIsIdentifier(this.state.type)) {
  3959. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  3960. enumName
  3961. });
  3962. }
  3963. const {
  3964. value
  3965. } = this.state;
  3966. this.next();
  3967. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  3968. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  3969. enumName,
  3970. invalidEnumType: value
  3971. });
  3972. }
  3973. return value;
  3974. }
  3975. flowEnumBody(node, id) {
  3976. const enumName = id.name;
  3977. const nameLoc = id.loc.start;
  3978. const explicitType = this.flowEnumParseExplicitType({
  3979. enumName
  3980. });
  3981. this.expect(5);
  3982. const {
  3983. members,
  3984. hasUnknownMembers
  3985. } = this.flowEnumMembers({
  3986. enumName,
  3987. explicitType
  3988. });
  3989. node.hasUnknownMembers = hasUnknownMembers;
  3990. switch (explicitType) {
  3991. case "boolean":
  3992. node.explicitType = true;
  3993. node.members = members.booleanMembers;
  3994. this.expect(8);
  3995. return this.finishNode(node, "EnumBooleanBody");
  3996. case "number":
  3997. node.explicitType = true;
  3998. node.members = members.numberMembers;
  3999. this.expect(8);
  4000. return this.finishNode(node, "EnumNumberBody");
  4001. case "string":
  4002. node.explicitType = true;
  4003. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4004. enumName
  4005. });
  4006. this.expect(8);
  4007. return this.finishNode(node, "EnumStringBody");
  4008. case "symbol":
  4009. node.members = members.defaultedMembers;
  4010. this.expect(8);
  4011. return this.finishNode(node, "EnumSymbolBody");
  4012. default:
  4013. {
  4014. const empty = () => {
  4015. node.members = [];
  4016. this.expect(8);
  4017. return this.finishNode(node, "EnumStringBody");
  4018. };
  4019. node.explicitType = false;
  4020. const boolsLen = members.booleanMembers.length;
  4021. const numsLen = members.numberMembers.length;
  4022. const strsLen = members.stringMembers.length;
  4023. const defaultedLen = members.defaultedMembers.length;
  4024. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  4025. return empty();
  4026. } else if (!boolsLen && !numsLen) {
  4027. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4028. enumName
  4029. });
  4030. this.expect(8);
  4031. return this.finishNode(node, "EnumStringBody");
  4032. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  4033. for (const member of members.defaultedMembers) {
  4034. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  4035. enumName,
  4036. memberName: member.id.name
  4037. });
  4038. }
  4039. node.members = members.booleanMembers;
  4040. this.expect(8);
  4041. return this.finishNode(node, "EnumBooleanBody");
  4042. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  4043. for (const member of members.defaultedMembers) {
  4044. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  4045. enumName,
  4046. memberName: member.id.name
  4047. });
  4048. }
  4049. node.members = members.numberMembers;
  4050. this.expect(8);
  4051. return this.finishNode(node, "EnumNumberBody");
  4052. } else {
  4053. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  4054. enumName
  4055. });
  4056. return empty();
  4057. }
  4058. }
  4059. }
  4060. }
  4061. flowParseEnumDeclaration(node) {
  4062. const id = this.parseIdentifier();
  4063. node.id = id;
  4064. node.body = this.flowEnumBody(this.startNode(), id);
  4065. return this.finishNode(node, "EnumDeclaration");
  4066. }
  4067. jsxParseOpeningElementAfterName(node) {
  4068. if (this.shouldParseTypes()) {
  4069. if (this.match(47) || this.match(51)) {
  4070. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  4071. }
  4072. }
  4073. return super.jsxParseOpeningElementAfterName(node);
  4074. }
  4075. isLookaheadToken_lt() {
  4076. const next = this.nextTokenStart();
  4077. if (this.input.charCodeAt(next) === 60) {
  4078. const afterNext = this.input.charCodeAt(next + 1);
  4079. return afterNext !== 60 && afterNext !== 61;
  4080. }
  4081. return false;
  4082. }
  4083. reScan_lt_gt() {
  4084. const {
  4085. type
  4086. } = this.state;
  4087. if (type === 47) {
  4088. this.state.pos -= 1;
  4089. this.readToken_lt();
  4090. } else if (type === 48) {
  4091. this.state.pos -= 1;
  4092. this.readToken_gt();
  4093. }
  4094. }
  4095. reScan_lt() {
  4096. const {
  4097. type
  4098. } = this.state;
  4099. if (type === 51) {
  4100. this.state.pos -= 2;
  4101. this.finishOp(47, 1);
  4102. return 47;
  4103. }
  4104. return type;
  4105. }
  4106. maybeUnwrapTypeCastExpression(node) {
  4107. return node.type === "TypeCastExpression" ? node.expression : node;
  4108. }
  4109. };
  4110. const entities = {
  4111. __proto__: null,
  4112. quot: "\u0022",
  4113. amp: "&",
  4114. apos: "\u0027",
  4115. lt: "<",
  4116. gt: ">",
  4117. nbsp: "\u00A0",
  4118. iexcl: "\u00A1",
  4119. cent: "\u00A2",
  4120. pound: "\u00A3",
  4121. curren: "\u00A4",
  4122. yen: "\u00A5",
  4123. brvbar: "\u00A6",
  4124. sect: "\u00A7",
  4125. uml: "\u00A8",
  4126. copy: "\u00A9",
  4127. ordf: "\u00AA",
  4128. laquo: "\u00AB",
  4129. not: "\u00AC",
  4130. shy: "\u00AD",
  4131. reg: "\u00AE",
  4132. macr: "\u00AF",
  4133. deg: "\u00B0",
  4134. plusmn: "\u00B1",
  4135. sup2: "\u00B2",
  4136. sup3: "\u00B3",
  4137. acute: "\u00B4",
  4138. micro: "\u00B5",
  4139. para: "\u00B6",
  4140. middot: "\u00B7",
  4141. cedil: "\u00B8",
  4142. sup1: "\u00B9",
  4143. ordm: "\u00BA",
  4144. raquo: "\u00BB",
  4145. frac14: "\u00BC",
  4146. frac12: "\u00BD",
  4147. frac34: "\u00BE",
  4148. iquest: "\u00BF",
  4149. Agrave: "\u00C0",
  4150. Aacute: "\u00C1",
  4151. Acirc: "\u00C2",
  4152. Atilde: "\u00C3",
  4153. Auml: "\u00C4",
  4154. Aring: "\u00C5",
  4155. AElig: "\u00C6",
  4156. Ccedil: "\u00C7",
  4157. Egrave: "\u00C8",
  4158. Eacute: "\u00C9",
  4159. Ecirc: "\u00CA",
  4160. Euml: "\u00CB",
  4161. Igrave: "\u00CC",
  4162. Iacute: "\u00CD",
  4163. Icirc: "\u00CE",
  4164. Iuml: "\u00CF",
  4165. ETH: "\u00D0",
  4166. Ntilde: "\u00D1",
  4167. Ograve: "\u00D2",
  4168. Oacute: "\u00D3",
  4169. Ocirc: "\u00D4",
  4170. Otilde: "\u00D5",
  4171. Ouml: "\u00D6",
  4172. times: "\u00D7",
  4173. Oslash: "\u00D8",
  4174. Ugrave: "\u00D9",
  4175. Uacute: "\u00DA",
  4176. Ucirc: "\u00DB",
  4177. Uuml: "\u00DC",
  4178. Yacute: "\u00DD",
  4179. THORN: "\u00DE",
  4180. szlig: "\u00DF",
  4181. agrave: "\u00E0",
  4182. aacute: "\u00E1",
  4183. acirc: "\u00E2",
  4184. atilde: "\u00E3",
  4185. auml: "\u00E4",
  4186. aring: "\u00E5",
  4187. aelig: "\u00E6",
  4188. ccedil: "\u00E7",
  4189. egrave: "\u00E8",
  4190. eacute: "\u00E9",
  4191. ecirc: "\u00EA",
  4192. euml: "\u00EB",
  4193. igrave: "\u00EC",
  4194. iacute: "\u00ED",
  4195. icirc: "\u00EE",
  4196. iuml: "\u00EF",
  4197. eth: "\u00F0",
  4198. ntilde: "\u00F1",
  4199. ograve: "\u00F2",
  4200. oacute: "\u00F3",
  4201. ocirc: "\u00F4",
  4202. otilde: "\u00F5",
  4203. ouml: "\u00F6",
  4204. divide: "\u00F7",
  4205. oslash: "\u00F8",
  4206. ugrave: "\u00F9",
  4207. uacute: "\u00FA",
  4208. ucirc: "\u00FB",
  4209. uuml: "\u00FC",
  4210. yacute: "\u00FD",
  4211. thorn: "\u00FE",
  4212. yuml: "\u00FF",
  4213. OElig: "\u0152",
  4214. oelig: "\u0153",
  4215. Scaron: "\u0160",
  4216. scaron: "\u0161",
  4217. Yuml: "\u0178",
  4218. fnof: "\u0192",
  4219. circ: "\u02C6",
  4220. tilde: "\u02DC",
  4221. Alpha: "\u0391",
  4222. Beta: "\u0392",
  4223. Gamma: "\u0393",
  4224. Delta: "\u0394",
  4225. Epsilon: "\u0395",
  4226. Zeta: "\u0396",
  4227. Eta: "\u0397",
  4228. Theta: "\u0398",
  4229. Iota: "\u0399",
  4230. Kappa: "\u039A",
  4231. Lambda: "\u039B",
  4232. Mu: "\u039C",
  4233. Nu: "\u039D",
  4234. Xi: "\u039E",
  4235. Omicron: "\u039F",
  4236. Pi: "\u03A0",
  4237. Rho: "\u03A1",
  4238. Sigma: "\u03A3",
  4239. Tau: "\u03A4",
  4240. Upsilon: "\u03A5",
  4241. Phi: "\u03A6",
  4242. Chi: "\u03A7",
  4243. Psi: "\u03A8",
  4244. Omega: "\u03A9",
  4245. alpha: "\u03B1",
  4246. beta: "\u03B2",
  4247. gamma: "\u03B3",
  4248. delta: "\u03B4",
  4249. epsilon: "\u03B5",
  4250. zeta: "\u03B6",
  4251. eta: "\u03B7",
  4252. theta: "\u03B8",
  4253. iota: "\u03B9",
  4254. kappa: "\u03BA",
  4255. lambda: "\u03BB",
  4256. mu: "\u03BC",
  4257. nu: "\u03BD",
  4258. xi: "\u03BE",
  4259. omicron: "\u03BF",
  4260. pi: "\u03C0",
  4261. rho: "\u03C1",
  4262. sigmaf: "\u03C2",
  4263. sigma: "\u03C3",
  4264. tau: "\u03C4",
  4265. upsilon: "\u03C5",
  4266. phi: "\u03C6",
  4267. chi: "\u03C7",
  4268. psi: "\u03C8",
  4269. omega: "\u03C9",
  4270. thetasym: "\u03D1",
  4271. upsih: "\u03D2",
  4272. piv: "\u03D6",
  4273. ensp: "\u2002",
  4274. emsp: "\u2003",
  4275. thinsp: "\u2009",
  4276. zwnj: "\u200C",
  4277. zwj: "\u200D",
  4278. lrm: "\u200E",
  4279. rlm: "\u200F",
  4280. ndash: "\u2013",
  4281. mdash: "\u2014",
  4282. lsquo: "\u2018",
  4283. rsquo: "\u2019",
  4284. sbquo: "\u201A",
  4285. ldquo: "\u201C",
  4286. rdquo: "\u201D",
  4287. bdquo: "\u201E",
  4288. dagger: "\u2020",
  4289. Dagger: "\u2021",
  4290. bull: "\u2022",
  4291. hellip: "\u2026",
  4292. permil: "\u2030",
  4293. prime: "\u2032",
  4294. Prime: "\u2033",
  4295. lsaquo: "\u2039",
  4296. rsaquo: "\u203A",
  4297. oline: "\u203E",
  4298. frasl: "\u2044",
  4299. euro: "\u20AC",
  4300. image: "\u2111",
  4301. weierp: "\u2118",
  4302. real: "\u211C",
  4303. trade: "\u2122",
  4304. alefsym: "\u2135",
  4305. larr: "\u2190",
  4306. uarr: "\u2191",
  4307. rarr: "\u2192",
  4308. darr: "\u2193",
  4309. harr: "\u2194",
  4310. crarr: "\u21B5",
  4311. lArr: "\u21D0",
  4312. uArr: "\u21D1",
  4313. rArr: "\u21D2",
  4314. dArr: "\u21D3",
  4315. hArr: "\u21D4",
  4316. forall: "\u2200",
  4317. part: "\u2202",
  4318. exist: "\u2203",
  4319. empty: "\u2205",
  4320. nabla: "\u2207",
  4321. isin: "\u2208",
  4322. notin: "\u2209",
  4323. ni: "\u220B",
  4324. prod: "\u220F",
  4325. sum: "\u2211",
  4326. minus: "\u2212",
  4327. lowast: "\u2217",
  4328. radic: "\u221A",
  4329. prop: "\u221D",
  4330. infin: "\u221E",
  4331. ang: "\u2220",
  4332. and: "\u2227",
  4333. or: "\u2228",
  4334. cap: "\u2229",
  4335. cup: "\u222A",
  4336. int: "\u222B",
  4337. there4: "\u2234",
  4338. sim: "\u223C",
  4339. cong: "\u2245",
  4340. asymp: "\u2248",
  4341. ne: "\u2260",
  4342. equiv: "\u2261",
  4343. le: "\u2264",
  4344. ge: "\u2265",
  4345. sub: "\u2282",
  4346. sup: "\u2283",
  4347. nsub: "\u2284",
  4348. sube: "\u2286",
  4349. supe: "\u2287",
  4350. oplus: "\u2295",
  4351. otimes: "\u2297",
  4352. perp: "\u22A5",
  4353. sdot: "\u22C5",
  4354. lceil: "\u2308",
  4355. rceil: "\u2309",
  4356. lfloor: "\u230A",
  4357. rfloor: "\u230B",
  4358. lang: "\u2329",
  4359. rang: "\u232A",
  4360. loz: "\u25CA",
  4361. spades: "\u2660",
  4362. clubs: "\u2663",
  4363. hearts: "\u2665",
  4364. diams: "\u2666"
  4365. };
  4366. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  4367. const lineBreakG = new RegExp(lineBreak.source, "g");
  4368. function isNewLine(code) {
  4369. switch (code) {
  4370. case 10:
  4371. case 13:
  4372. case 8232:
  4373. case 8233:
  4374. return true;
  4375. default:
  4376. return false;
  4377. }
  4378. }
  4379. function hasNewLine(input, start, end) {
  4380. for (let i = start; i < end; i++) {
  4381. if (isNewLine(input.charCodeAt(i))) {
  4382. return true;
  4383. }
  4384. }
  4385. return false;
  4386. }
  4387. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  4388. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  4389. function isWhitespace(code) {
  4390. switch (code) {
  4391. case 0x0009:
  4392. case 0x000b:
  4393. case 0x000c:
  4394. case 32:
  4395. case 160:
  4396. case 5760:
  4397. case 0x2000:
  4398. case 0x2001:
  4399. case 0x2002:
  4400. case 0x2003:
  4401. case 0x2004:
  4402. case 0x2005:
  4403. case 0x2006:
  4404. case 0x2007:
  4405. case 0x2008:
  4406. case 0x2009:
  4407. case 0x200a:
  4408. case 0x202f:
  4409. case 0x205f:
  4410. case 0x3000:
  4411. case 0xfeff:
  4412. return true;
  4413. default:
  4414. return false;
  4415. }
  4416. }
  4417. const JsxErrors = ParseErrorEnum`jsx`({
  4418. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  4419. MissingClosingTagElement: ({
  4420. openingTagName
  4421. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  4422. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  4423. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  4424. UnexpectedToken: ({
  4425. unexpected,
  4426. HTMLEntity
  4427. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  4428. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  4429. UnterminatedJsxContent: "Unterminated JSX contents.",
  4430. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  4431. });
  4432. function isFragment(object) {
  4433. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  4434. }
  4435. function getQualifiedJSXName(object) {
  4436. if (object.type === "JSXIdentifier") {
  4437. return object.name;
  4438. }
  4439. if (object.type === "JSXNamespacedName") {
  4440. return object.namespace.name + ":" + object.name.name;
  4441. }
  4442. if (object.type === "JSXMemberExpression") {
  4443. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  4444. }
  4445. throw new Error("Node had unexpected type: " + object.type);
  4446. }
  4447. var jsx = superClass => class JSXParserMixin extends superClass {
  4448. jsxReadToken() {
  4449. let out = "";
  4450. let chunkStart = this.state.pos;
  4451. for (;;) {
  4452. if (this.state.pos >= this.length) {
  4453. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  4454. }
  4455. const ch = this.input.charCodeAt(this.state.pos);
  4456. switch (ch) {
  4457. case 60:
  4458. case 123:
  4459. if (this.state.pos === this.state.start) {
  4460. if (ch === 60 && this.state.canStartJSXElement) {
  4461. ++this.state.pos;
  4462. this.finishToken(143);
  4463. } else {
  4464. super.getTokenFromCode(ch);
  4465. }
  4466. return;
  4467. }
  4468. out += this.input.slice(chunkStart, this.state.pos);
  4469. this.finishToken(142, out);
  4470. return;
  4471. case 38:
  4472. out += this.input.slice(chunkStart, this.state.pos);
  4473. out += this.jsxReadEntity();
  4474. chunkStart = this.state.pos;
  4475. break;
  4476. case 62:
  4477. case 125:
  4478. default:
  4479. if (isNewLine(ch)) {
  4480. out += this.input.slice(chunkStart, this.state.pos);
  4481. out += this.jsxReadNewLine(true);
  4482. chunkStart = this.state.pos;
  4483. } else {
  4484. ++this.state.pos;
  4485. }
  4486. }
  4487. }
  4488. }
  4489. jsxReadNewLine(normalizeCRLF) {
  4490. const ch = this.input.charCodeAt(this.state.pos);
  4491. let out;
  4492. ++this.state.pos;
  4493. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  4494. ++this.state.pos;
  4495. out = normalizeCRLF ? "\n" : "\r\n";
  4496. } else {
  4497. out = String.fromCharCode(ch);
  4498. }
  4499. ++this.state.curLine;
  4500. this.state.lineStart = this.state.pos;
  4501. return out;
  4502. }
  4503. jsxReadString(quote) {
  4504. let out = "";
  4505. let chunkStart = ++this.state.pos;
  4506. for (;;) {
  4507. if (this.state.pos >= this.length) {
  4508. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  4509. }
  4510. const ch = this.input.charCodeAt(this.state.pos);
  4511. if (ch === quote) break;
  4512. if (ch === 38) {
  4513. out += this.input.slice(chunkStart, this.state.pos);
  4514. out += this.jsxReadEntity();
  4515. chunkStart = this.state.pos;
  4516. } else if (isNewLine(ch)) {
  4517. out += this.input.slice(chunkStart, this.state.pos);
  4518. out += this.jsxReadNewLine(false);
  4519. chunkStart = this.state.pos;
  4520. } else {
  4521. ++this.state.pos;
  4522. }
  4523. }
  4524. out += this.input.slice(chunkStart, this.state.pos++);
  4525. this.finishToken(134, out);
  4526. }
  4527. jsxReadEntity() {
  4528. const startPos = ++this.state.pos;
  4529. if (this.codePointAtPos(this.state.pos) === 35) {
  4530. ++this.state.pos;
  4531. let radix = 10;
  4532. if (this.codePointAtPos(this.state.pos) === 120) {
  4533. radix = 16;
  4534. ++this.state.pos;
  4535. }
  4536. const codePoint = this.readInt(radix, undefined, false, "bail");
  4537. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  4538. ++this.state.pos;
  4539. return String.fromCodePoint(codePoint);
  4540. }
  4541. } else {
  4542. let count = 0;
  4543. let semi = false;
  4544. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  4545. ++this.state.pos;
  4546. }
  4547. if (semi) {
  4548. const desc = this.input.slice(startPos, this.state.pos);
  4549. const entity = entities[desc];
  4550. ++this.state.pos;
  4551. if (entity) {
  4552. return entity;
  4553. }
  4554. }
  4555. }
  4556. this.state.pos = startPos;
  4557. return "&";
  4558. }
  4559. jsxReadWord() {
  4560. let ch;
  4561. const start = this.state.pos;
  4562. do {
  4563. ch = this.input.charCodeAt(++this.state.pos);
  4564. } while (isIdentifierChar(ch) || ch === 45);
  4565. this.finishToken(141, this.input.slice(start, this.state.pos));
  4566. }
  4567. jsxParseIdentifier() {
  4568. const node = this.startNode();
  4569. if (this.match(141)) {
  4570. node.name = this.state.value;
  4571. } else if (tokenIsKeyword(this.state.type)) {
  4572. node.name = tokenLabelName(this.state.type);
  4573. } else {
  4574. this.unexpected();
  4575. }
  4576. this.next();
  4577. return this.finishNode(node, "JSXIdentifier");
  4578. }
  4579. jsxParseNamespacedName() {
  4580. const startLoc = this.state.startLoc;
  4581. const name = this.jsxParseIdentifier();
  4582. if (!this.eat(14)) return name;
  4583. const node = this.startNodeAt(startLoc);
  4584. node.namespace = name;
  4585. node.name = this.jsxParseIdentifier();
  4586. return this.finishNode(node, "JSXNamespacedName");
  4587. }
  4588. jsxParseElementName() {
  4589. const startLoc = this.state.startLoc;
  4590. let node = this.jsxParseNamespacedName();
  4591. if (node.type === "JSXNamespacedName") {
  4592. return node;
  4593. }
  4594. while (this.eat(16)) {
  4595. const newNode = this.startNodeAt(startLoc);
  4596. newNode.object = node;
  4597. newNode.property = this.jsxParseIdentifier();
  4598. node = this.finishNode(newNode, "JSXMemberExpression");
  4599. }
  4600. return node;
  4601. }
  4602. jsxParseAttributeValue() {
  4603. let node;
  4604. switch (this.state.type) {
  4605. case 5:
  4606. node = this.startNode();
  4607. this.setContext(types.brace);
  4608. this.next();
  4609. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  4610. if (node.expression.type === "JSXEmptyExpression") {
  4611. this.raise(JsxErrors.AttributeIsEmpty, node);
  4612. }
  4613. return node;
  4614. case 143:
  4615. case 134:
  4616. return this.parseExprAtom();
  4617. default:
  4618. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  4619. }
  4620. }
  4621. jsxParseEmptyExpression() {
  4622. const node = this.startNodeAt(this.state.lastTokEndLoc);
  4623. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  4624. }
  4625. jsxParseSpreadChild(node) {
  4626. this.next();
  4627. node.expression = this.parseExpression();
  4628. this.setContext(types.j_expr);
  4629. this.state.canStartJSXElement = true;
  4630. this.expect(8);
  4631. return this.finishNode(node, "JSXSpreadChild");
  4632. }
  4633. jsxParseExpressionContainer(node, previousContext) {
  4634. if (this.match(8)) {
  4635. node.expression = this.jsxParseEmptyExpression();
  4636. } else {
  4637. const expression = this.parseExpression();
  4638. node.expression = expression;
  4639. }
  4640. this.setContext(previousContext);
  4641. this.state.canStartJSXElement = true;
  4642. this.expect(8);
  4643. return this.finishNode(node, "JSXExpressionContainer");
  4644. }
  4645. jsxParseAttribute() {
  4646. const node = this.startNode();
  4647. if (this.match(5)) {
  4648. this.setContext(types.brace);
  4649. this.next();
  4650. this.expect(21);
  4651. node.argument = this.parseMaybeAssignAllowIn();
  4652. this.setContext(types.j_oTag);
  4653. this.state.canStartJSXElement = true;
  4654. this.expect(8);
  4655. return this.finishNode(node, "JSXSpreadAttribute");
  4656. }
  4657. node.name = this.jsxParseNamespacedName();
  4658. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  4659. return this.finishNode(node, "JSXAttribute");
  4660. }
  4661. jsxParseOpeningElementAt(startLoc) {
  4662. const node = this.startNodeAt(startLoc);
  4663. if (this.eat(144)) {
  4664. return this.finishNode(node, "JSXOpeningFragment");
  4665. }
  4666. node.name = this.jsxParseElementName();
  4667. return this.jsxParseOpeningElementAfterName(node);
  4668. }
  4669. jsxParseOpeningElementAfterName(node) {
  4670. const attributes = [];
  4671. while (!this.match(56) && !this.match(144)) {
  4672. attributes.push(this.jsxParseAttribute());
  4673. }
  4674. node.attributes = attributes;
  4675. node.selfClosing = this.eat(56);
  4676. this.expect(144);
  4677. return this.finishNode(node, "JSXOpeningElement");
  4678. }
  4679. jsxParseClosingElementAt(startLoc) {
  4680. const node = this.startNodeAt(startLoc);
  4681. if (this.eat(144)) {
  4682. return this.finishNode(node, "JSXClosingFragment");
  4683. }
  4684. node.name = this.jsxParseElementName();
  4685. this.expect(144);
  4686. return this.finishNode(node, "JSXClosingElement");
  4687. }
  4688. jsxParseElementAt(startLoc) {
  4689. const node = this.startNodeAt(startLoc);
  4690. const children = [];
  4691. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  4692. let closingElement = null;
  4693. if (!openingElement.selfClosing) {
  4694. contents: for (;;) {
  4695. switch (this.state.type) {
  4696. case 143:
  4697. startLoc = this.state.startLoc;
  4698. this.next();
  4699. if (this.eat(56)) {
  4700. closingElement = this.jsxParseClosingElementAt(startLoc);
  4701. break contents;
  4702. }
  4703. children.push(this.jsxParseElementAt(startLoc));
  4704. break;
  4705. case 142:
  4706. children.push(this.parseLiteral(this.state.value, "JSXText"));
  4707. break;
  4708. case 5:
  4709. {
  4710. const node = this.startNode();
  4711. this.setContext(types.brace);
  4712. this.next();
  4713. if (this.match(21)) {
  4714. children.push(this.jsxParseSpreadChild(node));
  4715. } else {
  4716. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  4717. }
  4718. break;
  4719. }
  4720. default:
  4721. this.unexpected();
  4722. }
  4723. }
  4724. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  4725. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  4726. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  4727. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4728. openingTagName: getQualifiedJSXName(openingElement.name)
  4729. });
  4730. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  4731. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  4732. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4733. openingTagName: getQualifiedJSXName(openingElement.name)
  4734. });
  4735. }
  4736. }
  4737. }
  4738. if (isFragment(openingElement)) {
  4739. node.openingFragment = openingElement;
  4740. node.closingFragment = closingElement;
  4741. } else {
  4742. node.openingElement = openingElement;
  4743. node.closingElement = closingElement;
  4744. }
  4745. node.children = children;
  4746. if (this.match(47)) {
  4747. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  4748. }
  4749. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  4750. }
  4751. jsxParseElement() {
  4752. const startLoc = this.state.startLoc;
  4753. this.next();
  4754. return this.jsxParseElementAt(startLoc);
  4755. }
  4756. setContext(newContext) {
  4757. const {
  4758. context
  4759. } = this.state;
  4760. context[context.length - 1] = newContext;
  4761. }
  4762. parseExprAtom(refExpressionErrors) {
  4763. if (this.match(143)) {
  4764. return this.jsxParseElement();
  4765. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  4766. this.replaceToken(143);
  4767. return this.jsxParseElement();
  4768. } else {
  4769. return super.parseExprAtom(refExpressionErrors);
  4770. }
  4771. }
  4772. skipSpace() {
  4773. const curContext = this.curContext();
  4774. if (!curContext.preserveSpace) super.skipSpace();
  4775. }
  4776. getTokenFromCode(code) {
  4777. const context = this.curContext();
  4778. if (context === types.j_expr) {
  4779. this.jsxReadToken();
  4780. return;
  4781. }
  4782. if (context === types.j_oTag || context === types.j_cTag) {
  4783. if (isIdentifierStart(code)) {
  4784. this.jsxReadWord();
  4785. return;
  4786. }
  4787. if (code === 62) {
  4788. ++this.state.pos;
  4789. this.finishToken(144);
  4790. return;
  4791. }
  4792. if ((code === 34 || code === 39) && context === types.j_oTag) {
  4793. this.jsxReadString(code);
  4794. return;
  4795. }
  4796. }
  4797. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  4798. ++this.state.pos;
  4799. this.finishToken(143);
  4800. return;
  4801. }
  4802. super.getTokenFromCode(code);
  4803. }
  4804. updateContext(prevType) {
  4805. const {
  4806. context,
  4807. type
  4808. } = this.state;
  4809. if (type === 56 && prevType === 143) {
  4810. context.splice(-2, 2, types.j_cTag);
  4811. this.state.canStartJSXElement = false;
  4812. } else if (type === 143) {
  4813. context.push(types.j_oTag);
  4814. } else if (type === 144) {
  4815. const out = context[context.length - 1];
  4816. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  4817. context.pop();
  4818. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  4819. } else {
  4820. this.setContext(types.j_expr);
  4821. this.state.canStartJSXElement = true;
  4822. }
  4823. } else {
  4824. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  4825. }
  4826. }
  4827. };
  4828. class TypeScriptScope extends Scope {
  4829. constructor(...args) {
  4830. super(...args);
  4831. this.tsNames = new Map();
  4832. }
  4833. }
  4834. class TypeScriptScopeHandler extends ScopeHandler {
  4835. constructor(...args) {
  4836. super(...args);
  4837. this.importsStack = [];
  4838. }
  4839. createScope(flags) {
  4840. this.importsStack.push(new Set());
  4841. return new TypeScriptScope(flags);
  4842. }
  4843. enter(flags) {
  4844. if (flags === 256) {
  4845. this.importsStack.push(new Set());
  4846. }
  4847. super.enter(flags);
  4848. }
  4849. exit() {
  4850. const flags = super.exit();
  4851. if (flags === 256) {
  4852. this.importsStack.pop();
  4853. }
  4854. return flags;
  4855. }
  4856. hasImport(name, allowShadow) {
  4857. const len = this.importsStack.length;
  4858. if (this.importsStack[len - 1].has(name)) {
  4859. return true;
  4860. }
  4861. if (!allowShadow && len > 1) {
  4862. for (let i = 0; i < len - 1; i++) {
  4863. if (this.importsStack[i].has(name)) return true;
  4864. }
  4865. }
  4866. return false;
  4867. }
  4868. declareName(name, bindingType, loc) {
  4869. if (bindingType & 4096) {
  4870. if (this.hasImport(name, true)) {
  4871. this.parser.raise(Errors.VarRedeclaration, loc, {
  4872. identifierName: name
  4873. });
  4874. }
  4875. this.importsStack[this.importsStack.length - 1].add(name);
  4876. return;
  4877. }
  4878. const scope = this.currentScope();
  4879. let type = scope.tsNames.get(name) || 0;
  4880. if (bindingType & 1024) {
  4881. this.maybeExportDefined(scope, name);
  4882. scope.tsNames.set(name, type | 16);
  4883. return;
  4884. }
  4885. super.declareName(name, bindingType, loc);
  4886. if (bindingType & 2) {
  4887. if (!(bindingType & 1)) {
  4888. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4889. this.maybeExportDefined(scope, name);
  4890. }
  4891. type = type | 1;
  4892. }
  4893. if (bindingType & 256) {
  4894. type = type | 2;
  4895. }
  4896. if (bindingType & 512) {
  4897. type = type | 4;
  4898. }
  4899. if (bindingType & 128) {
  4900. type = type | 8;
  4901. }
  4902. if (type) scope.tsNames.set(name, type);
  4903. }
  4904. isRedeclaredInScope(scope, name, bindingType) {
  4905. const type = scope.tsNames.get(name);
  4906. if ((type & 2) > 0) {
  4907. if (bindingType & 256) {
  4908. const isConst = !!(bindingType & 512);
  4909. const wasConst = (type & 4) > 0;
  4910. return isConst !== wasConst;
  4911. }
  4912. return true;
  4913. }
  4914. if (bindingType & 128 && (type & 8) > 0) {
  4915. if (scope.names.get(name) & 2) {
  4916. return !!(bindingType & 1);
  4917. } else {
  4918. return false;
  4919. }
  4920. }
  4921. if (bindingType & 2 && (type & 1) > 0) {
  4922. return true;
  4923. }
  4924. return super.isRedeclaredInScope(scope, name, bindingType);
  4925. }
  4926. checkLocalExport(id) {
  4927. const {
  4928. name
  4929. } = id;
  4930. if (this.hasImport(name)) return;
  4931. const len = this.scopeStack.length;
  4932. for (let i = len - 1; i >= 0; i--) {
  4933. const scope = this.scopeStack[i];
  4934. const type = scope.tsNames.get(name);
  4935. if ((type & 1) > 0 || (type & 16) > 0) {
  4936. return;
  4937. }
  4938. }
  4939. super.checkLocalExport(id);
  4940. }
  4941. }
  4942. class ProductionParameterHandler {
  4943. constructor() {
  4944. this.stacks = [];
  4945. }
  4946. enter(flags) {
  4947. this.stacks.push(flags);
  4948. }
  4949. exit() {
  4950. this.stacks.pop();
  4951. }
  4952. currentFlags() {
  4953. return this.stacks[this.stacks.length - 1];
  4954. }
  4955. get hasAwait() {
  4956. return (this.currentFlags() & 2) > 0;
  4957. }
  4958. get hasYield() {
  4959. return (this.currentFlags() & 1) > 0;
  4960. }
  4961. get hasReturn() {
  4962. return (this.currentFlags() & 4) > 0;
  4963. }
  4964. get hasIn() {
  4965. return (this.currentFlags() & 8) > 0;
  4966. }
  4967. }
  4968. function functionFlags(isAsync, isGenerator) {
  4969. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  4970. }
  4971. class BaseParser {
  4972. constructor() {
  4973. this.sawUnambiguousESM = false;
  4974. this.ambiguousScriptDifferentAst = false;
  4975. }
  4976. sourceToOffsetPos(sourcePos) {
  4977. return sourcePos + this.startIndex;
  4978. }
  4979. offsetToSourcePos(offsetPos) {
  4980. return offsetPos - this.startIndex;
  4981. }
  4982. hasPlugin(pluginConfig) {
  4983. if (typeof pluginConfig === "string") {
  4984. return this.plugins.has(pluginConfig);
  4985. } else {
  4986. const [pluginName, pluginOptions] = pluginConfig;
  4987. if (!this.hasPlugin(pluginName)) {
  4988. return false;
  4989. }
  4990. const actualOptions = this.plugins.get(pluginName);
  4991. for (const key of Object.keys(pluginOptions)) {
  4992. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  4993. return false;
  4994. }
  4995. }
  4996. return true;
  4997. }
  4998. }
  4999. getPluginOption(plugin, name) {
  5000. var _this$plugins$get;
  5001. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  5002. }
  5003. }
  5004. function setTrailingComments(node, comments) {
  5005. if (node.trailingComments === undefined) {
  5006. node.trailingComments = comments;
  5007. } else {
  5008. node.trailingComments.unshift(...comments);
  5009. }
  5010. }
  5011. function setLeadingComments(node, comments) {
  5012. if (node.leadingComments === undefined) {
  5013. node.leadingComments = comments;
  5014. } else {
  5015. node.leadingComments.unshift(...comments);
  5016. }
  5017. }
  5018. function setInnerComments(node, comments) {
  5019. if (node.innerComments === undefined) {
  5020. node.innerComments = comments;
  5021. } else {
  5022. node.innerComments.unshift(...comments);
  5023. }
  5024. }
  5025. function adjustInnerComments(node, elements, commentWS) {
  5026. let lastElement = null;
  5027. let i = elements.length;
  5028. while (lastElement === null && i > 0) {
  5029. lastElement = elements[--i];
  5030. }
  5031. if (lastElement === null || lastElement.start > commentWS.start) {
  5032. setInnerComments(node, commentWS.comments);
  5033. } else {
  5034. setTrailingComments(lastElement, commentWS.comments);
  5035. }
  5036. }
  5037. class CommentsParser extends BaseParser {
  5038. addComment(comment) {
  5039. if (this.filename) comment.loc.filename = this.filename;
  5040. const {
  5041. commentsLen
  5042. } = this.state;
  5043. if (this.comments.length !== commentsLen) {
  5044. this.comments.length = commentsLen;
  5045. }
  5046. this.comments.push(comment);
  5047. this.state.commentsLen++;
  5048. }
  5049. processComment(node) {
  5050. const {
  5051. commentStack
  5052. } = this.state;
  5053. const commentStackLength = commentStack.length;
  5054. if (commentStackLength === 0) return;
  5055. let i = commentStackLength - 1;
  5056. const lastCommentWS = commentStack[i];
  5057. if (lastCommentWS.start === node.end) {
  5058. lastCommentWS.leadingNode = node;
  5059. i--;
  5060. }
  5061. const {
  5062. start: nodeStart
  5063. } = node;
  5064. for (; i >= 0; i--) {
  5065. const commentWS = commentStack[i];
  5066. const commentEnd = commentWS.end;
  5067. if (commentEnd > nodeStart) {
  5068. commentWS.containingNode = node;
  5069. this.finalizeComment(commentWS);
  5070. commentStack.splice(i, 1);
  5071. } else {
  5072. if (commentEnd === nodeStart) {
  5073. commentWS.trailingNode = node;
  5074. }
  5075. break;
  5076. }
  5077. }
  5078. }
  5079. finalizeComment(commentWS) {
  5080. const {
  5081. comments
  5082. } = commentWS;
  5083. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  5084. if (commentWS.leadingNode !== null) {
  5085. setTrailingComments(commentWS.leadingNode, comments);
  5086. }
  5087. if (commentWS.trailingNode !== null) {
  5088. setLeadingComments(commentWS.trailingNode, comments);
  5089. }
  5090. } else {
  5091. const {
  5092. containingNode: node,
  5093. start: commentStart
  5094. } = commentWS;
  5095. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  5096. switch (node.type) {
  5097. case "ObjectExpression":
  5098. case "ObjectPattern":
  5099. case "RecordExpression":
  5100. adjustInnerComments(node, node.properties, commentWS);
  5101. break;
  5102. case "CallExpression":
  5103. case "OptionalCallExpression":
  5104. adjustInnerComments(node, node.arguments, commentWS);
  5105. break;
  5106. case "FunctionDeclaration":
  5107. case "FunctionExpression":
  5108. case "ArrowFunctionExpression":
  5109. case "ObjectMethod":
  5110. case "ClassMethod":
  5111. case "ClassPrivateMethod":
  5112. adjustInnerComments(node, node.params, commentWS);
  5113. break;
  5114. case "ArrayExpression":
  5115. case "ArrayPattern":
  5116. case "TupleExpression":
  5117. adjustInnerComments(node, node.elements, commentWS);
  5118. break;
  5119. case "ExportNamedDeclaration":
  5120. case "ImportDeclaration":
  5121. adjustInnerComments(node, node.specifiers, commentWS);
  5122. break;
  5123. case "TSEnumDeclaration":
  5124. {
  5125. adjustInnerComments(node, node.members, commentWS);
  5126. }
  5127. break;
  5128. case "TSEnumBody":
  5129. adjustInnerComments(node, node.members, commentWS);
  5130. break;
  5131. default:
  5132. {
  5133. setInnerComments(node, comments);
  5134. }
  5135. }
  5136. } else {
  5137. setInnerComments(node, comments);
  5138. }
  5139. }
  5140. }
  5141. finalizeRemainingComments() {
  5142. const {
  5143. commentStack
  5144. } = this.state;
  5145. for (let i = commentStack.length - 1; i >= 0; i--) {
  5146. this.finalizeComment(commentStack[i]);
  5147. }
  5148. this.state.commentStack = [];
  5149. }
  5150. resetPreviousNodeTrailingComments(node) {
  5151. const {
  5152. commentStack
  5153. } = this.state;
  5154. const {
  5155. length
  5156. } = commentStack;
  5157. if (length === 0) return;
  5158. const commentWS = commentStack[length - 1];
  5159. if (commentWS.leadingNode === node) {
  5160. commentWS.leadingNode = null;
  5161. }
  5162. }
  5163. resetPreviousIdentifierLeadingComments(node) {
  5164. const {
  5165. commentStack
  5166. } = this.state;
  5167. const {
  5168. length
  5169. } = commentStack;
  5170. if (length === 0) return;
  5171. if (commentStack[length - 1].trailingNode === node) {
  5172. commentStack[length - 1].trailingNode = null;
  5173. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  5174. commentStack[length - 2].trailingNode = null;
  5175. }
  5176. }
  5177. takeSurroundingComments(node, start, end) {
  5178. const {
  5179. commentStack
  5180. } = this.state;
  5181. const commentStackLength = commentStack.length;
  5182. if (commentStackLength === 0) return;
  5183. let i = commentStackLength - 1;
  5184. for (; i >= 0; i--) {
  5185. const commentWS = commentStack[i];
  5186. const commentEnd = commentWS.end;
  5187. const commentStart = commentWS.start;
  5188. if (commentStart === end) {
  5189. commentWS.leadingNode = node;
  5190. } else if (commentEnd === start) {
  5191. commentWS.trailingNode = node;
  5192. } else if (commentEnd < start) {
  5193. break;
  5194. }
  5195. }
  5196. }
  5197. }
  5198. class State {
  5199. constructor() {
  5200. this.flags = 1024;
  5201. this.startIndex = void 0;
  5202. this.curLine = void 0;
  5203. this.lineStart = void 0;
  5204. this.startLoc = void 0;
  5205. this.endLoc = void 0;
  5206. this.errors = [];
  5207. this.potentialArrowAt = -1;
  5208. this.noArrowAt = [];
  5209. this.noArrowParamsConversionAt = [];
  5210. this.topicContext = {
  5211. maxNumOfResolvableTopics: 0,
  5212. maxTopicIndex: null
  5213. };
  5214. this.labels = [];
  5215. this.commentsLen = 0;
  5216. this.commentStack = [];
  5217. this.pos = 0;
  5218. this.type = 140;
  5219. this.value = null;
  5220. this.start = 0;
  5221. this.end = 0;
  5222. this.lastTokEndLoc = null;
  5223. this.lastTokStartLoc = null;
  5224. this.context = [types.brace];
  5225. this.firstInvalidTemplateEscapePos = null;
  5226. this.strictErrors = new Map();
  5227. this.tokensLength = 0;
  5228. }
  5229. get strict() {
  5230. return (this.flags & 1) > 0;
  5231. }
  5232. set strict(v) {
  5233. if (v) this.flags |= 1;else this.flags &= -2;
  5234. }
  5235. init({
  5236. strictMode,
  5237. sourceType,
  5238. startIndex,
  5239. startLine,
  5240. startColumn
  5241. }) {
  5242. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  5243. this.startIndex = startIndex;
  5244. this.curLine = startLine;
  5245. this.lineStart = -startColumn;
  5246. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  5247. }
  5248. get maybeInArrowParameters() {
  5249. return (this.flags & 2) > 0;
  5250. }
  5251. set maybeInArrowParameters(v) {
  5252. if (v) this.flags |= 2;else this.flags &= -3;
  5253. }
  5254. get inType() {
  5255. return (this.flags & 4) > 0;
  5256. }
  5257. set inType(v) {
  5258. if (v) this.flags |= 4;else this.flags &= -5;
  5259. }
  5260. get noAnonFunctionType() {
  5261. return (this.flags & 8) > 0;
  5262. }
  5263. set noAnonFunctionType(v) {
  5264. if (v) this.flags |= 8;else this.flags &= -9;
  5265. }
  5266. get hasFlowComment() {
  5267. return (this.flags & 16) > 0;
  5268. }
  5269. set hasFlowComment(v) {
  5270. if (v) this.flags |= 16;else this.flags &= -17;
  5271. }
  5272. get isAmbientContext() {
  5273. return (this.flags & 32) > 0;
  5274. }
  5275. set isAmbientContext(v) {
  5276. if (v) this.flags |= 32;else this.flags &= -33;
  5277. }
  5278. get inAbstractClass() {
  5279. return (this.flags & 64) > 0;
  5280. }
  5281. set inAbstractClass(v) {
  5282. if (v) this.flags |= 64;else this.flags &= -65;
  5283. }
  5284. get inDisallowConditionalTypesContext() {
  5285. return (this.flags & 128) > 0;
  5286. }
  5287. set inDisallowConditionalTypesContext(v) {
  5288. if (v) this.flags |= 128;else this.flags &= -129;
  5289. }
  5290. get soloAwait() {
  5291. return (this.flags & 256) > 0;
  5292. }
  5293. set soloAwait(v) {
  5294. if (v) this.flags |= 256;else this.flags &= -257;
  5295. }
  5296. get inFSharpPipelineDirectBody() {
  5297. return (this.flags & 512) > 0;
  5298. }
  5299. set inFSharpPipelineDirectBody(v) {
  5300. if (v) this.flags |= 512;else this.flags &= -513;
  5301. }
  5302. get canStartJSXElement() {
  5303. return (this.flags & 1024) > 0;
  5304. }
  5305. set canStartJSXElement(v) {
  5306. if (v) this.flags |= 1024;else this.flags &= -1025;
  5307. }
  5308. get containsEsc() {
  5309. return (this.flags & 2048) > 0;
  5310. }
  5311. set containsEsc(v) {
  5312. if (v) this.flags |= 2048;else this.flags &= -2049;
  5313. }
  5314. get hasTopLevelAwait() {
  5315. return (this.flags & 4096) > 0;
  5316. }
  5317. set hasTopLevelAwait(v) {
  5318. if (v) this.flags |= 4096;else this.flags &= -4097;
  5319. }
  5320. curPosition() {
  5321. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  5322. }
  5323. clone() {
  5324. const state = new State();
  5325. state.flags = this.flags;
  5326. state.startIndex = this.startIndex;
  5327. state.curLine = this.curLine;
  5328. state.lineStart = this.lineStart;
  5329. state.startLoc = this.startLoc;
  5330. state.endLoc = this.endLoc;
  5331. state.errors = this.errors.slice();
  5332. state.potentialArrowAt = this.potentialArrowAt;
  5333. state.noArrowAt = this.noArrowAt.slice();
  5334. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  5335. state.topicContext = this.topicContext;
  5336. state.labels = this.labels.slice();
  5337. state.commentsLen = this.commentsLen;
  5338. state.commentStack = this.commentStack.slice();
  5339. state.pos = this.pos;
  5340. state.type = this.type;
  5341. state.value = this.value;
  5342. state.start = this.start;
  5343. state.end = this.end;
  5344. state.lastTokEndLoc = this.lastTokEndLoc;
  5345. state.lastTokStartLoc = this.lastTokStartLoc;
  5346. state.context = this.context.slice();
  5347. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  5348. state.strictErrors = this.strictErrors;
  5349. state.tokensLength = this.tokensLength;
  5350. return state;
  5351. }
  5352. }
  5353. var _isDigit = function isDigit(code) {
  5354. return code >= 48 && code <= 57;
  5355. };
  5356. const forbiddenNumericSeparatorSiblings = {
  5357. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  5358. hex: new Set([46, 88, 95, 120])
  5359. };
  5360. const isAllowedNumericSeparatorSibling = {
  5361. bin: ch => ch === 48 || ch === 49,
  5362. oct: ch => ch >= 48 && ch <= 55,
  5363. dec: ch => ch >= 48 && ch <= 57,
  5364. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  5365. };
  5366. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  5367. const initialPos = pos;
  5368. const initialLineStart = lineStart;
  5369. const initialCurLine = curLine;
  5370. let out = "";
  5371. let firstInvalidLoc = null;
  5372. let chunkStart = pos;
  5373. const {
  5374. length
  5375. } = input;
  5376. for (;;) {
  5377. if (pos >= length) {
  5378. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5379. out += input.slice(chunkStart, pos);
  5380. break;
  5381. }
  5382. const ch = input.charCodeAt(pos);
  5383. if (isStringEnd(type, ch, input, pos)) {
  5384. out += input.slice(chunkStart, pos);
  5385. break;
  5386. }
  5387. if (ch === 92) {
  5388. out += input.slice(chunkStart, pos);
  5389. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  5390. if (res.ch === null && !firstInvalidLoc) {
  5391. firstInvalidLoc = {
  5392. pos,
  5393. lineStart,
  5394. curLine
  5395. };
  5396. } else {
  5397. out += res.ch;
  5398. }
  5399. ({
  5400. pos,
  5401. lineStart,
  5402. curLine
  5403. } = res);
  5404. chunkStart = pos;
  5405. } else if (ch === 8232 || ch === 8233) {
  5406. ++pos;
  5407. ++curLine;
  5408. lineStart = pos;
  5409. } else if (ch === 10 || ch === 13) {
  5410. if (type === "template") {
  5411. out += input.slice(chunkStart, pos) + "\n";
  5412. ++pos;
  5413. if (ch === 13 && input.charCodeAt(pos) === 10) {
  5414. ++pos;
  5415. }
  5416. ++curLine;
  5417. chunkStart = lineStart = pos;
  5418. } else {
  5419. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5420. }
  5421. } else {
  5422. ++pos;
  5423. }
  5424. }
  5425. return {
  5426. pos,
  5427. str: out,
  5428. firstInvalidLoc,
  5429. lineStart,
  5430. curLine,
  5431. containsInvalid: !!firstInvalidLoc
  5432. };
  5433. }
  5434. function isStringEnd(type, ch, input, pos) {
  5435. if (type === "template") {
  5436. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  5437. }
  5438. return ch === (type === "double" ? 34 : 39);
  5439. }
  5440. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  5441. const throwOnInvalid = !inTemplate;
  5442. pos++;
  5443. const res = ch => ({
  5444. pos,
  5445. ch,
  5446. lineStart,
  5447. curLine
  5448. });
  5449. const ch = input.charCodeAt(pos++);
  5450. switch (ch) {
  5451. case 110:
  5452. return res("\n");
  5453. case 114:
  5454. return res("\r");
  5455. case 120:
  5456. {
  5457. let code;
  5458. ({
  5459. code,
  5460. pos
  5461. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  5462. return res(code === null ? null : String.fromCharCode(code));
  5463. }
  5464. case 117:
  5465. {
  5466. let code;
  5467. ({
  5468. code,
  5469. pos
  5470. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  5471. return res(code === null ? null : String.fromCodePoint(code));
  5472. }
  5473. case 116:
  5474. return res("\t");
  5475. case 98:
  5476. return res("\b");
  5477. case 118:
  5478. return res("\u000b");
  5479. case 102:
  5480. return res("\f");
  5481. case 13:
  5482. if (input.charCodeAt(pos) === 10) {
  5483. ++pos;
  5484. }
  5485. case 10:
  5486. lineStart = pos;
  5487. ++curLine;
  5488. case 8232:
  5489. case 8233:
  5490. return res("");
  5491. case 56:
  5492. case 57:
  5493. if (inTemplate) {
  5494. return res(null);
  5495. } else {
  5496. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  5497. }
  5498. default:
  5499. if (ch >= 48 && ch <= 55) {
  5500. const startPos = pos - 1;
  5501. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  5502. let octalStr = match[0];
  5503. let octal = parseInt(octalStr, 8);
  5504. if (octal > 255) {
  5505. octalStr = octalStr.slice(0, -1);
  5506. octal = parseInt(octalStr, 8);
  5507. }
  5508. pos += octalStr.length - 1;
  5509. const next = input.charCodeAt(pos);
  5510. if (octalStr !== "0" || next === 56 || next === 57) {
  5511. if (inTemplate) {
  5512. return res(null);
  5513. } else {
  5514. errors.strictNumericEscape(startPos, lineStart, curLine);
  5515. }
  5516. }
  5517. return res(String.fromCharCode(octal));
  5518. }
  5519. return res(String.fromCharCode(ch));
  5520. }
  5521. }
  5522. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  5523. const initialPos = pos;
  5524. let n;
  5525. ({
  5526. n,
  5527. pos
  5528. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  5529. if (n === null) {
  5530. if (throwOnInvalid) {
  5531. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  5532. } else {
  5533. pos = initialPos - 1;
  5534. }
  5535. }
  5536. return {
  5537. code: n,
  5538. pos
  5539. };
  5540. }
  5541. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  5542. const start = pos;
  5543. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  5544. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  5545. let invalid = false;
  5546. let total = 0;
  5547. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  5548. const code = input.charCodeAt(pos);
  5549. let val;
  5550. if (code === 95 && allowNumSeparator !== "bail") {
  5551. const prev = input.charCodeAt(pos - 1);
  5552. const next = input.charCodeAt(pos + 1);
  5553. if (!allowNumSeparator) {
  5554. if (bailOnError) return {
  5555. n: null,
  5556. pos
  5557. };
  5558. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  5559. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  5560. if (bailOnError) return {
  5561. n: null,
  5562. pos
  5563. };
  5564. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  5565. }
  5566. ++pos;
  5567. continue;
  5568. }
  5569. if (code >= 97) {
  5570. val = code - 97 + 10;
  5571. } else if (code >= 65) {
  5572. val = code - 65 + 10;
  5573. } else if (_isDigit(code)) {
  5574. val = code - 48;
  5575. } else {
  5576. val = Infinity;
  5577. }
  5578. if (val >= radix) {
  5579. if (val <= 9 && bailOnError) {
  5580. return {
  5581. n: null,
  5582. pos
  5583. };
  5584. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  5585. val = 0;
  5586. } else if (forceLen) {
  5587. val = 0;
  5588. invalid = true;
  5589. } else {
  5590. break;
  5591. }
  5592. }
  5593. ++pos;
  5594. total = total * radix + val;
  5595. }
  5596. if (pos === start || len != null && pos - start !== len || invalid) {
  5597. return {
  5598. n: null,
  5599. pos
  5600. };
  5601. }
  5602. return {
  5603. n: total,
  5604. pos
  5605. };
  5606. }
  5607. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  5608. const ch = input.charCodeAt(pos);
  5609. let code;
  5610. if (ch === 123) {
  5611. ++pos;
  5612. ({
  5613. code,
  5614. pos
  5615. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  5616. ++pos;
  5617. if (code !== null && code > 0x10ffff) {
  5618. if (throwOnInvalid) {
  5619. errors.invalidCodePoint(pos, lineStart, curLine);
  5620. } else {
  5621. return {
  5622. code: null,
  5623. pos
  5624. };
  5625. }
  5626. }
  5627. } else {
  5628. ({
  5629. code,
  5630. pos
  5631. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  5632. }
  5633. return {
  5634. code,
  5635. pos
  5636. };
  5637. }
  5638. function buildPosition(pos, lineStart, curLine) {
  5639. return new Position(curLine, pos - lineStart, pos);
  5640. }
  5641. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  5642. class Token {
  5643. constructor(state) {
  5644. const startIndex = state.startIndex || 0;
  5645. this.type = state.type;
  5646. this.value = state.value;
  5647. this.start = startIndex + state.start;
  5648. this.end = startIndex + state.end;
  5649. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  5650. }
  5651. }
  5652. class Tokenizer extends CommentsParser {
  5653. constructor(options, input) {
  5654. super();
  5655. this.isLookahead = void 0;
  5656. this.tokens = [];
  5657. this.errorHandlers_readInt = {
  5658. invalidDigit: (pos, lineStart, curLine, radix) => {
  5659. if (!(this.optionFlags & 2048)) return false;
  5660. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  5661. radix
  5662. });
  5663. return true;
  5664. },
  5665. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  5666. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  5667. };
  5668. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  5669. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  5670. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  5671. });
  5672. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  5673. strictNumericEscape: (pos, lineStart, curLine) => {
  5674. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  5675. },
  5676. unterminated: (pos, lineStart, curLine) => {
  5677. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  5678. }
  5679. });
  5680. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  5681. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  5682. unterminated: (pos, lineStart, curLine) => {
  5683. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  5684. }
  5685. });
  5686. this.state = new State();
  5687. this.state.init(options);
  5688. this.input = input;
  5689. this.length = input.length;
  5690. this.comments = [];
  5691. this.isLookahead = false;
  5692. }
  5693. pushToken(token) {
  5694. this.tokens.length = this.state.tokensLength;
  5695. this.tokens.push(token);
  5696. ++this.state.tokensLength;
  5697. }
  5698. next() {
  5699. this.checkKeywordEscapes();
  5700. if (this.optionFlags & 256) {
  5701. this.pushToken(new Token(this.state));
  5702. }
  5703. this.state.lastTokEndLoc = this.state.endLoc;
  5704. this.state.lastTokStartLoc = this.state.startLoc;
  5705. this.nextToken();
  5706. }
  5707. eat(type) {
  5708. if (this.match(type)) {
  5709. this.next();
  5710. return true;
  5711. } else {
  5712. return false;
  5713. }
  5714. }
  5715. match(type) {
  5716. return this.state.type === type;
  5717. }
  5718. createLookaheadState(state) {
  5719. return {
  5720. pos: state.pos,
  5721. value: null,
  5722. type: state.type,
  5723. start: state.start,
  5724. end: state.end,
  5725. context: [this.curContext()],
  5726. inType: state.inType,
  5727. startLoc: state.startLoc,
  5728. lastTokEndLoc: state.lastTokEndLoc,
  5729. curLine: state.curLine,
  5730. lineStart: state.lineStart,
  5731. curPosition: state.curPosition
  5732. };
  5733. }
  5734. lookahead() {
  5735. const old = this.state;
  5736. this.state = this.createLookaheadState(old);
  5737. this.isLookahead = true;
  5738. this.nextToken();
  5739. this.isLookahead = false;
  5740. const curr = this.state;
  5741. this.state = old;
  5742. return curr;
  5743. }
  5744. nextTokenStart() {
  5745. return this.nextTokenStartSince(this.state.pos);
  5746. }
  5747. nextTokenStartSince(pos) {
  5748. skipWhiteSpace.lastIndex = pos;
  5749. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  5750. }
  5751. lookaheadCharCode() {
  5752. return this.lookaheadCharCodeSince(this.state.pos);
  5753. }
  5754. lookaheadCharCodeSince(pos) {
  5755. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  5756. }
  5757. nextTokenInLineStart() {
  5758. return this.nextTokenInLineStartSince(this.state.pos);
  5759. }
  5760. nextTokenInLineStartSince(pos) {
  5761. skipWhiteSpaceInLine.lastIndex = pos;
  5762. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  5763. }
  5764. lookaheadInLineCharCode() {
  5765. return this.input.charCodeAt(this.nextTokenInLineStart());
  5766. }
  5767. codePointAtPos(pos) {
  5768. let cp = this.input.charCodeAt(pos);
  5769. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  5770. const trail = this.input.charCodeAt(pos);
  5771. if ((trail & 0xfc00) === 0xdc00) {
  5772. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  5773. }
  5774. }
  5775. return cp;
  5776. }
  5777. setStrict(strict) {
  5778. this.state.strict = strict;
  5779. if (strict) {
  5780. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  5781. this.state.strictErrors.clear();
  5782. }
  5783. }
  5784. curContext() {
  5785. return this.state.context[this.state.context.length - 1];
  5786. }
  5787. nextToken() {
  5788. this.skipSpace();
  5789. this.state.start = this.state.pos;
  5790. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  5791. if (this.state.pos >= this.length) {
  5792. this.finishToken(140);
  5793. return;
  5794. }
  5795. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  5796. }
  5797. skipBlockComment(commentEnd) {
  5798. let startLoc;
  5799. if (!this.isLookahead) startLoc = this.state.curPosition();
  5800. const start = this.state.pos;
  5801. const end = this.input.indexOf(commentEnd, start + 2);
  5802. if (end === -1) {
  5803. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5804. }
  5805. this.state.pos = end + commentEnd.length;
  5806. lineBreakG.lastIndex = start + 2;
  5807. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  5808. ++this.state.curLine;
  5809. this.state.lineStart = lineBreakG.lastIndex;
  5810. }
  5811. if (this.isLookahead) return;
  5812. const comment = {
  5813. type: "CommentBlock",
  5814. value: this.input.slice(start + 2, end),
  5815. start: this.sourceToOffsetPos(start),
  5816. end: this.sourceToOffsetPos(end + commentEnd.length),
  5817. loc: new SourceLocation(startLoc, this.state.curPosition())
  5818. };
  5819. if (this.optionFlags & 256) this.pushToken(comment);
  5820. return comment;
  5821. }
  5822. skipLineComment(startSkip) {
  5823. const start = this.state.pos;
  5824. let startLoc;
  5825. if (!this.isLookahead) startLoc = this.state.curPosition();
  5826. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  5827. if (this.state.pos < this.length) {
  5828. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  5829. ch = this.input.charCodeAt(this.state.pos);
  5830. }
  5831. }
  5832. if (this.isLookahead) return;
  5833. const end = this.state.pos;
  5834. const value = this.input.slice(start + startSkip, end);
  5835. const comment = {
  5836. type: "CommentLine",
  5837. value,
  5838. start: this.sourceToOffsetPos(start),
  5839. end: this.sourceToOffsetPos(end),
  5840. loc: new SourceLocation(startLoc, this.state.curPosition())
  5841. };
  5842. if (this.optionFlags & 256) this.pushToken(comment);
  5843. return comment;
  5844. }
  5845. skipSpace() {
  5846. const spaceStart = this.state.pos;
  5847. const comments = this.optionFlags & 4096 ? [] : null;
  5848. loop: while (this.state.pos < this.length) {
  5849. const ch = this.input.charCodeAt(this.state.pos);
  5850. switch (ch) {
  5851. case 32:
  5852. case 160:
  5853. case 9:
  5854. ++this.state.pos;
  5855. break;
  5856. case 13:
  5857. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  5858. ++this.state.pos;
  5859. }
  5860. case 10:
  5861. case 8232:
  5862. case 8233:
  5863. ++this.state.pos;
  5864. ++this.state.curLine;
  5865. this.state.lineStart = this.state.pos;
  5866. break;
  5867. case 47:
  5868. switch (this.input.charCodeAt(this.state.pos + 1)) {
  5869. case 42:
  5870. {
  5871. const comment = this.skipBlockComment("*/");
  5872. if (comment !== undefined) {
  5873. this.addComment(comment);
  5874. comments == null || comments.push(comment);
  5875. }
  5876. break;
  5877. }
  5878. case 47:
  5879. {
  5880. const comment = this.skipLineComment(2);
  5881. if (comment !== undefined) {
  5882. this.addComment(comment);
  5883. comments == null || comments.push(comment);
  5884. }
  5885. break;
  5886. }
  5887. default:
  5888. break loop;
  5889. }
  5890. break;
  5891. default:
  5892. if (isWhitespace(ch)) {
  5893. ++this.state.pos;
  5894. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  5895. const pos = this.state.pos;
  5896. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  5897. const comment = this.skipLineComment(3);
  5898. if (comment !== undefined) {
  5899. this.addComment(comment);
  5900. comments == null || comments.push(comment);
  5901. }
  5902. } else {
  5903. break loop;
  5904. }
  5905. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  5906. const pos = this.state.pos;
  5907. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  5908. const comment = this.skipLineComment(4);
  5909. if (comment !== undefined) {
  5910. this.addComment(comment);
  5911. comments == null || comments.push(comment);
  5912. }
  5913. } else {
  5914. break loop;
  5915. }
  5916. } else {
  5917. break loop;
  5918. }
  5919. }
  5920. }
  5921. if ((comments == null ? void 0 : comments.length) > 0) {
  5922. const end = this.state.pos;
  5923. const commentWhitespace = {
  5924. start: this.sourceToOffsetPos(spaceStart),
  5925. end: this.sourceToOffsetPos(end),
  5926. comments,
  5927. leadingNode: null,
  5928. trailingNode: null,
  5929. containingNode: null
  5930. };
  5931. this.state.commentStack.push(commentWhitespace);
  5932. }
  5933. }
  5934. finishToken(type, val) {
  5935. this.state.end = this.state.pos;
  5936. this.state.endLoc = this.state.curPosition();
  5937. const prevType = this.state.type;
  5938. this.state.type = type;
  5939. this.state.value = val;
  5940. if (!this.isLookahead) {
  5941. this.updateContext(prevType);
  5942. }
  5943. }
  5944. replaceToken(type) {
  5945. this.state.type = type;
  5946. this.updateContext();
  5947. }
  5948. readToken_numberSign() {
  5949. if (this.state.pos === 0 && this.readToken_interpreter()) {
  5950. return;
  5951. }
  5952. const nextPos = this.state.pos + 1;
  5953. const next = this.codePointAtPos(nextPos);
  5954. if (next >= 48 && next <= 57) {
  5955. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  5956. }
  5957. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  5958. this.expectPlugin("recordAndTuple");
  5959. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  5960. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  5961. }
  5962. this.state.pos += 2;
  5963. if (next === 123) {
  5964. this.finishToken(7);
  5965. } else {
  5966. this.finishToken(1);
  5967. }
  5968. } else if (isIdentifierStart(next)) {
  5969. ++this.state.pos;
  5970. this.finishToken(139, this.readWord1(next));
  5971. } else if (next === 92) {
  5972. ++this.state.pos;
  5973. this.finishToken(139, this.readWord1());
  5974. } else {
  5975. this.finishOp(27, 1);
  5976. }
  5977. }
  5978. readToken_dot() {
  5979. const next = this.input.charCodeAt(this.state.pos + 1);
  5980. if (next >= 48 && next <= 57) {
  5981. this.readNumber(true);
  5982. return;
  5983. }
  5984. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  5985. this.state.pos += 3;
  5986. this.finishToken(21);
  5987. } else {
  5988. ++this.state.pos;
  5989. this.finishToken(16);
  5990. }
  5991. }
  5992. readToken_slash() {
  5993. const next = this.input.charCodeAt(this.state.pos + 1);
  5994. if (next === 61) {
  5995. this.finishOp(31, 2);
  5996. } else {
  5997. this.finishOp(56, 1);
  5998. }
  5999. }
  6000. readToken_interpreter() {
  6001. if (this.state.pos !== 0 || this.length < 2) return false;
  6002. let ch = this.input.charCodeAt(this.state.pos + 1);
  6003. if (ch !== 33) return false;
  6004. const start = this.state.pos;
  6005. this.state.pos += 1;
  6006. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  6007. ch = this.input.charCodeAt(this.state.pos);
  6008. }
  6009. const value = this.input.slice(start + 2, this.state.pos);
  6010. this.finishToken(28, value);
  6011. return true;
  6012. }
  6013. readToken_mult_modulo(code) {
  6014. let type = code === 42 ? 55 : 54;
  6015. let width = 1;
  6016. let next = this.input.charCodeAt(this.state.pos + 1);
  6017. if (code === 42 && next === 42) {
  6018. width++;
  6019. next = this.input.charCodeAt(this.state.pos + 2);
  6020. type = 57;
  6021. }
  6022. if (next === 61 && !this.state.inType) {
  6023. width++;
  6024. type = code === 37 ? 33 : 30;
  6025. }
  6026. this.finishOp(type, width);
  6027. }
  6028. readToken_pipe_amp(code) {
  6029. const next = this.input.charCodeAt(this.state.pos + 1);
  6030. if (next === code) {
  6031. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  6032. this.finishOp(30, 3);
  6033. } else {
  6034. this.finishOp(code === 124 ? 41 : 42, 2);
  6035. }
  6036. return;
  6037. }
  6038. if (code === 124) {
  6039. if (next === 62) {
  6040. this.finishOp(39, 2);
  6041. return;
  6042. }
  6043. if (this.hasPlugin("recordAndTuple") && next === 125) {
  6044. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6045. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6046. }
  6047. this.state.pos += 2;
  6048. this.finishToken(9);
  6049. return;
  6050. }
  6051. if (this.hasPlugin("recordAndTuple") && next === 93) {
  6052. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6053. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6054. }
  6055. this.state.pos += 2;
  6056. this.finishToken(4);
  6057. return;
  6058. }
  6059. }
  6060. if (next === 61) {
  6061. this.finishOp(30, 2);
  6062. return;
  6063. }
  6064. this.finishOp(code === 124 ? 43 : 45, 1);
  6065. }
  6066. readToken_caret() {
  6067. const next = this.input.charCodeAt(this.state.pos + 1);
  6068. if (next === 61 && !this.state.inType) {
  6069. this.finishOp(32, 2);
  6070. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  6071. proposal: "hack",
  6072. topicToken: "^^"
  6073. }])) {
  6074. this.finishOp(37, 2);
  6075. const lookaheadCh = this.input.codePointAt(this.state.pos);
  6076. if (lookaheadCh === 94) {
  6077. this.unexpected();
  6078. }
  6079. } else {
  6080. this.finishOp(44, 1);
  6081. }
  6082. }
  6083. readToken_atSign() {
  6084. const next = this.input.charCodeAt(this.state.pos + 1);
  6085. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  6086. proposal: "hack",
  6087. topicToken: "@@"
  6088. }])) {
  6089. this.finishOp(38, 2);
  6090. } else {
  6091. this.finishOp(26, 1);
  6092. }
  6093. }
  6094. readToken_plus_min(code) {
  6095. const next = this.input.charCodeAt(this.state.pos + 1);
  6096. if (next === code) {
  6097. this.finishOp(34, 2);
  6098. return;
  6099. }
  6100. if (next === 61) {
  6101. this.finishOp(30, 2);
  6102. } else {
  6103. this.finishOp(53, 1);
  6104. }
  6105. }
  6106. readToken_lt() {
  6107. const {
  6108. pos
  6109. } = this.state;
  6110. const next = this.input.charCodeAt(pos + 1);
  6111. if (next === 60) {
  6112. if (this.input.charCodeAt(pos + 2) === 61) {
  6113. this.finishOp(30, 3);
  6114. return;
  6115. }
  6116. this.finishOp(51, 2);
  6117. return;
  6118. }
  6119. if (next === 61) {
  6120. this.finishOp(49, 2);
  6121. return;
  6122. }
  6123. this.finishOp(47, 1);
  6124. }
  6125. readToken_gt() {
  6126. const {
  6127. pos
  6128. } = this.state;
  6129. const next = this.input.charCodeAt(pos + 1);
  6130. if (next === 62) {
  6131. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  6132. if (this.input.charCodeAt(pos + size) === 61) {
  6133. this.finishOp(30, size + 1);
  6134. return;
  6135. }
  6136. this.finishOp(52, size);
  6137. return;
  6138. }
  6139. if (next === 61) {
  6140. this.finishOp(49, 2);
  6141. return;
  6142. }
  6143. this.finishOp(48, 1);
  6144. }
  6145. readToken_eq_excl(code) {
  6146. const next = this.input.charCodeAt(this.state.pos + 1);
  6147. if (next === 61) {
  6148. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  6149. return;
  6150. }
  6151. if (code === 61 && next === 62) {
  6152. this.state.pos += 2;
  6153. this.finishToken(19);
  6154. return;
  6155. }
  6156. this.finishOp(code === 61 ? 29 : 35, 1);
  6157. }
  6158. readToken_question() {
  6159. const next = this.input.charCodeAt(this.state.pos + 1);
  6160. const next2 = this.input.charCodeAt(this.state.pos + 2);
  6161. if (next === 63) {
  6162. if (next2 === 61) {
  6163. this.finishOp(30, 3);
  6164. } else {
  6165. this.finishOp(40, 2);
  6166. }
  6167. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  6168. this.state.pos += 2;
  6169. this.finishToken(18);
  6170. } else {
  6171. ++this.state.pos;
  6172. this.finishToken(17);
  6173. }
  6174. }
  6175. getTokenFromCode(code) {
  6176. switch (code) {
  6177. case 46:
  6178. this.readToken_dot();
  6179. return;
  6180. case 40:
  6181. ++this.state.pos;
  6182. this.finishToken(10);
  6183. return;
  6184. case 41:
  6185. ++this.state.pos;
  6186. this.finishToken(11);
  6187. return;
  6188. case 59:
  6189. ++this.state.pos;
  6190. this.finishToken(13);
  6191. return;
  6192. case 44:
  6193. ++this.state.pos;
  6194. this.finishToken(12);
  6195. return;
  6196. case 91:
  6197. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6198. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6199. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6200. }
  6201. this.state.pos += 2;
  6202. this.finishToken(2);
  6203. } else {
  6204. ++this.state.pos;
  6205. this.finishToken(0);
  6206. }
  6207. return;
  6208. case 93:
  6209. ++this.state.pos;
  6210. this.finishToken(3);
  6211. return;
  6212. case 123:
  6213. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6214. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6215. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6216. }
  6217. this.state.pos += 2;
  6218. this.finishToken(6);
  6219. } else {
  6220. ++this.state.pos;
  6221. this.finishToken(5);
  6222. }
  6223. return;
  6224. case 125:
  6225. ++this.state.pos;
  6226. this.finishToken(8);
  6227. return;
  6228. case 58:
  6229. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  6230. this.finishOp(15, 2);
  6231. } else {
  6232. ++this.state.pos;
  6233. this.finishToken(14);
  6234. }
  6235. return;
  6236. case 63:
  6237. this.readToken_question();
  6238. return;
  6239. case 96:
  6240. this.readTemplateToken();
  6241. return;
  6242. case 48:
  6243. {
  6244. const next = this.input.charCodeAt(this.state.pos + 1);
  6245. if (next === 120 || next === 88) {
  6246. this.readRadixNumber(16);
  6247. return;
  6248. }
  6249. if (next === 111 || next === 79) {
  6250. this.readRadixNumber(8);
  6251. return;
  6252. }
  6253. if (next === 98 || next === 66) {
  6254. this.readRadixNumber(2);
  6255. return;
  6256. }
  6257. }
  6258. case 49:
  6259. case 50:
  6260. case 51:
  6261. case 52:
  6262. case 53:
  6263. case 54:
  6264. case 55:
  6265. case 56:
  6266. case 57:
  6267. this.readNumber(false);
  6268. return;
  6269. case 34:
  6270. case 39:
  6271. this.readString(code);
  6272. return;
  6273. case 47:
  6274. this.readToken_slash();
  6275. return;
  6276. case 37:
  6277. case 42:
  6278. this.readToken_mult_modulo(code);
  6279. return;
  6280. case 124:
  6281. case 38:
  6282. this.readToken_pipe_amp(code);
  6283. return;
  6284. case 94:
  6285. this.readToken_caret();
  6286. return;
  6287. case 43:
  6288. case 45:
  6289. this.readToken_plus_min(code);
  6290. return;
  6291. case 60:
  6292. this.readToken_lt();
  6293. return;
  6294. case 62:
  6295. this.readToken_gt();
  6296. return;
  6297. case 61:
  6298. case 33:
  6299. this.readToken_eq_excl(code);
  6300. return;
  6301. case 126:
  6302. this.finishOp(36, 1);
  6303. return;
  6304. case 64:
  6305. this.readToken_atSign();
  6306. return;
  6307. case 35:
  6308. this.readToken_numberSign();
  6309. return;
  6310. case 92:
  6311. this.readWord();
  6312. return;
  6313. default:
  6314. if (isIdentifierStart(code)) {
  6315. this.readWord(code);
  6316. return;
  6317. }
  6318. }
  6319. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  6320. unexpected: String.fromCodePoint(code)
  6321. });
  6322. }
  6323. finishOp(type, size) {
  6324. const str = this.input.slice(this.state.pos, this.state.pos + size);
  6325. this.state.pos += size;
  6326. this.finishToken(type, str);
  6327. }
  6328. readRegexp() {
  6329. const startLoc = this.state.startLoc;
  6330. const start = this.state.start + 1;
  6331. let escaped, inClass;
  6332. let {
  6333. pos
  6334. } = this.state;
  6335. for (;; ++pos) {
  6336. if (pos >= this.length) {
  6337. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6338. }
  6339. const ch = this.input.charCodeAt(pos);
  6340. if (isNewLine(ch)) {
  6341. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6342. }
  6343. if (escaped) {
  6344. escaped = false;
  6345. } else {
  6346. if (ch === 91) {
  6347. inClass = true;
  6348. } else if (ch === 93 && inClass) {
  6349. inClass = false;
  6350. } else if (ch === 47 && !inClass) {
  6351. break;
  6352. }
  6353. escaped = ch === 92;
  6354. }
  6355. }
  6356. const content = this.input.slice(start, pos);
  6357. ++pos;
  6358. let mods = "";
  6359. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  6360. while (pos < this.length) {
  6361. const cp = this.codePointAtPos(pos);
  6362. const char = String.fromCharCode(cp);
  6363. if (VALID_REGEX_FLAGS.has(cp)) {
  6364. if (cp === 118) {
  6365. if (mods.includes("u")) {
  6366. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6367. }
  6368. } else if (cp === 117) {
  6369. if (mods.includes("v")) {
  6370. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6371. }
  6372. }
  6373. if (mods.includes(char)) {
  6374. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  6375. }
  6376. } else if (isIdentifierChar(cp) || cp === 92) {
  6377. this.raise(Errors.MalformedRegExpFlags, nextPos());
  6378. } else {
  6379. break;
  6380. }
  6381. ++pos;
  6382. mods += char;
  6383. }
  6384. this.state.pos = pos;
  6385. this.finishToken(138, {
  6386. pattern: content,
  6387. flags: mods
  6388. });
  6389. }
  6390. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  6391. const {
  6392. n,
  6393. pos
  6394. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  6395. this.state.pos = pos;
  6396. return n;
  6397. }
  6398. readRadixNumber(radix) {
  6399. const start = this.state.pos;
  6400. const startLoc = this.state.curPosition();
  6401. let isBigInt = false;
  6402. this.state.pos += 2;
  6403. const val = this.readInt(radix);
  6404. if (val == null) {
  6405. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  6406. radix
  6407. });
  6408. }
  6409. const next = this.input.charCodeAt(this.state.pos);
  6410. if (next === 110) {
  6411. ++this.state.pos;
  6412. isBigInt = true;
  6413. } else if (next === 109) {
  6414. throw this.raise(Errors.InvalidDecimal, startLoc);
  6415. }
  6416. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6417. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6418. }
  6419. if (isBigInt) {
  6420. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  6421. this.finishToken(136, str);
  6422. return;
  6423. }
  6424. this.finishToken(135, val);
  6425. }
  6426. readNumber(startsWithDot) {
  6427. const start = this.state.pos;
  6428. const startLoc = this.state.curPosition();
  6429. let isFloat = false;
  6430. let isBigInt = false;
  6431. let hasExponent = false;
  6432. let isOctal = false;
  6433. if (!startsWithDot && this.readInt(10) === null) {
  6434. this.raise(Errors.InvalidNumber, this.state.curPosition());
  6435. }
  6436. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  6437. if (hasLeadingZero) {
  6438. const integer = this.input.slice(start, this.state.pos);
  6439. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  6440. if (!this.state.strict) {
  6441. const underscorePos = integer.indexOf("_");
  6442. if (underscorePos > 0) {
  6443. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  6444. }
  6445. }
  6446. isOctal = hasLeadingZero && !/[89]/.test(integer);
  6447. }
  6448. let next = this.input.charCodeAt(this.state.pos);
  6449. if (next === 46 && !isOctal) {
  6450. ++this.state.pos;
  6451. this.readInt(10);
  6452. isFloat = true;
  6453. next = this.input.charCodeAt(this.state.pos);
  6454. }
  6455. if ((next === 69 || next === 101) && !isOctal) {
  6456. next = this.input.charCodeAt(++this.state.pos);
  6457. if (next === 43 || next === 45) {
  6458. ++this.state.pos;
  6459. }
  6460. if (this.readInt(10) === null) {
  6461. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  6462. }
  6463. isFloat = true;
  6464. hasExponent = true;
  6465. next = this.input.charCodeAt(this.state.pos);
  6466. }
  6467. if (next === 110) {
  6468. if (isFloat || hasLeadingZero) {
  6469. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  6470. }
  6471. ++this.state.pos;
  6472. isBigInt = true;
  6473. }
  6474. if (next === 109) {
  6475. this.expectPlugin("decimal", this.state.curPosition());
  6476. if (hasExponent || hasLeadingZero) {
  6477. this.raise(Errors.InvalidDecimal, startLoc);
  6478. }
  6479. ++this.state.pos;
  6480. var isDecimal = true;
  6481. }
  6482. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6483. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6484. }
  6485. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  6486. if (isBigInt) {
  6487. this.finishToken(136, str);
  6488. return;
  6489. }
  6490. if (isDecimal) {
  6491. this.finishToken(137, str);
  6492. return;
  6493. }
  6494. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  6495. this.finishToken(135, val);
  6496. }
  6497. readCodePoint(throwOnInvalid) {
  6498. const {
  6499. code,
  6500. pos
  6501. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  6502. this.state.pos = pos;
  6503. return code;
  6504. }
  6505. readString(quote) {
  6506. const {
  6507. str,
  6508. pos,
  6509. curLine,
  6510. lineStart
  6511. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  6512. this.state.pos = pos + 1;
  6513. this.state.lineStart = lineStart;
  6514. this.state.curLine = curLine;
  6515. this.finishToken(134, str);
  6516. }
  6517. readTemplateContinuation() {
  6518. if (!this.match(8)) {
  6519. this.unexpected(null, 8);
  6520. }
  6521. this.state.pos--;
  6522. this.readTemplateToken();
  6523. }
  6524. readTemplateToken() {
  6525. const opening = this.input[this.state.pos];
  6526. const {
  6527. str,
  6528. firstInvalidLoc,
  6529. pos,
  6530. curLine,
  6531. lineStart
  6532. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  6533. this.state.pos = pos + 1;
  6534. this.state.lineStart = lineStart;
  6535. this.state.curLine = curLine;
  6536. if (firstInvalidLoc) {
  6537. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  6538. }
  6539. if (this.input.codePointAt(pos) === 96) {
  6540. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  6541. } else {
  6542. this.state.pos++;
  6543. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  6544. }
  6545. }
  6546. recordStrictModeErrors(toParseError, at) {
  6547. const index = at.index;
  6548. if (this.state.strict && !this.state.strictErrors.has(index)) {
  6549. this.raise(toParseError, at);
  6550. } else {
  6551. this.state.strictErrors.set(index, [toParseError, at]);
  6552. }
  6553. }
  6554. readWord1(firstCode) {
  6555. this.state.containsEsc = false;
  6556. let word = "";
  6557. const start = this.state.pos;
  6558. let chunkStart = this.state.pos;
  6559. if (firstCode !== undefined) {
  6560. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  6561. }
  6562. while (this.state.pos < this.length) {
  6563. const ch = this.codePointAtPos(this.state.pos);
  6564. if (isIdentifierChar(ch)) {
  6565. this.state.pos += ch <= 0xffff ? 1 : 2;
  6566. } else if (ch === 92) {
  6567. this.state.containsEsc = true;
  6568. word += this.input.slice(chunkStart, this.state.pos);
  6569. const escStart = this.state.curPosition();
  6570. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  6571. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  6572. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  6573. chunkStart = this.state.pos - 1;
  6574. continue;
  6575. }
  6576. ++this.state.pos;
  6577. const esc = this.readCodePoint(true);
  6578. if (esc !== null) {
  6579. if (!identifierCheck(esc)) {
  6580. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  6581. }
  6582. word += String.fromCodePoint(esc);
  6583. }
  6584. chunkStart = this.state.pos;
  6585. } else {
  6586. break;
  6587. }
  6588. }
  6589. return word + this.input.slice(chunkStart, this.state.pos);
  6590. }
  6591. readWord(firstCode) {
  6592. const word = this.readWord1(firstCode);
  6593. const type = keywords$1.get(word);
  6594. if (type !== undefined) {
  6595. this.finishToken(type, tokenLabelName(type));
  6596. } else {
  6597. this.finishToken(132, word);
  6598. }
  6599. }
  6600. checkKeywordEscapes() {
  6601. const {
  6602. type
  6603. } = this.state;
  6604. if (tokenIsKeyword(type) && this.state.containsEsc) {
  6605. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  6606. reservedWord: tokenLabelName(type)
  6607. });
  6608. }
  6609. }
  6610. raise(toParseError, at, details = {}) {
  6611. const loc = at instanceof Position ? at : at.loc.start;
  6612. const error = toParseError(loc, details);
  6613. if (!(this.optionFlags & 2048)) throw error;
  6614. if (!this.isLookahead) this.state.errors.push(error);
  6615. return error;
  6616. }
  6617. raiseOverwrite(toParseError, at, details = {}) {
  6618. const loc = at instanceof Position ? at : at.loc.start;
  6619. const pos = loc.index;
  6620. const errors = this.state.errors;
  6621. for (let i = errors.length - 1; i >= 0; i--) {
  6622. const error = errors[i];
  6623. if (error.loc.index === pos) {
  6624. return errors[i] = toParseError(loc, details);
  6625. }
  6626. if (error.loc.index < pos) break;
  6627. }
  6628. return this.raise(toParseError, at, details);
  6629. }
  6630. updateContext(prevType) {}
  6631. unexpected(loc, type) {
  6632. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  6633. expected: type ? tokenLabelName(type) : null
  6634. });
  6635. }
  6636. expectPlugin(pluginName, loc) {
  6637. if (this.hasPlugin(pluginName)) {
  6638. return true;
  6639. }
  6640. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  6641. missingPlugin: [pluginName]
  6642. });
  6643. }
  6644. expectOnePlugin(pluginNames) {
  6645. if (!pluginNames.some(name => this.hasPlugin(name))) {
  6646. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  6647. missingPlugin: pluginNames
  6648. });
  6649. }
  6650. }
  6651. errorBuilder(error) {
  6652. return (pos, lineStart, curLine) => {
  6653. this.raise(error, buildPosition(pos, lineStart, curLine));
  6654. };
  6655. }
  6656. }
  6657. class ClassScope {
  6658. constructor() {
  6659. this.privateNames = new Set();
  6660. this.loneAccessors = new Map();
  6661. this.undefinedPrivateNames = new Map();
  6662. }
  6663. }
  6664. class ClassScopeHandler {
  6665. constructor(parser) {
  6666. this.parser = void 0;
  6667. this.stack = [];
  6668. this.undefinedPrivateNames = new Map();
  6669. this.parser = parser;
  6670. }
  6671. current() {
  6672. return this.stack[this.stack.length - 1];
  6673. }
  6674. enter() {
  6675. this.stack.push(new ClassScope());
  6676. }
  6677. exit() {
  6678. const oldClassScope = this.stack.pop();
  6679. const current = this.current();
  6680. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  6681. if (current) {
  6682. if (!current.undefinedPrivateNames.has(name)) {
  6683. current.undefinedPrivateNames.set(name, loc);
  6684. }
  6685. } else {
  6686. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6687. identifierName: name
  6688. });
  6689. }
  6690. }
  6691. }
  6692. declarePrivateName(name, elementType, loc) {
  6693. const {
  6694. privateNames,
  6695. loneAccessors,
  6696. undefinedPrivateNames
  6697. } = this.current();
  6698. let redefined = privateNames.has(name);
  6699. if (elementType & 3) {
  6700. const accessor = redefined && loneAccessors.get(name);
  6701. if (accessor) {
  6702. const oldStatic = accessor & 4;
  6703. const newStatic = elementType & 4;
  6704. const oldKind = accessor & 3;
  6705. const newKind = elementType & 3;
  6706. redefined = oldKind === newKind || oldStatic !== newStatic;
  6707. if (!redefined) loneAccessors.delete(name);
  6708. } else if (!redefined) {
  6709. loneAccessors.set(name, elementType);
  6710. }
  6711. }
  6712. if (redefined) {
  6713. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  6714. identifierName: name
  6715. });
  6716. }
  6717. privateNames.add(name);
  6718. undefinedPrivateNames.delete(name);
  6719. }
  6720. usePrivateName(name, loc) {
  6721. let classScope;
  6722. for (classScope of this.stack) {
  6723. if (classScope.privateNames.has(name)) return;
  6724. }
  6725. if (classScope) {
  6726. classScope.undefinedPrivateNames.set(name, loc);
  6727. } else {
  6728. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6729. identifierName: name
  6730. });
  6731. }
  6732. }
  6733. }
  6734. class ExpressionScope {
  6735. constructor(type = 0) {
  6736. this.type = type;
  6737. }
  6738. canBeArrowParameterDeclaration() {
  6739. return this.type === 2 || this.type === 1;
  6740. }
  6741. isCertainlyParameterDeclaration() {
  6742. return this.type === 3;
  6743. }
  6744. }
  6745. class ArrowHeadParsingScope extends ExpressionScope {
  6746. constructor(type) {
  6747. super(type);
  6748. this.declarationErrors = new Map();
  6749. }
  6750. recordDeclarationError(ParsingErrorClass, at) {
  6751. const index = at.index;
  6752. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  6753. }
  6754. clearDeclarationError(index) {
  6755. this.declarationErrors.delete(index);
  6756. }
  6757. iterateErrors(iterator) {
  6758. this.declarationErrors.forEach(iterator);
  6759. }
  6760. }
  6761. class ExpressionScopeHandler {
  6762. constructor(parser) {
  6763. this.parser = void 0;
  6764. this.stack = [new ExpressionScope()];
  6765. this.parser = parser;
  6766. }
  6767. enter(scope) {
  6768. this.stack.push(scope);
  6769. }
  6770. exit() {
  6771. this.stack.pop();
  6772. }
  6773. recordParameterInitializerError(toParseError, node) {
  6774. const origin = node.loc.start;
  6775. const {
  6776. stack
  6777. } = this;
  6778. let i = stack.length - 1;
  6779. let scope = stack[i];
  6780. while (!scope.isCertainlyParameterDeclaration()) {
  6781. if (scope.canBeArrowParameterDeclaration()) {
  6782. scope.recordDeclarationError(toParseError, origin);
  6783. } else {
  6784. return;
  6785. }
  6786. scope = stack[--i];
  6787. }
  6788. this.parser.raise(toParseError, origin);
  6789. }
  6790. recordArrowParameterBindingError(error, node) {
  6791. const {
  6792. stack
  6793. } = this;
  6794. const scope = stack[stack.length - 1];
  6795. const origin = node.loc.start;
  6796. if (scope.isCertainlyParameterDeclaration()) {
  6797. this.parser.raise(error, origin);
  6798. } else if (scope.canBeArrowParameterDeclaration()) {
  6799. scope.recordDeclarationError(error, origin);
  6800. } else {
  6801. return;
  6802. }
  6803. }
  6804. recordAsyncArrowParametersError(at) {
  6805. const {
  6806. stack
  6807. } = this;
  6808. let i = stack.length - 1;
  6809. let scope = stack[i];
  6810. while (scope.canBeArrowParameterDeclaration()) {
  6811. if (scope.type === 2) {
  6812. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  6813. }
  6814. scope = stack[--i];
  6815. }
  6816. }
  6817. validateAsPattern() {
  6818. const {
  6819. stack
  6820. } = this;
  6821. const currentScope = stack[stack.length - 1];
  6822. if (!currentScope.canBeArrowParameterDeclaration()) return;
  6823. currentScope.iterateErrors(([toParseError, loc]) => {
  6824. this.parser.raise(toParseError, loc);
  6825. let i = stack.length - 2;
  6826. let scope = stack[i];
  6827. while (scope.canBeArrowParameterDeclaration()) {
  6828. scope.clearDeclarationError(loc.index);
  6829. scope = stack[--i];
  6830. }
  6831. });
  6832. }
  6833. }
  6834. function newParameterDeclarationScope() {
  6835. return new ExpressionScope(3);
  6836. }
  6837. function newArrowHeadScope() {
  6838. return new ArrowHeadParsingScope(1);
  6839. }
  6840. function newAsyncArrowScope() {
  6841. return new ArrowHeadParsingScope(2);
  6842. }
  6843. function newExpressionScope() {
  6844. return new ExpressionScope();
  6845. }
  6846. class UtilParser extends Tokenizer {
  6847. addExtra(node, key, value, enumerable = true) {
  6848. if (!node) return;
  6849. let {
  6850. extra
  6851. } = node;
  6852. if (extra == null) {
  6853. extra = {};
  6854. node.extra = extra;
  6855. }
  6856. if (enumerable) {
  6857. extra[key] = value;
  6858. } else {
  6859. Object.defineProperty(extra, key, {
  6860. enumerable,
  6861. value
  6862. });
  6863. }
  6864. }
  6865. isContextual(token) {
  6866. return this.state.type === token && !this.state.containsEsc;
  6867. }
  6868. isUnparsedContextual(nameStart, name) {
  6869. const nameEnd = nameStart + name.length;
  6870. if (this.input.slice(nameStart, nameEnd) === name) {
  6871. const nextCh = this.input.charCodeAt(nameEnd);
  6872. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  6873. }
  6874. return false;
  6875. }
  6876. isLookaheadContextual(name) {
  6877. const next = this.nextTokenStart();
  6878. return this.isUnparsedContextual(next, name);
  6879. }
  6880. eatContextual(token) {
  6881. if (this.isContextual(token)) {
  6882. this.next();
  6883. return true;
  6884. }
  6885. return false;
  6886. }
  6887. expectContextual(token, toParseError) {
  6888. if (!this.eatContextual(token)) {
  6889. if (toParseError != null) {
  6890. throw this.raise(toParseError, this.state.startLoc);
  6891. }
  6892. this.unexpected(null, token);
  6893. }
  6894. }
  6895. canInsertSemicolon() {
  6896. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  6897. }
  6898. hasPrecedingLineBreak() {
  6899. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  6900. }
  6901. hasFollowingLineBreak() {
  6902. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  6903. }
  6904. isLineTerminator() {
  6905. return this.eat(13) || this.canInsertSemicolon();
  6906. }
  6907. semicolon(allowAsi = true) {
  6908. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  6909. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  6910. }
  6911. expect(type, loc) {
  6912. if (!this.eat(type)) {
  6913. this.unexpected(loc, type);
  6914. }
  6915. }
  6916. tryParse(fn, oldState = this.state.clone()) {
  6917. const abortSignal = {
  6918. node: null
  6919. };
  6920. try {
  6921. const node = fn((node = null) => {
  6922. abortSignal.node = node;
  6923. throw abortSignal;
  6924. });
  6925. if (this.state.errors.length > oldState.errors.length) {
  6926. const failState = this.state;
  6927. this.state = oldState;
  6928. this.state.tokensLength = failState.tokensLength;
  6929. return {
  6930. node,
  6931. error: failState.errors[oldState.errors.length],
  6932. thrown: false,
  6933. aborted: false,
  6934. failState
  6935. };
  6936. }
  6937. return {
  6938. node,
  6939. error: null,
  6940. thrown: false,
  6941. aborted: false,
  6942. failState: null
  6943. };
  6944. } catch (error) {
  6945. const failState = this.state;
  6946. this.state = oldState;
  6947. if (error instanceof SyntaxError) {
  6948. return {
  6949. node: null,
  6950. error,
  6951. thrown: true,
  6952. aborted: false,
  6953. failState
  6954. };
  6955. }
  6956. if (error === abortSignal) {
  6957. return {
  6958. node: abortSignal.node,
  6959. error: null,
  6960. thrown: false,
  6961. aborted: true,
  6962. failState
  6963. };
  6964. }
  6965. throw error;
  6966. }
  6967. }
  6968. checkExpressionErrors(refExpressionErrors, andThrow) {
  6969. if (!refExpressionErrors) return false;
  6970. const {
  6971. shorthandAssignLoc,
  6972. doubleProtoLoc,
  6973. privateKeyLoc,
  6974. optionalParametersLoc
  6975. } = refExpressionErrors;
  6976. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  6977. if (!andThrow) {
  6978. return hasErrors;
  6979. }
  6980. if (shorthandAssignLoc != null) {
  6981. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  6982. }
  6983. if (doubleProtoLoc != null) {
  6984. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  6985. }
  6986. if (privateKeyLoc != null) {
  6987. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  6988. }
  6989. if (optionalParametersLoc != null) {
  6990. this.unexpected(optionalParametersLoc);
  6991. }
  6992. }
  6993. isLiteralPropertyName() {
  6994. return tokenIsLiteralPropertyName(this.state.type);
  6995. }
  6996. isPrivateName(node) {
  6997. return node.type === "PrivateName";
  6998. }
  6999. getPrivateNameSV(node) {
  7000. return node.id.name;
  7001. }
  7002. hasPropertyAsPrivateName(node) {
  7003. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  7004. }
  7005. isObjectProperty(node) {
  7006. return node.type === "ObjectProperty";
  7007. }
  7008. isObjectMethod(node) {
  7009. return node.type === "ObjectMethod";
  7010. }
  7011. initializeScopes(inModule = this.options.sourceType === "module") {
  7012. const oldLabels = this.state.labels;
  7013. this.state.labels = [];
  7014. const oldExportedIdentifiers = this.exportedIdentifiers;
  7015. this.exportedIdentifiers = new Set();
  7016. const oldInModule = this.inModule;
  7017. this.inModule = inModule;
  7018. const oldScope = this.scope;
  7019. const ScopeHandler = this.getScopeHandler();
  7020. this.scope = new ScopeHandler(this, inModule);
  7021. const oldProdParam = this.prodParam;
  7022. this.prodParam = new ProductionParameterHandler();
  7023. const oldClassScope = this.classScope;
  7024. this.classScope = new ClassScopeHandler(this);
  7025. const oldExpressionScope = this.expressionScope;
  7026. this.expressionScope = new ExpressionScopeHandler(this);
  7027. return () => {
  7028. this.state.labels = oldLabels;
  7029. this.exportedIdentifiers = oldExportedIdentifiers;
  7030. this.inModule = oldInModule;
  7031. this.scope = oldScope;
  7032. this.prodParam = oldProdParam;
  7033. this.classScope = oldClassScope;
  7034. this.expressionScope = oldExpressionScope;
  7035. };
  7036. }
  7037. enterInitialScopes() {
  7038. let paramFlags = 0;
  7039. if (this.inModule) {
  7040. paramFlags |= 2;
  7041. }
  7042. if (this.optionFlags & 32) {
  7043. paramFlags |= 1;
  7044. }
  7045. this.scope.enter(1);
  7046. this.prodParam.enter(paramFlags);
  7047. }
  7048. checkDestructuringPrivate(refExpressionErrors) {
  7049. const {
  7050. privateKeyLoc
  7051. } = refExpressionErrors;
  7052. if (privateKeyLoc !== null) {
  7053. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  7054. }
  7055. }
  7056. }
  7057. class ExpressionErrors {
  7058. constructor() {
  7059. this.shorthandAssignLoc = null;
  7060. this.doubleProtoLoc = null;
  7061. this.privateKeyLoc = null;
  7062. this.optionalParametersLoc = null;
  7063. }
  7064. }
  7065. class Node {
  7066. constructor(parser, pos, loc) {
  7067. this.type = "";
  7068. this.start = pos;
  7069. this.end = 0;
  7070. this.loc = new SourceLocation(loc);
  7071. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  7072. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  7073. }
  7074. }
  7075. const NodePrototype = Node.prototype;
  7076. {
  7077. NodePrototype.__clone = function () {
  7078. const newNode = new Node(undefined, this.start, this.loc.start);
  7079. const keys = Object.keys(this);
  7080. for (let i = 0, length = keys.length; i < length; i++) {
  7081. const key = keys[i];
  7082. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  7083. newNode[key] = this[key];
  7084. }
  7085. }
  7086. return newNode;
  7087. };
  7088. }
  7089. class NodeUtils extends UtilParser {
  7090. startNode() {
  7091. const loc = this.state.startLoc;
  7092. return new Node(this, loc.index, loc);
  7093. }
  7094. startNodeAt(loc) {
  7095. return new Node(this, loc.index, loc);
  7096. }
  7097. startNodeAtNode(type) {
  7098. return this.startNodeAt(type.loc.start);
  7099. }
  7100. finishNode(node, type) {
  7101. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  7102. }
  7103. finishNodeAt(node, type, endLoc) {
  7104. node.type = type;
  7105. node.end = endLoc.index;
  7106. node.loc.end = endLoc;
  7107. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7108. if (this.optionFlags & 4096) {
  7109. this.processComment(node);
  7110. }
  7111. return node;
  7112. }
  7113. resetStartLocation(node, startLoc) {
  7114. node.start = startLoc.index;
  7115. node.loc.start = startLoc;
  7116. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  7117. }
  7118. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  7119. node.end = endLoc.index;
  7120. node.loc.end = endLoc;
  7121. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7122. }
  7123. resetStartLocationFromNode(node, locationNode) {
  7124. this.resetStartLocation(node, locationNode.loc.start);
  7125. }
  7126. castNodeTo(node, type) {
  7127. node.type = type;
  7128. return node;
  7129. }
  7130. cloneIdentifier(node) {
  7131. const {
  7132. type,
  7133. start,
  7134. end,
  7135. loc,
  7136. range,
  7137. name
  7138. } = node;
  7139. const cloned = Object.create(NodePrototype);
  7140. cloned.type = type;
  7141. cloned.start = start;
  7142. cloned.end = end;
  7143. cloned.loc = loc;
  7144. cloned.range = range;
  7145. cloned.name = name;
  7146. if (node.extra) cloned.extra = node.extra;
  7147. return cloned;
  7148. }
  7149. cloneStringLiteral(node) {
  7150. const {
  7151. type,
  7152. start,
  7153. end,
  7154. loc,
  7155. range,
  7156. extra
  7157. } = node;
  7158. const cloned = Object.create(NodePrototype);
  7159. cloned.type = type;
  7160. cloned.start = start;
  7161. cloned.end = end;
  7162. cloned.loc = loc;
  7163. cloned.range = range;
  7164. cloned.extra = extra;
  7165. cloned.value = node.value;
  7166. return cloned;
  7167. }
  7168. }
  7169. const unwrapParenthesizedExpression = node => {
  7170. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7171. };
  7172. class LValParser extends NodeUtils {
  7173. toAssignable(node, isLHS = false) {
  7174. var _node$extra, _node$extra3;
  7175. let parenthesized = undefined;
  7176. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7177. parenthesized = unwrapParenthesizedExpression(node);
  7178. if (isLHS) {
  7179. if (parenthesized.type === "Identifier") {
  7180. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7181. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7182. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7183. }
  7184. } else {
  7185. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7186. }
  7187. }
  7188. switch (node.type) {
  7189. case "Identifier":
  7190. case "ObjectPattern":
  7191. case "ArrayPattern":
  7192. case "AssignmentPattern":
  7193. case "RestElement":
  7194. break;
  7195. case "ObjectExpression":
  7196. this.castNodeTo(node, "ObjectPattern");
  7197. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7198. var _node$extra2;
  7199. const prop = node.properties[i];
  7200. const isLast = i === last;
  7201. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7202. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7203. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7204. }
  7205. }
  7206. break;
  7207. case "ObjectProperty":
  7208. {
  7209. const {
  7210. key,
  7211. value
  7212. } = node;
  7213. if (this.isPrivateName(key)) {
  7214. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7215. }
  7216. this.toAssignable(value, isLHS);
  7217. break;
  7218. }
  7219. case "SpreadElement":
  7220. {
  7221. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7222. }
  7223. case "ArrayExpression":
  7224. this.castNodeTo(node, "ArrayPattern");
  7225. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7226. break;
  7227. case "AssignmentExpression":
  7228. if (node.operator !== "=") {
  7229. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7230. }
  7231. this.castNodeTo(node, "AssignmentPattern");
  7232. delete node.operator;
  7233. this.toAssignable(node.left, isLHS);
  7234. break;
  7235. case "ParenthesizedExpression":
  7236. this.toAssignable(parenthesized, isLHS);
  7237. break;
  7238. }
  7239. }
  7240. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7241. if (prop.type === "ObjectMethod") {
  7242. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7243. } else if (prop.type === "SpreadElement") {
  7244. this.castNodeTo(prop, "RestElement");
  7245. const arg = prop.argument;
  7246. this.checkToRestConversion(arg, false);
  7247. this.toAssignable(arg, isLHS);
  7248. if (!isLast) {
  7249. this.raise(Errors.RestTrailingComma, prop);
  7250. }
  7251. } else {
  7252. this.toAssignable(prop, isLHS);
  7253. }
  7254. }
  7255. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7256. const end = exprList.length - 1;
  7257. for (let i = 0; i <= end; i++) {
  7258. const elt = exprList[i];
  7259. if (!elt) continue;
  7260. this.toAssignableListItem(exprList, i, isLHS);
  7261. if (elt.type === "RestElement") {
  7262. if (i < end) {
  7263. this.raise(Errors.RestTrailingComma, elt);
  7264. } else if (trailingCommaLoc) {
  7265. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7266. }
  7267. }
  7268. }
  7269. }
  7270. toAssignableListItem(exprList, index, isLHS) {
  7271. const node = exprList[index];
  7272. if (node.type === "SpreadElement") {
  7273. this.castNodeTo(node, "RestElement");
  7274. const arg = node.argument;
  7275. this.checkToRestConversion(arg, true);
  7276. this.toAssignable(arg, isLHS);
  7277. } else {
  7278. this.toAssignable(node, isLHS);
  7279. }
  7280. }
  7281. isAssignable(node, isBinding) {
  7282. switch (node.type) {
  7283. case "Identifier":
  7284. case "ObjectPattern":
  7285. case "ArrayPattern":
  7286. case "AssignmentPattern":
  7287. case "RestElement":
  7288. return true;
  7289. case "ObjectExpression":
  7290. {
  7291. const last = node.properties.length - 1;
  7292. return node.properties.every((prop, i) => {
  7293. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7294. });
  7295. }
  7296. case "ObjectProperty":
  7297. return this.isAssignable(node.value);
  7298. case "SpreadElement":
  7299. return this.isAssignable(node.argument);
  7300. case "ArrayExpression":
  7301. return node.elements.every(element => element === null || this.isAssignable(element));
  7302. case "AssignmentExpression":
  7303. return node.operator === "=";
  7304. case "ParenthesizedExpression":
  7305. return this.isAssignable(node.expression);
  7306. case "MemberExpression":
  7307. case "OptionalMemberExpression":
  7308. return !isBinding;
  7309. default:
  7310. return false;
  7311. }
  7312. }
  7313. toReferencedList(exprList, isParenthesizedExpr) {
  7314. return exprList;
  7315. }
  7316. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7317. this.toReferencedList(exprList, isParenthesizedExpr);
  7318. for (const expr of exprList) {
  7319. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7320. this.toReferencedListDeep(expr.elements);
  7321. }
  7322. }
  7323. }
  7324. parseSpread(refExpressionErrors) {
  7325. const node = this.startNode();
  7326. this.next();
  7327. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7328. return this.finishNode(node, "SpreadElement");
  7329. }
  7330. parseRestBinding() {
  7331. const node = this.startNode();
  7332. this.next();
  7333. node.argument = this.parseBindingAtom();
  7334. return this.finishNode(node, "RestElement");
  7335. }
  7336. parseBindingAtom() {
  7337. switch (this.state.type) {
  7338. case 0:
  7339. {
  7340. const node = this.startNode();
  7341. this.next();
  7342. node.elements = this.parseBindingList(3, 93, 1);
  7343. return this.finishNode(node, "ArrayPattern");
  7344. }
  7345. case 5:
  7346. return this.parseObjectLike(8, true);
  7347. }
  7348. return this.parseIdentifier();
  7349. }
  7350. parseBindingList(close, closeCharCode, flags) {
  7351. const allowEmpty = flags & 1;
  7352. const elts = [];
  7353. let first = true;
  7354. while (!this.eat(close)) {
  7355. if (first) {
  7356. first = false;
  7357. } else {
  7358. this.expect(12);
  7359. }
  7360. if (allowEmpty && this.match(12)) {
  7361. elts.push(null);
  7362. } else if (this.eat(close)) {
  7363. break;
  7364. } else if (this.match(21)) {
  7365. let rest = this.parseRestBinding();
  7366. if (this.hasPlugin("flow") || flags & 2) {
  7367. rest = this.parseFunctionParamType(rest);
  7368. }
  7369. elts.push(rest);
  7370. if (!this.checkCommaAfterRest(closeCharCode)) {
  7371. this.expect(close);
  7372. break;
  7373. }
  7374. } else {
  7375. const decorators = [];
  7376. if (flags & 2) {
  7377. if (this.match(26) && this.hasPlugin("decorators")) {
  7378. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7379. }
  7380. while (this.match(26)) {
  7381. decorators.push(this.parseDecorator());
  7382. }
  7383. }
  7384. elts.push(this.parseBindingElement(flags, decorators));
  7385. }
  7386. }
  7387. return elts;
  7388. }
  7389. parseBindingRestProperty(prop) {
  7390. this.next();
  7391. prop.argument = this.parseIdentifier();
  7392. this.checkCommaAfterRest(125);
  7393. return this.finishNode(prop, "RestElement");
  7394. }
  7395. parseBindingProperty() {
  7396. const {
  7397. type,
  7398. startLoc
  7399. } = this.state;
  7400. if (type === 21) {
  7401. return this.parseBindingRestProperty(this.startNode());
  7402. }
  7403. const prop = this.startNode();
  7404. if (type === 139) {
  7405. this.expectPlugin("destructuringPrivate", startLoc);
  7406. this.classScope.usePrivateName(this.state.value, startLoc);
  7407. prop.key = this.parsePrivateName();
  7408. } else {
  7409. this.parsePropertyName(prop);
  7410. }
  7411. prop.method = false;
  7412. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7413. }
  7414. parseBindingElement(flags, decorators) {
  7415. const left = this.parseMaybeDefault();
  7416. if (this.hasPlugin("flow") || flags & 2) {
  7417. this.parseFunctionParamType(left);
  7418. }
  7419. if (decorators.length) {
  7420. left.decorators = decorators;
  7421. this.resetStartLocationFromNode(left, decorators[0]);
  7422. }
  7423. const elt = this.parseMaybeDefault(left.loc.start, left);
  7424. return elt;
  7425. }
  7426. parseFunctionParamType(param) {
  7427. return param;
  7428. }
  7429. parseMaybeDefault(startLoc, left) {
  7430. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  7431. left = left != null ? left : this.parseBindingAtom();
  7432. if (!this.eat(29)) return left;
  7433. const node = this.startNodeAt(startLoc);
  7434. node.left = left;
  7435. node.right = this.parseMaybeAssignAllowIn();
  7436. return this.finishNode(node, "AssignmentPattern");
  7437. }
  7438. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7439. switch (type) {
  7440. case "AssignmentPattern":
  7441. return "left";
  7442. case "RestElement":
  7443. return "argument";
  7444. case "ObjectProperty":
  7445. return "value";
  7446. case "ParenthesizedExpression":
  7447. return "expression";
  7448. case "ArrayPattern":
  7449. return "elements";
  7450. case "ObjectPattern":
  7451. return "properties";
  7452. }
  7453. return false;
  7454. }
  7455. isOptionalMemberExpression(expression) {
  7456. return expression.type === "OptionalMemberExpression";
  7457. }
  7458. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false) {
  7459. var _expression$extra;
  7460. const type = expression.type;
  7461. if (this.isObjectMethod(expression)) return;
  7462. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7463. if (isOptionalMemberExpression || type === "MemberExpression") {
  7464. if (isOptionalMemberExpression) {
  7465. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7466. if (ancestor.type !== "AssignmentExpression") {
  7467. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7468. ancestor
  7469. });
  7470. }
  7471. }
  7472. if (binding !== 64) {
  7473. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7474. }
  7475. return;
  7476. }
  7477. if (type === "Identifier") {
  7478. this.checkIdentifier(expression, binding, strictModeChanged);
  7479. const {
  7480. name
  7481. } = expression;
  7482. if (checkClashes) {
  7483. if (checkClashes.has(name)) {
  7484. this.raise(Errors.ParamDupe, expression);
  7485. } else {
  7486. checkClashes.add(name);
  7487. }
  7488. }
  7489. return;
  7490. }
  7491. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7492. if (validity === true) return;
  7493. if (validity === false) {
  7494. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7495. this.raise(ParseErrorClass, expression, {
  7496. ancestor
  7497. });
  7498. return;
  7499. }
  7500. let key, isParenthesizedExpression;
  7501. if (typeof validity === "string") {
  7502. key = validity;
  7503. isParenthesizedExpression = type === "ParenthesizedExpression";
  7504. } else {
  7505. [key, isParenthesizedExpression] = validity;
  7506. }
  7507. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7508. type
  7509. } : ancestor;
  7510. const val = expression[key];
  7511. if (Array.isArray(val)) {
  7512. for (const child of val) {
  7513. if (child) {
  7514. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  7515. }
  7516. }
  7517. } else if (val) {
  7518. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  7519. }
  7520. }
  7521. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7522. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7523. if (bindingType === 64) {
  7524. this.raise(Errors.StrictEvalArguments, at, {
  7525. referenceName: at.name
  7526. });
  7527. } else {
  7528. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  7529. bindingName: at.name
  7530. });
  7531. }
  7532. }
  7533. if (bindingType & 8192 && at.name === "let") {
  7534. this.raise(Errors.LetInLexicalBinding, at);
  7535. }
  7536. if (!(bindingType & 64)) {
  7537. this.declareNameFromIdentifier(at, bindingType);
  7538. }
  7539. }
  7540. declareNameFromIdentifier(identifier, binding) {
  7541. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7542. }
  7543. checkToRestConversion(node, allowPattern) {
  7544. switch (node.type) {
  7545. case "ParenthesizedExpression":
  7546. this.checkToRestConversion(node.expression, allowPattern);
  7547. break;
  7548. case "Identifier":
  7549. case "MemberExpression":
  7550. break;
  7551. case "ArrayExpression":
  7552. case "ObjectExpression":
  7553. if (allowPattern) break;
  7554. default:
  7555. this.raise(Errors.InvalidRestAssignmentPattern, node);
  7556. }
  7557. }
  7558. checkCommaAfterRest(close) {
  7559. if (!this.match(12)) {
  7560. return false;
  7561. }
  7562. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  7563. return true;
  7564. }
  7565. }
  7566. function nonNull(x) {
  7567. if (x == null) {
  7568. throw new Error(`Unexpected ${x} value.`);
  7569. }
  7570. return x;
  7571. }
  7572. function assert(x) {
  7573. if (!x) {
  7574. throw new Error("Assert fail");
  7575. }
  7576. }
  7577. const TSErrors = ParseErrorEnum`typescript`({
  7578. AbstractMethodHasImplementation: ({
  7579. methodName
  7580. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7581. AbstractPropertyHasInitializer: ({
  7582. propertyName
  7583. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7584. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7585. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7586. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7587. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7588. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7589. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7590. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7591. DeclareAccessor: ({
  7592. kind
  7593. }) => `'declare' is not allowed in ${kind}ters.`,
  7594. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7595. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7596. DuplicateAccessibilityModifier: ({
  7597. modifier
  7598. }) => `Accessibility modifier already seen.`,
  7599. DuplicateModifier: ({
  7600. modifier
  7601. }) => `Duplicate modifier: '${modifier}'.`,
  7602. EmptyHeritageClauseType: ({
  7603. token
  7604. }) => `'${token}' list cannot be empty.`,
  7605. EmptyTypeArguments: "Type argument list cannot be empty.",
  7606. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7607. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7608. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7609. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7610. IncompatibleModifiers: ({
  7611. modifiers
  7612. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7613. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7614. IndexSignatureHasAccessibility: ({
  7615. modifier
  7616. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7617. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7618. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7619. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7620. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7621. InvalidHeritageClauseType: ({
  7622. token
  7623. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  7624. InvalidModifierOnTypeMember: ({
  7625. modifier
  7626. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7627. InvalidModifierOnTypeParameter: ({
  7628. modifier
  7629. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7630. InvalidModifierOnTypeParameterPositions: ({
  7631. modifier
  7632. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7633. InvalidModifiersOrder: ({
  7634. orderedModifiers
  7635. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7636. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7637. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7638. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7639. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7640. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7641. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7642. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7643. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7644. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7645. PrivateElementHasAccessibility: ({
  7646. modifier
  7647. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7648. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7649. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7650. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7651. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7652. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7653. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7654. SingleTypeParameterWithoutTrailingComma: ({
  7655. typeParameterName
  7656. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7657. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7658. 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?`).",
  7659. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7660. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7661. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7662. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7663. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7664. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7665. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7666. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7667. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7668. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7669. UnsupportedSignatureParameterKind: ({
  7670. type
  7671. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7672. });
  7673. function keywordTypeFromName(value) {
  7674. switch (value) {
  7675. case "any":
  7676. return "TSAnyKeyword";
  7677. case "boolean":
  7678. return "TSBooleanKeyword";
  7679. case "bigint":
  7680. return "TSBigIntKeyword";
  7681. case "never":
  7682. return "TSNeverKeyword";
  7683. case "number":
  7684. return "TSNumberKeyword";
  7685. case "object":
  7686. return "TSObjectKeyword";
  7687. case "string":
  7688. return "TSStringKeyword";
  7689. case "symbol":
  7690. return "TSSymbolKeyword";
  7691. case "undefined":
  7692. return "TSUndefinedKeyword";
  7693. case "unknown":
  7694. return "TSUnknownKeyword";
  7695. default:
  7696. return undefined;
  7697. }
  7698. }
  7699. function tsIsAccessModifier(modifier) {
  7700. return modifier === "private" || modifier === "public" || modifier === "protected";
  7701. }
  7702. function tsIsVarianceAnnotations(modifier) {
  7703. return modifier === "in" || modifier === "out";
  7704. }
  7705. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7706. constructor(...args) {
  7707. super(...args);
  7708. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7709. allowedModifiers: ["in", "out"],
  7710. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7711. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7712. });
  7713. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7714. allowedModifiers: ["const"],
  7715. disallowedModifiers: ["in", "out"],
  7716. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7717. });
  7718. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7719. allowedModifiers: ["in", "out", "const"],
  7720. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7721. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7722. });
  7723. }
  7724. getScopeHandler() {
  7725. return TypeScriptScopeHandler;
  7726. }
  7727. tsIsIdentifier() {
  7728. return tokenIsIdentifier(this.state.type);
  7729. }
  7730. tsTokenCanFollowModifier() {
  7731. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  7732. }
  7733. tsNextTokenOnSameLineAndCanFollowModifier() {
  7734. this.next();
  7735. if (this.hasPrecedingLineBreak()) {
  7736. return false;
  7737. }
  7738. return this.tsTokenCanFollowModifier();
  7739. }
  7740. tsNextTokenCanFollowModifier() {
  7741. if (this.match(106)) {
  7742. this.next();
  7743. return this.tsTokenCanFollowModifier();
  7744. }
  7745. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  7746. }
  7747. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7748. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7749. return undefined;
  7750. }
  7751. const modifier = this.state.value;
  7752. if (allowedModifiers.includes(modifier)) {
  7753. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7754. return undefined;
  7755. }
  7756. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7757. return modifier;
  7758. }
  7759. }
  7760. return undefined;
  7761. }
  7762. tsParseModifiers({
  7763. allowedModifiers,
  7764. disallowedModifiers,
  7765. stopOnStartOfClassStaticBlock,
  7766. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7767. }, modified) {
  7768. const enforceOrder = (loc, modifier, before, after) => {
  7769. if (modifier === before && modified[after]) {
  7770. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7771. orderedModifiers: [before, after]
  7772. });
  7773. }
  7774. };
  7775. const incompatible = (loc, modifier, mod1, mod2) => {
  7776. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7777. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7778. modifiers: [mod1, mod2]
  7779. });
  7780. }
  7781. };
  7782. for (;;) {
  7783. const {
  7784. startLoc
  7785. } = this.state;
  7786. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7787. if (!modifier) break;
  7788. if (tsIsAccessModifier(modifier)) {
  7789. if (modified.accessibility) {
  7790. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7791. modifier
  7792. });
  7793. } else {
  7794. enforceOrder(startLoc, modifier, modifier, "override");
  7795. enforceOrder(startLoc, modifier, modifier, "static");
  7796. enforceOrder(startLoc, modifier, modifier, "readonly");
  7797. modified.accessibility = modifier;
  7798. }
  7799. } else if (tsIsVarianceAnnotations(modifier)) {
  7800. if (modified[modifier]) {
  7801. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7802. modifier
  7803. });
  7804. }
  7805. modified[modifier] = true;
  7806. enforceOrder(startLoc, modifier, "in", "out");
  7807. } else {
  7808. if (hasOwnProperty.call(modified, modifier)) {
  7809. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7810. modifier
  7811. });
  7812. } else {
  7813. enforceOrder(startLoc, modifier, "static", "readonly");
  7814. enforceOrder(startLoc, modifier, "static", "override");
  7815. enforceOrder(startLoc, modifier, "override", "readonly");
  7816. enforceOrder(startLoc, modifier, "abstract", "override");
  7817. incompatible(startLoc, modifier, "declare", "override");
  7818. incompatible(startLoc, modifier, "static", "abstract");
  7819. }
  7820. modified[modifier] = true;
  7821. }
  7822. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7823. this.raise(errorTemplate, startLoc, {
  7824. modifier
  7825. });
  7826. }
  7827. }
  7828. }
  7829. tsIsListTerminator(kind) {
  7830. switch (kind) {
  7831. case "EnumMembers":
  7832. case "TypeMembers":
  7833. return this.match(8);
  7834. case "HeritageClauseElement":
  7835. return this.match(5);
  7836. case "TupleElementTypes":
  7837. return this.match(3);
  7838. case "TypeParametersOrArguments":
  7839. return this.match(48);
  7840. }
  7841. }
  7842. tsParseList(kind, parseElement) {
  7843. const result = [];
  7844. while (!this.tsIsListTerminator(kind)) {
  7845. result.push(parseElement());
  7846. }
  7847. return result;
  7848. }
  7849. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7850. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7851. }
  7852. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7853. const result = [];
  7854. let trailingCommaPos = -1;
  7855. for (;;) {
  7856. if (this.tsIsListTerminator(kind)) {
  7857. break;
  7858. }
  7859. trailingCommaPos = -1;
  7860. const element = parseElement();
  7861. if (element == null) {
  7862. return undefined;
  7863. }
  7864. result.push(element);
  7865. if (this.eat(12)) {
  7866. trailingCommaPos = this.state.lastTokStartLoc.index;
  7867. continue;
  7868. }
  7869. if (this.tsIsListTerminator(kind)) {
  7870. break;
  7871. }
  7872. if (expectSuccess) {
  7873. this.expect(12);
  7874. }
  7875. return undefined;
  7876. }
  7877. if (refTrailingCommaPos) {
  7878. refTrailingCommaPos.value = trailingCommaPos;
  7879. }
  7880. return result;
  7881. }
  7882. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7883. if (!skipFirstToken) {
  7884. if (bracket) {
  7885. this.expect(0);
  7886. } else {
  7887. this.expect(47);
  7888. }
  7889. }
  7890. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7891. if (bracket) {
  7892. this.expect(3);
  7893. } else {
  7894. this.expect(48);
  7895. }
  7896. return result;
  7897. }
  7898. tsParseImportType() {
  7899. const node = this.startNode();
  7900. this.expect(83);
  7901. this.expect(10);
  7902. if (!this.match(134)) {
  7903. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7904. {
  7905. node.argument = super.parseExprAtom();
  7906. }
  7907. } else {
  7908. {
  7909. node.argument = this.parseStringLiteral(this.state.value);
  7910. }
  7911. }
  7912. if (this.eat(12)) {
  7913. node.options = this.tsParseImportTypeOptions();
  7914. } else {
  7915. node.options = null;
  7916. }
  7917. this.expect(11);
  7918. if (this.eat(16)) {
  7919. node.qualifier = this.tsParseEntityName(1 | 2);
  7920. }
  7921. if (this.match(47)) {
  7922. {
  7923. node.typeParameters = this.tsParseTypeArguments();
  7924. }
  7925. }
  7926. return this.finishNode(node, "TSImportType");
  7927. }
  7928. tsParseImportTypeOptions() {
  7929. const node = this.startNode();
  7930. this.expect(5);
  7931. const withProperty = this.startNode();
  7932. if (this.isContextual(76)) {
  7933. withProperty.method = false;
  7934. withProperty.key = this.parseIdentifier(true);
  7935. withProperty.computed = false;
  7936. withProperty.shorthand = false;
  7937. } else {
  7938. this.unexpected(null, 76);
  7939. }
  7940. this.expect(14);
  7941. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  7942. node.properties = [this.finishObjectProperty(withProperty)];
  7943. this.expect(8);
  7944. return this.finishNode(node, "ObjectExpression");
  7945. }
  7946. tsParseImportTypeWithPropertyValue() {
  7947. const node = this.startNode();
  7948. const properties = [];
  7949. this.expect(5);
  7950. while (!this.match(8)) {
  7951. const type = this.state.type;
  7952. if (tokenIsIdentifier(type) || type === 134) {
  7953. properties.push(super.parsePropertyDefinition(null));
  7954. } else {
  7955. this.unexpected();
  7956. }
  7957. this.eat(12);
  7958. }
  7959. node.properties = properties;
  7960. this.next();
  7961. return this.finishNode(node, "ObjectExpression");
  7962. }
  7963. tsParseEntityName(flags) {
  7964. let entity;
  7965. if (flags & 1 && this.match(78)) {
  7966. if (flags & 2) {
  7967. entity = this.parseIdentifier(true);
  7968. } else {
  7969. const node = this.startNode();
  7970. this.next();
  7971. entity = this.finishNode(node, "ThisExpression");
  7972. }
  7973. } else {
  7974. entity = this.parseIdentifier(!!(flags & 1));
  7975. }
  7976. while (this.eat(16)) {
  7977. const node = this.startNodeAtNode(entity);
  7978. node.left = entity;
  7979. node.right = this.parseIdentifier(!!(flags & 1));
  7980. entity = this.finishNode(node, "TSQualifiedName");
  7981. }
  7982. return entity;
  7983. }
  7984. tsParseTypeReference() {
  7985. const node = this.startNode();
  7986. node.typeName = this.tsParseEntityName(1);
  7987. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7988. {
  7989. node.typeParameters = this.tsParseTypeArguments();
  7990. }
  7991. }
  7992. return this.finishNode(node, "TSTypeReference");
  7993. }
  7994. tsParseThisTypePredicate(lhs) {
  7995. this.next();
  7996. const node = this.startNodeAtNode(lhs);
  7997. node.parameterName = lhs;
  7998. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7999. node.asserts = false;
  8000. return this.finishNode(node, "TSTypePredicate");
  8001. }
  8002. tsParseThisTypeNode() {
  8003. const node = this.startNode();
  8004. this.next();
  8005. return this.finishNode(node, "TSThisType");
  8006. }
  8007. tsParseTypeQuery() {
  8008. const node = this.startNode();
  8009. this.expect(87);
  8010. if (this.match(83)) {
  8011. node.exprName = this.tsParseImportType();
  8012. } else {
  8013. {
  8014. node.exprName = this.tsParseEntityName(1 | 2);
  8015. }
  8016. }
  8017. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8018. {
  8019. node.typeParameters = this.tsParseTypeArguments();
  8020. }
  8021. }
  8022. return this.finishNode(node, "TSTypeQuery");
  8023. }
  8024. tsParseTypeParameter(parseModifiers) {
  8025. const node = this.startNode();
  8026. parseModifiers(node);
  8027. node.name = this.tsParseTypeParameterName();
  8028. node.constraint = this.tsEatThenParseType(81);
  8029. node.default = this.tsEatThenParseType(29);
  8030. return this.finishNode(node, "TSTypeParameter");
  8031. }
  8032. tsTryParseTypeParameters(parseModifiers) {
  8033. if (this.match(47)) {
  8034. return this.tsParseTypeParameters(parseModifiers);
  8035. }
  8036. }
  8037. tsParseTypeParameters(parseModifiers) {
  8038. const node = this.startNode();
  8039. if (this.match(47) || this.match(143)) {
  8040. this.next();
  8041. } else {
  8042. this.unexpected();
  8043. }
  8044. const refTrailingCommaPos = {
  8045. value: -1
  8046. };
  8047. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  8048. if (node.params.length === 0) {
  8049. this.raise(TSErrors.EmptyTypeParameters, node);
  8050. }
  8051. if (refTrailingCommaPos.value !== -1) {
  8052. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  8053. }
  8054. return this.finishNode(node, "TSTypeParameterDeclaration");
  8055. }
  8056. tsFillSignature(returnToken, signature) {
  8057. const returnTokenRequired = returnToken === 19;
  8058. const paramsKey = "parameters";
  8059. const returnTypeKey = "typeAnnotation";
  8060. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  8061. this.expect(10);
  8062. signature[paramsKey] = this.tsParseBindingListForSignature();
  8063. if (returnTokenRequired) {
  8064. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8065. } else if (this.match(returnToken)) {
  8066. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8067. }
  8068. }
  8069. tsParseBindingListForSignature() {
  8070. const list = super.parseBindingList(11, 41, 2);
  8071. for (const pattern of list) {
  8072. const {
  8073. type
  8074. } = pattern;
  8075. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  8076. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  8077. type
  8078. });
  8079. }
  8080. }
  8081. return list;
  8082. }
  8083. tsParseTypeMemberSemicolon() {
  8084. if (!this.eat(12) && !this.isLineTerminator()) {
  8085. this.expect(13);
  8086. }
  8087. }
  8088. tsParseSignatureMember(kind, node) {
  8089. this.tsFillSignature(14, node);
  8090. this.tsParseTypeMemberSemicolon();
  8091. return this.finishNode(node, kind);
  8092. }
  8093. tsIsUnambiguouslyIndexSignature() {
  8094. this.next();
  8095. if (tokenIsIdentifier(this.state.type)) {
  8096. this.next();
  8097. return this.match(14);
  8098. }
  8099. return false;
  8100. }
  8101. tsTryParseIndexSignature(node) {
  8102. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8103. return;
  8104. }
  8105. this.expect(0);
  8106. const id = this.parseIdentifier();
  8107. id.typeAnnotation = this.tsParseTypeAnnotation();
  8108. this.resetEndLocation(id);
  8109. this.expect(3);
  8110. node.parameters = [id];
  8111. const type = this.tsTryParseTypeAnnotation();
  8112. if (type) node.typeAnnotation = type;
  8113. this.tsParseTypeMemberSemicolon();
  8114. return this.finishNode(node, "TSIndexSignature");
  8115. }
  8116. tsParsePropertyOrMethodSignature(node, readonly) {
  8117. if (this.eat(17)) node.optional = true;
  8118. if (this.match(10) || this.match(47)) {
  8119. if (readonly) {
  8120. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  8121. }
  8122. const method = node;
  8123. if (method.kind && this.match(47)) {
  8124. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  8125. }
  8126. this.tsFillSignature(14, method);
  8127. this.tsParseTypeMemberSemicolon();
  8128. const paramsKey = "parameters";
  8129. const returnTypeKey = "typeAnnotation";
  8130. if (method.kind === "get") {
  8131. if (method[paramsKey].length > 0) {
  8132. this.raise(Errors.BadGetterArity, this.state.curPosition());
  8133. if (this.isThisParam(method[paramsKey][0])) {
  8134. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8135. }
  8136. }
  8137. } else if (method.kind === "set") {
  8138. if (method[paramsKey].length !== 1) {
  8139. this.raise(Errors.BadSetterArity, this.state.curPosition());
  8140. } else {
  8141. const firstParameter = method[paramsKey][0];
  8142. if (this.isThisParam(firstParameter)) {
  8143. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8144. }
  8145. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8146. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  8147. }
  8148. if (firstParameter.type === "RestElement") {
  8149. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  8150. }
  8151. }
  8152. if (method[returnTypeKey]) {
  8153. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  8154. }
  8155. } else {
  8156. method.kind = "method";
  8157. }
  8158. return this.finishNode(method, "TSMethodSignature");
  8159. } else {
  8160. const property = node;
  8161. if (readonly) property.readonly = true;
  8162. const type = this.tsTryParseTypeAnnotation();
  8163. if (type) property.typeAnnotation = type;
  8164. this.tsParseTypeMemberSemicolon();
  8165. return this.finishNode(property, "TSPropertySignature");
  8166. }
  8167. }
  8168. tsParseTypeMember() {
  8169. const node = this.startNode();
  8170. if (this.match(10) || this.match(47)) {
  8171. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8172. }
  8173. if (this.match(77)) {
  8174. const id = this.startNode();
  8175. this.next();
  8176. if (this.match(10) || this.match(47)) {
  8177. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8178. } else {
  8179. node.key = this.createIdentifier(id, "new");
  8180. return this.tsParsePropertyOrMethodSignature(node, false);
  8181. }
  8182. }
  8183. this.tsParseModifiers({
  8184. allowedModifiers: ["readonly"],
  8185. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8186. }, node);
  8187. const idx = this.tsTryParseIndexSignature(node);
  8188. if (idx) {
  8189. return idx;
  8190. }
  8191. super.parsePropertyName(node);
  8192. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8193. node.kind = node.key.name;
  8194. super.parsePropertyName(node);
  8195. if (!this.match(10) && !this.match(47)) {
  8196. this.unexpected(null, 10);
  8197. }
  8198. }
  8199. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8200. }
  8201. tsParseTypeLiteral() {
  8202. const node = this.startNode();
  8203. node.members = this.tsParseObjectTypeMembers();
  8204. return this.finishNode(node, "TSTypeLiteral");
  8205. }
  8206. tsParseObjectTypeMembers() {
  8207. this.expect(5);
  8208. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8209. this.expect(8);
  8210. return members;
  8211. }
  8212. tsIsStartOfMappedType() {
  8213. this.next();
  8214. if (this.eat(53)) {
  8215. return this.isContextual(122);
  8216. }
  8217. if (this.isContextual(122)) {
  8218. this.next();
  8219. }
  8220. if (!this.match(0)) {
  8221. return false;
  8222. }
  8223. this.next();
  8224. if (!this.tsIsIdentifier()) {
  8225. return false;
  8226. }
  8227. this.next();
  8228. return this.match(58);
  8229. }
  8230. tsParseMappedType() {
  8231. const node = this.startNode();
  8232. this.expect(5);
  8233. if (this.match(53)) {
  8234. node.readonly = this.state.value;
  8235. this.next();
  8236. this.expectContextual(122);
  8237. } else if (this.eatContextual(122)) {
  8238. node.readonly = true;
  8239. }
  8240. this.expect(0);
  8241. {
  8242. const typeParameter = this.startNode();
  8243. typeParameter.name = this.tsParseTypeParameterName();
  8244. typeParameter.constraint = this.tsExpectThenParseType(58);
  8245. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8246. }
  8247. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8248. this.expect(3);
  8249. if (this.match(53)) {
  8250. node.optional = this.state.value;
  8251. this.next();
  8252. this.expect(17);
  8253. } else if (this.eat(17)) {
  8254. node.optional = true;
  8255. }
  8256. node.typeAnnotation = this.tsTryParseType();
  8257. this.semicolon();
  8258. this.expect(8);
  8259. return this.finishNode(node, "TSMappedType");
  8260. }
  8261. tsParseTupleType() {
  8262. const node = this.startNode();
  8263. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8264. let seenOptionalElement = false;
  8265. node.elementTypes.forEach(elementNode => {
  8266. const {
  8267. type
  8268. } = elementNode;
  8269. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8270. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8271. }
  8272. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8273. });
  8274. return this.finishNode(node, "TSTupleType");
  8275. }
  8276. tsParseTupleElementType() {
  8277. const restStartLoc = this.state.startLoc;
  8278. const rest = this.eat(21);
  8279. const {
  8280. startLoc
  8281. } = this.state;
  8282. let labeled;
  8283. let label;
  8284. let optional;
  8285. let type;
  8286. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8287. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8288. if (chAfterWord === 58) {
  8289. labeled = true;
  8290. optional = false;
  8291. label = this.parseIdentifier(true);
  8292. this.expect(14);
  8293. type = this.tsParseType();
  8294. } else if (chAfterWord === 63) {
  8295. optional = true;
  8296. const wordName = this.state.value;
  8297. const typeOrLabel = this.tsParseNonArrayType();
  8298. if (this.lookaheadCharCode() === 58) {
  8299. labeled = true;
  8300. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8301. this.expect(17);
  8302. this.expect(14);
  8303. type = this.tsParseType();
  8304. } else {
  8305. labeled = false;
  8306. type = typeOrLabel;
  8307. this.expect(17);
  8308. }
  8309. } else {
  8310. type = this.tsParseType();
  8311. optional = this.eat(17);
  8312. labeled = this.eat(14);
  8313. }
  8314. if (labeled) {
  8315. let labeledNode;
  8316. if (label) {
  8317. labeledNode = this.startNodeAt(startLoc);
  8318. labeledNode.optional = optional;
  8319. labeledNode.label = label;
  8320. labeledNode.elementType = type;
  8321. if (this.eat(17)) {
  8322. labeledNode.optional = true;
  8323. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8324. }
  8325. } else {
  8326. labeledNode = this.startNodeAt(startLoc);
  8327. labeledNode.optional = optional;
  8328. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8329. labeledNode.label = type;
  8330. labeledNode.elementType = this.tsParseType();
  8331. }
  8332. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8333. } else if (optional) {
  8334. const optionalTypeNode = this.startNodeAt(startLoc);
  8335. optionalTypeNode.typeAnnotation = type;
  8336. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8337. }
  8338. if (rest) {
  8339. const restNode = this.startNodeAt(restStartLoc);
  8340. restNode.typeAnnotation = type;
  8341. type = this.finishNode(restNode, "TSRestType");
  8342. }
  8343. return type;
  8344. }
  8345. tsParseParenthesizedType() {
  8346. const node = this.startNode();
  8347. this.expect(10);
  8348. node.typeAnnotation = this.tsParseType();
  8349. this.expect(11);
  8350. return this.finishNode(node, "TSParenthesizedType");
  8351. }
  8352. tsParseFunctionOrConstructorType(type, abstract) {
  8353. const node = this.startNode();
  8354. if (type === "TSConstructorType") {
  8355. node.abstract = !!abstract;
  8356. if (abstract) this.next();
  8357. this.next();
  8358. }
  8359. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8360. return this.finishNode(node, type);
  8361. }
  8362. tsParseLiteralTypeNode() {
  8363. const node = this.startNode();
  8364. switch (this.state.type) {
  8365. case 135:
  8366. case 136:
  8367. case 134:
  8368. case 85:
  8369. case 86:
  8370. node.literal = super.parseExprAtom();
  8371. break;
  8372. default:
  8373. this.unexpected();
  8374. }
  8375. return this.finishNode(node, "TSLiteralType");
  8376. }
  8377. tsParseTemplateLiteralType() {
  8378. {
  8379. const node = this.startNode();
  8380. node.literal = super.parseTemplate(false);
  8381. return this.finishNode(node, "TSLiteralType");
  8382. }
  8383. }
  8384. parseTemplateSubstitution() {
  8385. if (this.state.inType) return this.tsParseType();
  8386. return super.parseTemplateSubstitution();
  8387. }
  8388. tsParseThisTypeOrThisTypePredicate() {
  8389. const thisKeyword = this.tsParseThisTypeNode();
  8390. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8391. return this.tsParseThisTypePredicate(thisKeyword);
  8392. } else {
  8393. return thisKeyword;
  8394. }
  8395. }
  8396. tsParseNonArrayType() {
  8397. switch (this.state.type) {
  8398. case 134:
  8399. case 135:
  8400. case 136:
  8401. case 85:
  8402. case 86:
  8403. return this.tsParseLiteralTypeNode();
  8404. case 53:
  8405. if (this.state.value === "-") {
  8406. const node = this.startNode();
  8407. const nextToken = this.lookahead();
  8408. if (nextToken.type !== 135 && nextToken.type !== 136) {
  8409. this.unexpected();
  8410. }
  8411. node.literal = this.parseMaybeUnary();
  8412. return this.finishNode(node, "TSLiteralType");
  8413. }
  8414. break;
  8415. case 78:
  8416. return this.tsParseThisTypeOrThisTypePredicate();
  8417. case 87:
  8418. return this.tsParseTypeQuery();
  8419. case 83:
  8420. return this.tsParseImportType();
  8421. case 5:
  8422. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8423. case 0:
  8424. return this.tsParseTupleType();
  8425. case 10:
  8426. return this.tsParseParenthesizedType();
  8427. case 25:
  8428. case 24:
  8429. return this.tsParseTemplateLiteralType();
  8430. default:
  8431. {
  8432. const {
  8433. type
  8434. } = this.state;
  8435. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8436. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8437. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8438. const node = this.startNode();
  8439. this.next();
  8440. return this.finishNode(node, nodeType);
  8441. }
  8442. return this.tsParseTypeReference();
  8443. }
  8444. }
  8445. }
  8446. this.unexpected();
  8447. }
  8448. tsParseArrayTypeOrHigher() {
  8449. const {
  8450. startLoc
  8451. } = this.state;
  8452. let type = this.tsParseNonArrayType();
  8453. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8454. if (this.match(3)) {
  8455. const node = this.startNodeAt(startLoc);
  8456. node.elementType = type;
  8457. this.expect(3);
  8458. type = this.finishNode(node, "TSArrayType");
  8459. } else {
  8460. const node = this.startNodeAt(startLoc);
  8461. node.objectType = type;
  8462. node.indexType = this.tsParseType();
  8463. this.expect(3);
  8464. type = this.finishNode(node, "TSIndexedAccessType");
  8465. }
  8466. }
  8467. return type;
  8468. }
  8469. tsParseTypeOperator() {
  8470. const node = this.startNode();
  8471. const operator = this.state.value;
  8472. this.next();
  8473. node.operator = operator;
  8474. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8475. if (operator === "readonly") {
  8476. this.tsCheckTypeAnnotationForReadOnly(node);
  8477. }
  8478. return this.finishNode(node, "TSTypeOperator");
  8479. }
  8480. tsCheckTypeAnnotationForReadOnly(node) {
  8481. switch (node.typeAnnotation.type) {
  8482. case "TSTupleType":
  8483. case "TSArrayType":
  8484. return;
  8485. default:
  8486. this.raise(TSErrors.UnexpectedReadonly, node);
  8487. }
  8488. }
  8489. tsParseInferType() {
  8490. const node = this.startNode();
  8491. this.expectContextual(115);
  8492. const typeParameter = this.startNode();
  8493. typeParameter.name = this.tsParseTypeParameterName();
  8494. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8495. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8496. return this.finishNode(node, "TSInferType");
  8497. }
  8498. tsParseConstraintForInferType() {
  8499. if (this.eat(81)) {
  8500. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8501. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8502. return constraint;
  8503. }
  8504. }
  8505. }
  8506. tsParseTypeOperatorOrHigher() {
  8507. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8508. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8509. }
  8510. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8511. const node = this.startNode();
  8512. const hasLeadingOperator = this.eat(operator);
  8513. const types = [];
  8514. do {
  8515. types.push(parseConstituentType());
  8516. } while (this.eat(operator));
  8517. if (types.length === 1 && !hasLeadingOperator) {
  8518. return types[0];
  8519. }
  8520. node.types = types;
  8521. return this.finishNode(node, kind);
  8522. }
  8523. tsParseIntersectionTypeOrHigher() {
  8524. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8525. }
  8526. tsParseUnionTypeOrHigher() {
  8527. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8528. }
  8529. tsIsStartOfFunctionType() {
  8530. if (this.match(47)) {
  8531. return true;
  8532. }
  8533. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8534. }
  8535. tsSkipParameterStart() {
  8536. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8537. this.next();
  8538. return true;
  8539. }
  8540. if (this.match(5)) {
  8541. const {
  8542. errors
  8543. } = this.state;
  8544. const previousErrorCount = errors.length;
  8545. try {
  8546. this.parseObjectLike(8, true);
  8547. return errors.length === previousErrorCount;
  8548. } catch (_unused) {
  8549. return false;
  8550. }
  8551. }
  8552. if (this.match(0)) {
  8553. this.next();
  8554. const {
  8555. errors
  8556. } = this.state;
  8557. const previousErrorCount = errors.length;
  8558. try {
  8559. super.parseBindingList(3, 93, 1);
  8560. return errors.length === previousErrorCount;
  8561. } catch (_unused2) {
  8562. return false;
  8563. }
  8564. }
  8565. return false;
  8566. }
  8567. tsIsUnambiguouslyStartOfFunctionType() {
  8568. this.next();
  8569. if (this.match(11) || this.match(21)) {
  8570. return true;
  8571. }
  8572. if (this.tsSkipParameterStart()) {
  8573. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8574. return true;
  8575. }
  8576. if (this.match(11)) {
  8577. this.next();
  8578. if (this.match(19)) {
  8579. return true;
  8580. }
  8581. }
  8582. }
  8583. return false;
  8584. }
  8585. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8586. return this.tsInType(() => {
  8587. const t = this.startNode();
  8588. this.expect(returnToken);
  8589. const node = this.startNode();
  8590. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8591. if (asserts && this.match(78)) {
  8592. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8593. if (thisTypePredicate.type === "TSThisType") {
  8594. node.parameterName = thisTypePredicate;
  8595. node.asserts = true;
  8596. node.typeAnnotation = null;
  8597. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8598. } else {
  8599. this.resetStartLocationFromNode(thisTypePredicate, node);
  8600. thisTypePredicate.asserts = true;
  8601. }
  8602. t.typeAnnotation = thisTypePredicate;
  8603. return this.finishNode(t, "TSTypeAnnotation");
  8604. }
  8605. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8606. if (!typePredicateVariable) {
  8607. if (!asserts) {
  8608. return this.tsParseTypeAnnotation(false, t);
  8609. }
  8610. node.parameterName = this.parseIdentifier();
  8611. node.asserts = asserts;
  8612. node.typeAnnotation = null;
  8613. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8614. return this.finishNode(t, "TSTypeAnnotation");
  8615. }
  8616. const type = this.tsParseTypeAnnotation(false);
  8617. node.parameterName = typePredicateVariable;
  8618. node.typeAnnotation = type;
  8619. node.asserts = asserts;
  8620. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8621. return this.finishNode(t, "TSTypeAnnotation");
  8622. });
  8623. }
  8624. tsTryParseTypeOrTypePredicateAnnotation() {
  8625. if (this.match(14)) {
  8626. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8627. }
  8628. }
  8629. tsTryParseTypeAnnotation() {
  8630. if (this.match(14)) {
  8631. return this.tsParseTypeAnnotation();
  8632. }
  8633. }
  8634. tsTryParseType() {
  8635. return this.tsEatThenParseType(14);
  8636. }
  8637. tsParseTypePredicatePrefix() {
  8638. const id = this.parseIdentifier();
  8639. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8640. this.next();
  8641. return id;
  8642. }
  8643. }
  8644. tsParseTypePredicateAsserts() {
  8645. if (this.state.type !== 109) {
  8646. return false;
  8647. }
  8648. const containsEsc = this.state.containsEsc;
  8649. this.next();
  8650. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8651. return false;
  8652. }
  8653. if (containsEsc) {
  8654. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8655. reservedWord: "asserts"
  8656. });
  8657. }
  8658. return true;
  8659. }
  8660. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8661. this.tsInType(() => {
  8662. if (eatColon) this.expect(14);
  8663. t.typeAnnotation = this.tsParseType();
  8664. });
  8665. return this.finishNode(t, "TSTypeAnnotation");
  8666. }
  8667. tsParseType() {
  8668. assert(this.state.inType);
  8669. const type = this.tsParseNonConditionalType();
  8670. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8671. return type;
  8672. }
  8673. const node = this.startNodeAtNode(type);
  8674. node.checkType = type;
  8675. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8676. this.expect(17);
  8677. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8678. this.expect(14);
  8679. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8680. return this.finishNode(node, "TSConditionalType");
  8681. }
  8682. isAbstractConstructorSignature() {
  8683. return this.isContextual(124) && this.lookahead().type === 77;
  8684. }
  8685. tsParseNonConditionalType() {
  8686. if (this.tsIsStartOfFunctionType()) {
  8687. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8688. }
  8689. if (this.match(77)) {
  8690. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8691. } else if (this.isAbstractConstructorSignature()) {
  8692. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8693. }
  8694. return this.tsParseUnionTypeOrHigher();
  8695. }
  8696. tsParseTypeAssertion() {
  8697. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8698. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8699. }
  8700. const node = this.startNode();
  8701. node.typeAnnotation = this.tsInType(() => {
  8702. this.next();
  8703. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8704. });
  8705. this.expect(48);
  8706. node.expression = this.parseMaybeUnary();
  8707. return this.finishNode(node, "TSTypeAssertion");
  8708. }
  8709. tsParseHeritageClause(token) {
  8710. const originalStartLoc = this.state.startLoc;
  8711. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8712. {
  8713. const node = this.startNode();
  8714. node.expression = this.tsParseEntityName(1 | 2);
  8715. if (this.match(47)) {
  8716. node.typeParameters = this.tsParseTypeArguments();
  8717. }
  8718. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8719. }
  8720. });
  8721. if (!delimitedList.length) {
  8722. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8723. token
  8724. });
  8725. }
  8726. return delimitedList;
  8727. }
  8728. tsParseInterfaceDeclaration(node, properties = {}) {
  8729. if (this.hasFollowingLineBreak()) return null;
  8730. this.expectContextual(129);
  8731. if (properties.declare) node.declare = true;
  8732. if (tokenIsIdentifier(this.state.type)) {
  8733. node.id = this.parseIdentifier();
  8734. this.checkIdentifier(node.id, 130);
  8735. } else {
  8736. node.id = null;
  8737. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8738. }
  8739. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8740. if (this.eat(81)) {
  8741. node.extends = this.tsParseHeritageClause("extends");
  8742. }
  8743. const body = this.startNode();
  8744. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8745. node.body = this.finishNode(body, "TSInterfaceBody");
  8746. return this.finishNode(node, "TSInterfaceDeclaration");
  8747. }
  8748. tsParseTypeAliasDeclaration(node) {
  8749. node.id = this.parseIdentifier();
  8750. this.checkIdentifier(node.id, 2);
  8751. node.typeAnnotation = this.tsInType(() => {
  8752. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8753. this.expect(29);
  8754. if (this.isContextual(114) && this.lookahead().type !== 16) {
  8755. const node = this.startNode();
  8756. this.next();
  8757. return this.finishNode(node, "TSIntrinsicKeyword");
  8758. }
  8759. return this.tsParseType();
  8760. });
  8761. this.semicolon();
  8762. return this.finishNode(node, "TSTypeAliasDeclaration");
  8763. }
  8764. tsInTopLevelContext(cb) {
  8765. if (this.curContext() !== types.brace) {
  8766. const oldContext = this.state.context;
  8767. this.state.context = [oldContext[0]];
  8768. try {
  8769. return cb();
  8770. } finally {
  8771. this.state.context = oldContext;
  8772. }
  8773. } else {
  8774. return cb();
  8775. }
  8776. }
  8777. tsInType(cb) {
  8778. const oldInType = this.state.inType;
  8779. this.state.inType = true;
  8780. try {
  8781. return cb();
  8782. } finally {
  8783. this.state.inType = oldInType;
  8784. }
  8785. }
  8786. tsInDisallowConditionalTypesContext(cb) {
  8787. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8788. this.state.inDisallowConditionalTypesContext = true;
  8789. try {
  8790. return cb();
  8791. } finally {
  8792. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8793. }
  8794. }
  8795. tsInAllowConditionalTypesContext(cb) {
  8796. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8797. this.state.inDisallowConditionalTypesContext = false;
  8798. try {
  8799. return cb();
  8800. } finally {
  8801. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8802. }
  8803. }
  8804. tsEatThenParseType(token) {
  8805. if (this.match(token)) {
  8806. return this.tsNextThenParseType();
  8807. }
  8808. }
  8809. tsExpectThenParseType(token) {
  8810. return this.tsInType(() => {
  8811. this.expect(token);
  8812. return this.tsParseType();
  8813. });
  8814. }
  8815. tsNextThenParseType() {
  8816. return this.tsInType(() => {
  8817. this.next();
  8818. return this.tsParseType();
  8819. });
  8820. }
  8821. tsParseEnumMember() {
  8822. const node = this.startNode();
  8823. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8824. if (this.eat(29)) {
  8825. node.initializer = super.parseMaybeAssignAllowIn();
  8826. }
  8827. return this.finishNode(node, "TSEnumMember");
  8828. }
  8829. tsParseEnumDeclaration(node, properties = {}) {
  8830. if (properties.const) node.const = true;
  8831. if (properties.declare) node.declare = true;
  8832. this.expectContextual(126);
  8833. node.id = this.parseIdentifier();
  8834. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8835. {
  8836. this.expect(5);
  8837. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8838. this.expect(8);
  8839. }
  8840. return this.finishNode(node, "TSEnumDeclaration");
  8841. }
  8842. tsParseEnumBody() {
  8843. const node = this.startNode();
  8844. this.expect(5);
  8845. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8846. this.expect(8);
  8847. return this.finishNode(node, "TSEnumBody");
  8848. }
  8849. tsParseModuleBlock() {
  8850. const node = this.startNode();
  8851. this.scope.enter(0);
  8852. this.expect(5);
  8853. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8854. this.scope.exit();
  8855. return this.finishNode(node, "TSModuleBlock");
  8856. }
  8857. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8858. node.id = this.parseIdentifier();
  8859. if (!nested) {
  8860. this.checkIdentifier(node.id, 1024);
  8861. }
  8862. if (this.eat(16)) {
  8863. const inner = this.startNode();
  8864. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8865. node.body = inner;
  8866. } else {
  8867. this.scope.enter(256);
  8868. this.prodParam.enter(0);
  8869. node.body = this.tsParseModuleBlock();
  8870. this.prodParam.exit();
  8871. this.scope.exit();
  8872. }
  8873. return this.finishNode(node, "TSModuleDeclaration");
  8874. }
  8875. tsParseAmbientExternalModuleDeclaration(node) {
  8876. if (this.isContextual(112)) {
  8877. node.kind = "global";
  8878. {
  8879. node.global = true;
  8880. }
  8881. node.id = this.parseIdentifier();
  8882. } else if (this.match(134)) {
  8883. node.kind = "module";
  8884. node.id = super.parseStringLiteral(this.state.value);
  8885. } else {
  8886. this.unexpected();
  8887. }
  8888. if (this.match(5)) {
  8889. this.scope.enter(256);
  8890. this.prodParam.enter(0);
  8891. node.body = this.tsParseModuleBlock();
  8892. this.prodParam.exit();
  8893. this.scope.exit();
  8894. } else {
  8895. this.semicolon();
  8896. }
  8897. return this.finishNode(node, "TSModuleDeclaration");
  8898. }
  8899. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8900. {
  8901. node.isExport = isExport || false;
  8902. }
  8903. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8904. this.checkIdentifier(node.id, 4096);
  8905. this.expect(29);
  8906. const moduleReference = this.tsParseModuleReference();
  8907. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8908. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8909. }
  8910. node.moduleReference = moduleReference;
  8911. this.semicolon();
  8912. return this.finishNode(node, "TSImportEqualsDeclaration");
  8913. }
  8914. tsIsExternalModuleReference() {
  8915. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8916. }
  8917. tsParseModuleReference() {
  8918. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  8919. }
  8920. tsParseExternalModuleReference() {
  8921. const node = this.startNode();
  8922. this.expectContextual(119);
  8923. this.expect(10);
  8924. if (!this.match(134)) {
  8925. this.unexpected();
  8926. }
  8927. node.expression = super.parseExprAtom();
  8928. this.expect(11);
  8929. this.sawUnambiguousESM = true;
  8930. return this.finishNode(node, "TSExternalModuleReference");
  8931. }
  8932. tsLookAhead(f) {
  8933. const state = this.state.clone();
  8934. const res = f();
  8935. this.state = state;
  8936. return res;
  8937. }
  8938. tsTryParseAndCatch(f) {
  8939. const result = this.tryParse(abort => f() || abort());
  8940. if (result.aborted || !result.node) return;
  8941. if (result.error) this.state = result.failState;
  8942. return result.node;
  8943. }
  8944. tsTryParse(f) {
  8945. const state = this.state.clone();
  8946. const result = f();
  8947. if (result !== undefined && result !== false) {
  8948. return result;
  8949. }
  8950. this.state = state;
  8951. }
  8952. tsTryParseDeclare(nany) {
  8953. if (this.isLineTerminator()) {
  8954. return;
  8955. }
  8956. let startType = this.state.type;
  8957. let kind;
  8958. if (this.isContextual(100)) {
  8959. startType = 74;
  8960. kind = "let";
  8961. }
  8962. return this.tsInAmbientContext(() => {
  8963. switch (startType) {
  8964. case 68:
  8965. nany.declare = true;
  8966. return super.parseFunctionStatement(nany, false, false);
  8967. case 80:
  8968. nany.declare = true;
  8969. return this.parseClass(nany, true, false);
  8970. case 126:
  8971. return this.tsParseEnumDeclaration(nany, {
  8972. declare: true
  8973. });
  8974. case 112:
  8975. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8976. case 75:
  8977. case 74:
  8978. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8979. nany.declare = true;
  8980. return this.parseVarStatement(nany, kind || this.state.value, true);
  8981. }
  8982. this.expect(75);
  8983. return this.tsParseEnumDeclaration(nany, {
  8984. const: true,
  8985. declare: true
  8986. });
  8987. case 129:
  8988. {
  8989. const result = this.tsParseInterfaceDeclaration(nany, {
  8990. declare: true
  8991. });
  8992. if (result) return result;
  8993. }
  8994. default:
  8995. if (tokenIsIdentifier(startType)) {
  8996. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8997. }
  8998. }
  8999. });
  9000. }
  9001. tsTryParseExportDeclaration() {
  9002. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  9003. }
  9004. tsParseExpressionStatement(node, expr, decorators) {
  9005. switch (expr.name) {
  9006. case "declare":
  9007. {
  9008. const declaration = this.tsTryParseDeclare(node);
  9009. if (declaration) {
  9010. declaration.declare = true;
  9011. }
  9012. return declaration;
  9013. }
  9014. case "global":
  9015. if (this.match(5)) {
  9016. this.scope.enter(256);
  9017. this.prodParam.enter(0);
  9018. const mod = node;
  9019. mod.kind = "global";
  9020. {
  9021. node.global = true;
  9022. }
  9023. mod.id = expr;
  9024. mod.body = this.tsParseModuleBlock();
  9025. this.scope.exit();
  9026. this.prodParam.exit();
  9027. return this.finishNode(mod, "TSModuleDeclaration");
  9028. }
  9029. break;
  9030. default:
  9031. return this.tsParseDeclaration(node, expr.name, false, decorators);
  9032. }
  9033. }
  9034. tsParseDeclaration(node, value, next, decorators) {
  9035. switch (value) {
  9036. case "abstract":
  9037. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  9038. return this.tsParseAbstractDeclaration(node, decorators);
  9039. }
  9040. break;
  9041. case "module":
  9042. if (this.tsCheckLineTerminator(next)) {
  9043. if (this.match(134)) {
  9044. return this.tsParseAmbientExternalModuleDeclaration(node);
  9045. } else if (tokenIsIdentifier(this.state.type)) {
  9046. node.kind = "module";
  9047. return this.tsParseModuleOrNamespaceDeclaration(node);
  9048. }
  9049. }
  9050. break;
  9051. case "namespace":
  9052. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9053. node.kind = "namespace";
  9054. return this.tsParseModuleOrNamespaceDeclaration(node);
  9055. }
  9056. break;
  9057. case "type":
  9058. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9059. return this.tsParseTypeAliasDeclaration(node);
  9060. }
  9061. break;
  9062. }
  9063. }
  9064. tsCheckLineTerminator(next) {
  9065. if (next) {
  9066. if (this.hasFollowingLineBreak()) return false;
  9067. this.next();
  9068. return true;
  9069. }
  9070. return !this.isLineTerminator();
  9071. }
  9072. tsTryParseGenericAsyncArrowFunction(startLoc) {
  9073. if (!this.match(47)) return;
  9074. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9075. this.state.maybeInArrowParameters = true;
  9076. const res = this.tsTryParseAndCatch(() => {
  9077. const node = this.startNodeAt(startLoc);
  9078. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9079. super.parseFunctionParams(node);
  9080. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9081. this.expect(19);
  9082. return node;
  9083. });
  9084. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9085. if (!res) return;
  9086. return super.parseArrowExpression(res, null, true);
  9087. }
  9088. tsParseTypeArgumentsInExpression() {
  9089. if (this.reScan_lt() !== 47) return;
  9090. return this.tsParseTypeArguments();
  9091. }
  9092. tsParseTypeArguments() {
  9093. const node = this.startNode();
  9094. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  9095. this.expect(47);
  9096. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9097. }));
  9098. if (node.params.length === 0) {
  9099. this.raise(TSErrors.EmptyTypeArguments, node);
  9100. } else if (!this.state.inType && this.curContext() === types.brace) {
  9101. this.reScan_lt_gt();
  9102. }
  9103. this.expect(48);
  9104. return this.finishNode(node, "TSTypeParameterInstantiation");
  9105. }
  9106. tsIsDeclarationStart() {
  9107. return tokenIsTSDeclarationStart(this.state.type);
  9108. }
  9109. isExportDefaultSpecifier() {
  9110. if (this.tsIsDeclarationStart()) return false;
  9111. return super.isExportDefaultSpecifier();
  9112. }
  9113. parseBindingElement(flags, decorators) {
  9114. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  9115. const modified = {};
  9116. this.tsParseModifiers({
  9117. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9118. }, modified);
  9119. const accessibility = modified.accessibility;
  9120. const override = modified.override;
  9121. const readonly = modified.readonly;
  9122. if (!(flags & 4) && (accessibility || readonly || override)) {
  9123. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  9124. }
  9125. const left = this.parseMaybeDefault();
  9126. if (flags & 2) {
  9127. this.parseFunctionParamType(left);
  9128. }
  9129. const elt = this.parseMaybeDefault(left.loc.start, left);
  9130. if (accessibility || readonly || override) {
  9131. const pp = this.startNodeAt(startLoc);
  9132. if (decorators.length) {
  9133. pp.decorators = decorators;
  9134. }
  9135. if (accessibility) pp.accessibility = accessibility;
  9136. if (readonly) pp.readonly = readonly;
  9137. if (override) pp.override = override;
  9138. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9139. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  9140. }
  9141. pp.parameter = elt;
  9142. return this.finishNode(pp, "TSParameterProperty");
  9143. }
  9144. if (decorators.length) {
  9145. left.decorators = decorators;
  9146. }
  9147. return elt;
  9148. }
  9149. isSimpleParameter(node) {
  9150. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9151. }
  9152. tsDisallowOptionalPattern(node) {
  9153. for (const param of node.params) {
  9154. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9155. this.raise(TSErrors.PatternIsOptional, param);
  9156. }
  9157. }
  9158. }
  9159. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9160. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9161. this.tsDisallowOptionalPattern(node);
  9162. }
  9163. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9164. if (this.match(14)) {
  9165. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9166. }
  9167. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9168. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9169. return this.finishNode(node, bodilessType);
  9170. }
  9171. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9172. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  9173. if (node.declare) {
  9174. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9175. }
  9176. }
  9177. this.tsDisallowOptionalPattern(node);
  9178. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9179. }
  9180. registerFunctionStatementId(node) {
  9181. if (!node.body && node.id) {
  9182. this.checkIdentifier(node.id, 1024);
  9183. } else {
  9184. super.registerFunctionStatementId(node);
  9185. }
  9186. }
  9187. tsCheckForInvalidTypeCasts(items) {
  9188. items.forEach(node => {
  9189. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9190. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  9191. }
  9192. });
  9193. }
  9194. toReferencedList(exprList, isInParens) {
  9195. this.tsCheckForInvalidTypeCasts(exprList);
  9196. return exprList;
  9197. }
  9198. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9199. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9200. if (node.type === "ArrayExpression") {
  9201. this.tsCheckForInvalidTypeCasts(node.elements);
  9202. }
  9203. return node;
  9204. }
  9205. parseSubscript(base, startLoc, noCalls, state) {
  9206. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9207. this.state.canStartJSXElement = false;
  9208. this.next();
  9209. const nonNullExpression = this.startNodeAt(startLoc);
  9210. nonNullExpression.expression = base;
  9211. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9212. }
  9213. let isOptionalCall = false;
  9214. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9215. if (noCalls) {
  9216. state.stop = true;
  9217. return base;
  9218. }
  9219. state.optionalChainMember = isOptionalCall = true;
  9220. this.next();
  9221. }
  9222. if (this.match(47) || this.match(51)) {
  9223. let missingParenErrorLoc;
  9224. const result = this.tsTryParseAndCatch(() => {
  9225. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9226. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9227. if (asyncArrowFn) {
  9228. return asyncArrowFn;
  9229. }
  9230. }
  9231. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9232. if (!typeArguments) return;
  9233. if (isOptionalCall && !this.match(10)) {
  9234. missingParenErrorLoc = this.state.curPosition();
  9235. return;
  9236. }
  9237. if (tokenIsTemplate(this.state.type)) {
  9238. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9239. {
  9240. result.typeParameters = typeArguments;
  9241. }
  9242. return result;
  9243. }
  9244. if (!noCalls && this.eat(10)) {
  9245. const node = this.startNodeAt(startLoc);
  9246. node.callee = base;
  9247. node.arguments = this.parseCallExpressionArguments(11);
  9248. this.tsCheckForInvalidTypeCasts(node.arguments);
  9249. {
  9250. node.typeParameters = typeArguments;
  9251. }
  9252. if (state.optionalChainMember) {
  9253. node.optional = isOptionalCall;
  9254. }
  9255. return this.finishCallExpression(node, state.optionalChainMember);
  9256. }
  9257. const tokenType = this.state.type;
  9258. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9259. return;
  9260. }
  9261. const node = this.startNodeAt(startLoc);
  9262. node.expression = base;
  9263. {
  9264. node.typeParameters = typeArguments;
  9265. }
  9266. return this.finishNode(node, "TSInstantiationExpression");
  9267. });
  9268. if (missingParenErrorLoc) {
  9269. this.unexpected(missingParenErrorLoc, 10);
  9270. }
  9271. if (result) {
  9272. if (result.type === "TSInstantiationExpression") {
  9273. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  9274. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  9275. }
  9276. if (!this.match(16) && !this.match(18)) {
  9277. result.expression = super.stopParseSubscript(base, state);
  9278. }
  9279. }
  9280. return result;
  9281. }
  9282. }
  9283. return super.parseSubscript(base, startLoc, noCalls, state);
  9284. }
  9285. parseNewCallee(node) {
  9286. var _callee$extra;
  9287. super.parseNewCallee(node);
  9288. const {
  9289. callee
  9290. } = node;
  9291. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9292. {
  9293. node.typeParameters = callee.typeParameters;
  9294. }
  9295. node.callee = callee.expression;
  9296. }
  9297. }
  9298. parseExprOp(left, leftStartLoc, minPrec) {
  9299. let isSatisfies;
  9300. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9301. const node = this.startNodeAt(leftStartLoc);
  9302. node.expression = left;
  9303. node.typeAnnotation = this.tsInType(() => {
  9304. this.next();
  9305. if (this.match(75)) {
  9306. if (isSatisfies) {
  9307. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9308. keyword: "const"
  9309. });
  9310. }
  9311. return this.tsParseTypeReference();
  9312. }
  9313. return this.tsParseType();
  9314. });
  9315. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9316. this.reScan_lt_gt();
  9317. return this.parseExprOp(node, leftStartLoc, minPrec);
  9318. }
  9319. return super.parseExprOp(left, leftStartLoc, minPrec);
  9320. }
  9321. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9322. if (!this.state.isAmbientContext) {
  9323. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9324. }
  9325. }
  9326. checkImportReflection(node) {
  9327. super.checkImportReflection(node);
  9328. if (node.module && node.importKind !== "value") {
  9329. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9330. }
  9331. }
  9332. checkDuplicateExports() {}
  9333. isPotentialImportPhase(isExport) {
  9334. if (super.isPotentialImportPhase(isExport)) return true;
  9335. if (this.isContextual(130)) {
  9336. const ch = this.lookaheadCharCode();
  9337. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9338. }
  9339. return !isExport && this.isContextual(87);
  9340. }
  9341. applyImportPhase(node, isExport, phase, loc) {
  9342. super.applyImportPhase(node, isExport, phase, loc);
  9343. if (isExport) {
  9344. node.exportKind = phase === "type" ? "type" : "value";
  9345. } else {
  9346. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9347. }
  9348. }
  9349. parseImport(node) {
  9350. if (this.match(134)) {
  9351. node.importKind = "value";
  9352. return super.parseImport(node);
  9353. }
  9354. let importNode;
  9355. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9356. node.importKind = "value";
  9357. return this.tsParseImportEqualsDeclaration(node);
  9358. } else if (this.isContextual(130)) {
  9359. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9360. if (this.lookaheadCharCode() === 61) {
  9361. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9362. } else {
  9363. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9364. }
  9365. } else {
  9366. importNode = super.parseImport(node);
  9367. }
  9368. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9369. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9370. }
  9371. return importNode;
  9372. }
  9373. parseExport(node, decorators) {
  9374. if (this.match(83)) {
  9375. const nodeImportEquals = node;
  9376. this.next();
  9377. let maybeDefaultIdentifier = null;
  9378. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9379. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9380. } else {
  9381. nodeImportEquals.importKind = "value";
  9382. }
  9383. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9384. {
  9385. return declaration;
  9386. }
  9387. } else if (this.eat(29)) {
  9388. const assign = node;
  9389. assign.expression = super.parseExpression();
  9390. this.semicolon();
  9391. this.sawUnambiguousESM = true;
  9392. return this.finishNode(assign, "TSExportAssignment");
  9393. } else if (this.eatContextual(93)) {
  9394. const decl = node;
  9395. this.expectContextual(128);
  9396. decl.id = this.parseIdentifier();
  9397. this.semicolon();
  9398. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9399. } else {
  9400. return super.parseExport(node, decorators);
  9401. }
  9402. }
  9403. isAbstractClass() {
  9404. return this.isContextual(124) && this.lookahead().type === 80;
  9405. }
  9406. parseExportDefaultExpression() {
  9407. if (this.isAbstractClass()) {
  9408. const cls = this.startNode();
  9409. this.next();
  9410. cls.abstract = true;
  9411. return this.parseClass(cls, true, true);
  9412. }
  9413. if (this.match(129)) {
  9414. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9415. if (result) return result;
  9416. }
  9417. return super.parseExportDefaultExpression();
  9418. }
  9419. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9420. const {
  9421. isAmbientContext
  9422. } = this.state;
  9423. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9424. if (!isAmbientContext) return declaration;
  9425. for (const {
  9426. id,
  9427. init
  9428. } of declaration.declarations) {
  9429. if (!init) continue;
  9430. if (kind !== "const" || !!id.typeAnnotation) {
  9431. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9432. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9433. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9434. }
  9435. }
  9436. return declaration;
  9437. }
  9438. parseStatementContent(flags, decorators) {
  9439. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9440. const node = this.startNode();
  9441. this.expect(75);
  9442. return this.tsParseEnumDeclaration(node, {
  9443. const: true
  9444. });
  9445. }
  9446. if (this.isContextual(126)) {
  9447. return this.tsParseEnumDeclaration(this.startNode());
  9448. }
  9449. if (this.isContextual(129)) {
  9450. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9451. if (result) return result;
  9452. }
  9453. return super.parseStatementContent(flags, decorators);
  9454. }
  9455. parseAccessModifier() {
  9456. return this.tsParseModifier(["public", "protected", "private"]);
  9457. }
  9458. tsHasSomeModifiers(member, modifiers) {
  9459. return modifiers.some(modifier => {
  9460. if (tsIsAccessModifier(modifier)) {
  9461. return member.accessibility === modifier;
  9462. }
  9463. return !!member[modifier];
  9464. });
  9465. }
  9466. tsIsStartOfStaticBlocks() {
  9467. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9468. }
  9469. parseClassMember(classBody, member, state) {
  9470. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9471. this.tsParseModifiers({
  9472. allowedModifiers: modifiers,
  9473. disallowedModifiers: ["in", "out"],
  9474. stopOnStartOfClassStaticBlock: true,
  9475. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9476. }, member);
  9477. const callParseClassMemberWithIsStatic = () => {
  9478. if (this.tsIsStartOfStaticBlocks()) {
  9479. this.next();
  9480. this.next();
  9481. if (this.tsHasSomeModifiers(member, modifiers)) {
  9482. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9483. }
  9484. super.parseClassStaticBlock(classBody, member);
  9485. } else {
  9486. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9487. }
  9488. };
  9489. if (member.declare) {
  9490. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9491. } else {
  9492. callParseClassMemberWithIsStatic();
  9493. }
  9494. }
  9495. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9496. const idx = this.tsTryParseIndexSignature(member);
  9497. if (idx) {
  9498. classBody.body.push(idx);
  9499. if (member.abstract) {
  9500. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9501. }
  9502. if (member.accessibility) {
  9503. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9504. modifier: member.accessibility
  9505. });
  9506. }
  9507. if (member.declare) {
  9508. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9509. }
  9510. if (member.override) {
  9511. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9512. }
  9513. return;
  9514. }
  9515. if (!this.state.inAbstractClass && member.abstract) {
  9516. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9517. }
  9518. if (member.override) {
  9519. if (!state.hadSuperClass) {
  9520. this.raise(TSErrors.OverrideNotInSubClass, member);
  9521. }
  9522. }
  9523. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9524. }
  9525. parsePostMemberNameModifiers(methodOrProp) {
  9526. const optional = this.eat(17);
  9527. if (optional) methodOrProp.optional = true;
  9528. if (methodOrProp.readonly && this.match(10)) {
  9529. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9530. }
  9531. if (methodOrProp.declare && this.match(10)) {
  9532. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9533. }
  9534. }
  9535. parseExpressionStatement(node, expr, decorators) {
  9536. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9537. return decl || super.parseExpressionStatement(node, expr, decorators);
  9538. }
  9539. shouldParseExportDeclaration() {
  9540. if (this.tsIsDeclarationStart()) return true;
  9541. return super.shouldParseExportDeclaration();
  9542. }
  9543. parseConditional(expr, startLoc, refExpressionErrors) {
  9544. if (!this.match(17)) return expr;
  9545. if (this.state.maybeInArrowParameters) {
  9546. const nextCh = this.lookaheadCharCode();
  9547. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  9548. this.setOptionalParametersError(refExpressionErrors);
  9549. return expr;
  9550. }
  9551. }
  9552. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9553. }
  9554. parseParenItem(node, startLoc) {
  9555. const newNode = super.parseParenItem(node, startLoc);
  9556. if (this.eat(17)) {
  9557. newNode.optional = true;
  9558. this.resetEndLocation(node);
  9559. }
  9560. if (this.match(14)) {
  9561. const typeCastNode = this.startNodeAt(startLoc);
  9562. typeCastNode.expression = node;
  9563. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9564. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9565. }
  9566. return node;
  9567. }
  9568. parseExportDeclaration(node) {
  9569. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9570. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9571. }
  9572. const startLoc = this.state.startLoc;
  9573. const isDeclare = this.eatContextual(125);
  9574. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9575. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9576. }
  9577. const isIdentifier = tokenIsIdentifier(this.state.type);
  9578. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9579. if (!declaration) return null;
  9580. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9581. node.exportKind = "type";
  9582. }
  9583. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  9584. this.resetStartLocation(declaration, startLoc);
  9585. declaration.declare = true;
  9586. }
  9587. return declaration;
  9588. }
  9589. parseClassId(node, isStatement, optionalId, bindingType) {
  9590. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9591. return;
  9592. }
  9593. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9594. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9595. if (typeParameters) node.typeParameters = typeParameters;
  9596. }
  9597. parseClassPropertyAnnotation(node) {
  9598. if (!node.optional) {
  9599. if (this.eat(35)) {
  9600. node.definite = true;
  9601. } else if (this.eat(17)) {
  9602. node.optional = true;
  9603. }
  9604. }
  9605. const type = this.tsTryParseTypeAnnotation();
  9606. if (type) node.typeAnnotation = type;
  9607. }
  9608. parseClassProperty(node) {
  9609. this.parseClassPropertyAnnotation(node);
  9610. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9611. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9612. }
  9613. if (node.abstract && this.match(29)) {
  9614. const {
  9615. key
  9616. } = node;
  9617. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9618. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9619. });
  9620. }
  9621. return super.parseClassProperty(node);
  9622. }
  9623. parseClassPrivateProperty(node) {
  9624. if (node.abstract) {
  9625. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9626. }
  9627. if (node.accessibility) {
  9628. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9629. modifier: node.accessibility
  9630. });
  9631. }
  9632. this.parseClassPropertyAnnotation(node);
  9633. return super.parseClassPrivateProperty(node);
  9634. }
  9635. parseClassAccessorProperty(node) {
  9636. this.parseClassPropertyAnnotation(node);
  9637. if (node.optional) {
  9638. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9639. }
  9640. return super.parseClassAccessorProperty(node);
  9641. }
  9642. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9643. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9644. if (typeParameters && isConstructor) {
  9645. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9646. }
  9647. const {
  9648. declare = false,
  9649. kind
  9650. } = method;
  9651. if (declare && (kind === "get" || kind === "set")) {
  9652. this.raise(TSErrors.DeclareAccessor, method, {
  9653. kind
  9654. });
  9655. }
  9656. if (typeParameters) method.typeParameters = typeParameters;
  9657. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9658. }
  9659. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9660. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9661. if (typeParameters) method.typeParameters = typeParameters;
  9662. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9663. }
  9664. declareClassPrivateMethodInScope(node, kind) {
  9665. if (node.type === "TSDeclareMethod") return;
  9666. if (node.type === "MethodDefinition" && node.value.body == null) {
  9667. return;
  9668. }
  9669. super.declareClassPrivateMethodInScope(node, kind);
  9670. }
  9671. parseClassSuper(node) {
  9672. super.parseClassSuper(node);
  9673. if (node.superClass && (this.match(47) || this.match(51))) {
  9674. {
  9675. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9676. }
  9677. }
  9678. if (this.eatContextual(113)) {
  9679. node.implements = this.tsParseHeritageClause("implements");
  9680. }
  9681. }
  9682. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9683. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9684. if (typeParameters) prop.typeParameters = typeParameters;
  9685. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9686. }
  9687. parseFunctionParams(node, isConstructor) {
  9688. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9689. if (typeParameters) node.typeParameters = typeParameters;
  9690. super.parseFunctionParams(node, isConstructor);
  9691. }
  9692. parseVarId(decl, kind) {
  9693. super.parseVarId(decl, kind);
  9694. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9695. decl.definite = true;
  9696. }
  9697. const type = this.tsTryParseTypeAnnotation();
  9698. if (type) {
  9699. decl.id.typeAnnotation = type;
  9700. this.resetEndLocation(decl.id);
  9701. }
  9702. }
  9703. parseAsyncArrowFromCallExpression(node, call) {
  9704. if (this.match(14)) {
  9705. node.returnType = this.tsParseTypeAnnotation();
  9706. }
  9707. return super.parseAsyncArrowFromCallExpression(node, call);
  9708. }
  9709. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9710. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9711. let state;
  9712. let jsx;
  9713. let typeCast;
  9714. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  9715. state = this.state.clone();
  9716. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9717. if (!jsx.error) return jsx.node;
  9718. const {
  9719. context
  9720. } = this.state;
  9721. const currentContext = context[context.length - 1];
  9722. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9723. context.pop();
  9724. }
  9725. }
  9726. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9727. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9728. }
  9729. if (!state || state === this.state) state = this.state.clone();
  9730. let typeParameters;
  9731. const arrow = this.tryParse(abort => {
  9732. var _expr$extra, _typeParameters;
  9733. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9734. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9735. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9736. abort();
  9737. }
  9738. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9739. this.resetStartLocationFromNode(expr, typeParameters);
  9740. }
  9741. expr.typeParameters = typeParameters;
  9742. return expr;
  9743. }, state);
  9744. if (!arrow.error && !arrow.aborted) {
  9745. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9746. return arrow.node;
  9747. }
  9748. if (!jsx) {
  9749. assert(!this.hasPlugin("jsx"));
  9750. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9751. if (!typeCast.error) return typeCast.node;
  9752. }
  9753. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9754. this.state = jsx.failState;
  9755. return jsx.node;
  9756. }
  9757. if (arrow.node) {
  9758. this.state = arrow.failState;
  9759. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9760. return arrow.node;
  9761. }
  9762. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9763. this.state = typeCast.failState;
  9764. return typeCast.node;
  9765. }
  9766. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9767. }
  9768. reportReservedArrowTypeParam(node) {
  9769. var _node$extra2;
  9770. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9771. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9772. }
  9773. }
  9774. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9775. if (!this.hasPlugin("jsx") && this.match(47)) {
  9776. return this.tsParseTypeAssertion();
  9777. }
  9778. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9779. }
  9780. parseArrow(node) {
  9781. if (this.match(14)) {
  9782. const result = this.tryParse(abort => {
  9783. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9784. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9785. return returnType;
  9786. });
  9787. if (result.aborted) return;
  9788. if (!result.thrown) {
  9789. if (result.error) this.state = result.failState;
  9790. node.returnType = result.node;
  9791. }
  9792. }
  9793. return super.parseArrow(node);
  9794. }
  9795. parseFunctionParamType(param) {
  9796. if (this.eat(17)) {
  9797. param.optional = true;
  9798. }
  9799. const type = this.tsTryParseTypeAnnotation();
  9800. if (type) param.typeAnnotation = type;
  9801. this.resetEndLocation(param);
  9802. return param;
  9803. }
  9804. isAssignable(node, isBinding) {
  9805. switch (node.type) {
  9806. case "TSTypeCastExpression":
  9807. return this.isAssignable(node.expression, isBinding);
  9808. case "TSParameterProperty":
  9809. return true;
  9810. default:
  9811. return super.isAssignable(node, isBinding);
  9812. }
  9813. }
  9814. toAssignable(node, isLHS = false) {
  9815. switch (node.type) {
  9816. case "ParenthesizedExpression":
  9817. this.toAssignableParenthesizedExpression(node, isLHS);
  9818. break;
  9819. case "TSAsExpression":
  9820. case "TSSatisfiesExpression":
  9821. case "TSNonNullExpression":
  9822. case "TSTypeAssertion":
  9823. if (isLHS) {
  9824. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9825. } else {
  9826. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9827. }
  9828. this.toAssignable(node.expression, isLHS);
  9829. break;
  9830. case "AssignmentExpression":
  9831. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9832. node.left = this.typeCastToParameter(node.left);
  9833. }
  9834. default:
  9835. super.toAssignable(node, isLHS);
  9836. }
  9837. }
  9838. toAssignableParenthesizedExpression(node, isLHS) {
  9839. switch (node.expression.type) {
  9840. case "TSAsExpression":
  9841. case "TSSatisfiesExpression":
  9842. case "TSNonNullExpression":
  9843. case "TSTypeAssertion":
  9844. case "ParenthesizedExpression":
  9845. this.toAssignable(node.expression, isLHS);
  9846. break;
  9847. default:
  9848. super.toAssignable(node, isLHS);
  9849. }
  9850. }
  9851. checkToRestConversion(node, allowPattern) {
  9852. switch (node.type) {
  9853. case "TSAsExpression":
  9854. case "TSSatisfiesExpression":
  9855. case "TSTypeAssertion":
  9856. case "TSNonNullExpression":
  9857. this.checkToRestConversion(node.expression, false);
  9858. break;
  9859. default:
  9860. super.checkToRestConversion(node, allowPattern);
  9861. }
  9862. }
  9863. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9864. switch (type) {
  9865. case "TSTypeCastExpression":
  9866. return true;
  9867. case "TSParameterProperty":
  9868. return "parameter";
  9869. case "TSNonNullExpression":
  9870. return "expression";
  9871. case "TSAsExpression":
  9872. case "TSSatisfiesExpression":
  9873. case "TSTypeAssertion":
  9874. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  9875. default:
  9876. return super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9877. }
  9878. }
  9879. parseBindingAtom() {
  9880. if (this.state.type === 78) {
  9881. return this.parseIdentifier(true);
  9882. }
  9883. return super.parseBindingAtom();
  9884. }
  9885. parseMaybeDecoratorArguments(expr, startLoc) {
  9886. if (this.match(47) || this.match(51)) {
  9887. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9888. if (this.match(10)) {
  9889. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  9890. {
  9891. call.typeParameters = typeArguments;
  9892. }
  9893. return call;
  9894. }
  9895. this.unexpected(null, 10);
  9896. }
  9897. return super.parseMaybeDecoratorArguments(expr, startLoc);
  9898. }
  9899. checkCommaAfterRest(close) {
  9900. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9901. this.next();
  9902. return false;
  9903. }
  9904. return super.checkCommaAfterRest(close);
  9905. }
  9906. isClassMethod() {
  9907. return this.match(47) || super.isClassMethod();
  9908. }
  9909. isClassProperty() {
  9910. return this.match(35) || this.match(14) || super.isClassProperty();
  9911. }
  9912. parseMaybeDefault(startLoc, left) {
  9913. const node = super.parseMaybeDefault(startLoc, left);
  9914. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9915. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  9916. }
  9917. return node;
  9918. }
  9919. getTokenFromCode(code) {
  9920. if (this.state.inType) {
  9921. if (code === 62) {
  9922. this.finishOp(48, 1);
  9923. return;
  9924. }
  9925. if (code === 60) {
  9926. this.finishOp(47, 1);
  9927. return;
  9928. }
  9929. }
  9930. super.getTokenFromCode(code);
  9931. }
  9932. reScan_lt_gt() {
  9933. const {
  9934. type
  9935. } = this.state;
  9936. if (type === 47) {
  9937. this.state.pos -= 1;
  9938. this.readToken_lt();
  9939. } else if (type === 48) {
  9940. this.state.pos -= 1;
  9941. this.readToken_gt();
  9942. }
  9943. }
  9944. reScan_lt() {
  9945. const {
  9946. type
  9947. } = this.state;
  9948. if (type === 51) {
  9949. this.state.pos -= 2;
  9950. this.finishOp(47, 1);
  9951. return 47;
  9952. }
  9953. return type;
  9954. }
  9955. toAssignableListItem(exprList, index, isLHS) {
  9956. const node = exprList[index];
  9957. if (node.type === "TSTypeCastExpression") {
  9958. exprList[index] = this.typeCastToParameter(node);
  9959. }
  9960. super.toAssignableListItem(exprList, index, isLHS);
  9961. }
  9962. typeCastToParameter(node) {
  9963. node.expression.typeAnnotation = node.typeAnnotation;
  9964. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9965. return node.expression;
  9966. }
  9967. shouldParseArrow(params) {
  9968. if (this.match(14)) {
  9969. return params.every(expr => this.isAssignable(expr, true));
  9970. }
  9971. return super.shouldParseArrow(params);
  9972. }
  9973. shouldParseAsyncArrow() {
  9974. return this.match(14) || super.shouldParseAsyncArrow();
  9975. }
  9976. canHaveLeadingDecorator() {
  9977. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9978. }
  9979. jsxParseOpeningElementAfterName(node) {
  9980. if (this.match(47) || this.match(51)) {
  9981. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9982. if (typeArguments) {
  9983. {
  9984. node.typeParameters = typeArguments;
  9985. }
  9986. }
  9987. }
  9988. return super.jsxParseOpeningElementAfterName(node);
  9989. }
  9990. getGetterSetterExpectedParamCount(method) {
  9991. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9992. const params = this.getObjectOrClassMethodParams(method);
  9993. const firstParam = params[0];
  9994. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9995. return hasContextParam ? baseCount + 1 : baseCount;
  9996. }
  9997. parseCatchClauseParam() {
  9998. const param = super.parseCatchClauseParam();
  9999. const type = this.tsTryParseTypeAnnotation();
  10000. if (type) {
  10001. param.typeAnnotation = type;
  10002. this.resetEndLocation(param);
  10003. }
  10004. return param;
  10005. }
  10006. tsInAmbientContext(cb) {
  10007. const {
  10008. isAmbientContext: oldIsAmbientContext,
  10009. strict: oldStrict
  10010. } = this.state;
  10011. this.state.isAmbientContext = true;
  10012. this.state.strict = false;
  10013. try {
  10014. return cb();
  10015. } finally {
  10016. this.state.isAmbientContext = oldIsAmbientContext;
  10017. this.state.strict = oldStrict;
  10018. }
  10019. }
  10020. parseClass(node, isStatement, optionalId) {
  10021. const oldInAbstractClass = this.state.inAbstractClass;
  10022. this.state.inAbstractClass = !!node.abstract;
  10023. try {
  10024. return super.parseClass(node, isStatement, optionalId);
  10025. } finally {
  10026. this.state.inAbstractClass = oldInAbstractClass;
  10027. }
  10028. }
  10029. tsParseAbstractDeclaration(node, decorators) {
  10030. if (this.match(80)) {
  10031. node.abstract = true;
  10032. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  10033. } else if (this.isContextual(129)) {
  10034. if (!this.hasFollowingLineBreak()) {
  10035. node.abstract = true;
  10036. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, node);
  10037. return this.tsParseInterfaceDeclaration(node);
  10038. }
  10039. } else {
  10040. this.unexpected(null, 80);
  10041. }
  10042. }
  10043. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  10044. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  10045. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  10046. const hasEstreePlugin = this.hasPlugin("estree");
  10047. const methodFn = hasEstreePlugin ? method.value : method;
  10048. if (methodFn.body) {
  10049. const {
  10050. key
  10051. } = method;
  10052. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  10053. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  10054. });
  10055. }
  10056. }
  10057. return method;
  10058. }
  10059. tsParseTypeParameterName() {
  10060. const typeName = this.parseIdentifier();
  10061. return typeName.name;
  10062. }
  10063. shouldParseAsAmbientContext() {
  10064. return !!this.getPluginOption("typescript", "dts");
  10065. }
  10066. parse() {
  10067. if (this.shouldParseAsAmbientContext()) {
  10068. this.state.isAmbientContext = true;
  10069. }
  10070. return super.parse();
  10071. }
  10072. getExpression() {
  10073. if (this.shouldParseAsAmbientContext()) {
  10074. this.state.isAmbientContext = true;
  10075. }
  10076. return super.getExpression();
  10077. }
  10078. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10079. if (!isString && isMaybeTypeOnly) {
  10080. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10081. return this.finishNode(node, "ExportSpecifier");
  10082. }
  10083. node.exportKind = "value";
  10084. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10085. }
  10086. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10087. if (!importedIsString && isMaybeTypeOnly) {
  10088. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10089. return this.finishNode(specifier, "ImportSpecifier");
  10090. }
  10091. specifier.importKind = "value";
  10092. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  10093. }
  10094. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10095. const leftOfAsKey = isImport ? "imported" : "local";
  10096. const rightOfAsKey = isImport ? "local" : "exported";
  10097. let leftOfAs = node[leftOfAsKey];
  10098. let rightOfAs;
  10099. let hasTypeSpecifier = false;
  10100. let canParseAsKeyword = true;
  10101. const loc = leftOfAs.loc.start;
  10102. if (this.isContextual(93)) {
  10103. const firstAs = this.parseIdentifier();
  10104. if (this.isContextual(93)) {
  10105. const secondAs = this.parseIdentifier();
  10106. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10107. hasTypeSpecifier = true;
  10108. leftOfAs = firstAs;
  10109. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10110. canParseAsKeyword = false;
  10111. } else {
  10112. rightOfAs = secondAs;
  10113. canParseAsKeyword = false;
  10114. }
  10115. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10116. canParseAsKeyword = false;
  10117. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10118. } else {
  10119. hasTypeSpecifier = true;
  10120. leftOfAs = firstAs;
  10121. }
  10122. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10123. hasTypeSpecifier = true;
  10124. if (isImport) {
  10125. leftOfAs = this.parseIdentifier(true);
  10126. if (!this.isContextual(93)) {
  10127. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10128. }
  10129. } else {
  10130. leftOfAs = this.parseModuleExportName();
  10131. }
  10132. }
  10133. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10134. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  10135. }
  10136. node[leftOfAsKey] = leftOfAs;
  10137. node[rightOfAsKey] = rightOfAs;
  10138. const kindKey = isImport ? "importKind" : "exportKind";
  10139. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10140. if (canParseAsKeyword && this.eatContextual(93)) {
  10141. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10142. }
  10143. if (!node[rightOfAsKey]) {
  10144. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  10145. }
  10146. if (isImport) {
  10147. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10148. }
  10149. }
  10150. fillOptionalPropertiesForTSESLint(node) {
  10151. var _node$directive, _node$decorators, _node$optional, _node$typeAnnotation, _node$accessibility, _node$decorators2, _node$override, _node$readonly, _node$static, _node$declare, _node$returnType, _node$typeParameters, _node$optional2, _node$optional3, _node$accessibility2, _node$readonly2, _node$static2, _node$declare2, _node$definite, _node$readonly3, _node$typeAnnotation2, _node$accessibility3, _node$decorators3, _node$override2, _node$optional4, _node$id, _node$abstract, _node$declare3, _node$decorators4, _node$implements, _node$superTypeArgume, _node$typeParameters2, _node$declare4, _node$definite2, _node$const, _node$declare5, _node$computed, _node$qualifier, _node$options, _node$declare6, _node$extends, _node$declare7, _node$global, _node$const2, _node$in, _node$out;
  10152. switch (node.type) {
  10153. case "ExpressionStatement":
  10154. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  10155. return;
  10156. case "RestElement":
  10157. node.value = undefined;
  10158. case "Identifier":
  10159. case "ArrayPattern":
  10160. case "AssignmentPattern":
  10161. case "ObjectPattern":
  10162. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  10163. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  10164. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  10165. return;
  10166. case "TSParameterProperty":
  10167. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  10168. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  10169. (_node$override = node.override) != null ? _node$override : node.override = false;
  10170. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  10171. (_node$static = node.static) != null ? _node$static : node.static = false;
  10172. return;
  10173. case "TSEmptyBodyFunctionExpression":
  10174. node.body = null;
  10175. case "TSDeclareFunction":
  10176. case "FunctionDeclaration":
  10177. case "FunctionExpression":
  10178. case "ClassMethod":
  10179. case "ClassPrivateMethod":
  10180. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  10181. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  10182. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  10183. return;
  10184. case "Property":
  10185. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  10186. return;
  10187. case "TSMethodSignature":
  10188. case "TSPropertySignature":
  10189. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  10190. case "TSIndexSignature":
  10191. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  10192. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  10193. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  10194. return;
  10195. case "TSAbstractPropertyDefinition":
  10196. case "PropertyDefinition":
  10197. case "TSAbstractAccessorProperty":
  10198. case "AccessorProperty":
  10199. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  10200. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  10201. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  10202. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  10203. case "TSAbstractMethodDefinition":
  10204. case "MethodDefinition":
  10205. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  10206. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  10207. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  10208. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  10209. return;
  10210. case "ClassExpression":
  10211. (_node$id = node.id) != null ? _node$id : node.id = null;
  10212. case "ClassDeclaration":
  10213. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  10214. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  10215. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  10216. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  10217. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  10218. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  10219. return;
  10220. case "TSTypeAliasDeclaration":
  10221. case "VariableDeclaration":
  10222. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  10223. return;
  10224. case "VariableDeclarator":
  10225. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  10226. return;
  10227. case "TSEnumDeclaration":
  10228. (_node$const = node.const) != null ? _node$const : node.const = false;
  10229. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  10230. return;
  10231. case "TSEnumMember":
  10232. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  10233. return;
  10234. case "TSImportType":
  10235. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  10236. (_node$options = node.options) != null ? _node$options : node.options = null;
  10237. return;
  10238. case "TSInterfaceDeclaration":
  10239. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  10240. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  10241. return;
  10242. case "TSModuleDeclaration":
  10243. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  10244. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  10245. return;
  10246. case "TSTypeParameter":
  10247. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  10248. (_node$in = node.in) != null ? _node$in : node.in = false;
  10249. (_node$out = node.out) != null ? _node$out : node.out = false;
  10250. return;
  10251. }
  10252. }
  10253. };
  10254. function isPossiblyLiteralEnum(expression) {
  10255. if (expression.type !== "MemberExpression") return false;
  10256. const {
  10257. computed,
  10258. property
  10259. } = expression;
  10260. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10261. return false;
  10262. }
  10263. return isUncomputedMemberExpressionChain(expression.object);
  10264. }
  10265. function isValidAmbientConstInitializer(expression, estree) {
  10266. var _expression$extra;
  10267. const {
  10268. type
  10269. } = expression;
  10270. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10271. return false;
  10272. }
  10273. if (estree) {
  10274. if (type === "Literal") {
  10275. const {
  10276. value
  10277. } = expression;
  10278. if (typeof value === "string" || typeof value === "boolean") {
  10279. return true;
  10280. }
  10281. }
  10282. } else {
  10283. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10284. return true;
  10285. }
  10286. }
  10287. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10288. return true;
  10289. }
  10290. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10291. return true;
  10292. }
  10293. if (isPossiblyLiteralEnum(expression)) {
  10294. return true;
  10295. }
  10296. return false;
  10297. }
  10298. function isNumber(expression, estree) {
  10299. if (estree) {
  10300. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10301. }
  10302. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10303. }
  10304. function isNegativeNumber(expression, estree) {
  10305. if (expression.type === "UnaryExpression") {
  10306. const {
  10307. operator,
  10308. argument
  10309. } = expression;
  10310. if (operator === "-" && isNumber(argument, estree)) {
  10311. return true;
  10312. }
  10313. }
  10314. return false;
  10315. }
  10316. function isUncomputedMemberExpressionChain(expression) {
  10317. if (expression.type === "Identifier") return true;
  10318. if (expression.type !== "MemberExpression" || expression.computed) {
  10319. return false;
  10320. }
  10321. return isUncomputedMemberExpressionChain(expression.object);
  10322. }
  10323. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10324. ClassNameIsRequired: "A class name is required.",
  10325. UnexpectedSpace: "Unexpected space in placeholder."
  10326. });
  10327. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10328. parsePlaceholder(expectedNode) {
  10329. if (this.match(133)) {
  10330. const node = this.startNode();
  10331. this.next();
  10332. this.assertNoSpace();
  10333. node.name = super.parseIdentifier(true);
  10334. this.assertNoSpace();
  10335. this.expect(133);
  10336. return this.finishPlaceholder(node, expectedNode);
  10337. }
  10338. }
  10339. finishPlaceholder(node, expectedNode) {
  10340. let placeholder = node;
  10341. if (!placeholder.expectedNode || !placeholder.type) {
  10342. placeholder = this.finishNode(placeholder, "Placeholder");
  10343. }
  10344. placeholder.expectedNode = expectedNode;
  10345. return placeholder;
  10346. }
  10347. getTokenFromCode(code) {
  10348. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10349. this.finishOp(133, 2);
  10350. } else {
  10351. super.getTokenFromCode(code);
  10352. }
  10353. }
  10354. parseExprAtom(refExpressionErrors) {
  10355. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10356. }
  10357. parseIdentifier(liberal) {
  10358. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10359. }
  10360. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10361. if (word !== undefined) {
  10362. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10363. }
  10364. }
  10365. cloneIdentifier(node) {
  10366. const cloned = super.cloneIdentifier(node);
  10367. if (cloned.type === "Placeholder") {
  10368. cloned.expectedNode = node.expectedNode;
  10369. }
  10370. return cloned;
  10371. }
  10372. cloneStringLiteral(node) {
  10373. if (node.type === "Placeholder") {
  10374. return this.cloneIdentifier(node);
  10375. }
  10376. return super.cloneStringLiteral(node);
  10377. }
  10378. parseBindingAtom() {
  10379. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10380. }
  10381. isValidLVal(type, isParenthesized, binding) {
  10382. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10383. }
  10384. toAssignable(node, isLHS) {
  10385. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10386. node.expectedNode = "Pattern";
  10387. } else {
  10388. super.toAssignable(node, isLHS);
  10389. }
  10390. }
  10391. chStartsBindingIdentifier(ch, pos) {
  10392. if (super.chStartsBindingIdentifier(ch, pos)) {
  10393. return true;
  10394. }
  10395. const nextToken = this.lookahead();
  10396. if (nextToken.type === 133) {
  10397. return true;
  10398. }
  10399. return false;
  10400. }
  10401. verifyBreakContinue(node, isBreak) {
  10402. if (node.label && node.label.type === "Placeholder") return;
  10403. super.verifyBreakContinue(node, isBreak);
  10404. }
  10405. parseExpressionStatement(node, expr) {
  10406. var _expr$extra;
  10407. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10408. return super.parseExpressionStatement(node, expr);
  10409. }
  10410. if (this.match(14)) {
  10411. const stmt = node;
  10412. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10413. this.next();
  10414. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10415. return this.finishNode(stmt, "LabeledStatement");
  10416. }
  10417. this.semicolon();
  10418. const stmtPlaceholder = node;
  10419. stmtPlaceholder.name = expr.name;
  10420. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  10421. }
  10422. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10423. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10424. }
  10425. parseFunctionId(requireId) {
  10426. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10427. }
  10428. parseClass(node, isStatement, optionalId) {
  10429. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10430. this.next();
  10431. const oldStrict = this.state.strict;
  10432. const placeholder = this.parsePlaceholder("Identifier");
  10433. if (placeholder) {
  10434. if (this.match(81) || this.match(133) || this.match(5)) {
  10435. node.id = placeholder;
  10436. } else if (optionalId || !isStatement) {
  10437. node.id = null;
  10438. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10439. return this.finishNode(node, type);
  10440. } else {
  10441. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10442. }
  10443. } else {
  10444. this.parseClassId(node, isStatement, optionalId);
  10445. }
  10446. super.parseClassSuper(node);
  10447. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10448. return this.finishNode(node, type);
  10449. }
  10450. parseExport(node, decorators) {
  10451. const placeholder = this.parsePlaceholder("Identifier");
  10452. if (!placeholder) return super.parseExport(node, decorators);
  10453. const node2 = node;
  10454. if (!this.isContextual(98) && !this.match(12)) {
  10455. node2.specifiers = [];
  10456. node2.source = null;
  10457. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10458. return this.finishNode(node2, "ExportNamedDeclaration");
  10459. }
  10460. this.expectPlugin("exportDefaultFrom");
  10461. const specifier = this.startNode();
  10462. specifier.exported = placeholder;
  10463. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10464. return super.parseExport(node2, decorators);
  10465. }
  10466. isExportDefaultSpecifier() {
  10467. if (this.match(65)) {
  10468. const next = this.nextTokenStart();
  10469. if (this.isUnparsedContextual(next, "from")) {
  10470. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  10471. return true;
  10472. }
  10473. }
  10474. }
  10475. return super.isExportDefaultSpecifier();
  10476. }
  10477. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10478. var _specifiers;
  10479. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10480. return true;
  10481. }
  10482. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10483. }
  10484. checkExport(node) {
  10485. const {
  10486. specifiers
  10487. } = node;
  10488. if (specifiers != null && specifiers.length) {
  10489. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10490. }
  10491. super.checkExport(node);
  10492. node.specifiers = specifiers;
  10493. }
  10494. parseImport(node) {
  10495. const placeholder = this.parsePlaceholder("Identifier");
  10496. if (!placeholder) return super.parseImport(node);
  10497. node.specifiers = [];
  10498. if (!this.isContextual(98) && !this.match(12)) {
  10499. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10500. this.semicolon();
  10501. return this.finishNode(node, "ImportDeclaration");
  10502. }
  10503. const specifier = this.startNodeAtNode(placeholder);
  10504. specifier.local = placeholder;
  10505. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10506. if (this.eat(12)) {
  10507. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10508. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10509. }
  10510. this.expectContextual(98);
  10511. node.source = this.parseImportSource();
  10512. this.semicolon();
  10513. return this.finishNode(node, "ImportDeclaration");
  10514. }
  10515. parseImportSource() {
  10516. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10517. }
  10518. assertNoSpace() {
  10519. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  10520. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10521. }
  10522. }
  10523. };
  10524. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10525. parseV8Intrinsic() {
  10526. if (this.match(54)) {
  10527. const v8IntrinsicStartLoc = this.state.startLoc;
  10528. const node = this.startNode();
  10529. this.next();
  10530. if (tokenIsIdentifier(this.state.type)) {
  10531. const name = this.parseIdentifierName();
  10532. const identifier = this.createIdentifier(node, name);
  10533. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  10534. if (this.match(10)) {
  10535. return identifier;
  10536. }
  10537. }
  10538. this.unexpected(v8IntrinsicStartLoc);
  10539. }
  10540. }
  10541. parseExprAtom(refExpressionErrors) {
  10542. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10543. }
  10544. };
  10545. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10546. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10547. function validatePlugins(pluginsMap) {
  10548. if (pluginsMap.has("decorators")) {
  10549. if (pluginsMap.has("decorators-legacy")) {
  10550. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10551. }
  10552. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  10553. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10554. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10555. }
  10556. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  10557. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10558. throw new Error("'allowCallParenthesized' must be a boolean.");
  10559. }
  10560. }
  10561. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  10562. throw new Error("Cannot combine flow and typescript plugins.");
  10563. }
  10564. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  10565. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10566. }
  10567. if (pluginsMap.has("pipelineOperator")) {
  10568. var _pluginsMap$get2;
  10569. const proposal = pluginsMap.get("pipelineOperator").proposal;
  10570. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10571. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10572. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10573. }
  10574. if (proposal === "hack") {
  10575. if (pluginsMap.has("placeholders")) {
  10576. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10577. }
  10578. if (pluginsMap.has("v8intrinsic")) {
  10579. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10580. }
  10581. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  10582. if (!TOPIC_TOKENS.includes(topicToken)) {
  10583. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10584. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10585. }
  10586. {
  10587. var _pluginsMap$get;
  10588. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  10589. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10590. }
  10591. }
  10592. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  10593. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10594. }
  10595. }
  10596. if (pluginsMap.has("moduleAttributes")) {
  10597. {
  10598. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  10599. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  10600. }
  10601. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  10602. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10603. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10604. }
  10605. }
  10606. }
  10607. if (pluginsMap.has("importAssertions")) {
  10608. if (pluginsMap.has("deprecatedImportAssert")) {
  10609. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  10610. }
  10611. }
  10612. if (!pluginsMap.has("deprecatedImportAssert") && pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  10613. {
  10614. pluginsMap.set("deprecatedImportAssert", {});
  10615. }
  10616. }
  10617. if (pluginsMap.has("recordAndTuple")) {
  10618. {
  10619. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  10620. if (syntaxType != null) {
  10621. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10622. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  10623. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10624. }
  10625. }
  10626. }
  10627. }
  10628. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  10629. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10630. error.missingPlugins = "doExpressions";
  10631. throw error;
  10632. }
  10633. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  10634. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10635. }
  10636. }
  10637. const mixinPlugins = {
  10638. estree,
  10639. jsx,
  10640. flow,
  10641. typescript,
  10642. v8intrinsic,
  10643. placeholders
  10644. };
  10645. const mixinPluginNames = Object.keys(mixinPlugins);
  10646. class ExpressionParser extends LValParser {
  10647. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  10648. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10649. return sawProto;
  10650. }
  10651. const key = prop.key;
  10652. const name = key.type === "Identifier" ? key.name : key.value;
  10653. if (name === "__proto__") {
  10654. if (isRecord) {
  10655. this.raise(Errors.RecordNoProto, key);
  10656. return true;
  10657. }
  10658. if (sawProto) {
  10659. if (refExpressionErrors) {
  10660. if (refExpressionErrors.doubleProtoLoc === null) {
  10661. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10662. }
  10663. } else {
  10664. this.raise(Errors.DuplicateProto, key);
  10665. }
  10666. }
  10667. return true;
  10668. }
  10669. return sawProto;
  10670. }
  10671. shouldExitDescending(expr, potentialArrowAt) {
  10672. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  10673. }
  10674. getExpression() {
  10675. this.enterInitialScopes();
  10676. this.nextToken();
  10677. const expr = this.parseExpression();
  10678. if (!this.match(140)) {
  10679. this.unexpected();
  10680. }
  10681. this.finalizeRemainingComments();
  10682. expr.comments = this.comments;
  10683. expr.errors = this.state.errors;
  10684. if (this.optionFlags & 256) {
  10685. expr.tokens = this.tokens;
  10686. }
  10687. return expr;
  10688. }
  10689. parseExpression(disallowIn, refExpressionErrors) {
  10690. if (disallowIn) {
  10691. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10692. }
  10693. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10694. }
  10695. parseExpressionBase(refExpressionErrors) {
  10696. const startLoc = this.state.startLoc;
  10697. const expr = this.parseMaybeAssign(refExpressionErrors);
  10698. if (this.match(12)) {
  10699. const node = this.startNodeAt(startLoc);
  10700. node.expressions = [expr];
  10701. while (this.eat(12)) {
  10702. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10703. }
  10704. this.toReferencedList(node.expressions);
  10705. return this.finishNode(node, "SequenceExpression");
  10706. }
  10707. return expr;
  10708. }
  10709. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10710. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10711. }
  10712. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10713. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10714. }
  10715. setOptionalParametersError(refExpressionErrors) {
  10716. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  10717. }
  10718. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10719. const startLoc = this.state.startLoc;
  10720. const isYield = this.isContextual(108);
  10721. if (isYield) {
  10722. if (this.prodParam.hasYield) {
  10723. this.next();
  10724. let left = this.parseYield(startLoc);
  10725. if (afterLeftParse) {
  10726. left = afterLeftParse.call(this, left, startLoc);
  10727. }
  10728. return left;
  10729. }
  10730. }
  10731. let ownExpressionErrors;
  10732. if (refExpressionErrors) {
  10733. ownExpressionErrors = false;
  10734. } else {
  10735. refExpressionErrors = new ExpressionErrors();
  10736. ownExpressionErrors = true;
  10737. }
  10738. const {
  10739. type
  10740. } = this.state;
  10741. if (type === 10 || tokenIsIdentifier(type)) {
  10742. this.state.potentialArrowAt = this.state.start;
  10743. }
  10744. let left = this.parseMaybeConditional(refExpressionErrors);
  10745. if (afterLeftParse) {
  10746. left = afterLeftParse.call(this, left, startLoc);
  10747. }
  10748. if (tokenIsAssignment(this.state.type)) {
  10749. const node = this.startNodeAt(startLoc);
  10750. const operator = this.state.value;
  10751. node.operator = operator;
  10752. if (this.match(29)) {
  10753. this.toAssignable(left, true);
  10754. node.left = left;
  10755. const startIndex = startLoc.index;
  10756. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10757. refExpressionErrors.doubleProtoLoc = null;
  10758. }
  10759. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10760. refExpressionErrors.shorthandAssignLoc = null;
  10761. }
  10762. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10763. this.checkDestructuringPrivate(refExpressionErrors);
  10764. refExpressionErrors.privateKeyLoc = null;
  10765. }
  10766. } else {
  10767. node.left = left;
  10768. }
  10769. this.next();
  10770. node.right = this.parseMaybeAssign();
  10771. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"));
  10772. return node;
  10773. } else if (ownExpressionErrors) {
  10774. this.checkExpressionErrors(refExpressionErrors, true);
  10775. }
  10776. if (isYield) {
  10777. const {
  10778. type
  10779. } = this.state;
  10780. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10781. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  10782. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  10783. return this.parseYield(startLoc);
  10784. }
  10785. }
  10786. return left;
  10787. }
  10788. parseMaybeConditional(refExpressionErrors) {
  10789. const startLoc = this.state.startLoc;
  10790. const potentialArrowAt = this.state.potentialArrowAt;
  10791. const expr = this.parseExprOps(refExpressionErrors);
  10792. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10793. return expr;
  10794. }
  10795. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10796. }
  10797. parseConditional(expr, startLoc, refExpressionErrors) {
  10798. if (this.eat(17)) {
  10799. const node = this.startNodeAt(startLoc);
  10800. node.test = expr;
  10801. node.consequent = this.parseMaybeAssignAllowIn();
  10802. this.expect(14);
  10803. node.alternate = this.parseMaybeAssign();
  10804. return this.finishNode(node, "ConditionalExpression");
  10805. }
  10806. return expr;
  10807. }
  10808. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10809. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10810. }
  10811. parseExprOps(refExpressionErrors) {
  10812. const startLoc = this.state.startLoc;
  10813. const potentialArrowAt = this.state.potentialArrowAt;
  10814. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10815. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10816. return expr;
  10817. }
  10818. return this.parseExprOp(expr, startLoc, -1);
  10819. }
  10820. parseExprOp(left, leftStartLoc, minPrec) {
  10821. if (this.isPrivateName(left)) {
  10822. const value = this.getPrivateNameSV(left);
  10823. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10824. this.raise(Errors.PrivateInExpectedIn, left, {
  10825. identifierName: value
  10826. });
  10827. }
  10828. this.classScope.usePrivateName(value, left.loc.start);
  10829. }
  10830. const op = this.state.type;
  10831. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10832. let prec = tokenOperatorPrecedence(op);
  10833. if (prec > minPrec) {
  10834. if (op === 39) {
  10835. this.expectPlugin("pipelineOperator");
  10836. if (this.state.inFSharpPipelineDirectBody) {
  10837. return left;
  10838. }
  10839. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10840. }
  10841. const node = this.startNodeAt(leftStartLoc);
  10842. node.left = left;
  10843. node.operator = this.state.value;
  10844. const logical = op === 41 || op === 42;
  10845. const coalesce = op === 40;
  10846. if (coalesce) {
  10847. prec = tokenOperatorPrecedence(42);
  10848. }
  10849. this.next();
  10850. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10851. proposal: "minimal"
  10852. }])) {
  10853. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10854. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  10855. }
  10856. }
  10857. node.right = this.parseExprOpRightExpr(op, prec);
  10858. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10859. const nextOp = this.state.type;
  10860. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10861. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  10862. }
  10863. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10864. }
  10865. }
  10866. return left;
  10867. }
  10868. parseExprOpRightExpr(op, prec) {
  10869. const startLoc = this.state.startLoc;
  10870. switch (op) {
  10871. case 39:
  10872. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10873. case "hack":
  10874. return this.withTopicBindingContext(() => {
  10875. return this.parseHackPipeBody();
  10876. });
  10877. case "fsharp":
  10878. return this.withSoloAwaitPermittingContext(() => {
  10879. return this.parseFSharpPipelineBody(prec);
  10880. });
  10881. }
  10882. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  10883. return this.withTopicBindingContext(() => {
  10884. if (this.prodParam.hasYield && this.isContextual(108)) {
  10885. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  10886. }
  10887. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10888. });
  10889. }
  10890. default:
  10891. return this.parseExprOpBaseRightExpr(op, prec);
  10892. }
  10893. }
  10894. parseExprOpBaseRightExpr(op, prec) {
  10895. const startLoc = this.state.startLoc;
  10896. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10897. }
  10898. parseHackPipeBody() {
  10899. var _body$extra;
  10900. const {
  10901. startLoc
  10902. } = this.state;
  10903. const body = this.parseMaybeAssign();
  10904. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10905. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10906. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  10907. type: body.type
  10908. });
  10909. }
  10910. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10911. this.raise(Errors.PipeTopicUnused, startLoc);
  10912. }
  10913. return body;
  10914. }
  10915. checkExponentialAfterUnary(node) {
  10916. if (this.match(57)) {
  10917. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  10918. }
  10919. }
  10920. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10921. const startLoc = this.state.startLoc;
  10922. const isAwait = this.isContextual(96);
  10923. if (isAwait && this.recordAwaitIfAllowed()) {
  10924. this.next();
  10925. const expr = this.parseAwait(startLoc);
  10926. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10927. return expr;
  10928. }
  10929. const update = this.match(34);
  10930. const node = this.startNode();
  10931. if (tokenIsPrefix(this.state.type)) {
  10932. node.operator = this.state.value;
  10933. node.prefix = true;
  10934. if (this.match(72)) {
  10935. this.expectPlugin("throwExpressions");
  10936. }
  10937. const isDelete = this.match(89);
  10938. this.next();
  10939. node.argument = this.parseMaybeUnary(null, true);
  10940. this.checkExpressionErrors(refExpressionErrors, true);
  10941. if (this.state.strict && isDelete) {
  10942. const arg = node.argument;
  10943. if (arg.type === "Identifier") {
  10944. this.raise(Errors.StrictDelete, node);
  10945. } else if (this.hasPropertyAsPrivateName(arg)) {
  10946. this.raise(Errors.DeletePrivateField, node);
  10947. }
  10948. }
  10949. if (!update) {
  10950. if (!sawUnary) {
  10951. this.checkExponentialAfterUnary(node);
  10952. }
  10953. return this.finishNode(node, "UnaryExpression");
  10954. }
  10955. }
  10956. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10957. if (isAwait) {
  10958. const {
  10959. type
  10960. } = this.state;
  10961. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10962. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  10963. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  10964. return this.parseAwait(startLoc);
  10965. }
  10966. }
  10967. return expr;
  10968. }
  10969. parseUpdate(node, update, refExpressionErrors) {
  10970. if (update) {
  10971. const updateExpressionNode = node;
  10972. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  10973. return node;
  10974. }
  10975. const startLoc = this.state.startLoc;
  10976. let expr = this.parseExprSubscripts(refExpressionErrors);
  10977. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10978. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10979. const node = this.startNodeAt(startLoc);
  10980. node.operator = this.state.value;
  10981. node.prefix = false;
  10982. node.argument = expr;
  10983. this.next();
  10984. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  10985. }
  10986. return expr;
  10987. }
  10988. parseExprSubscripts(refExpressionErrors) {
  10989. const startLoc = this.state.startLoc;
  10990. const potentialArrowAt = this.state.potentialArrowAt;
  10991. const expr = this.parseExprAtom(refExpressionErrors);
  10992. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10993. return expr;
  10994. }
  10995. return this.parseSubscripts(expr, startLoc);
  10996. }
  10997. parseSubscripts(base, startLoc, noCalls) {
  10998. const state = {
  10999. optionalChainMember: false,
  11000. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  11001. stop: false
  11002. };
  11003. do {
  11004. base = this.parseSubscript(base, startLoc, noCalls, state);
  11005. state.maybeAsyncArrow = false;
  11006. } while (!state.stop);
  11007. return base;
  11008. }
  11009. parseSubscript(base, startLoc, noCalls, state) {
  11010. const {
  11011. type
  11012. } = this.state;
  11013. if (!noCalls && type === 15) {
  11014. return this.parseBind(base, startLoc, noCalls, state);
  11015. } else if (tokenIsTemplate(type)) {
  11016. return this.parseTaggedTemplateExpression(base, startLoc, state);
  11017. }
  11018. let optional = false;
  11019. if (type === 18) {
  11020. if (noCalls) {
  11021. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  11022. if (this.lookaheadCharCode() === 40) {
  11023. return this.stopParseSubscript(base, state);
  11024. }
  11025. }
  11026. state.optionalChainMember = optional = true;
  11027. this.next();
  11028. }
  11029. if (!noCalls && this.match(10)) {
  11030. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  11031. } else {
  11032. const computed = this.eat(0);
  11033. if (computed || optional || this.eat(16)) {
  11034. return this.parseMember(base, startLoc, state, computed, optional);
  11035. } else {
  11036. return this.stopParseSubscript(base, state);
  11037. }
  11038. }
  11039. }
  11040. stopParseSubscript(base, state) {
  11041. state.stop = true;
  11042. return base;
  11043. }
  11044. parseMember(base, startLoc, state, computed, optional) {
  11045. const node = this.startNodeAt(startLoc);
  11046. node.object = base;
  11047. node.computed = computed;
  11048. if (computed) {
  11049. node.property = this.parseExpression();
  11050. this.expect(3);
  11051. } else if (this.match(139)) {
  11052. if (base.type === "Super") {
  11053. this.raise(Errors.SuperPrivateField, startLoc);
  11054. }
  11055. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  11056. node.property = this.parsePrivateName();
  11057. } else {
  11058. node.property = this.parseIdentifier(true);
  11059. }
  11060. if (state.optionalChainMember) {
  11061. node.optional = optional;
  11062. return this.finishNode(node, "OptionalMemberExpression");
  11063. } else {
  11064. return this.finishNode(node, "MemberExpression");
  11065. }
  11066. }
  11067. parseBind(base, startLoc, noCalls, state) {
  11068. const node = this.startNodeAt(startLoc);
  11069. node.object = base;
  11070. this.next();
  11071. node.callee = this.parseNoCallExpr();
  11072. state.stop = true;
  11073. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  11074. }
  11075. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  11076. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11077. let refExpressionErrors = null;
  11078. this.state.maybeInArrowParameters = true;
  11079. this.next();
  11080. const node = this.startNodeAt(startLoc);
  11081. node.callee = base;
  11082. const {
  11083. maybeAsyncArrow,
  11084. optionalChainMember
  11085. } = state;
  11086. if (maybeAsyncArrow) {
  11087. this.expressionScope.enter(newAsyncArrowScope());
  11088. refExpressionErrors = new ExpressionErrors();
  11089. }
  11090. if (optionalChainMember) {
  11091. node.optional = optional;
  11092. }
  11093. if (optional) {
  11094. node.arguments = this.parseCallExpressionArguments(11);
  11095. } else {
  11096. node.arguments = this.parseCallExpressionArguments(11, base.type !== "Super", node, refExpressionErrors);
  11097. }
  11098. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  11099. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  11100. state.stop = true;
  11101. this.checkDestructuringPrivate(refExpressionErrors);
  11102. this.expressionScope.validateAsPattern();
  11103. this.expressionScope.exit();
  11104. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  11105. } else {
  11106. if (maybeAsyncArrow) {
  11107. this.checkExpressionErrors(refExpressionErrors, true);
  11108. this.expressionScope.exit();
  11109. }
  11110. this.toReferencedArguments(finishedNode);
  11111. }
  11112. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11113. return finishedNode;
  11114. }
  11115. toReferencedArguments(node, isParenthesizedExpr) {
  11116. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11117. }
  11118. parseTaggedTemplateExpression(base, startLoc, state) {
  11119. const node = this.startNodeAt(startLoc);
  11120. node.tag = base;
  11121. node.quasi = this.parseTemplate(true);
  11122. if (state.optionalChainMember) {
  11123. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  11124. }
  11125. return this.finishNode(node, "TaggedTemplateExpression");
  11126. }
  11127. atPossibleAsyncArrow(base) {
  11128. 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;
  11129. }
  11130. finishCallExpression(node, optional) {
  11131. if (node.callee.type === "Import") {
  11132. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11133. this.raise(Errors.ImportCallArity, node);
  11134. } else {
  11135. for (const arg of node.arguments) {
  11136. if (arg.type === "SpreadElement") {
  11137. this.raise(Errors.ImportCallSpreadArgument, arg);
  11138. }
  11139. }
  11140. }
  11141. }
  11142. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11143. }
  11144. parseCallExpressionArguments(close, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11145. const elts = [];
  11146. let first = true;
  11147. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11148. this.state.inFSharpPipelineDirectBody = false;
  11149. while (!this.eat(close)) {
  11150. if (first) {
  11151. first = false;
  11152. } else {
  11153. this.expect(12);
  11154. if (this.match(close)) {
  11155. if (nodeForExtra) {
  11156. this.addTrailingCommaExtraToNode(nodeForExtra);
  11157. }
  11158. this.next();
  11159. break;
  11160. }
  11161. }
  11162. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  11163. }
  11164. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11165. return elts;
  11166. }
  11167. shouldParseAsyncArrow() {
  11168. return this.match(19) && !this.canInsertSemicolon();
  11169. }
  11170. parseAsyncArrowFromCallExpression(node, call) {
  11171. var _call$extra;
  11172. this.resetPreviousNodeTrailingComments(call);
  11173. this.expect(19);
  11174. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11175. if (call.innerComments) {
  11176. setInnerComments(node, call.innerComments);
  11177. }
  11178. if (call.callee.trailingComments) {
  11179. setInnerComments(node, call.callee.trailingComments);
  11180. }
  11181. return node;
  11182. }
  11183. parseNoCallExpr() {
  11184. const startLoc = this.state.startLoc;
  11185. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11186. }
  11187. parseExprAtom(refExpressionErrors) {
  11188. let node;
  11189. let decorators = null;
  11190. const {
  11191. type
  11192. } = this.state;
  11193. switch (type) {
  11194. case 79:
  11195. return this.parseSuper();
  11196. case 83:
  11197. node = this.startNode();
  11198. this.next();
  11199. if (this.match(16)) {
  11200. return this.parseImportMetaProperty(node);
  11201. }
  11202. if (this.match(10)) {
  11203. if (this.optionFlags & 512) {
  11204. return this.parseImportCall(node);
  11205. } else {
  11206. return this.finishNode(node, "Import");
  11207. }
  11208. } else {
  11209. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  11210. return this.finishNode(node, "Import");
  11211. }
  11212. case 78:
  11213. node = this.startNode();
  11214. this.next();
  11215. return this.finishNode(node, "ThisExpression");
  11216. case 90:
  11217. {
  11218. return this.parseDo(this.startNode(), false);
  11219. }
  11220. case 56:
  11221. case 31:
  11222. {
  11223. this.readRegexp();
  11224. return this.parseRegExpLiteral(this.state.value);
  11225. }
  11226. case 135:
  11227. return this.parseNumericLiteral(this.state.value);
  11228. case 136:
  11229. return this.parseBigIntLiteral(this.state.value);
  11230. case 134:
  11231. return this.parseStringLiteral(this.state.value);
  11232. case 84:
  11233. return this.parseNullLiteral();
  11234. case 85:
  11235. return this.parseBooleanLiteral(true);
  11236. case 86:
  11237. return this.parseBooleanLiteral(false);
  11238. case 10:
  11239. {
  11240. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11241. return this.parseParenAndDistinguishExpression(canBeArrow);
  11242. }
  11243. case 0:
  11244. {
  11245. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11246. }
  11247. case 5:
  11248. {
  11249. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11250. }
  11251. case 68:
  11252. return this.parseFunctionOrFunctionSent();
  11253. case 26:
  11254. decorators = this.parseDecorators();
  11255. case 80:
  11256. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11257. case 77:
  11258. return this.parseNewOrNewTarget();
  11259. case 25:
  11260. case 24:
  11261. return this.parseTemplate(false);
  11262. case 15:
  11263. {
  11264. node = this.startNode();
  11265. this.next();
  11266. node.object = null;
  11267. const callee = node.callee = this.parseNoCallExpr();
  11268. if (callee.type === "MemberExpression") {
  11269. return this.finishNode(node, "BindExpression");
  11270. } else {
  11271. throw this.raise(Errors.UnsupportedBind, callee);
  11272. }
  11273. }
  11274. case 139:
  11275. {
  11276. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  11277. identifierName: this.state.value
  11278. });
  11279. return this.parsePrivateName();
  11280. }
  11281. case 33:
  11282. {
  11283. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11284. }
  11285. case 32:
  11286. {
  11287. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11288. }
  11289. case 37:
  11290. case 38:
  11291. {
  11292. return this.parseTopicReference("hack");
  11293. }
  11294. case 44:
  11295. case 54:
  11296. case 27:
  11297. {
  11298. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11299. if (pipeProposal) {
  11300. return this.parseTopicReference(pipeProposal);
  11301. }
  11302. this.unexpected();
  11303. break;
  11304. }
  11305. case 47:
  11306. {
  11307. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11308. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11309. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11310. } else {
  11311. this.unexpected();
  11312. }
  11313. break;
  11314. }
  11315. default:
  11316. {
  11317. if (type === 137) {
  11318. return this.parseDecimalLiteral(this.state.value);
  11319. } else if (type === 2 || type === 1) {
  11320. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11321. } else if (type === 6 || type === 7) {
  11322. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11323. }
  11324. }
  11325. if (tokenIsIdentifier(type)) {
  11326. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11327. return this.parseModuleExpression();
  11328. }
  11329. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11330. const containsEsc = this.state.containsEsc;
  11331. const id = this.parseIdentifier();
  11332. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11333. const {
  11334. type
  11335. } = this.state;
  11336. if (type === 68) {
  11337. this.resetPreviousNodeTrailingComments(id);
  11338. this.next();
  11339. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11340. } else if (tokenIsIdentifier(type)) {
  11341. if (this.lookaheadCharCode() === 61) {
  11342. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11343. } else {
  11344. return id;
  11345. }
  11346. } else if (type === 90) {
  11347. this.resetPreviousNodeTrailingComments(id);
  11348. return this.parseDo(this.startNodeAtNode(id), true);
  11349. }
  11350. }
  11351. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11352. this.next();
  11353. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11354. }
  11355. return id;
  11356. } else {
  11357. this.unexpected();
  11358. }
  11359. }
  11360. }
  11361. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11362. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11363. if (pipeProposal) {
  11364. this.state.type = topicTokenType;
  11365. this.state.value = topicTokenValue;
  11366. this.state.pos--;
  11367. this.state.end--;
  11368. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11369. return this.parseTopicReference(pipeProposal);
  11370. } else {
  11371. this.unexpected();
  11372. }
  11373. }
  11374. parseTopicReference(pipeProposal) {
  11375. const node = this.startNode();
  11376. const startLoc = this.state.startLoc;
  11377. const tokenType = this.state.type;
  11378. this.next();
  11379. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11380. }
  11381. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11382. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11383. if (pipeProposal === "hack") {
  11384. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11385. this.raise(Errors.PipeTopicUnbound, startLoc);
  11386. }
  11387. this.registerTopicReference();
  11388. return this.finishNode(node, "TopicReference");
  11389. } else {
  11390. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11391. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  11392. }
  11393. this.registerTopicReference();
  11394. return this.finishNode(node, "PipelinePrimaryTopicReference");
  11395. }
  11396. } else {
  11397. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11398. token: tokenLabelName(tokenType)
  11399. });
  11400. }
  11401. }
  11402. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11403. switch (pipeProposal) {
  11404. case "hack":
  11405. {
  11406. return this.hasPlugin(["pipelineOperator", {
  11407. topicToken: tokenLabelName(tokenType)
  11408. }]);
  11409. }
  11410. case "smart":
  11411. return tokenType === 27;
  11412. default:
  11413. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11414. }
  11415. }
  11416. parseAsyncArrowUnaryFunction(node) {
  11417. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11418. const params = [this.parseIdentifier()];
  11419. this.prodParam.exit();
  11420. if (this.hasPrecedingLineBreak()) {
  11421. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11422. }
  11423. this.expect(19);
  11424. return this.parseArrowExpression(node, params, true);
  11425. }
  11426. parseDo(node, isAsync) {
  11427. this.expectPlugin("doExpressions");
  11428. if (isAsync) {
  11429. this.expectPlugin("asyncDoExpressions");
  11430. }
  11431. node.async = isAsync;
  11432. this.next();
  11433. const oldLabels = this.state.labels;
  11434. this.state.labels = [];
  11435. if (isAsync) {
  11436. this.prodParam.enter(2);
  11437. node.body = this.parseBlock();
  11438. this.prodParam.exit();
  11439. } else {
  11440. node.body = this.parseBlock();
  11441. }
  11442. this.state.labels = oldLabels;
  11443. return this.finishNode(node, "DoExpression");
  11444. }
  11445. parseSuper() {
  11446. const node = this.startNode();
  11447. this.next();
  11448. if (this.match(10) && !this.scope.allowDirectSuper && !(this.optionFlags & 16)) {
  11449. this.raise(Errors.SuperNotAllowed, node);
  11450. } else if (!this.scope.allowSuper && !(this.optionFlags & 16)) {
  11451. this.raise(Errors.UnexpectedSuper, node);
  11452. }
  11453. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11454. this.raise(Errors.UnsupportedSuper, node);
  11455. }
  11456. return this.finishNode(node, "Super");
  11457. }
  11458. parsePrivateName() {
  11459. const node = this.startNode();
  11460. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11461. const name = this.state.value;
  11462. this.next();
  11463. node.id = this.createIdentifier(id, name);
  11464. return this.finishNode(node, "PrivateName");
  11465. }
  11466. parseFunctionOrFunctionSent() {
  11467. const node = this.startNode();
  11468. this.next();
  11469. if (this.prodParam.hasYield && this.match(16)) {
  11470. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11471. this.next();
  11472. if (this.match(103)) {
  11473. this.expectPlugin("functionSent");
  11474. } else if (!this.hasPlugin("functionSent")) {
  11475. this.unexpected();
  11476. }
  11477. return this.parseMetaProperty(node, meta, "sent");
  11478. }
  11479. return this.parseFunction(node);
  11480. }
  11481. parseMetaProperty(node, meta, propertyName) {
  11482. node.meta = meta;
  11483. const containsEsc = this.state.containsEsc;
  11484. node.property = this.parseIdentifier(true);
  11485. if (node.property.name !== propertyName || containsEsc) {
  11486. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11487. target: meta.name,
  11488. onlyValidPropertyName: propertyName
  11489. });
  11490. }
  11491. return this.finishNode(node, "MetaProperty");
  11492. }
  11493. parseImportMetaProperty(node) {
  11494. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11495. this.next();
  11496. if (this.isContextual(101)) {
  11497. if (!this.inModule) {
  11498. this.raise(Errors.ImportMetaOutsideModule, id);
  11499. }
  11500. this.sawUnambiguousESM = true;
  11501. } else if (this.isContextual(105) || this.isContextual(97)) {
  11502. const isSource = this.isContextual(105);
  11503. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11504. if (!(this.optionFlags & 512)) {
  11505. throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, this.state.startLoc, {
  11506. phase: this.state.value
  11507. });
  11508. }
  11509. this.next();
  11510. node.phase = isSource ? "source" : "defer";
  11511. return this.parseImportCall(node);
  11512. }
  11513. return this.parseMetaProperty(node, id, "meta");
  11514. }
  11515. parseLiteralAtNode(value, type, node) {
  11516. this.addExtra(node, "rawValue", value);
  11517. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11518. node.value = value;
  11519. this.next();
  11520. return this.finishNode(node, type);
  11521. }
  11522. parseLiteral(value, type) {
  11523. const node = this.startNode();
  11524. return this.parseLiteralAtNode(value, type, node);
  11525. }
  11526. parseStringLiteral(value) {
  11527. return this.parseLiteral(value, "StringLiteral");
  11528. }
  11529. parseNumericLiteral(value) {
  11530. return this.parseLiteral(value, "NumericLiteral");
  11531. }
  11532. parseBigIntLiteral(value) {
  11533. return this.parseLiteral(value, "BigIntLiteral");
  11534. }
  11535. parseDecimalLiteral(value) {
  11536. return this.parseLiteral(value, "DecimalLiteral");
  11537. }
  11538. parseRegExpLiteral(value) {
  11539. const node = this.startNode();
  11540. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11541. node.pattern = value.pattern;
  11542. node.flags = value.flags;
  11543. this.next();
  11544. return this.finishNode(node, "RegExpLiteral");
  11545. }
  11546. parseBooleanLiteral(value) {
  11547. const node = this.startNode();
  11548. node.value = value;
  11549. this.next();
  11550. return this.finishNode(node, "BooleanLiteral");
  11551. }
  11552. parseNullLiteral() {
  11553. const node = this.startNode();
  11554. this.next();
  11555. return this.finishNode(node, "NullLiteral");
  11556. }
  11557. parseParenAndDistinguishExpression(canBeArrow) {
  11558. const startLoc = this.state.startLoc;
  11559. let val;
  11560. this.next();
  11561. this.expressionScope.enter(newArrowHeadScope());
  11562. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11563. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11564. this.state.maybeInArrowParameters = true;
  11565. this.state.inFSharpPipelineDirectBody = false;
  11566. const innerStartLoc = this.state.startLoc;
  11567. const exprList = [];
  11568. const refExpressionErrors = new ExpressionErrors();
  11569. let first = true;
  11570. let spreadStartLoc;
  11571. let optionalCommaStartLoc;
  11572. while (!this.match(11)) {
  11573. if (first) {
  11574. first = false;
  11575. } else {
  11576. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11577. if (this.match(11)) {
  11578. optionalCommaStartLoc = this.state.startLoc;
  11579. break;
  11580. }
  11581. }
  11582. if (this.match(21)) {
  11583. const spreadNodeStartLoc = this.state.startLoc;
  11584. spreadStartLoc = this.state.startLoc;
  11585. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11586. if (!this.checkCommaAfterRest(41)) {
  11587. break;
  11588. }
  11589. } else {
  11590. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11591. }
  11592. }
  11593. const innerEndLoc = this.state.lastTokEndLoc;
  11594. this.expect(11);
  11595. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11596. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11597. let arrowNode = this.startNodeAt(startLoc);
  11598. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11599. this.checkDestructuringPrivate(refExpressionErrors);
  11600. this.expressionScope.validateAsPattern();
  11601. this.expressionScope.exit();
  11602. this.parseArrowExpression(arrowNode, exprList, false);
  11603. return arrowNode;
  11604. }
  11605. this.expressionScope.exit();
  11606. if (!exprList.length) {
  11607. this.unexpected(this.state.lastTokStartLoc);
  11608. }
  11609. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11610. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11611. this.checkExpressionErrors(refExpressionErrors, true);
  11612. this.toReferencedListDeep(exprList, true);
  11613. if (exprList.length > 1) {
  11614. val = this.startNodeAt(innerStartLoc);
  11615. val.expressions = exprList;
  11616. this.finishNode(val, "SequenceExpression");
  11617. this.resetEndLocation(val, innerEndLoc);
  11618. } else {
  11619. val = exprList[0];
  11620. }
  11621. return this.wrapParenthesis(startLoc, val);
  11622. }
  11623. wrapParenthesis(startLoc, expression) {
  11624. if (!(this.optionFlags & 1024)) {
  11625. this.addExtra(expression, "parenthesized", true);
  11626. this.addExtra(expression, "parenStart", startLoc.index);
  11627. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11628. return expression;
  11629. }
  11630. const parenExpression = this.startNodeAt(startLoc);
  11631. parenExpression.expression = expression;
  11632. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11633. }
  11634. shouldParseArrow(params) {
  11635. return !this.canInsertSemicolon();
  11636. }
  11637. parseArrow(node) {
  11638. if (this.eat(19)) {
  11639. return node;
  11640. }
  11641. }
  11642. parseParenItem(node, startLoc) {
  11643. return node;
  11644. }
  11645. parseNewOrNewTarget() {
  11646. const node = this.startNode();
  11647. this.next();
  11648. if (this.match(16)) {
  11649. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11650. this.next();
  11651. const metaProp = this.parseMetaProperty(node, meta, "target");
  11652. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !(this.optionFlags & 4)) {
  11653. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11654. }
  11655. return metaProp;
  11656. }
  11657. return this.parseNew(node);
  11658. }
  11659. parseNew(node) {
  11660. this.parseNewCallee(node);
  11661. if (this.eat(10)) {
  11662. const args = this.parseExprList(11);
  11663. this.toReferencedList(args);
  11664. node.arguments = args;
  11665. } else {
  11666. node.arguments = [];
  11667. }
  11668. return this.finishNode(node, "NewExpression");
  11669. }
  11670. parseNewCallee(node) {
  11671. const isImport = this.match(83);
  11672. const callee = this.parseNoCallExpr();
  11673. node.callee = callee;
  11674. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11675. this.raise(Errors.ImportCallNotNewExpression, callee);
  11676. }
  11677. }
  11678. parseTemplateElement(isTagged) {
  11679. const {
  11680. start,
  11681. startLoc,
  11682. end,
  11683. value
  11684. } = this.state;
  11685. const elemStart = start + 1;
  11686. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11687. if (value === null) {
  11688. if (!isTagged) {
  11689. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11690. }
  11691. }
  11692. const isTail = this.match(24);
  11693. const endOffset = isTail ? -1 : -2;
  11694. const elemEnd = end + endOffset;
  11695. elem.value = {
  11696. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11697. cooked: value === null ? null : value.slice(1, endOffset)
  11698. };
  11699. elem.tail = isTail;
  11700. this.next();
  11701. const finishedNode = this.finishNode(elem, "TemplateElement");
  11702. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11703. return finishedNode;
  11704. }
  11705. parseTemplate(isTagged) {
  11706. const node = this.startNode();
  11707. let curElt = this.parseTemplateElement(isTagged);
  11708. const quasis = [curElt];
  11709. const substitutions = [];
  11710. while (!curElt.tail) {
  11711. substitutions.push(this.parseTemplateSubstitution());
  11712. this.readTemplateContinuation();
  11713. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11714. }
  11715. node.expressions = substitutions;
  11716. node.quasis = quasis;
  11717. return this.finishNode(node, "TemplateLiteral");
  11718. }
  11719. parseTemplateSubstitution() {
  11720. return this.parseExpression();
  11721. }
  11722. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11723. if (isRecord) {
  11724. this.expectPlugin("recordAndTuple");
  11725. }
  11726. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11727. this.state.inFSharpPipelineDirectBody = false;
  11728. let sawProto = false;
  11729. let first = true;
  11730. const node = this.startNode();
  11731. node.properties = [];
  11732. this.next();
  11733. while (!this.match(close)) {
  11734. if (first) {
  11735. first = false;
  11736. } else {
  11737. this.expect(12);
  11738. if (this.match(close)) {
  11739. this.addTrailingCommaExtraToNode(node);
  11740. break;
  11741. }
  11742. }
  11743. let prop;
  11744. if (isPattern) {
  11745. prop = this.parseBindingProperty();
  11746. } else {
  11747. prop = this.parsePropertyDefinition(refExpressionErrors);
  11748. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  11749. }
  11750. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11751. this.raise(Errors.InvalidRecordProperty, prop);
  11752. }
  11753. {
  11754. if (prop.shorthand) {
  11755. this.addExtra(prop, "shorthand", true);
  11756. }
  11757. }
  11758. node.properties.push(prop);
  11759. }
  11760. this.next();
  11761. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11762. let type = "ObjectExpression";
  11763. if (isPattern) {
  11764. type = "ObjectPattern";
  11765. } else if (isRecord) {
  11766. type = "RecordExpression";
  11767. }
  11768. return this.finishNode(node, type);
  11769. }
  11770. addTrailingCommaExtraToNode(node) {
  11771. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11772. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11773. }
  11774. maybeAsyncOrAccessorProp(prop) {
  11775. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11776. }
  11777. parsePropertyDefinition(refExpressionErrors) {
  11778. let decorators = [];
  11779. if (this.match(26)) {
  11780. if (this.hasPlugin("decorators")) {
  11781. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11782. }
  11783. while (this.match(26)) {
  11784. decorators.push(this.parseDecorator());
  11785. }
  11786. }
  11787. const prop = this.startNode();
  11788. let isAsync = false;
  11789. let isAccessor = false;
  11790. let startLoc;
  11791. if (this.match(21)) {
  11792. if (decorators.length) this.unexpected();
  11793. return this.parseSpread();
  11794. }
  11795. if (decorators.length) {
  11796. prop.decorators = decorators;
  11797. decorators = [];
  11798. }
  11799. prop.method = false;
  11800. if (refExpressionErrors) {
  11801. startLoc = this.state.startLoc;
  11802. }
  11803. let isGenerator = this.eat(55);
  11804. this.parsePropertyNamePrefixOperator(prop);
  11805. const containsEsc = this.state.containsEsc;
  11806. this.parsePropertyName(prop, refExpressionErrors);
  11807. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11808. const {
  11809. key
  11810. } = prop;
  11811. const keyName = key.name;
  11812. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11813. isAsync = true;
  11814. this.resetPreviousNodeTrailingComments(key);
  11815. isGenerator = this.eat(55);
  11816. this.parsePropertyName(prop);
  11817. }
  11818. if (keyName === "get" || keyName === "set") {
  11819. isAccessor = true;
  11820. this.resetPreviousNodeTrailingComments(key);
  11821. prop.kind = keyName;
  11822. if (this.match(55)) {
  11823. isGenerator = true;
  11824. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11825. kind: keyName
  11826. });
  11827. this.next();
  11828. }
  11829. this.parsePropertyName(prop);
  11830. }
  11831. }
  11832. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11833. }
  11834. getGetterSetterExpectedParamCount(method) {
  11835. return method.kind === "get" ? 0 : 1;
  11836. }
  11837. getObjectOrClassMethodParams(method) {
  11838. return method.params;
  11839. }
  11840. checkGetterSetterParams(method) {
  11841. var _params;
  11842. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11843. const params = this.getObjectOrClassMethodParams(method);
  11844. if (params.length !== paramCount) {
  11845. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  11846. }
  11847. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11848. this.raise(Errors.BadSetterRestParameter, method);
  11849. }
  11850. }
  11851. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11852. if (isAccessor) {
  11853. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11854. this.checkGetterSetterParams(finishedProp);
  11855. return finishedProp;
  11856. }
  11857. if (isAsync || isGenerator || this.match(10)) {
  11858. if (isPattern) this.unexpected();
  11859. prop.kind = "method";
  11860. prop.method = true;
  11861. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11862. }
  11863. }
  11864. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11865. prop.shorthand = false;
  11866. if (this.eat(14)) {
  11867. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11868. return this.finishObjectProperty(prop);
  11869. }
  11870. if (!prop.computed && prop.key.type === "Identifier") {
  11871. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11872. if (isPattern) {
  11873. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  11874. } else if (this.match(29)) {
  11875. const shorthandAssignLoc = this.state.startLoc;
  11876. if (refExpressionErrors != null) {
  11877. if (refExpressionErrors.shorthandAssignLoc === null) {
  11878. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11879. }
  11880. } else {
  11881. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11882. }
  11883. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  11884. } else {
  11885. prop.value = this.cloneIdentifier(prop.key);
  11886. }
  11887. prop.shorthand = true;
  11888. return this.finishObjectProperty(prop);
  11889. }
  11890. }
  11891. finishObjectProperty(node) {
  11892. return this.finishNode(node, "ObjectProperty");
  11893. }
  11894. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11895. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11896. if (!node) this.unexpected();
  11897. return node;
  11898. }
  11899. parsePropertyName(prop, refExpressionErrors) {
  11900. if (this.eat(0)) {
  11901. prop.computed = true;
  11902. prop.key = this.parseMaybeAssignAllowIn();
  11903. this.expect(3);
  11904. } else {
  11905. const {
  11906. type,
  11907. value
  11908. } = this.state;
  11909. let key;
  11910. if (tokenIsKeywordOrIdentifier(type)) {
  11911. key = this.parseIdentifier(true);
  11912. } else {
  11913. switch (type) {
  11914. case 135:
  11915. key = this.parseNumericLiteral(value);
  11916. break;
  11917. case 134:
  11918. key = this.parseStringLiteral(value);
  11919. break;
  11920. case 136:
  11921. key = this.parseBigIntLiteral(value);
  11922. break;
  11923. case 139:
  11924. {
  11925. const privateKeyLoc = this.state.startLoc;
  11926. if (refExpressionErrors != null) {
  11927. if (refExpressionErrors.privateKeyLoc === null) {
  11928. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11929. }
  11930. } else {
  11931. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  11932. }
  11933. key = this.parsePrivateName();
  11934. break;
  11935. }
  11936. default:
  11937. if (type === 137) {
  11938. key = this.parseDecimalLiteral(value);
  11939. break;
  11940. }
  11941. this.unexpected();
  11942. }
  11943. }
  11944. prop.key = key;
  11945. if (type !== 139) {
  11946. prop.computed = false;
  11947. }
  11948. }
  11949. }
  11950. initFunction(node, isAsync) {
  11951. node.id = null;
  11952. node.generator = false;
  11953. node.async = isAsync;
  11954. }
  11955. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11956. this.initFunction(node, isAsync);
  11957. node.generator = isGenerator;
  11958. this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
  11959. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11960. this.parseFunctionParams(node, isConstructor);
  11961. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11962. this.prodParam.exit();
  11963. this.scope.exit();
  11964. return finishedNode;
  11965. }
  11966. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11967. if (isTuple) {
  11968. this.expectPlugin("recordAndTuple");
  11969. }
  11970. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11971. this.state.inFSharpPipelineDirectBody = false;
  11972. const node = this.startNode();
  11973. this.next();
  11974. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11975. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11976. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11977. }
  11978. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11979. this.scope.enter(2 | 4);
  11980. let flags = functionFlags(isAsync, false);
  11981. if (!this.match(5) && this.prodParam.hasIn) {
  11982. flags |= 8;
  11983. }
  11984. this.prodParam.enter(flags);
  11985. this.initFunction(node, isAsync);
  11986. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11987. if (params) {
  11988. this.state.maybeInArrowParameters = true;
  11989. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11990. }
  11991. this.state.maybeInArrowParameters = false;
  11992. this.parseFunctionBody(node, true);
  11993. this.prodParam.exit();
  11994. this.scope.exit();
  11995. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11996. return this.finishNode(node, "ArrowFunctionExpression");
  11997. }
  11998. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11999. this.toAssignableList(params, trailingCommaLoc, false);
  12000. node.params = params;
  12001. }
  12002. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  12003. this.parseFunctionBody(node, false, isMethod);
  12004. return this.finishNode(node, type);
  12005. }
  12006. parseFunctionBody(node, allowExpression, isMethod = false) {
  12007. const isExpression = allowExpression && !this.match(5);
  12008. this.expressionScope.enter(newExpressionScope());
  12009. if (isExpression) {
  12010. node.body = this.parseMaybeAssign();
  12011. this.checkParams(node, false, allowExpression, false);
  12012. } else {
  12013. const oldStrict = this.state.strict;
  12014. const oldLabels = this.state.labels;
  12015. this.state.labels = [];
  12016. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  12017. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  12018. const nonSimple = !this.isSimpleParamList(node.params);
  12019. if (hasStrictModeDirective && nonSimple) {
  12020. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  12021. }
  12022. const strictModeChanged = !oldStrict && this.state.strict;
  12023. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  12024. if (this.state.strict && node.id) {
  12025. this.checkIdentifier(node.id, 65, strictModeChanged);
  12026. }
  12027. });
  12028. this.prodParam.exit();
  12029. this.state.labels = oldLabels;
  12030. }
  12031. this.expressionScope.exit();
  12032. }
  12033. isSimpleParameter(node) {
  12034. return node.type === "Identifier";
  12035. }
  12036. isSimpleParamList(params) {
  12037. for (let i = 0, len = params.length; i < len; i++) {
  12038. if (!this.isSimpleParameter(params[i])) return false;
  12039. }
  12040. return true;
  12041. }
  12042. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  12043. const checkClashes = !allowDuplicates && new Set();
  12044. const formalParameters = {
  12045. type: "FormalParameters"
  12046. };
  12047. for (const param of node.params) {
  12048. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  12049. }
  12050. }
  12051. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  12052. const elts = [];
  12053. let first = true;
  12054. while (!this.eat(close)) {
  12055. if (first) {
  12056. first = false;
  12057. } else {
  12058. this.expect(12);
  12059. if (this.match(close)) {
  12060. if (nodeForExtra) {
  12061. this.addTrailingCommaExtraToNode(nodeForExtra);
  12062. }
  12063. this.next();
  12064. break;
  12065. }
  12066. }
  12067. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  12068. }
  12069. return elts;
  12070. }
  12071. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  12072. let elt;
  12073. if (this.match(12)) {
  12074. if (!allowEmpty) {
  12075. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  12076. unexpected: ","
  12077. });
  12078. }
  12079. elt = null;
  12080. } else if (this.match(21)) {
  12081. const spreadNodeStartLoc = this.state.startLoc;
  12082. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12083. } else if (this.match(17)) {
  12084. this.expectPlugin("partialApplication");
  12085. if (!allowPlaceholder) {
  12086. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  12087. }
  12088. const node = this.startNode();
  12089. this.next();
  12090. elt = this.finishNode(node, "ArgumentPlaceholder");
  12091. } else {
  12092. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  12093. }
  12094. return elt;
  12095. }
  12096. parseIdentifier(liberal) {
  12097. const node = this.startNode();
  12098. const name = this.parseIdentifierName(liberal);
  12099. return this.createIdentifier(node, name);
  12100. }
  12101. createIdentifier(node, name) {
  12102. node.name = name;
  12103. node.loc.identifierName = name;
  12104. return this.finishNode(node, "Identifier");
  12105. }
  12106. parseIdentifierName(liberal) {
  12107. let name;
  12108. const {
  12109. startLoc,
  12110. type
  12111. } = this.state;
  12112. if (tokenIsKeywordOrIdentifier(type)) {
  12113. name = this.state.value;
  12114. } else {
  12115. this.unexpected();
  12116. }
  12117. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12118. if (liberal) {
  12119. if (tokenIsKeyword) {
  12120. this.replaceToken(132);
  12121. }
  12122. } else {
  12123. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12124. }
  12125. this.next();
  12126. return name;
  12127. }
  12128. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12129. if (word.length > 10) {
  12130. return;
  12131. }
  12132. if (!canBeReservedWord(word)) {
  12133. return;
  12134. }
  12135. if (checkKeywords && isKeyword(word)) {
  12136. this.raise(Errors.UnexpectedKeyword, startLoc, {
  12137. keyword: word
  12138. });
  12139. return;
  12140. }
  12141. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12142. if (reservedTest(word, this.inModule)) {
  12143. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  12144. reservedWord: word
  12145. });
  12146. return;
  12147. } else if (word === "yield") {
  12148. if (this.prodParam.hasYield) {
  12149. this.raise(Errors.YieldBindingIdentifier, startLoc);
  12150. return;
  12151. }
  12152. } else if (word === "await") {
  12153. if (this.prodParam.hasAwait) {
  12154. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  12155. return;
  12156. }
  12157. if (this.scope.inStaticBlock) {
  12158. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  12159. return;
  12160. }
  12161. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  12162. } else if (word === "arguments") {
  12163. if (this.scope.inClassAndNotInNonArrowFunction) {
  12164. this.raise(Errors.ArgumentsInClass, startLoc);
  12165. return;
  12166. }
  12167. }
  12168. }
  12169. recordAwaitIfAllowed() {
  12170. const isAwaitAllowed = this.prodParam.hasAwait || this.optionFlags & 1 && !this.scope.inFunction;
  12171. if (isAwaitAllowed && !this.scope.inFunction) {
  12172. this.state.hasTopLevelAwait = true;
  12173. }
  12174. return isAwaitAllowed;
  12175. }
  12176. parseAwait(startLoc) {
  12177. const node = this.startNodeAt(startLoc);
  12178. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  12179. if (this.eat(55)) {
  12180. this.raise(Errors.ObsoleteAwaitStar, node);
  12181. }
  12182. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  12183. if (this.isAmbiguousPrefixOrIdentifier()) {
  12184. this.ambiguousScriptDifferentAst = true;
  12185. } else {
  12186. this.sawUnambiguousESM = true;
  12187. }
  12188. }
  12189. if (!this.state.soloAwait) {
  12190. node.argument = this.parseMaybeUnary(null, true);
  12191. }
  12192. return this.finishNode(node, "AwaitExpression");
  12193. }
  12194. isAmbiguousPrefixOrIdentifier() {
  12195. if (this.hasPrecedingLineBreak()) return true;
  12196. const {
  12197. type
  12198. } = this.state;
  12199. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12200. }
  12201. parseYield(startLoc) {
  12202. const node = this.startNodeAt(startLoc);
  12203. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  12204. let delegating = false;
  12205. let argument = null;
  12206. if (!this.hasPrecedingLineBreak()) {
  12207. delegating = this.eat(55);
  12208. switch (this.state.type) {
  12209. case 13:
  12210. case 140:
  12211. case 8:
  12212. case 11:
  12213. case 3:
  12214. case 9:
  12215. case 14:
  12216. case 12:
  12217. if (!delegating) break;
  12218. default:
  12219. argument = this.parseMaybeAssign();
  12220. }
  12221. }
  12222. node.delegate = delegating;
  12223. node.argument = argument;
  12224. return this.finishNode(node, "YieldExpression");
  12225. }
  12226. parseImportCall(node) {
  12227. this.next();
  12228. node.source = this.parseMaybeAssignAllowIn();
  12229. node.options = null;
  12230. if (this.eat(12)) {
  12231. if (!this.match(11)) {
  12232. node.options = this.parseMaybeAssignAllowIn();
  12233. if (this.eat(12) && !this.match(11)) {
  12234. do {
  12235. this.parseMaybeAssignAllowIn();
  12236. } while (this.eat(12) && !this.match(11));
  12237. this.raise(Errors.ImportCallArity, node);
  12238. }
  12239. }
  12240. }
  12241. this.expect(11);
  12242. return this.finishNode(node, "ImportExpression");
  12243. }
  12244. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12245. if (this.hasPlugin(["pipelineOperator", {
  12246. proposal: "smart"
  12247. }])) {
  12248. if (left.type === "SequenceExpression") {
  12249. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  12250. }
  12251. }
  12252. }
  12253. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12254. if (this.isSimpleReference(childExpr)) {
  12255. const bodyNode = this.startNodeAt(startLoc);
  12256. bodyNode.callee = childExpr;
  12257. return this.finishNode(bodyNode, "PipelineBareFunction");
  12258. } else {
  12259. const bodyNode = this.startNodeAt(startLoc);
  12260. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12261. bodyNode.expression = childExpr;
  12262. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12263. }
  12264. }
  12265. isSimpleReference(expression) {
  12266. switch (expression.type) {
  12267. case "MemberExpression":
  12268. return !expression.computed && this.isSimpleReference(expression.object);
  12269. case "Identifier":
  12270. return true;
  12271. default:
  12272. return false;
  12273. }
  12274. }
  12275. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12276. if (this.match(19)) {
  12277. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  12278. }
  12279. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12280. this.raise(Errors.PipelineTopicUnused, startLoc);
  12281. }
  12282. }
  12283. withTopicBindingContext(callback) {
  12284. const outerContextTopicState = this.state.topicContext;
  12285. this.state.topicContext = {
  12286. maxNumOfResolvableTopics: 1,
  12287. maxTopicIndex: null
  12288. };
  12289. try {
  12290. return callback();
  12291. } finally {
  12292. this.state.topicContext = outerContextTopicState;
  12293. }
  12294. }
  12295. withSmartMixTopicForbiddingContext(callback) {
  12296. if (this.hasPlugin(["pipelineOperator", {
  12297. proposal: "smart"
  12298. }])) {
  12299. const outerContextTopicState = this.state.topicContext;
  12300. this.state.topicContext = {
  12301. maxNumOfResolvableTopics: 0,
  12302. maxTopicIndex: null
  12303. };
  12304. try {
  12305. return callback();
  12306. } finally {
  12307. this.state.topicContext = outerContextTopicState;
  12308. }
  12309. } else {
  12310. return callback();
  12311. }
  12312. }
  12313. withSoloAwaitPermittingContext(callback) {
  12314. const outerContextSoloAwaitState = this.state.soloAwait;
  12315. this.state.soloAwait = true;
  12316. try {
  12317. return callback();
  12318. } finally {
  12319. this.state.soloAwait = outerContextSoloAwaitState;
  12320. }
  12321. }
  12322. allowInAnd(callback) {
  12323. const flags = this.prodParam.currentFlags();
  12324. const prodParamToSet = 8 & ~flags;
  12325. if (prodParamToSet) {
  12326. this.prodParam.enter(flags | 8);
  12327. try {
  12328. return callback();
  12329. } finally {
  12330. this.prodParam.exit();
  12331. }
  12332. }
  12333. return callback();
  12334. }
  12335. disallowInAnd(callback) {
  12336. const flags = this.prodParam.currentFlags();
  12337. const prodParamToClear = 8 & flags;
  12338. if (prodParamToClear) {
  12339. this.prodParam.enter(flags & ~8);
  12340. try {
  12341. return callback();
  12342. } finally {
  12343. this.prodParam.exit();
  12344. }
  12345. }
  12346. return callback();
  12347. }
  12348. registerTopicReference() {
  12349. this.state.topicContext.maxTopicIndex = 0;
  12350. }
  12351. topicReferenceIsAllowedInCurrentContext() {
  12352. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12353. }
  12354. topicReferenceWasUsedInCurrentContext() {
  12355. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12356. }
  12357. parseFSharpPipelineBody(prec) {
  12358. const startLoc = this.state.startLoc;
  12359. this.state.potentialArrowAt = this.state.start;
  12360. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12361. this.state.inFSharpPipelineDirectBody = true;
  12362. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12363. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12364. return ret;
  12365. }
  12366. parseModuleExpression() {
  12367. this.expectPlugin("moduleBlocks");
  12368. const node = this.startNode();
  12369. this.next();
  12370. if (!this.match(5)) {
  12371. this.unexpected(null, 5);
  12372. }
  12373. const program = this.startNodeAt(this.state.endLoc);
  12374. this.next();
  12375. const revertScopes = this.initializeScopes(true);
  12376. this.enterInitialScopes();
  12377. try {
  12378. node.body = this.parseProgram(program, 8, "module");
  12379. } finally {
  12380. revertScopes();
  12381. }
  12382. return this.finishNode(node, "ModuleExpression");
  12383. }
  12384. parsePropertyNamePrefixOperator(prop) {}
  12385. }
  12386. const loopLabel = {
  12387. kind: 1
  12388. },
  12389. switchLabel = {
  12390. kind: 2
  12391. };
  12392. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12393. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12394. function babel7CompatTokens(tokens, input, startIndex) {
  12395. for (let i = 0; i < tokens.length; i++) {
  12396. const token = tokens[i];
  12397. const {
  12398. type
  12399. } = token;
  12400. if (typeof type === "number") {
  12401. {
  12402. if (type === 139) {
  12403. const {
  12404. loc,
  12405. start,
  12406. value,
  12407. end
  12408. } = token;
  12409. const hashEndPos = start + 1;
  12410. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12411. tokens.splice(i, 1, new Token({
  12412. type: getExportedToken(27),
  12413. value: "#",
  12414. start: start,
  12415. end: hashEndPos,
  12416. startLoc: loc.start,
  12417. endLoc: hashEndLoc
  12418. }), new Token({
  12419. type: getExportedToken(132),
  12420. value: value,
  12421. start: hashEndPos,
  12422. end: end,
  12423. startLoc: hashEndLoc,
  12424. endLoc: loc.end
  12425. }));
  12426. i++;
  12427. continue;
  12428. }
  12429. if (tokenIsTemplate(type)) {
  12430. const {
  12431. loc,
  12432. start,
  12433. value,
  12434. end
  12435. } = token;
  12436. const backquoteEnd = start + 1;
  12437. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12438. let startToken;
  12439. if (input.charCodeAt(start - startIndex) === 96) {
  12440. startToken = new Token({
  12441. type: getExportedToken(22),
  12442. value: "`",
  12443. start: start,
  12444. end: backquoteEnd,
  12445. startLoc: loc.start,
  12446. endLoc: backquoteEndLoc
  12447. });
  12448. } else {
  12449. startToken = new Token({
  12450. type: getExportedToken(8),
  12451. value: "}",
  12452. start: start,
  12453. end: backquoteEnd,
  12454. startLoc: loc.start,
  12455. endLoc: backquoteEndLoc
  12456. });
  12457. }
  12458. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12459. if (type === 24) {
  12460. templateElementEnd = end - 1;
  12461. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12462. templateValue = value === null ? null : value.slice(1, -1);
  12463. endToken = new Token({
  12464. type: getExportedToken(22),
  12465. value: "`",
  12466. start: templateElementEnd,
  12467. end: end,
  12468. startLoc: templateElementEndLoc,
  12469. endLoc: loc.end
  12470. });
  12471. } else {
  12472. templateElementEnd = end - 2;
  12473. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12474. templateValue = value === null ? null : value.slice(1, -2);
  12475. endToken = new Token({
  12476. type: getExportedToken(23),
  12477. value: "${",
  12478. start: templateElementEnd,
  12479. end: end,
  12480. startLoc: templateElementEndLoc,
  12481. endLoc: loc.end
  12482. });
  12483. }
  12484. tokens.splice(i, 1, startToken, new Token({
  12485. type: getExportedToken(20),
  12486. value: templateValue,
  12487. start: backquoteEnd,
  12488. end: templateElementEnd,
  12489. startLoc: backquoteEndLoc,
  12490. endLoc: templateElementEndLoc
  12491. }), endToken);
  12492. i += 2;
  12493. continue;
  12494. }
  12495. }
  12496. token.type = getExportedToken(type);
  12497. }
  12498. }
  12499. return tokens;
  12500. }
  12501. class StatementParser extends ExpressionParser {
  12502. parseTopLevel(file, program) {
  12503. file.program = this.parseProgram(program);
  12504. file.comments = this.comments;
  12505. if (this.optionFlags & 256) {
  12506. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  12507. }
  12508. return this.finishNode(file, "File");
  12509. }
  12510. parseProgram(program, end = 140, sourceType = this.options.sourceType) {
  12511. program.sourceType = sourceType;
  12512. program.interpreter = this.parseInterpreterDirective();
  12513. this.parseBlockBody(program, true, true, end);
  12514. if (this.inModule) {
  12515. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  12516. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12517. this.raise(Errors.ModuleExportUndefined, at, {
  12518. localName
  12519. });
  12520. }
  12521. }
  12522. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  12523. }
  12524. let finishedProgram;
  12525. if (end === 140) {
  12526. finishedProgram = this.finishNode(program, "Program");
  12527. } else {
  12528. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12529. }
  12530. return finishedProgram;
  12531. }
  12532. stmtToDirective(stmt) {
  12533. const directive = this.castNodeTo(stmt, "Directive");
  12534. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  12535. const expressionValue = directiveLiteral.value;
  12536. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  12537. const val = directiveLiteral.value = raw.slice(1, -1);
  12538. this.addExtra(directiveLiteral, "raw", raw);
  12539. this.addExtra(directiveLiteral, "rawValue", val);
  12540. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12541. directive.value = directiveLiteral;
  12542. delete stmt.expression;
  12543. return directive;
  12544. }
  12545. parseInterpreterDirective() {
  12546. if (!this.match(28)) {
  12547. return null;
  12548. }
  12549. const node = this.startNode();
  12550. node.value = this.state.value;
  12551. this.next();
  12552. return this.finishNode(node, "InterpreterDirective");
  12553. }
  12554. isLet() {
  12555. if (!this.isContextual(100)) {
  12556. return false;
  12557. }
  12558. return this.hasFollowingBindingAtom();
  12559. }
  12560. chStartsBindingIdentifier(ch, pos) {
  12561. if (isIdentifierStart(ch)) {
  12562. keywordRelationalOperator.lastIndex = pos;
  12563. if (keywordRelationalOperator.test(this.input)) {
  12564. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12565. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12566. return false;
  12567. }
  12568. }
  12569. return true;
  12570. } else if (ch === 92) {
  12571. return true;
  12572. } else {
  12573. return false;
  12574. }
  12575. }
  12576. chStartsBindingPattern(ch) {
  12577. return ch === 91 || ch === 123;
  12578. }
  12579. hasFollowingBindingAtom() {
  12580. const next = this.nextTokenStart();
  12581. const nextCh = this.codePointAtPos(next);
  12582. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12583. }
  12584. hasInLineFollowingBindingIdentifierOrBrace() {
  12585. const next = this.nextTokenInLineStart();
  12586. const nextCh = this.codePointAtPos(next);
  12587. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  12588. }
  12589. allowsForUsing() {
  12590. const {
  12591. type,
  12592. containsEsc,
  12593. end
  12594. } = this.lookahead();
  12595. if (type === 102 && !containsEsc) {
  12596. const nextCharAfterOf = this.lookaheadCharCodeSince(end);
  12597. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  12598. return false;
  12599. }
  12600. }
  12601. if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12602. this.expectPlugin("explicitResourceManagement");
  12603. return true;
  12604. }
  12605. return false;
  12606. }
  12607. startsAwaitUsing() {
  12608. let next = this.nextTokenInLineStart();
  12609. if (this.isUnparsedContextual(next, "using")) {
  12610. next = this.nextTokenInLineStartSince(next + 5);
  12611. const nextCh = this.codePointAtPos(next);
  12612. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12613. this.expectPlugin("explicitResourceManagement");
  12614. return true;
  12615. }
  12616. }
  12617. return false;
  12618. }
  12619. parseModuleItem() {
  12620. return this.parseStatementLike(1 | 2 | 4 | 8);
  12621. }
  12622. parseStatementListItem() {
  12623. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12624. }
  12625. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12626. let flags = 0;
  12627. if (this.options.annexB && !this.state.strict) {
  12628. flags |= 4;
  12629. if (allowLabeledFunction) {
  12630. flags |= 8;
  12631. }
  12632. }
  12633. return this.parseStatementLike(flags);
  12634. }
  12635. parseStatement() {
  12636. return this.parseStatementLike(0);
  12637. }
  12638. parseStatementLike(flags) {
  12639. let decorators = null;
  12640. if (this.match(26)) {
  12641. decorators = this.parseDecorators(true);
  12642. }
  12643. return this.parseStatementContent(flags, decorators);
  12644. }
  12645. parseStatementContent(flags, decorators) {
  12646. const startType = this.state.type;
  12647. const node = this.startNode();
  12648. const allowDeclaration = !!(flags & 2);
  12649. const allowFunctionDeclaration = !!(flags & 4);
  12650. const topLevel = flags & 1;
  12651. switch (startType) {
  12652. case 60:
  12653. return this.parseBreakContinueStatement(node, true);
  12654. case 63:
  12655. return this.parseBreakContinueStatement(node, false);
  12656. case 64:
  12657. return this.parseDebuggerStatement(node);
  12658. case 90:
  12659. return this.parseDoWhileStatement(node);
  12660. case 91:
  12661. return this.parseForStatement(node);
  12662. case 68:
  12663. if (this.lookaheadCharCode() === 46) break;
  12664. if (!allowFunctionDeclaration) {
  12665. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12666. }
  12667. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12668. case 80:
  12669. if (!allowDeclaration) this.unexpected();
  12670. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12671. case 69:
  12672. return this.parseIfStatement(node);
  12673. case 70:
  12674. return this.parseReturnStatement(node);
  12675. case 71:
  12676. return this.parseSwitchStatement(node);
  12677. case 72:
  12678. return this.parseThrowStatement(node);
  12679. case 73:
  12680. return this.parseTryStatement(node);
  12681. case 96:
  12682. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  12683. if (!this.recordAwaitIfAllowed()) {
  12684. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12685. } else if (!allowDeclaration) {
  12686. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12687. }
  12688. this.next();
  12689. return this.parseVarStatement(node, "await using");
  12690. }
  12691. break;
  12692. case 107:
  12693. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  12694. break;
  12695. }
  12696. this.expectPlugin("explicitResourceManagement");
  12697. if (!this.scope.inModule && this.scope.inTopLevel) {
  12698. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12699. } else if (!allowDeclaration) {
  12700. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12701. }
  12702. return this.parseVarStatement(node, "using");
  12703. case 100:
  12704. {
  12705. if (this.state.containsEsc) {
  12706. break;
  12707. }
  12708. const next = this.nextTokenStart();
  12709. const nextCh = this.codePointAtPos(next);
  12710. if (nextCh !== 91) {
  12711. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12712. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12713. break;
  12714. }
  12715. }
  12716. }
  12717. case 75:
  12718. {
  12719. if (!allowDeclaration) {
  12720. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12721. }
  12722. }
  12723. case 74:
  12724. {
  12725. const kind = this.state.value;
  12726. return this.parseVarStatement(node, kind);
  12727. }
  12728. case 92:
  12729. return this.parseWhileStatement(node);
  12730. case 76:
  12731. return this.parseWithStatement(node);
  12732. case 5:
  12733. return this.parseBlock();
  12734. case 13:
  12735. return this.parseEmptyStatement(node);
  12736. case 83:
  12737. {
  12738. const nextTokenCharCode = this.lookaheadCharCode();
  12739. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12740. break;
  12741. }
  12742. }
  12743. case 82:
  12744. {
  12745. if (!(this.optionFlags & 8) && !topLevel) {
  12746. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12747. }
  12748. this.next();
  12749. let result;
  12750. if (startType === 83) {
  12751. result = this.parseImport(node);
  12752. } else {
  12753. result = this.parseExport(node, decorators);
  12754. }
  12755. this.assertModuleNodeAllowed(result);
  12756. return result;
  12757. }
  12758. default:
  12759. {
  12760. if (this.isAsyncFunction()) {
  12761. if (!allowDeclaration) {
  12762. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12763. }
  12764. this.next();
  12765. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12766. }
  12767. }
  12768. }
  12769. const maybeName = this.state.value;
  12770. const expr = this.parseExpression();
  12771. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  12772. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12773. } else {
  12774. return this.parseExpressionStatement(node, expr, decorators);
  12775. }
  12776. }
  12777. assertModuleNodeAllowed(node) {
  12778. if (!(this.optionFlags & 8) && !this.inModule) {
  12779. this.raise(Errors.ImportOutsideModule, node);
  12780. }
  12781. }
  12782. decoratorsEnabledBeforeExport() {
  12783. if (this.hasPlugin("decorators-legacy")) return true;
  12784. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12785. }
  12786. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12787. if (maybeDecorators) {
  12788. var _classNode$decorators;
  12789. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  12790. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12791. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12792. }
  12793. classNode.decorators.unshift(...maybeDecorators);
  12794. } else {
  12795. classNode.decorators = maybeDecorators;
  12796. }
  12797. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12798. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12799. }
  12800. return classNode;
  12801. }
  12802. canHaveLeadingDecorator() {
  12803. return this.match(80);
  12804. }
  12805. parseDecorators(allowExport) {
  12806. const decorators = [];
  12807. do {
  12808. decorators.push(this.parseDecorator());
  12809. } while (this.match(26));
  12810. if (this.match(82)) {
  12811. if (!allowExport) {
  12812. this.unexpected();
  12813. }
  12814. if (!this.decoratorsEnabledBeforeExport()) {
  12815. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  12816. }
  12817. } else if (!this.canHaveLeadingDecorator()) {
  12818. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  12819. }
  12820. return decorators;
  12821. }
  12822. parseDecorator() {
  12823. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12824. const node = this.startNode();
  12825. this.next();
  12826. if (this.hasPlugin("decorators")) {
  12827. const startLoc = this.state.startLoc;
  12828. let expr;
  12829. if (this.match(10)) {
  12830. const startLoc = this.state.startLoc;
  12831. this.next();
  12832. expr = this.parseExpression();
  12833. this.expect(11);
  12834. expr = this.wrapParenthesis(startLoc, expr);
  12835. const paramsStartLoc = this.state.startLoc;
  12836. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12837. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12838. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  12839. }
  12840. } else {
  12841. expr = this.parseIdentifier(false);
  12842. while (this.eat(16)) {
  12843. const node = this.startNodeAt(startLoc);
  12844. node.object = expr;
  12845. if (this.match(139)) {
  12846. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12847. node.property = this.parsePrivateName();
  12848. } else {
  12849. node.property = this.parseIdentifier(true);
  12850. }
  12851. node.computed = false;
  12852. expr = this.finishNode(node, "MemberExpression");
  12853. }
  12854. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12855. }
  12856. } else {
  12857. node.expression = this.parseExprSubscripts();
  12858. }
  12859. return this.finishNode(node, "Decorator");
  12860. }
  12861. parseMaybeDecoratorArguments(expr, startLoc) {
  12862. if (this.eat(10)) {
  12863. const node = this.startNodeAt(startLoc);
  12864. node.callee = expr;
  12865. node.arguments = this.parseCallExpressionArguments(11);
  12866. this.toReferencedList(node.arguments);
  12867. return this.finishNode(node, "CallExpression");
  12868. }
  12869. return expr;
  12870. }
  12871. parseBreakContinueStatement(node, isBreak) {
  12872. this.next();
  12873. if (this.isLineTerminator()) {
  12874. node.label = null;
  12875. } else {
  12876. node.label = this.parseIdentifier();
  12877. this.semicolon();
  12878. }
  12879. this.verifyBreakContinue(node, isBreak);
  12880. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12881. }
  12882. verifyBreakContinue(node, isBreak) {
  12883. let i;
  12884. for (i = 0; i < this.state.labels.length; ++i) {
  12885. const lab = this.state.labels[i];
  12886. if (node.label == null || lab.name === node.label.name) {
  12887. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  12888. break;
  12889. }
  12890. if (node.label && isBreak) break;
  12891. }
  12892. }
  12893. if (i === this.state.labels.length) {
  12894. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12895. this.raise(Errors.IllegalBreakContinue, node, {
  12896. type
  12897. });
  12898. }
  12899. }
  12900. parseDebuggerStatement(node) {
  12901. this.next();
  12902. this.semicolon();
  12903. return this.finishNode(node, "DebuggerStatement");
  12904. }
  12905. parseHeaderExpression() {
  12906. this.expect(10);
  12907. const val = this.parseExpression();
  12908. this.expect(11);
  12909. return val;
  12910. }
  12911. parseDoWhileStatement(node) {
  12912. this.next();
  12913. this.state.labels.push(loopLabel);
  12914. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12915. this.state.labels.pop();
  12916. this.expect(92);
  12917. node.test = this.parseHeaderExpression();
  12918. this.eat(13);
  12919. return this.finishNode(node, "DoWhileStatement");
  12920. }
  12921. parseForStatement(node) {
  12922. this.next();
  12923. this.state.labels.push(loopLabel);
  12924. let awaitAt = null;
  12925. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  12926. awaitAt = this.state.startLoc;
  12927. this.next();
  12928. }
  12929. this.scope.enter(0);
  12930. this.expect(10);
  12931. if (this.match(13)) {
  12932. if (awaitAt !== null) {
  12933. this.unexpected(awaitAt);
  12934. }
  12935. return this.parseFor(node, null);
  12936. }
  12937. const startsWithLet = this.isContextual(100);
  12938. {
  12939. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  12940. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(107) && this.allowsForUsing();
  12941. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  12942. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12943. const initNode = this.startNode();
  12944. let kind;
  12945. if (startsWithAwaitUsing) {
  12946. kind = "await using";
  12947. if (!this.recordAwaitIfAllowed()) {
  12948. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  12949. }
  12950. this.next();
  12951. } else {
  12952. kind = this.state.value;
  12953. }
  12954. this.next();
  12955. this.parseVar(initNode, true, kind);
  12956. const init = this.finishNode(initNode, "VariableDeclaration");
  12957. const isForIn = this.match(58);
  12958. if (isForIn && starsWithUsingDeclaration) {
  12959. this.raise(Errors.ForInUsing, init);
  12960. }
  12961. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  12962. return this.parseForIn(node, init, awaitAt);
  12963. }
  12964. if (awaitAt !== null) {
  12965. this.unexpected(awaitAt);
  12966. }
  12967. return this.parseFor(node, init);
  12968. }
  12969. }
  12970. const startsWithAsync = this.isContextual(95);
  12971. const refExpressionErrors = new ExpressionErrors();
  12972. const init = this.parseExpression(true, refExpressionErrors);
  12973. const isForOf = this.isContextual(102);
  12974. if (isForOf) {
  12975. if (startsWithLet) {
  12976. this.raise(Errors.ForOfLet, init);
  12977. }
  12978. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12979. this.raise(Errors.ForOfAsync, init);
  12980. }
  12981. }
  12982. if (isForOf || this.match(58)) {
  12983. this.checkDestructuringPrivate(refExpressionErrors);
  12984. this.toAssignable(init, true);
  12985. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12986. this.checkLVal(init, {
  12987. type
  12988. });
  12989. return this.parseForIn(node, init, awaitAt);
  12990. } else {
  12991. this.checkExpressionErrors(refExpressionErrors, true);
  12992. }
  12993. if (awaitAt !== null) {
  12994. this.unexpected(awaitAt);
  12995. }
  12996. return this.parseFor(node, init);
  12997. }
  12998. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12999. this.next();
  13000. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  13001. }
  13002. parseIfStatement(node) {
  13003. this.next();
  13004. node.test = this.parseHeaderExpression();
  13005. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  13006. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  13007. return this.finishNode(node, "IfStatement");
  13008. }
  13009. parseReturnStatement(node) {
  13010. if (!this.prodParam.hasReturn && !(this.optionFlags & 2)) {
  13011. this.raise(Errors.IllegalReturn, this.state.startLoc);
  13012. }
  13013. this.next();
  13014. if (this.isLineTerminator()) {
  13015. node.argument = null;
  13016. } else {
  13017. node.argument = this.parseExpression();
  13018. this.semicolon();
  13019. }
  13020. return this.finishNode(node, "ReturnStatement");
  13021. }
  13022. parseSwitchStatement(node) {
  13023. this.next();
  13024. node.discriminant = this.parseHeaderExpression();
  13025. const cases = node.cases = [];
  13026. this.expect(5);
  13027. this.state.labels.push(switchLabel);
  13028. this.scope.enter(0);
  13029. let cur;
  13030. for (let sawDefault; !this.match(8);) {
  13031. if (this.match(61) || this.match(65)) {
  13032. const isCase = this.match(61);
  13033. if (cur) this.finishNode(cur, "SwitchCase");
  13034. cases.push(cur = this.startNode());
  13035. cur.consequent = [];
  13036. this.next();
  13037. if (isCase) {
  13038. cur.test = this.parseExpression();
  13039. } else {
  13040. if (sawDefault) {
  13041. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  13042. }
  13043. sawDefault = true;
  13044. cur.test = null;
  13045. }
  13046. this.expect(14);
  13047. } else {
  13048. if (cur) {
  13049. cur.consequent.push(this.parseStatementListItem());
  13050. } else {
  13051. this.unexpected();
  13052. }
  13053. }
  13054. }
  13055. this.scope.exit();
  13056. if (cur) this.finishNode(cur, "SwitchCase");
  13057. this.next();
  13058. this.state.labels.pop();
  13059. return this.finishNode(node, "SwitchStatement");
  13060. }
  13061. parseThrowStatement(node) {
  13062. this.next();
  13063. if (this.hasPrecedingLineBreak()) {
  13064. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  13065. }
  13066. node.argument = this.parseExpression();
  13067. this.semicolon();
  13068. return this.finishNode(node, "ThrowStatement");
  13069. }
  13070. parseCatchClauseParam() {
  13071. const param = this.parseBindingAtom();
  13072. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13073. this.checkLVal(param, {
  13074. type: "CatchClause"
  13075. }, 9);
  13076. return param;
  13077. }
  13078. parseTryStatement(node) {
  13079. this.next();
  13080. node.block = this.parseBlock();
  13081. node.handler = null;
  13082. if (this.match(62)) {
  13083. const clause = this.startNode();
  13084. this.next();
  13085. if (this.match(10)) {
  13086. this.expect(10);
  13087. clause.param = this.parseCatchClauseParam();
  13088. this.expect(11);
  13089. } else {
  13090. clause.param = null;
  13091. this.scope.enter(0);
  13092. }
  13093. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13094. this.scope.exit();
  13095. node.handler = this.finishNode(clause, "CatchClause");
  13096. }
  13097. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13098. if (!node.handler && !node.finalizer) {
  13099. this.raise(Errors.NoCatchOrFinally, node);
  13100. }
  13101. return this.finishNode(node, "TryStatement");
  13102. }
  13103. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13104. this.next();
  13105. this.parseVar(node, false, kind, allowMissingInitializer);
  13106. this.semicolon();
  13107. return this.finishNode(node, "VariableDeclaration");
  13108. }
  13109. parseWhileStatement(node) {
  13110. this.next();
  13111. node.test = this.parseHeaderExpression();
  13112. this.state.labels.push(loopLabel);
  13113. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13114. this.state.labels.pop();
  13115. return this.finishNode(node, "WhileStatement");
  13116. }
  13117. parseWithStatement(node) {
  13118. if (this.state.strict) {
  13119. this.raise(Errors.StrictWith, this.state.startLoc);
  13120. }
  13121. this.next();
  13122. node.object = this.parseHeaderExpression();
  13123. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13124. return this.finishNode(node, "WithStatement");
  13125. }
  13126. parseEmptyStatement(node) {
  13127. this.next();
  13128. return this.finishNode(node, "EmptyStatement");
  13129. }
  13130. parseLabeledStatement(node, maybeName, expr, flags) {
  13131. for (const label of this.state.labels) {
  13132. if (label.name === maybeName) {
  13133. this.raise(Errors.LabelRedeclaration, expr, {
  13134. labelName: maybeName
  13135. });
  13136. }
  13137. }
  13138. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  13139. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13140. const label = this.state.labels[i];
  13141. if (label.statementStart === node.start) {
  13142. label.statementStart = this.sourceToOffsetPos(this.state.start);
  13143. label.kind = kind;
  13144. } else {
  13145. break;
  13146. }
  13147. }
  13148. this.state.labels.push({
  13149. name: maybeName,
  13150. kind: kind,
  13151. statementStart: this.sourceToOffsetPos(this.state.start)
  13152. });
  13153. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13154. this.state.labels.pop();
  13155. node.label = expr;
  13156. return this.finishNode(node, "LabeledStatement");
  13157. }
  13158. parseExpressionStatement(node, expr, decorators) {
  13159. node.expression = expr;
  13160. this.semicolon();
  13161. return this.finishNode(node, "ExpressionStatement");
  13162. }
  13163. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13164. const node = this.startNode();
  13165. if (allowDirectives) {
  13166. this.state.strictErrors.clear();
  13167. }
  13168. this.expect(5);
  13169. if (createNewLexicalScope) {
  13170. this.scope.enter(0);
  13171. }
  13172. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13173. if (createNewLexicalScope) {
  13174. this.scope.exit();
  13175. }
  13176. return this.finishNode(node, "BlockStatement");
  13177. }
  13178. isValidDirective(stmt) {
  13179. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13180. }
  13181. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13182. const body = node.body = [];
  13183. const directives = node.directives = [];
  13184. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13185. }
  13186. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13187. const oldStrict = this.state.strict;
  13188. let hasStrictModeDirective = false;
  13189. let parsedNonDirective = false;
  13190. while (!this.match(end)) {
  13191. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13192. if (directives && !parsedNonDirective) {
  13193. if (this.isValidDirective(stmt)) {
  13194. const directive = this.stmtToDirective(stmt);
  13195. directives.push(directive);
  13196. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13197. hasStrictModeDirective = true;
  13198. this.setStrict(true);
  13199. }
  13200. continue;
  13201. }
  13202. parsedNonDirective = true;
  13203. this.state.strictErrors.clear();
  13204. }
  13205. body.push(stmt);
  13206. }
  13207. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  13208. if (!oldStrict) {
  13209. this.setStrict(false);
  13210. }
  13211. this.next();
  13212. }
  13213. parseFor(node, init) {
  13214. node.init = init;
  13215. this.semicolon(false);
  13216. node.test = this.match(13) ? null : this.parseExpression();
  13217. this.semicolon(false);
  13218. node.update = this.match(11) ? null : this.parseExpression();
  13219. this.expect(11);
  13220. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13221. this.scope.exit();
  13222. this.state.labels.pop();
  13223. return this.finishNode(node, "ForStatement");
  13224. }
  13225. parseForIn(node, init, awaitAt) {
  13226. const isForIn = this.match(58);
  13227. this.next();
  13228. if (isForIn) {
  13229. if (awaitAt !== null) this.unexpected(awaitAt);
  13230. } else {
  13231. node.await = awaitAt !== null;
  13232. }
  13233. 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")) {
  13234. this.raise(Errors.ForInOfLoopInitializer, init, {
  13235. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13236. });
  13237. }
  13238. if (init.type === "AssignmentPattern") {
  13239. this.raise(Errors.InvalidLhs, init, {
  13240. ancestor: {
  13241. type: "ForStatement"
  13242. }
  13243. });
  13244. }
  13245. node.left = init;
  13246. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13247. this.expect(11);
  13248. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13249. this.scope.exit();
  13250. this.state.labels.pop();
  13251. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13252. }
  13253. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13254. const declarations = node.declarations = [];
  13255. node.kind = kind;
  13256. for (;;) {
  13257. const decl = this.startNode();
  13258. this.parseVarId(decl, kind);
  13259. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13260. if (decl.init === null && !allowMissingInitializer) {
  13261. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13262. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13263. kind: "destructuring"
  13264. });
  13265. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  13266. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13267. kind
  13268. });
  13269. }
  13270. }
  13271. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13272. if (!this.eat(12)) break;
  13273. }
  13274. return node;
  13275. }
  13276. parseVarId(decl, kind) {
  13277. const id = this.parseBindingAtom();
  13278. if (kind === "using" || kind === "await using") {
  13279. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  13280. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  13281. }
  13282. }
  13283. this.checkLVal(id, {
  13284. type: "VariableDeclarator"
  13285. }, kind === "var" ? 5 : 8201);
  13286. decl.id = id;
  13287. }
  13288. parseAsyncFunctionExpression(node) {
  13289. return this.parseFunction(node, 8);
  13290. }
  13291. parseFunction(node, flags = 0) {
  13292. const hangingDeclaration = flags & 2;
  13293. const isDeclaration = !!(flags & 1);
  13294. const requireId = isDeclaration && !(flags & 4);
  13295. const isAsync = !!(flags & 8);
  13296. this.initFunction(node, isAsync);
  13297. if (this.match(55)) {
  13298. if (hangingDeclaration) {
  13299. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  13300. }
  13301. this.next();
  13302. node.generator = true;
  13303. }
  13304. if (isDeclaration) {
  13305. node.id = this.parseFunctionId(requireId);
  13306. }
  13307. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13308. this.state.maybeInArrowParameters = false;
  13309. this.scope.enter(2);
  13310. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13311. if (!isDeclaration) {
  13312. node.id = this.parseFunctionId();
  13313. }
  13314. this.parseFunctionParams(node, false);
  13315. this.withSmartMixTopicForbiddingContext(() => {
  13316. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13317. });
  13318. this.prodParam.exit();
  13319. this.scope.exit();
  13320. if (isDeclaration && !hangingDeclaration) {
  13321. this.registerFunctionStatementId(node);
  13322. }
  13323. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13324. return node;
  13325. }
  13326. parseFunctionId(requireId) {
  13327. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13328. }
  13329. parseFunctionParams(node, isConstructor) {
  13330. this.expect(10);
  13331. this.expressionScope.enter(newParameterDeclarationScope());
  13332. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13333. this.expressionScope.exit();
  13334. }
  13335. registerFunctionStatementId(node) {
  13336. if (!node.id) return;
  13337. 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);
  13338. }
  13339. parseClass(node, isStatement, optionalId) {
  13340. this.next();
  13341. const oldStrict = this.state.strict;
  13342. this.state.strict = true;
  13343. this.parseClassId(node, isStatement, optionalId);
  13344. this.parseClassSuper(node);
  13345. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13346. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13347. }
  13348. isClassProperty() {
  13349. return this.match(29) || this.match(13) || this.match(8);
  13350. }
  13351. isClassMethod() {
  13352. return this.match(10);
  13353. }
  13354. nameIsConstructor(key) {
  13355. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  13356. }
  13357. isNonstaticConstructor(method) {
  13358. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  13359. }
  13360. parseClassBody(hadSuperClass, oldStrict) {
  13361. this.classScope.enter();
  13362. const state = {
  13363. hadConstructor: false,
  13364. hadSuperClass
  13365. };
  13366. let decorators = [];
  13367. const classBody = this.startNode();
  13368. classBody.body = [];
  13369. this.expect(5);
  13370. this.withSmartMixTopicForbiddingContext(() => {
  13371. while (!this.match(8)) {
  13372. if (this.eat(13)) {
  13373. if (decorators.length > 0) {
  13374. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  13375. }
  13376. continue;
  13377. }
  13378. if (this.match(26)) {
  13379. decorators.push(this.parseDecorator());
  13380. continue;
  13381. }
  13382. const member = this.startNode();
  13383. if (decorators.length) {
  13384. member.decorators = decorators;
  13385. this.resetStartLocationFromNode(member, decorators[0]);
  13386. decorators = [];
  13387. }
  13388. this.parseClassMember(classBody, member, state);
  13389. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13390. this.raise(Errors.DecoratorConstructor, member);
  13391. }
  13392. }
  13393. });
  13394. this.state.strict = oldStrict;
  13395. this.next();
  13396. if (decorators.length) {
  13397. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13398. }
  13399. this.classScope.exit();
  13400. return this.finishNode(classBody, "ClassBody");
  13401. }
  13402. parseClassMemberFromModifier(classBody, member) {
  13403. const key = this.parseIdentifier(true);
  13404. if (this.isClassMethod()) {
  13405. const method = member;
  13406. method.kind = "method";
  13407. method.computed = false;
  13408. method.key = key;
  13409. method.static = false;
  13410. this.pushClassMethod(classBody, method, false, false, false, false);
  13411. return true;
  13412. } else if (this.isClassProperty()) {
  13413. const prop = member;
  13414. prop.computed = false;
  13415. prop.key = key;
  13416. prop.static = false;
  13417. classBody.body.push(this.parseClassProperty(prop));
  13418. return true;
  13419. }
  13420. this.resetPreviousNodeTrailingComments(key);
  13421. return false;
  13422. }
  13423. parseClassMember(classBody, member, state) {
  13424. const isStatic = this.isContextual(106);
  13425. if (isStatic) {
  13426. if (this.parseClassMemberFromModifier(classBody, member)) {
  13427. return;
  13428. }
  13429. if (this.eat(5)) {
  13430. this.parseClassStaticBlock(classBody, member);
  13431. return;
  13432. }
  13433. }
  13434. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13435. }
  13436. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13437. const publicMethod = member;
  13438. const privateMethod = member;
  13439. const publicProp = member;
  13440. const privateProp = member;
  13441. const accessorProp = member;
  13442. const method = publicMethod;
  13443. const publicMember = publicMethod;
  13444. member.static = isStatic;
  13445. this.parsePropertyNamePrefixOperator(member);
  13446. if (this.eat(55)) {
  13447. method.kind = "method";
  13448. const isPrivateName = this.match(139);
  13449. this.parseClassElementName(method);
  13450. if (isPrivateName) {
  13451. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13452. return;
  13453. }
  13454. if (this.isNonstaticConstructor(publicMethod)) {
  13455. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13456. }
  13457. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13458. return;
  13459. }
  13460. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13461. const key = this.parseClassElementName(member);
  13462. const maybeContextualKw = isContextual ? key.name : null;
  13463. const isPrivate = this.isPrivateName(key);
  13464. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13465. this.parsePostMemberNameModifiers(publicMember);
  13466. if (this.isClassMethod()) {
  13467. method.kind = "method";
  13468. if (isPrivate) {
  13469. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13470. return;
  13471. }
  13472. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13473. let allowsDirectSuper = false;
  13474. if (isConstructor) {
  13475. publicMethod.kind = "constructor";
  13476. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13477. this.raise(Errors.DuplicateConstructor, key);
  13478. }
  13479. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13480. this.raise(Errors.OverrideOnConstructor, key);
  13481. }
  13482. state.hadConstructor = true;
  13483. allowsDirectSuper = state.hadSuperClass;
  13484. }
  13485. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13486. } else if (this.isClassProperty()) {
  13487. if (isPrivate) {
  13488. this.pushClassPrivateProperty(classBody, privateProp);
  13489. } else {
  13490. this.pushClassProperty(classBody, publicProp);
  13491. }
  13492. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13493. this.resetPreviousNodeTrailingComments(key);
  13494. const isGenerator = this.eat(55);
  13495. if (publicMember.optional) {
  13496. this.unexpected(maybeQuestionTokenStartLoc);
  13497. }
  13498. method.kind = "method";
  13499. const isPrivate = this.match(139);
  13500. this.parseClassElementName(method);
  13501. this.parsePostMemberNameModifiers(publicMember);
  13502. if (isPrivate) {
  13503. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13504. } else {
  13505. if (this.isNonstaticConstructor(publicMethod)) {
  13506. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13507. }
  13508. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13509. }
  13510. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13511. this.resetPreviousNodeTrailingComments(key);
  13512. method.kind = maybeContextualKw;
  13513. const isPrivate = this.match(139);
  13514. this.parseClassElementName(publicMethod);
  13515. if (isPrivate) {
  13516. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13517. } else {
  13518. if (this.isNonstaticConstructor(publicMethod)) {
  13519. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13520. }
  13521. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13522. }
  13523. this.checkGetterSetterParams(publicMethod);
  13524. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13525. this.expectPlugin("decoratorAutoAccessors");
  13526. this.resetPreviousNodeTrailingComments(key);
  13527. const isPrivate = this.match(139);
  13528. this.parseClassElementName(publicProp);
  13529. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13530. } else if (this.isLineTerminator()) {
  13531. if (isPrivate) {
  13532. this.pushClassPrivateProperty(classBody, privateProp);
  13533. } else {
  13534. this.pushClassProperty(classBody, publicProp);
  13535. }
  13536. } else {
  13537. this.unexpected();
  13538. }
  13539. }
  13540. parseClassElementName(member) {
  13541. const {
  13542. type,
  13543. value
  13544. } = this.state;
  13545. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  13546. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13547. }
  13548. if (type === 139) {
  13549. if (value === "constructor") {
  13550. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13551. }
  13552. const key = this.parsePrivateName();
  13553. member.key = key;
  13554. return key;
  13555. }
  13556. this.parsePropertyName(member);
  13557. return member.key;
  13558. }
  13559. parseClassStaticBlock(classBody, member) {
  13560. var _member$decorators;
  13561. this.scope.enter(64 | 128 | 16);
  13562. const oldLabels = this.state.labels;
  13563. this.state.labels = [];
  13564. this.prodParam.enter(0);
  13565. const body = member.body = [];
  13566. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13567. this.prodParam.exit();
  13568. this.scope.exit();
  13569. this.state.labels = oldLabels;
  13570. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13571. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13572. this.raise(Errors.DecoratorStaticBlock, member);
  13573. }
  13574. }
  13575. pushClassProperty(classBody, prop) {
  13576. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13577. this.raise(Errors.ConstructorClassField, prop.key);
  13578. }
  13579. classBody.body.push(this.parseClassProperty(prop));
  13580. }
  13581. pushClassPrivateProperty(classBody, prop) {
  13582. const node = this.parseClassPrivateProperty(prop);
  13583. classBody.body.push(node);
  13584. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13585. }
  13586. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13587. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13588. this.raise(Errors.ConstructorClassField, prop.key);
  13589. }
  13590. const node = this.parseClassAccessorProperty(prop);
  13591. classBody.body.push(node);
  13592. if (isPrivate) {
  13593. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13594. }
  13595. }
  13596. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13597. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13598. }
  13599. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13600. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13601. classBody.body.push(node);
  13602. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13603. this.declareClassPrivateMethodInScope(node, kind);
  13604. }
  13605. declareClassPrivateMethodInScope(node, kind) {
  13606. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13607. }
  13608. parsePostMemberNameModifiers(methodOrProp) {}
  13609. parseClassPrivateProperty(node) {
  13610. this.parseInitializer(node);
  13611. this.semicolon();
  13612. return this.finishNode(node, "ClassPrivateProperty");
  13613. }
  13614. parseClassProperty(node) {
  13615. this.parseInitializer(node);
  13616. this.semicolon();
  13617. return this.finishNode(node, "ClassProperty");
  13618. }
  13619. parseClassAccessorProperty(node) {
  13620. this.parseInitializer(node);
  13621. this.semicolon();
  13622. return this.finishNode(node, "ClassAccessorProperty");
  13623. }
  13624. parseInitializer(node) {
  13625. this.scope.enter(64 | 16);
  13626. this.expressionScope.enter(newExpressionScope());
  13627. this.prodParam.enter(0);
  13628. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13629. this.expressionScope.exit();
  13630. this.prodParam.exit();
  13631. this.scope.exit();
  13632. }
  13633. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13634. if (tokenIsIdentifier(this.state.type)) {
  13635. node.id = this.parseIdentifier();
  13636. if (isStatement) {
  13637. this.declareNameFromIdentifier(node.id, bindingType);
  13638. }
  13639. } else {
  13640. if (optionalId || !isStatement) {
  13641. node.id = null;
  13642. } else {
  13643. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13644. }
  13645. }
  13646. }
  13647. parseClassSuper(node) {
  13648. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13649. }
  13650. parseExport(node, decorators) {
  13651. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13652. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13653. const parseAfterDefault = !hasDefault || this.eat(12);
  13654. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13655. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13656. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13657. const isFromRequired = hasDefault || hasStar;
  13658. if (hasStar && !hasNamespace) {
  13659. if (hasDefault) this.unexpected();
  13660. if (decorators) {
  13661. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13662. }
  13663. this.parseExportFrom(node, true);
  13664. this.sawUnambiguousESM = true;
  13665. return this.finishNode(node, "ExportAllDeclaration");
  13666. }
  13667. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13668. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13669. this.unexpected(null, 5);
  13670. }
  13671. if (hasNamespace && parseAfterNamespace) {
  13672. this.unexpected(null, 98);
  13673. }
  13674. let hasDeclaration;
  13675. if (isFromRequired || hasSpecifiers) {
  13676. hasDeclaration = false;
  13677. if (decorators) {
  13678. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13679. }
  13680. this.parseExportFrom(node, isFromRequired);
  13681. } else {
  13682. hasDeclaration = this.maybeParseExportDeclaration(node);
  13683. }
  13684. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13685. var _node2$declaration;
  13686. const node2 = node;
  13687. this.checkExport(node2, true, false, !!node2.source);
  13688. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13689. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13690. } else if (decorators) {
  13691. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13692. }
  13693. this.sawUnambiguousESM = true;
  13694. return this.finishNode(node2, "ExportNamedDeclaration");
  13695. }
  13696. if (this.eat(65)) {
  13697. const node2 = node;
  13698. const decl = this.parseExportDefaultExpression();
  13699. node2.declaration = decl;
  13700. if (decl.type === "ClassDeclaration") {
  13701. this.maybeTakeDecorators(decorators, decl, node2);
  13702. } else if (decorators) {
  13703. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13704. }
  13705. this.checkExport(node2, true, true);
  13706. this.sawUnambiguousESM = true;
  13707. return this.finishNode(node2, "ExportDefaultDeclaration");
  13708. }
  13709. this.unexpected(null, 5);
  13710. }
  13711. eatExportStar(node) {
  13712. return this.eat(55);
  13713. }
  13714. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13715. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13716. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13717. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13718. const specifier = this.startNodeAtNode(id);
  13719. specifier.exported = id;
  13720. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13721. return true;
  13722. }
  13723. return false;
  13724. }
  13725. maybeParseExportNamespaceSpecifier(node) {
  13726. if (this.isContextual(93)) {
  13727. var _ref, _ref$specifiers;
  13728. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13729. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13730. this.next();
  13731. specifier.exported = this.parseModuleExportName();
  13732. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13733. return true;
  13734. }
  13735. return false;
  13736. }
  13737. maybeParseExportNamedSpecifiers(node) {
  13738. if (this.match(5)) {
  13739. const node2 = node;
  13740. if (!node2.specifiers) node2.specifiers = [];
  13741. const isTypeExport = node2.exportKind === "type";
  13742. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13743. node2.source = null;
  13744. if (this.hasPlugin("importAssertions")) {
  13745. node2.assertions = [];
  13746. } else {
  13747. node2.attributes = [];
  13748. }
  13749. node2.declaration = null;
  13750. return true;
  13751. }
  13752. return false;
  13753. }
  13754. maybeParseExportDeclaration(node) {
  13755. if (this.shouldParseExportDeclaration()) {
  13756. node.specifiers = [];
  13757. node.source = null;
  13758. if (this.hasPlugin("importAssertions")) {
  13759. node.assertions = [];
  13760. } else {
  13761. node.attributes = [];
  13762. }
  13763. node.declaration = this.parseExportDeclaration(node);
  13764. return true;
  13765. }
  13766. return false;
  13767. }
  13768. isAsyncFunction() {
  13769. if (!this.isContextual(95)) return false;
  13770. const next = this.nextTokenInLineStart();
  13771. return this.isUnparsedContextual(next, "function");
  13772. }
  13773. parseExportDefaultExpression() {
  13774. const expr = this.startNode();
  13775. if (this.match(68)) {
  13776. this.next();
  13777. return this.parseFunction(expr, 1 | 4);
  13778. } else if (this.isAsyncFunction()) {
  13779. this.next();
  13780. this.next();
  13781. return this.parseFunction(expr, 1 | 4 | 8);
  13782. }
  13783. if (this.match(80)) {
  13784. return this.parseClass(expr, true, true);
  13785. }
  13786. if (this.match(26)) {
  13787. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13788. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13789. }
  13790. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13791. }
  13792. if (this.match(75) || this.match(74) || this.isLet()) {
  13793. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13794. }
  13795. const res = this.parseMaybeAssignAllowIn();
  13796. this.semicolon();
  13797. return res;
  13798. }
  13799. parseExportDeclaration(node) {
  13800. if (this.match(80)) {
  13801. const node = this.parseClass(this.startNode(), true, false);
  13802. return node;
  13803. }
  13804. return this.parseStatementListItem();
  13805. }
  13806. isExportDefaultSpecifier() {
  13807. const {
  13808. type
  13809. } = this.state;
  13810. if (tokenIsIdentifier(type)) {
  13811. if (type === 95 && !this.state.containsEsc || type === 100) {
  13812. return false;
  13813. }
  13814. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13815. const {
  13816. type: nextType
  13817. } = this.lookahead();
  13818. if (tokenIsIdentifier(nextType) && nextType !== 98 || nextType === 5) {
  13819. this.expectOnePlugin(["flow", "typescript"]);
  13820. return false;
  13821. }
  13822. }
  13823. } else if (!this.match(65)) {
  13824. return false;
  13825. }
  13826. const next = this.nextTokenStart();
  13827. const hasFrom = this.isUnparsedContextual(next, "from");
  13828. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13829. return true;
  13830. }
  13831. if (this.match(65) && hasFrom) {
  13832. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13833. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13834. }
  13835. return false;
  13836. }
  13837. parseExportFrom(node, expect) {
  13838. if (this.eatContextual(98)) {
  13839. node.source = this.parseImportSource();
  13840. this.checkExport(node);
  13841. this.maybeParseImportAttributes(node);
  13842. this.checkJSONModuleImport(node);
  13843. } else if (expect) {
  13844. this.unexpected();
  13845. }
  13846. this.semicolon();
  13847. }
  13848. shouldParseExportDeclaration() {
  13849. const {
  13850. type
  13851. } = this.state;
  13852. if (type === 26) {
  13853. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13854. if (this.hasPlugin("decorators")) {
  13855. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13856. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13857. }
  13858. return true;
  13859. }
  13860. }
  13861. if (this.isContextual(107)) {
  13862. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13863. return true;
  13864. }
  13865. if (this.isContextual(96) && this.startsAwaitUsing()) {
  13866. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13867. return true;
  13868. }
  13869. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13870. }
  13871. checkExport(node, checkNames, isDefault, isFrom) {
  13872. if (checkNames) {
  13873. var _node$specifiers;
  13874. if (isDefault) {
  13875. this.checkDuplicateExports(node, "default");
  13876. if (this.hasPlugin("exportDefaultFrom")) {
  13877. var _declaration$extra;
  13878. const declaration = node.declaration;
  13879. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13880. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  13881. }
  13882. }
  13883. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  13884. for (const specifier of node.specifiers) {
  13885. const {
  13886. exported
  13887. } = specifier;
  13888. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13889. this.checkDuplicateExports(specifier, exportName);
  13890. if (!isFrom && specifier.local) {
  13891. const {
  13892. local
  13893. } = specifier;
  13894. if (local.type !== "Identifier") {
  13895. this.raise(Errors.ExportBindingIsString, specifier, {
  13896. localName: local.value,
  13897. exportName
  13898. });
  13899. } else {
  13900. this.checkReservedWord(local.name, local.loc.start, true, false);
  13901. this.scope.checkLocalExport(local);
  13902. }
  13903. }
  13904. }
  13905. } else if (node.declaration) {
  13906. const decl = node.declaration;
  13907. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  13908. const {
  13909. id
  13910. } = decl;
  13911. if (!id) throw new Error("Assertion failure");
  13912. this.checkDuplicateExports(node, id.name);
  13913. } else if (decl.type === "VariableDeclaration") {
  13914. for (const declaration of decl.declarations) {
  13915. this.checkDeclaration(declaration.id);
  13916. }
  13917. }
  13918. }
  13919. }
  13920. }
  13921. checkDeclaration(node) {
  13922. if (node.type === "Identifier") {
  13923. this.checkDuplicateExports(node, node.name);
  13924. } else if (node.type === "ObjectPattern") {
  13925. for (const prop of node.properties) {
  13926. this.checkDeclaration(prop);
  13927. }
  13928. } else if (node.type === "ArrayPattern") {
  13929. for (const elem of node.elements) {
  13930. if (elem) {
  13931. this.checkDeclaration(elem);
  13932. }
  13933. }
  13934. } else if (node.type === "ObjectProperty") {
  13935. this.checkDeclaration(node.value);
  13936. } else if (node.type === "RestElement") {
  13937. this.checkDeclaration(node.argument);
  13938. } else if (node.type === "AssignmentPattern") {
  13939. this.checkDeclaration(node.left);
  13940. }
  13941. }
  13942. checkDuplicateExports(node, exportName) {
  13943. if (this.exportedIdentifiers.has(exportName)) {
  13944. if (exportName === "default") {
  13945. this.raise(Errors.DuplicateDefaultExport, node);
  13946. } else {
  13947. this.raise(Errors.DuplicateExport, node, {
  13948. exportName
  13949. });
  13950. }
  13951. }
  13952. this.exportedIdentifiers.add(exportName);
  13953. }
  13954. parseExportSpecifiers(isInTypeExport) {
  13955. const nodes = [];
  13956. let first = true;
  13957. this.expect(5);
  13958. while (!this.eat(8)) {
  13959. if (first) {
  13960. first = false;
  13961. } else {
  13962. this.expect(12);
  13963. if (this.eat(8)) break;
  13964. }
  13965. const isMaybeTypeOnly = this.isContextual(130);
  13966. const isString = this.match(134);
  13967. const node = this.startNode();
  13968. node.local = this.parseModuleExportName();
  13969. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13970. }
  13971. return nodes;
  13972. }
  13973. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  13974. if (this.eatContextual(93)) {
  13975. node.exported = this.parseModuleExportName();
  13976. } else if (isString) {
  13977. node.exported = this.cloneStringLiteral(node.local);
  13978. } else if (!node.exported) {
  13979. node.exported = this.cloneIdentifier(node.local);
  13980. }
  13981. return this.finishNode(node, "ExportSpecifier");
  13982. }
  13983. parseModuleExportName() {
  13984. if (this.match(134)) {
  13985. const result = this.parseStringLiteral(this.state.value);
  13986. const surrogate = loneSurrogate.exec(result.value);
  13987. if (surrogate) {
  13988. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  13989. surrogateCharCode: surrogate[0].charCodeAt(0)
  13990. });
  13991. }
  13992. return result;
  13993. }
  13994. return this.parseIdentifier(true);
  13995. }
  13996. isJSONModuleImport(node) {
  13997. if (node.assertions != null) {
  13998. return node.assertions.some(({
  13999. key,
  14000. value
  14001. }) => {
  14002. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14003. });
  14004. }
  14005. return false;
  14006. }
  14007. checkImportReflection(node) {
  14008. const {
  14009. specifiers
  14010. } = node;
  14011. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  14012. if (node.phase === "source") {
  14013. if (singleBindingType !== "ImportDefaultSpecifier") {
  14014. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  14015. }
  14016. } else if (node.phase === "defer") {
  14017. if (singleBindingType !== "ImportNamespaceSpecifier") {
  14018. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  14019. }
  14020. } else if (node.module) {
  14021. var _node$assertions;
  14022. if (singleBindingType !== "ImportDefaultSpecifier") {
  14023. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  14024. }
  14025. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14026. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  14027. }
  14028. }
  14029. }
  14030. checkJSONModuleImport(node) {
  14031. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14032. const {
  14033. specifiers
  14034. } = node;
  14035. if (specifiers != null) {
  14036. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14037. let imported;
  14038. if (specifier.type === "ExportSpecifier") {
  14039. imported = specifier.local;
  14040. } else if (specifier.type === "ImportSpecifier") {
  14041. imported = specifier.imported;
  14042. }
  14043. if (imported !== undefined) {
  14044. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14045. }
  14046. });
  14047. if (nonDefaultNamedSpecifier !== undefined) {
  14048. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  14049. }
  14050. }
  14051. }
  14052. }
  14053. isPotentialImportPhase(isExport) {
  14054. if (isExport) return false;
  14055. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  14056. }
  14057. applyImportPhase(node, isExport, phase, loc) {
  14058. if (isExport) {
  14059. return;
  14060. }
  14061. if (phase === "module") {
  14062. this.expectPlugin("importReflection", loc);
  14063. node.module = true;
  14064. } else if (this.hasPlugin("importReflection")) {
  14065. node.module = false;
  14066. }
  14067. if (phase === "source") {
  14068. this.expectPlugin("sourcePhaseImports", loc);
  14069. node.phase = "source";
  14070. } else if (phase === "defer") {
  14071. this.expectPlugin("deferredImportEvaluation", loc);
  14072. node.phase = "defer";
  14073. } else if (this.hasPlugin("sourcePhaseImports")) {
  14074. node.phase = null;
  14075. }
  14076. }
  14077. parseMaybeImportPhase(node, isExport) {
  14078. if (!this.isPotentialImportPhase(isExport)) {
  14079. this.applyImportPhase(node, isExport, null);
  14080. return null;
  14081. }
  14082. const phaseIdentifier = this.parseIdentifier(true);
  14083. const {
  14084. type
  14085. } = this.state;
  14086. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14087. if (isImportPhase) {
  14088. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  14089. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  14090. return null;
  14091. } else {
  14092. this.applyImportPhase(node, isExport, null);
  14093. return phaseIdentifier;
  14094. }
  14095. }
  14096. isPrecedingIdImportPhase(phase) {
  14097. const {
  14098. type
  14099. } = this.state;
  14100. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14101. }
  14102. parseImport(node) {
  14103. if (this.match(134)) {
  14104. return this.parseImportSourceAndAttributes(node);
  14105. }
  14106. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14107. }
  14108. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14109. node.specifiers = [];
  14110. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14111. const parseNext = !hasDefault || this.eat(12);
  14112. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14113. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14114. this.expectContextual(98);
  14115. return this.parseImportSourceAndAttributes(node);
  14116. }
  14117. parseImportSourceAndAttributes(node) {
  14118. var _node$specifiers2;
  14119. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14120. node.source = this.parseImportSource();
  14121. this.maybeParseImportAttributes(node);
  14122. this.checkImportReflection(node);
  14123. this.checkJSONModuleImport(node);
  14124. this.semicolon();
  14125. this.sawUnambiguousESM = true;
  14126. return this.finishNode(node, "ImportDeclaration");
  14127. }
  14128. parseImportSource() {
  14129. if (!this.match(134)) this.unexpected();
  14130. return this.parseExprAtom();
  14131. }
  14132. parseImportSpecifierLocal(node, specifier, type) {
  14133. specifier.local = this.parseIdentifier();
  14134. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14135. }
  14136. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14137. this.checkLVal(specifier.local, {
  14138. type
  14139. }, bindingType);
  14140. return this.finishNode(specifier, type);
  14141. }
  14142. parseImportAttributes() {
  14143. this.expect(5);
  14144. const attrs = [];
  14145. const attrNames = new Set();
  14146. do {
  14147. if (this.match(8)) {
  14148. break;
  14149. }
  14150. const node = this.startNode();
  14151. const keyName = this.state.value;
  14152. if (attrNames.has(keyName)) {
  14153. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  14154. key: keyName
  14155. });
  14156. }
  14157. attrNames.add(keyName);
  14158. if (this.match(134)) {
  14159. node.key = this.parseStringLiteral(keyName);
  14160. } else {
  14161. node.key = this.parseIdentifier(true);
  14162. }
  14163. this.expect(14);
  14164. if (!this.match(134)) {
  14165. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14166. }
  14167. node.value = this.parseStringLiteral(this.state.value);
  14168. attrs.push(this.finishNode(node, "ImportAttribute"));
  14169. } while (this.eat(12));
  14170. this.expect(8);
  14171. return attrs;
  14172. }
  14173. parseModuleAttributes() {
  14174. const attrs = [];
  14175. const attributes = new Set();
  14176. do {
  14177. const node = this.startNode();
  14178. node.key = this.parseIdentifier(true);
  14179. if (node.key.name !== "type") {
  14180. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  14181. }
  14182. if (attributes.has(node.key.name)) {
  14183. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  14184. key: node.key.name
  14185. });
  14186. }
  14187. attributes.add(node.key.name);
  14188. this.expect(14);
  14189. if (!this.match(134)) {
  14190. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14191. }
  14192. node.value = this.parseStringLiteral(this.state.value);
  14193. attrs.push(this.finishNode(node, "ImportAttribute"));
  14194. } while (this.eat(12));
  14195. return attrs;
  14196. }
  14197. maybeParseImportAttributes(node) {
  14198. let attributes;
  14199. {
  14200. var useWith = false;
  14201. }
  14202. if (this.match(76)) {
  14203. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14204. return;
  14205. }
  14206. this.next();
  14207. if (this.hasPlugin("moduleAttributes")) {
  14208. attributes = this.parseModuleAttributes();
  14209. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  14210. } else {
  14211. attributes = this.parseImportAttributes();
  14212. }
  14213. {
  14214. useWith = true;
  14215. }
  14216. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14217. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  14218. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  14219. }
  14220. if (!this.hasPlugin("importAssertions")) {
  14221. this.addExtra(node, "deprecatedAssertSyntax", true);
  14222. }
  14223. this.next();
  14224. attributes = this.parseImportAttributes();
  14225. } else {
  14226. attributes = [];
  14227. }
  14228. if (!useWith && this.hasPlugin("importAssertions")) {
  14229. node.assertions = attributes;
  14230. } else {
  14231. node.attributes = attributes;
  14232. }
  14233. }
  14234. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14235. if (maybeDefaultIdentifier) {
  14236. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14237. specifier.local = maybeDefaultIdentifier;
  14238. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14239. return true;
  14240. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14241. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14242. return true;
  14243. }
  14244. return false;
  14245. }
  14246. maybeParseStarImportSpecifier(node) {
  14247. if (this.match(55)) {
  14248. const specifier = this.startNode();
  14249. this.next();
  14250. this.expectContextual(93);
  14251. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14252. return true;
  14253. }
  14254. return false;
  14255. }
  14256. parseNamedImportSpecifiers(node) {
  14257. let first = true;
  14258. this.expect(5);
  14259. while (!this.eat(8)) {
  14260. if (first) {
  14261. first = false;
  14262. } else {
  14263. if (this.eat(14)) {
  14264. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  14265. }
  14266. this.expect(12);
  14267. if (this.eat(8)) break;
  14268. }
  14269. const specifier = this.startNode();
  14270. const importedIsString = this.match(134);
  14271. const isMaybeTypeOnly = this.isContextual(130);
  14272. specifier.imported = this.parseModuleExportName();
  14273. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14274. node.specifiers.push(importSpecifier);
  14275. }
  14276. }
  14277. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14278. if (this.eatContextual(93)) {
  14279. specifier.local = this.parseIdentifier();
  14280. } else {
  14281. const {
  14282. imported
  14283. } = specifier;
  14284. if (importedIsString) {
  14285. throw this.raise(Errors.ImportBindingIsString, specifier, {
  14286. importName: imported.value
  14287. });
  14288. }
  14289. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14290. if (!specifier.local) {
  14291. specifier.local = this.cloneIdentifier(imported);
  14292. }
  14293. }
  14294. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14295. }
  14296. isThisParam(param) {
  14297. return param.type === "Identifier" && param.name === "this";
  14298. }
  14299. }
  14300. class Parser extends StatementParser {
  14301. constructor(options, input, pluginsMap) {
  14302. options = getOptions(options);
  14303. super(options, input);
  14304. this.options = options;
  14305. this.initializeScopes();
  14306. this.plugins = pluginsMap;
  14307. this.filename = options.sourceFilename;
  14308. this.startIndex = options.startIndex;
  14309. let optionFlags = 0;
  14310. if (options.allowAwaitOutsideFunction) {
  14311. optionFlags |= 1;
  14312. }
  14313. if (options.allowReturnOutsideFunction) {
  14314. optionFlags |= 2;
  14315. }
  14316. if (options.allowImportExportEverywhere) {
  14317. optionFlags |= 8;
  14318. }
  14319. if (options.allowSuperOutsideMethod) {
  14320. optionFlags |= 16;
  14321. }
  14322. if (options.allowUndeclaredExports) {
  14323. optionFlags |= 64;
  14324. }
  14325. if (options.allowNewTargetOutsideFunction) {
  14326. optionFlags |= 4;
  14327. }
  14328. if (options.allowYieldOutsideFunction) {
  14329. optionFlags |= 32;
  14330. }
  14331. if (options.ranges) {
  14332. optionFlags |= 128;
  14333. }
  14334. if (options.tokens) {
  14335. optionFlags |= 256;
  14336. }
  14337. if (options.createImportExpressions) {
  14338. optionFlags |= 512;
  14339. }
  14340. if (options.createParenthesizedExpressions) {
  14341. optionFlags |= 1024;
  14342. }
  14343. if (options.errorRecovery) {
  14344. optionFlags |= 2048;
  14345. }
  14346. if (options.attachComment) {
  14347. optionFlags |= 4096;
  14348. }
  14349. if (options.annexB) {
  14350. optionFlags |= 8192;
  14351. }
  14352. this.optionFlags = optionFlags;
  14353. }
  14354. getScopeHandler() {
  14355. return ScopeHandler;
  14356. }
  14357. parse() {
  14358. this.enterInitialScopes();
  14359. const file = this.startNode();
  14360. const program = this.startNode();
  14361. this.nextToken();
  14362. file.errors = null;
  14363. this.parseTopLevel(file, program);
  14364. file.errors = this.state.errors;
  14365. file.comments.length = this.state.commentsLen;
  14366. return file;
  14367. }
  14368. }
  14369. function parse(input, options) {
  14370. var _options;
  14371. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14372. options = Object.assign({}, options);
  14373. try {
  14374. options.sourceType = "module";
  14375. const parser = getParser(options, input);
  14376. const ast = parser.parse();
  14377. if (parser.sawUnambiguousESM) {
  14378. return ast;
  14379. }
  14380. if (parser.ambiguousScriptDifferentAst) {
  14381. try {
  14382. options.sourceType = "script";
  14383. return getParser(options, input).parse();
  14384. } catch (_unused) {}
  14385. } else {
  14386. ast.program.sourceType = "script";
  14387. }
  14388. return ast;
  14389. } catch (moduleError) {
  14390. try {
  14391. options.sourceType = "script";
  14392. return getParser(options, input).parse();
  14393. } catch (_unused2) {}
  14394. throw moduleError;
  14395. }
  14396. } else {
  14397. return getParser(options, input).parse();
  14398. }
  14399. }
  14400. function parseExpression(input, options) {
  14401. const parser = getParser(options, input);
  14402. if (parser.options.strictMode) {
  14403. parser.state.strict = true;
  14404. }
  14405. return parser.getExpression();
  14406. }
  14407. function generateExportedTokenTypes(internalTokenTypes) {
  14408. const tokenTypes = {};
  14409. for (const typeName of Object.keys(internalTokenTypes)) {
  14410. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14411. }
  14412. return tokenTypes;
  14413. }
  14414. const tokTypes = generateExportedTokenTypes(tt);
  14415. function getParser(options, input) {
  14416. let cls = Parser;
  14417. const pluginsMap = new Map();
  14418. if (options != null && options.plugins) {
  14419. for (const plugin of options.plugins) {
  14420. let name, opts;
  14421. if (typeof plugin === "string") {
  14422. name = plugin;
  14423. } else {
  14424. [name, opts] = plugin;
  14425. }
  14426. if (!pluginsMap.has(name)) {
  14427. pluginsMap.set(name, opts || {});
  14428. }
  14429. }
  14430. validatePlugins(pluginsMap);
  14431. cls = getParserClass(pluginsMap);
  14432. }
  14433. return new cls(options, input, pluginsMap);
  14434. }
  14435. const parserClassCache = new Map();
  14436. function getParserClass(pluginsMap) {
  14437. const pluginList = [];
  14438. for (const name of mixinPluginNames) {
  14439. if (pluginsMap.has(name)) {
  14440. pluginList.push(name);
  14441. }
  14442. }
  14443. const key = pluginList.join("|");
  14444. let cls = parserClassCache.get(key);
  14445. if (!cls) {
  14446. cls = Parser;
  14447. for (const plugin of pluginList) {
  14448. cls = mixinPlugins[plugin](cls);
  14449. }
  14450. parserClassCache.set(key, cls);
  14451. }
  14452. return cls;
  14453. }
  14454. exports.parse = parse;
  14455. exports.parseExpression = parseExpression;
  14456. exports.tokTypes = tokTypes;
  14457. //# sourceMappingURL=index.js.map