index.js 497 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587
  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. ElementAfterRest: "Rest element must be last element.",
  119. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  120. ExportBindingIsString: ({
  121. localName,
  122. exportName
  123. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  124. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  125. ForInOfLoopInitializer: ({
  126. type
  127. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  128. ForInUsing: "For-in loop may not start with 'using' declaration.",
  129. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  130. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  131. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  132. IllegalBreakContinue: ({
  133. type
  134. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  135. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  136. IllegalReturn: "'return' outside of function.",
  137. 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.",
  138. ImportBindingIsString: ({
  139. importName
  140. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  141. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  142. ImportCallNotNewExpression: "Cannot use new with import(...).",
  143. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  144. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  145. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  146. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  147. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  148. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  149. InvalidCodePoint: "Code point out of bounds.",
  150. InvalidCoverDiscardElement: "'void' must be followed by an expression when not used in a binding position.",
  151. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  152. InvalidDecimal: "Invalid decimal.",
  153. InvalidDigit: ({
  154. radix
  155. }) => `Expected number in radix ${radix}.`,
  156. InvalidEscapeSequence: "Bad character escape sequence.",
  157. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  158. InvalidEscapedReservedWord: ({
  159. reservedWord
  160. }) => `Escape sequence in keyword ${reservedWord}.`,
  161. InvalidIdentifier: ({
  162. identifierName
  163. }) => `Invalid identifier ${identifierName}.`,
  164. InvalidLhs: ({
  165. ancestor
  166. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  167. InvalidLhsBinding: ({
  168. ancestor
  169. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  170. InvalidLhsOptionalChaining: ({
  171. ancestor
  172. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  173. InvalidNumber: "Invalid number.",
  174. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  175. InvalidOrUnexpectedToken: ({
  176. unexpected
  177. }) => `Unexpected character '${unexpected}'.`,
  178. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  179. InvalidPrivateFieldResolution: ({
  180. identifierName
  181. }) => `Private name #${identifierName} is not defined.`,
  182. InvalidPropertyBindingPattern: "Binding member expression.",
  183. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  184. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  185. LabelRedeclaration: ({
  186. labelName
  187. }) => `Label '${labelName}' is already declared.`,
  188. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  189. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  190. MalformedRegExpFlags: "Invalid regular expression flag.",
  191. MissingClassName: "A class name is required.",
  192. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  193. MissingSemicolon: "Missing semicolon.",
  194. MissingPlugin: ({
  195. missingPlugin
  196. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  197. MissingOneOfPlugins: ({
  198. missingPlugin
  199. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  200. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  201. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  202. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  203. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  204. ModuleAttributesWithDuplicateKeys: ({
  205. key
  206. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  207. ModuleExportNameHasLoneSurrogate: ({
  208. surrogateCharCode
  209. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  210. ModuleExportUndefined: ({
  211. localName
  212. }) => `Export '${localName}' is not defined.`,
  213. MultipleDefaultsInSwitch: "Multiple default clauses.",
  214. NewlineAfterThrow: "Illegal newline after throw.",
  215. NoCatchOrFinally: "Missing catch or finally clause.",
  216. NumberIdentifier: "Identifier directly after number.",
  217. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  218. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  219. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  220. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  221. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  222. ParamDupe: "Argument name clash.",
  223. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  224. PatternHasMethod: "Object pattern can't contain methods.",
  225. PrivateInExpectedIn: ({
  226. identifierName
  227. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  228. PrivateNameRedeclaration: ({
  229. identifierName
  230. }) => `Duplicate private name #${identifierName}.`,
  231. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  232. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  233. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  234. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  235. RestTrailingComma: "Unexpected trailing comma after rest element.",
  236. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  237. 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.",
  238. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  239. StaticPrototype: "Classes may not have static property named prototype.",
  240. 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?",
  241. SuperPrivateField: "Private fields can't be accessed on super.",
  242. TrailingDecorator: "Decorators must be attached to a class element.",
  243. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  244. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  245. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  246. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  247. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  248. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  249. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  250. UnexpectedKeyword: ({
  251. keyword
  252. }) => `Unexpected keyword '${keyword}'.`,
  253. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  254. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  255. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  256. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  257. UnexpectedPrivateField: "Unexpected private name.",
  258. UnexpectedReservedWord: ({
  259. reservedWord
  260. }) => `Unexpected reserved word '${reservedWord}'.`,
  261. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  262. UnexpectedToken: ({
  263. expected,
  264. unexpected
  265. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  266. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  267. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement.",
  268. UnexpectedVoidPattern: "Unexpected void binding.",
  269. UnsupportedBind: "Binding should be performed on object property.",
  270. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  271. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  272. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  273. UnsupportedMetaProperty: ({
  274. target,
  275. onlyValidPropertyName
  276. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  277. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  278. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  279. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  280. UnterminatedComment: "Unterminated comment.",
  281. UnterminatedRegExp: "Unterminated regular expression.",
  282. UnterminatedString: "Unterminated string constant.",
  283. UnterminatedTemplate: "Unterminated template.",
  284. UsingDeclarationExport: "Using declaration cannot be exported.",
  285. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  286. VarRedeclaration: ({
  287. identifierName
  288. }) => `Identifier '${identifierName}' has already been declared.`,
  289. VoidPatternCatchClauseParam: "A void binding can not be the catch clause parameter. Use `try { ... } catch { ... }` if you want to discard the caught error.",
  290. VoidPatternInitializer: "A void binding may not have an initializer.",
  291. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  292. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  293. YieldNotInGeneratorFunction: "'yield' is only allowed within generator functions.",
  294. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  295. };
  296. var StrictModeErrors = {
  297. StrictDelete: "Deleting local variable in strict mode.",
  298. StrictEvalArguments: ({
  299. referenceName
  300. }) => `Assigning to '${referenceName}' in strict mode.`,
  301. StrictEvalArgumentsBinding: ({
  302. bindingName
  303. }) => `Binding '${bindingName}' in strict mode.`,
  304. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  305. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  306. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  307. StrictWith: "'with' in strict mode."
  308. };
  309. var ParseExpressionErrors = {
  310. ParseExpressionEmptyInput: "Unexpected parseExpression() input: The input is empty or contains only comments.",
  311. ParseExpressionExpectsEOF: ({
  312. unexpected
  313. }) => `Unexpected parseExpression() input: The input should contain exactly one expression, but the first expression is followed by the unexpected character \`${String.fromCodePoint(unexpected)}\`.`
  314. };
  315. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  316. var PipelineOperatorErrors = Object.assign({
  317. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  318. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  319. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  320. PipeTopicUnconfiguredToken: ({
  321. token
  322. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  323. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  324. PipeUnparenthesizedBody: ({
  325. type
  326. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  327. type
  328. })}; please wrap it in parentheses.`
  329. }, {
  330. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  331. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  332. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  333. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  334. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  335. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  336. });
  337. const _excluded = ["message"];
  338. function defineHidden(obj, key, value) {
  339. Object.defineProperty(obj, key, {
  340. enumerable: false,
  341. configurable: true,
  342. value
  343. });
  344. }
  345. function toParseErrorConstructor({
  346. toMessage,
  347. code,
  348. reasonCode,
  349. syntaxPlugin
  350. }) {
  351. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  352. {
  353. const oldReasonCodes = {
  354. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  355. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  356. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  357. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  358. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  359. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  360. };
  361. if (oldReasonCodes[reasonCode]) {
  362. reasonCode = oldReasonCodes[reasonCode];
  363. }
  364. }
  365. return function constructor(loc, details) {
  366. const error = new SyntaxError();
  367. error.code = code;
  368. error.reasonCode = reasonCode;
  369. error.loc = loc;
  370. error.pos = loc.index;
  371. error.syntaxPlugin = syntaxPlugin;
  372. if (hasMissingPlugin) {
  373. error.missingPlugin = details.missingPlugin;
  374. }
  375. defineHidden(error, "clone", function clone(overrides = {}) {
  376. var _overrides$loc;
  377. const {
  378. line,
  379. column,
  380. index
  381. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  382. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  383. });
  384. defineHidden(error, "details", details);
  385. Object.defineProperty(error, "message", {
  386. configurable: true,
  387. get() {
  388. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  389. this.message = message;
  390. return message;
  391. },
  392. set(value) {
  393. Object.defineProperty(this, "message", {
  394. value,
  395. writable: true
  396. });
  397. }
  398. });
  399. return error;
  400. };
  401. }
  402. function ParseErrorEnum(argument, syntaxPlugin) {
  403. if (Array.isArray(argument)) {
  404. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  405. }
  406. const ParseErrorConstructors = {};
  407. for (const reasonCode of Object.keys(argument)) {
  408. const template = argument[reasonCode];
  409. const _ref = typeof template === "string" ? {
  410. message: () => template
  411. } : typeof template === "function" ? {
  412. message: template
  413. } : template,
  414. {
  415. message
  416. } = _ref,
  417. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  418. const toMessage = typeof message === "string" ? () => message : message;
  419. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  420. code: "BABEL_PARSER_SYNTAX_ERROR",
  421. reasonCode,
  422. toMessage
  423. }, syntaxPlugin ? {
  424. syntaxPlugin
  425. } : {}, rest));
  426. }
  427. return ParseErrorConstructors;
  428. }
  429. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum(ParseExpressionErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  430. function createDefaultOptions() {
  431. return {
  432. sourceType: "script",
  433. sourceFilename: undefined,
  434. startIndex: 0,
  435. startColumn: 0,
  436. startLine: 1,
  437. allowAwaitOutsideFunction: false,
  438. allowReturnOutsideFunction: false,
  439. allowNewTargetOutsideFunction: false,
  440. allowImportExportEverywhere: false,
  441. allowSuperOutsideMethod: false,
  442. allowUndeclaredExports: false,
  443. allowYieldOutsideFunction: false,
  444. plugins: [],
  445. strictMode: null,
  446. ranges: false,
  447. tokens: false,
  448. createImportExpressions: false,
  449. createParenthesizedExpressions: false,
  450. errorRecovery: false,
  451. attachComment: true,
  452. annexB: true
  453. };
  454. }
  455. function getOptions(opts) {
  456. const options = createDefaultOptions();
  457. if (opts == null) {
  458. return options;
  459. }
  460. if (opts.annexB != null && opts.annexB !== false) {
  461. throw new Error("The `annexB` option can only be set to `false`.");
  462. }
  463. for (const key of Object.keys(options)) {
  464. if (opts[key] != null) options[key] = opts[key];
  465. }
  466. if (options.startLine === 1) {
  467. if (opts.startIndex == null && options.startColumn > 0) {
  468. options.startIndex = options.startColumn;
  469. } else if (opts.startColumn == null && options.startIndex > 0) {
  470. options.startColumn = options.startIndex;
  471. }
  472. } else if (opts.startColumn == null || opts.startIndex == null) {
  473. if (opts.startIndex != null) {
  474. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  475. }
  476. }
  477. if (options.sourceType === "commonjs") {
  478. if (opts.allowAwaitOutsideFunction != null) {
  479. throw new Error("The `allowAwaitOutsideFunction` option cannot be used with `sourceType: 'commonjs'`.");
  480. }
  481. if (opts.allowReturnOutsideFunction != null) {
  482. throw new Error("`sourceType: 'commonjs'` implies `allowReturnOutsideFunction: true`, please remove the `allowReturnOutsideFunction` option or use `sourceType: 'script'`.");
  483. }
  484. if (opts.allowNewTargetOutsideFunction != null) {
  485. throw new Error("`sourceType: 'commonjs'` implies `allowNewTargetOutsideFunction: true`, please remove the `allowNewTargetOutsideFunction` option or use `sourceType: 'script'`.");
  486. }
  487. }
  488. return options;
  489. }
  490. const {
  491. defineProperty
  492. } = Object;
  493. const toUnenumerable = (object, key) => {
  494. if (object) {
  495. defineProperty(object, key, {
  496. enumerable: false,
  497. value: object[key]
  498. });
  499. }
  500. };
  501. function toESTreeLocation(node) {
  502. toUnenumerable(node.loc.start, "index");
  503. toUnenumerable(node.loc.end, "index");
  504. return node;
  505. }
  506. var estree = superClass => class ESTreeParserMixin extends superClass {
  507. parse() {
  508. const file = toESTreeLocation(super.parse());
  509. if (this.optionFlags & 256) {
  510. file.tokens = file.tokens.map(toESTreeLocation);
  511. }
  512. return file;
  513. }
  514. parseRegExpLiteral({
  515. pattern,
  516. flags
  517. }) {
  518. let regex = null;
  519. try {
  520. regex = new RegExp(pattern, flags);
  521. } catch (_) {}
  522. const node = this.estreeParseLiteral(regex);
  523. node.regex = {
  524. pattern,
  525. flags
  526. };
  527. return node;
  528. }
  529. parseBigIntLiteral(value) {
  530. let bigInt;
  531. try {
  532. bigInt = BigInt(value);
  533. } catch (_unused) {
  534. bigInt = null;
  535. }
  536. const node = this.estreeParseLiteral(bigInt);
  537. node.bigint = String(node.value || value);
  538. return node;
  539. }
  540. parseDecimalLiteral(value) {
  541. const decimal = null;
  542. const node = this.estreeParseLiteral(decimal);
  543. node.decimal = String(node.value || value);
  544. return node;
  545. }
  546. estreeParseLiteral(value) {
  547. return this.parseLiteral(value, "Literal");
  548. }
  549. parseStringLiteral(value) {
  550. return this.estreeParseLiteral(value);
  551. }
  552. parseNumericLiteral(value) {
  553. return this.estreeParseLiteral(value);
  554. }
  555. parseNullLiteral() {
  556. return this.estreeParseLiteral(null);
  557. }
  558. parseBooleanLiteral(value) {
  559. return this.estreeParseLiteral(value);
  560. }
  561. estreeParseChainExpression(node, endLoc) {
  562. const chain = this.startNodeAtNode(node);
  563. chain.expression = node;
  564. return this.finishNodeAt(chain, "ChainExpression", endLoc);
  565. }
  566. directiveToStmt(directive) {
  567. const expression = directive.value;
  568. delete directive.value;
  569. this.castNodeTo(expression, "Literal");
  570. expression.raw = expression.extra.raw;
  571. expression.value = expression.extra.expressionValue;
  572. const stmt = this.castNodeTo(directive, "ExpressionStatement");
  573. stmt.expression = expression;
  574. stmt.directive = expression.extra.rawValue;
  575. delete expression.extra;
  576. return stmt;
  577. }
  578. fillOptionalPropertiesForTSESLint(node) {}
  579. cloneEstreeStringLiteral(node) {
  580. const {
  581. start,
  582. end,
  583. loc,
  584. range,
  585. raw,
  586. value
  587. } = node;
  588. const cloned = Object.create(node.constructor.prototype);
  589. cloned.type = "Literal";
  590. cloned.start = start;
  591. cloned.end = end;
  592. cloned.loc = loc;
  593. cloned.range = range;
  594. cloned.raw = raw;
  595. cloned.value = value;
  596. return cloned;
  597. }
  598. initFunction(node, isAsync) {
  599. super.initFunction(node, isAsync);
  600. node.expression = false;
  601. }
  602. checkDeclaration(node) {
  603. if (node != null && this.isObjectProperty(node)) {
  604. this.checkDeclaration(node.value);
  605. } else {
  606. super.checkDeclaration(node);
  607. }
  608. }
  609. getObjectOrClassMethodParams(method) {
  610. return method.value.params;
  611. }
  612. isValidDirective(stmt) {
  613. var _stmt$expression$extr;
  614. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  615. }
  616. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  617. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  618. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  619. node.body = directiveStatements.concat(node.body);
  620. delete node.directives;
  621. }
  622. parsePrivateName() {
  623. const node = super.parsePrivateName();
  624. {
  625. if (!this.getPluginOption("estree", "classFeatures")) {
  626. return node;
  627. }
  628. }
  629. return this.convertPrivateNameToPrivateIdentifier(node);
  630. }
  631. convertPrivateNameToPrivateIdentifier(node) {
  632. const name = super.getPrivateNameSV(node);
  633. node = node;
  634. delete node.id;
  635. node.name = name;
  636. return this.castNodeTo(node, "PrivateIdentifier");
  637. }
  638. isPrivateName(node) {
  639. {
  640. if (!this.getPluginOption("estree", "classFeatures")) {
  641. return super.isPrivateName(node);
  642. }
  643. }
  644. return node.type === "PrivateIdentifier";
  645. }
  646. getPrivateNameSV(node) {
  647. {
  648. if (!this.getPluginOption("estree", "classFeatures")) {
  649. return super.getPrivateNameSV(node);
  650. }
  651. }
  652. return node.name;
  653. }
  654. parseLiteral(value, type) {
  655. const node = super.parseLiteral(value, type);
  656. node.raw = node.extra.raw;
  657. delete node.extra;
  658. return node;
  659. }
  660. parseFunctionBody(node, allowExpression, isMethod = false) {
  661. super.parseFunctionBody(node, allowExpression, isMethod);
  662. node.expression = node.body.type !== "BlockStatement";
  663. }
  664. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  665. let funcNode = this.startNode();
  666. funcNode.kind = node.kind;
  667. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  668. delete funcNode.kind;
  669. const {
  670. typeParameters
  671. } = node;
  672. if (typeParameters) {
  673. delete node.typeParameters;
  674. funcNode.typeParameters = typeParameters;
  675. this.resetStartLocationFromNode(funcNode, typeParameters);
  676. }
  677. const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
  678. node.value = valueNode;
  679. if (type === "ClassPrivateMethod") {
  680. node.computed = false;
  681. }
  682. if (type === "ObjectMethod") {
  683. if (node.kind === "method") {
  684. node.kind = "init";
  685. }
  686. node.shorthand = false;
  687. return this.finishNode(node, "Property");
  688. } else {
  689. return this.finishNode(node, "MethodDefinition");
  690. }
  691. }
  692. nameIsConstructor(key) {
  693. if (key.type === "Literal") return key.value === "constructor";
  694. return super.nameIsConstructor(key);
  695. }
  696. parseClassProperty(...args) {
  697. const propertyNode = super.parseClassProperty(...args);
  698. {
  699. if (!this.getPluginOption("estree", "classFeatures")) {
  700. return propertyNode;
  701. }
  702. }
  703. {
  704. this.castNodeTo(propertyNode, "PropertyDefinition");
  705. }
  706. return propertyNode;
  707. }
  708. parseClassPrivateProperty(...args) {
  709. const propertyNode = super.parseClassPrivateProperty(...args);
  710. {
  711. if (!this.getPluginOption("estree", "classFeatures")) {
  712. return propertyNode;
  713. }
  714. }
  715. {
  716. this.castNodeTo(propertyNode, "PropertyDefinition");
  717. }
  718. propertyNode.computed = false;
  719. return propertyNode;
  720. }
  721. parseClassAccessorProperty(node) {
  722. const accessorPropertyNode = super.parseClassAccessorProperty(node);
  723. {
  724. if (!this.getPluginOption("estree", "classFeatures")) {
  725. return accessorPropertyNode;
  726. }
  727. }
  728. if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
  729. delete accessorPropertyNode.abstract;
  730. this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
  731. } else {
  732. this.castNodeTo(accessorPropertyNode, "AccessorProperty");
  733. }
  734. return accessorPropertyNode;
  735. }
  736. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  737. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  738. if (node) {
  739. node.kind = "init";
  740. this.castNodeTo(node, "Property");
  741. }
  742. return node;
  743. }
  744. finishObjectProperty(node) {
  745. node.kind = "init";
  746. return this.finishNode(node, "Property");
  747. }
  748. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  749. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  750. }
  751. isAssignable(node, isBinding) {
  752. if (node != null && this.isObjectProperty(node)) {
  753. return this.isAssignable(node.value, isBinding);
  754. }
  755. return super.isAssignable(node, isBinding);
  756. }
  757. toAssignable(node, isLHS = false) {
  758. if (node != null && this.isObjectProperty(node)) {
  759. const {
  760. key,
  761. value
  762. } = node;
  763. if (this.isPrivateName(key)) {
  764. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  765. }
  766. this.toAssignable(value, isLHS);
  767. } else {
  768. super.toAssignable(node, isLHS);
  769. }
  770. }
  771. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  772. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  773. this.raise(Errors.PatternHasAccessor, prop.key);
  774. } else if (prop.type === "Property" && prop.method) {
  775. this.raise(Errors.PatternHasMethod, prop.key);
  776. } else {
  777. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  778. }
  779. }
  780. finishCallExpression(unfinished, optional) {
  781. const node = super.finishCallExpression(unfinished, optional);
  782. if (node.callee.type === "Import") {
  783. var _ref, _ref2;
  784. this.castNodeTo(node, "ImportExpression");
  785. node.source = node.arguments[0];
  786. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  787. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  788. delete node.arguments;
  789. delete node.callee;
  790. } else if (node.type === "OptionalCallExpression") {
  791. this.castNodeTo(node, "CallExpression");
  792. } else {
  793. node.optional = false;
  794. }
  795. return node;
  796. }
  797. toReferencedArguments(node) {
  798. if (node.type === "ImportExpression") {
  799. return;
  800. }
  801. super.toReferencedArguments(node);
  802. }
  803. parseExport(unfinished, decorators) {
  804. const exportStartLoc = this.state.lastTokStartLoc;
  805. const node = super.parseExport(unfinished, decorators);
  806. switch (node.type) {
  807. case "ExportAllDeclaration":
  808. node.exported = null;
  809. break;
  810. case "ExportNamedDeclaration":
  811. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  812. this.castNodeTo(node, "ExportAllDeclaration");
  813. node.exported = node.specifiers[0].exported;
  814. delete node.specifiers;
  815. }
  816. case "ExportDefaultDeclaration":
  817. {
  818. var _declaration$decorato;
  819. const {
  820. declaration
  821. } = node;
  822. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  823. this.resetStartLocation(node, exportStartLoc);
  824. }
  825. }
  826. break;
  827. }
  828. return node;
  829. }
  830. stopParseSubscript(base, state) {
  831. const node = super.stopParseSubscript(base, state);
  832. if (state.optionalChainMember) {
  833. return this.estreeParseChainExpression(node, base.loc.end);
  834. }
  835. return node;
  836. }
  837. parseMember(base, startLoc, state, computed, optional) {
  838. const node = super.parseMember(base, startLoc, state, computed, optional);
  839. if (node.type === "OptionalMemberExpression") {
  840. this.castNodeTo(node, "MemberExpression");
  841. } else {
  842. node.optional = false;
  843. }
  844. return node;
  845. }
  846. isOptionalMemberExpression(node) {
  847. if (node.type === "ChainExpression") {
  848. return node.expression.type === "MemberExpression";
  849. }
  850. return super.isOptionalMemberExpression(node);
  851. }
  852. hasPropertyAsPrivateName(node) {
  853. if (node.type === "ChainExpression") {
  854. node = node.expression;
  855. }
  856. return super.hasPropertyAsPrivateName(node);
  857. }
  858. isObjectProperty(node) {
  859. return node.type === "Property" && node.kind === "init" && !node.method;
  860. }
  861. isObjectMethod(node) {
  862. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  863. }
  864. castNodeTo(node, type) {
  865. const result = super.castNodeTo(node, type);
  866. this.fillOptionalPropertiesForTSESLint(result);
  867. return result;
  868. }
  869. cloneIdentifier(node) {
  870. const cloned = super.cloneIdentifier(node);
  871. this.fillOptionalPropertiesForTSESLint(cloned);
  872. return cloned;
  873. }
  874. cloneStringLiteral(node) {
  875. if (node.type === "Literal") {
  876. return this.cloneEstreeStringLiteral(node);
  877. }
  878. return super.cloneStringLiteral(node);
  879. }
  880. finishNodeAt(node, type, endLoc) {
  881. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  882. }
  883. finishNode(node, type) {
  884. const result = super.finishNode(node, type);
  885. this.fillOptionalPropertiesForTSESLint(result);
  886. return result;
  887. }
  888. resetStartLocation(node, startLoc) {
  889. super.resetStartLocation(node, startLoc);
  890. toESTreeLocation(node);
  891. }
  892. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  893. super.resetEndLocation(node, endLoc);
  894. toESTreeLocation(node);
  895. }
  896. };
  897. class TokContext {
  898. constructor(token, preserveSpace) {
  899. this.token = void 0;
  900. this.preserveSpace = void 0;
  901. this.token = token;
  902. this.preserveSpace = !!preserveSpace;
  903. }
  904. }
  905. const types = {
  906. brace: new TokContext("{"),
  907. j_oTag: new TokContext("<tag"),
  908. j_cTag: new TokContext("</tag"),
  909. j_expr: new TokContext("<tag>...</tag>", true)
  910. };
  911. {
  912. types.template = new TokContext("`", true);
  913. }
  914. const beforeExpr = true;
  915. const startsExpr = true;
  916. const isLoop = true;
  917. const isAssign = true;
  918. const prefix = true;
  919. const postfix = true;
  920. class ExportedTokenType {
  921. constructor(label, conf = {}) {
  922. this.label = void 0;
  923. this.keyword = void 0;
  924. this.beforeExpr = void 0;
  925. this.startsExpr = void 0;
  926. this.rightAssociative = void 0;
  927. this.isLoop = void 0;
  928. this.isAssign = void 0;
  929. this.prefix = void 0;
  930. this.postfix = void 0;
  931. this.binop = void 0;
  932. this.label = label;
  933. this.keyword = conf.keyword;
  934. this.beforeExpr = !!conf.beforeExpr;
  935. this.startsExpr = !!conf.startsExpr;
  936. this.rightAssociative = !!conf.rightAssociative;
  937. this.isLoop = !!conf.isLoop;
  938. this.isAssign = !!conf.isAssign;
  939. this.prefix = !!conf.prefix;
  940. this.postfix = !!conf.postfix;
  941. this.binop = conf.binop != null ? conf.binop : null;
  942. {
  943. this.updateContext = null;
  944. }
  945. }
  946. }
  947. const keywords$1 = new Map();
  948. function createKeyword(name, options = {}) {
  949. options.keyword = name;
  950. const token = createToken(name, options);
  951. keywords$1.set(name, token);
  952. return token;
  953. }
  954. function createBinop(name, binop) {
  955. return createToken(name, {
  956. beforeExpr,
  957. binop
  958. });
  959. }
  960. let tokenTypeCounter = -1;
  961. const tokenTypes = [];
  962. const tokenLabels = [];
  963. const tokenBinops = [];
  964. const tokenBeforeExprs = [];
  965. const tokenStartsExprs = [];
  966. const tokenPrefixes = [];
  967. function createToken(name, options = {}) {
  968. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  969. ++tokenTypeCounter;
  970. tokenLabels.push(name);
  971. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  972. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  973. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  974. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  975. tokenTypes.push(new ExportedTokenType(name, options));
  976. return tokenTypeCounter;
  977. }
  978. function createKeywordLike(name, options = {}) {
  979. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  980. ++tokenTypeCounter;
  981. keywords$1.set(name, tokenTypeCounter);
  982. tokenLabels.push(name);
  983. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  984. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  985. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  986. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  987. tokenTypes.push(new ExportedTokenType("name", options));
  988. return tokenTypeCounter;
  989. }
  990. const tt = {
  991. bracketL: createToken("[", {
  992. beforeExpr,
  993. startsExpr
  994. }),
  995. bracketHashL: createToken("#[", {
  996. beforeExpr,
  997. startsExpr
  998. }),
  999. bracketBarL: createToken("[|", {
  1000. beforeExpr,
  1001. startsExpr
  1002. }),
  1003. bracketR: createToken("]"),
  1004. bracketBarR: createToken("|]"),
  1005. braceL: createToken("{", {
  1006. beforeExpr,
  1007. startsExpr
  1008. }),
  1009. braceBarL: createToken("{|", {
  1010. beforeExpr,
  1011. startsExpr
  1012. }),
  1013. braceHashL: createToken("#{", {
  1014. beforeExpr,
  1015. startsExpr
  1016. }),
  1017. braceR: createToken("}"),
  1018. braceBarR: createToken("|}"),
  1019. parenL: createToken("(", {
  1020. beforeExpr,
  1021. startsExpr
  1022. }),
  1023. parenR: createToken(")"),
  1024. comma: createToken(",", {
  1025. beforeExpr
  1026. }),
  1027. semi: createToken(";", {
  1028. beforeExpr
  1029. }),
  1030. colon: createToken(":", {
  1031. beforeExpr
  1032. }),
  1033. doubleColon: createToken("::", {
  1034. beforeExpr
  1035. }),
  1036. dot: createToken("."),
  1037. question: createToken("?", {
  1038. beforeExpr
  1039. }),
  1040. questionDot: createToken("?."),
  1041. arrow: createToken("=>", {
  1042. beforeExpr
  1043. }),
  1044. template: createToken("template"),
  1045. ellipsis: createToken("...", {
  1046. beforeExpr
  1047. }),
  1048. backQuote: createToken("`", {
  1049. startsExpr
  1050. }),
  1051. dollarBraceL: createToken("${", {
  1052. beforeExpr,
  1053. startsExpr
  1054. }),
  1055. templateTail: createToken("...`", {
  1056. startsExpr
  1057. }),
  1058. templateNonTail: createToken("...${", {
  1059. beforeExpr,
  1060. startsExpr
  1061. }),
  1062. at: createToken("@"),
  1063. hash: createToken("#", {
  1064. startsExpr
  1065. }),
  1066. interpreterDirective: createToken("#!..."),
  1067. eq: createToken("=", {
  1068. beforeExpr,
  1069. isAssign
  1070. }),
  1071. assign: createToken("_=", {
  1072. beforeExpr,
  1073. isAssign
  1074. }),
  1075. slashAssign: createToken("_=", {
  1076. beforeExpr,
  1077. isAssign
  1078. }),
  1079. xorAssign: createToken("_=", {
  1080. beforeExpr,
  1081. isAssign
  1082. }),
  1083. moduloAssign: createToken("_=", {
  1084. beforeExpr,
  1085. isAssign
  1086. }),
  1087. incDec: createToken("++/--", {
  1088. prefix,
  1089. postfix,
  1090. startsExpr
  1091. }),
  1092. bang: createToken("!", {
  1093. beforeExpr,
  1094. prefix,
  1095. startsExpr
  1096. }),
  1097. tilde: createToken("~", {
  1098. beforeExpr,
  1099. prefix,
  1100. startsExpr
  1101. }),
  1102. doubleCaret: createToken("^^", {
  1103. startsExpr
  1104. }),
  1105. doubleAt: createToken("@@", {
  1106. startsExpr
  1107. }),
  1108. pipeline: createBinop("|>", 0),
  1109. nullishCoalescing: createBinop("??", 1),
  1110. logicalOR: createBinop("||", 1),
  1111. logicalAND: createBinop("&&", 2),
  1112. bitwiseOR: createBinop("|", 3),
  1113. bitwiseXOR: createBinop("^", 4),
  1114. bitwiseAND: createBinop("&", 5),
  1115. equality: createBinop("==/!=/===/!==", 6),
  1116. lt: createBinop("</>/<=/>=", 7),
  1117. gt: createBinop("</>/<=/>=", 7),
  1118. relational: createBinop("</>/<=/>=", 7),
  1119. bitShift: createBinop("<</>>/>>>", 8),
  1120. bitShiftL: createBinop("<</>>/>>>", 8),
  1121. bitShiftR: createBinop("<</>>/>>>", 8),
  1122. plusMin: createToken("+/-", {
  1123. beforeExpr,
  1124. binop: 9,
  1125. prefix,
  1126. startsExpr
  1127. }),
  1128. modulo: createToken("%", {
  1129. binop: 10,
  1130. startsExpr
  1131. }),
  1132. star: createToken("*", {
  1133. binop: 10
  1134. }),
  1135. slash: createBinop("/", 10),
  1136. exponent: createToken("**", {
  1137. beforeExpr,
  1138. binop: 11,
  1139. rightAssociative: true
  1140. }),
  1141. _in: createKeyword("in", {
  1142. beforeExpr,
  1143. binop: 7
  1144. }),
  1145. _instanceof: createKeyword("instanceof", {
  1146. beforeExpr,
  1147. binop: 7
  1148. }),
  1149. _break: createKeyword("break"),
  1150. _case: createKeyword("case", {
  1151. beforeExpr
  1152. }),
  1153. _catch: createKeyword("catch"),
  1154. _continue: createKeyword("continue"),
  1155. _debugger: createKeyword("debugger"),
  1156. _default: createKeyword("default", {
  1157. beforeExpr
  1158. }),
  1159. _else: createKeyword("else", {
  1160. beforeExpr
  1161. }),
  1162. _finally: createKeyword("finally"),
  1163. _function: createKeyword("function", {
  1164. startsExpr
  1165. }),
  1166. _if: createKeyword("if"),
  1167. _return: createKeyword("return", {
  1168. beforeExpr
  1169. }),
  1170. _switch: createKeyword("switch"),
  1171. _throw: createKeyword("throw", {
  1172. beforeExpr,
  1173. prefix,
  1174. startsExpr
  1175. }),
  1176. _try: createKeyword("try"),
  1177. _var: createKeyword("var"),
  1178. _const: createKeyword("const"),
  1179. _with: createKeyword("with"),
  1180. _new: createKeyword("new", {
  1181. beforeExpr,
  1182. startsExpr
  1183. }),
  1184. _this: createKeyword("this", {
  1185. startsExpr
  1186. }),
  1187. _super: createKeyword("super", {
  1188. startsExpr
  1189. }),
  1190. _class: createKeyword("class", {
  1191. startsExpr
  1192. }),
  1193. _extends: createKeyword("extends", {
  1194. beforeExpr
  1195. }),
  1196. _export: createKeyword("export"),
  1197. _import: createKeyword("import", {
  1198. startsExpr
  1199. }),
  1200. _null: createKeyword("null", {
  1201. startsExpr
  1202. }),
  1203. _true: createKeyword("true", {
  1204. startsExpr
  1205. }),
  1206. _false: createKeyword("false", {
  1207. startsExpr
  1208. }),
  1209. _typeof: createKeyword("typeof", {
  1210. beforeExpr,
  1211. prefix,
  1212. startsExpr
  1213. }),
  1214. _void: createKeyword("void", {
  1215. beforeExpr,
  1216. prefix,
  1217. startsExpr
  1218. }),
  1219. _delete: createKeyword("delete", {
  1220. beforeExpr,
  1221. prefix,
  1222. startsExpr
  1223. }),
  1224. _do: createKeyword("do", {
  1225. isLoop,
  1226. beforeExpr
  1227. }),
  1228. _for: createKeyword("for", {
  1229. isLoop
  1230. }),
  1231. _while: createKeyword("while", {
  1232. isLoop
  1233. }),
  1234. _as: createKeywordLike("as", {
  1235. startsExpr
  1236. }),
  1237. _assert: createKeywordLike("assert", {
  1238. startsExpr
  1239. }),
  1240. _async: createKeywordLike("async", {
  1241. startsExpr
  1242. }),
  1243. _await: createKeywordLike("await", {
  1244. startsExpr
  1245. }),
  1246. _defer: createKeywordLike("defer", {
  1247. startsExpr
  1248. }),
  1249. _from: createKeywordLike("from", {
  1250. startsExpr
  1251. }),
  1252. _get: createKeywordLike("get", {
  1253. startsExpr
  1254. }),
  1255. _let: createKeywordLike("let", {
  1256. startsExpr
  1257. }),
  1258. _meta: createKeywordLike("meta", {
  1259. startsExpr
  1260. }),
  1261. _of: createKeywordLike("of", {
  1262. startsExpr
  1263. }),
  1264. _sent: createKeywordLike("sent", {
  1265. startsExpr
  1266. }),
  1267. _set: createKeywordLike("set", {
  1268. startsExpr
  1269. }),
  1270. _source: createKeywordLike("source", {
  1271. startsExpr
  1272. }),
  1273. _static: createKeywordLike("static", {
  1274. startsExpr
  1275. }),
  1276. _using: createKeywordLike("using", {
  1277. startsExpr
  1278. }),
  1279. _yield: createKeywordLike("yield", {
  1280. startsExpr
  1281. }),
  1282. _asserts: createKeywordLike("asserts", {
  1283. startsExpr
  1284. }),
  1285. _checks: createKeywordLike("checks", {
  1286. startsExpr
  1287. }),
  1288. _exports: createKeywordLike("exports", {
  1289. startsExpr
  1290. }),
  1291. _global: createKeywordLike("global", {
  1292. startsExpr
  1293. }),
  1294. _implements: createKeywordLike("implements", {
  1295. startsExpr
  1296. }),
  1297. _intrinsic: createKeywordLike("intrinsic", {
  1298. startsExpr
  1299. }),
  1300. _infer: createKeywordLike("infer", {
  1301. startsExpr
  1302. }),
  1303. _is: createKeywordLike("is", {
  1304. startsExpr
  1305. }),
  1306. _mixins: createKeywordLike("mixins", {
  1307. startsExpr
  1308. }),
  1309. _proto: createKeywordLike("proto", {
  1310. startsExpr
  1311. }),
  1312. _require: createKeywordLike("require", {
  1313. startsExpr
  1314. }),
  1315. _satisfies: createKeywordLike("satisfies", {
  1316. startsExpr
  1317. }),
  1318. _keyof: createKeywordLike("keyof", {
  1319. startsExpr
  1320. }),
  1321. _readonly: createKeywordLike("readonly", {
  1322. startsExpr
  1323. }),
  1324. _unique: createKeywordLike("unique", {
  1325. startsExpr
  1326. }),
  1327. _abstract: createKeywordLike("abstract", {
  1328. startsExpr
  1329. }),
  1330. _declare: createKeywordLike("declare", {
  1331. startsExpr
  1332. }),
  1333. _enum: createKeywordLike("enum", {
  1334. startsExpr
  1335. }),
  1336. _module: createKeywordLike("module", {
  1337. startsExpr
  1338. }),
  1339. _namespace: createKeywordLike("namespace", {
  1340. startsExpr
  1341. }),
  1342. _interface: createKeywordLike("interface", {
  1343. startsExpr
  1344. }),
  1345. _type: createKeywordLike("type", {
  1346. startsExpr
  1347. }),
  1348. _opaque: createKeywordLike("opaque", {
  1349. startsExpr
  1350. }),
  1351. name: createToken("name", {
  1352. startsExpr
  1353. }),
  1354. placeholder: createToken("%%", {
  1355. startsExpr
  1356. }),
  1357. string: createToken("string", {
  1358. startsExpr
  1359. }),
  1360. num: createToken("num", {
  1361. startsExpr
  1362. }),
  1363. bigint: createToken("bigint", {
  1364. startsExpr
  1365. }),
  1366. decimal: createToken("decimal", {
  1367. startsExpr
  1368. }),
  1369. regexp: createToken("regexp", {
  1370. startsExpr
  1371. }),
  1372. privateName: createToken("#name", {
  1373. startsExpr
  1374. }),
  1375. eof: createToken("eof"),
  1376. jsxName: createToken("jsxName"),
  1377. jsxText: createToken("jsxText", {
  1378. beforeExpr
  1379. }),
  1380. jsxTagStart: createToken("jsxTagStart", {
  1381. startsExpr
  1382. }),
  1383. jsxTagEnd: createToken("jsxTagEnd")
  1384. };
  1385. function tokenIsIdentifier(token) {
  1386. return token >= 93 && token <= 133;
  1387. }
  1388. function tokenKeywordOrIdentifierIsKeyword(token) {
  1389. return token <= 92;
  1390. }
  1391. function tokenIsKeywordOrIdentifier(token) {
  1392. return token >= 58 && token <= 133;
  1393. }
  1394. function tokenIsLiteralPropertyName(token) {
  1395. return token >= 58 && token <= 137;
  1396. }
  1397. function tokenComesBeforeExpression(token) {
  1398. return tokenBeforeExprs[token];
  1399. }
  1400. function tokenCanStartExpression(token) {
  1401. return tokenStartsExprs[token];
  1402. }
  1403. function tokenIsAssignment(token) {
  1404. return token >= 29 && token <= 33;
  1405. }
  1406. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1407. return token >= 129 && token <= 131;
  1408. }
  1409. function tokenIsLoop(token) {
  1410. return token >= 90 && token <= 92;
  1411. }
  1412. function tokenIsKeyword(token) {
  1413. return token >= 58 && token <= 92;
  1414. }
  1415. function tokenIsOperator(token) {
  1416. return token >= 39 && token <= 59;
  1417. }
  1418. function tokenIsPostfix(token) {
  1419. return token === 34;
  1420. }
  1421. function tokenIsPrefix(token) {
  1422. return tokenPrefixes[token];
  1423. }
  1424. function tokenIsTSTypeOperator(token) {
  1425. return token >= 121 && token <= 123;
  1426. }
  1427. function tokenIsTSDeclarationStart(token) {
  1428. return token >= 124 && token <= 130;
  1429. }
  1430. function tokenLabelName(token) {
  1431. return tokenLabels[token];
  1432. }
  1433. function tokenOperatorPrecedence(token) {
  1434. return tokenBinops[token];
  1435. }
  1436. function tokenIsRightAssociative(token) {
  1437. return token === 57;
  1438. }
  1439. function tokenIsTemplate(token) {
  1440. return token >= 24 && token <= 25;
  1441. }
  1442. function getExportedToken(token) {
  1443. return tokenTypes[token];
  1444. }
  1445. {
  1446. tokenTypes[8].updateContext = context => {
  1447. context.pop();
  1448. };
  1449. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1450. context.push(types.brace);
  1451. };
  1452. tokenTypes[22].updateContext = context => {
  1453. if (context[context.length - 1] === types.template) {
  1454. context.pop();
  1455. } else {
  1456. context.push(types.template);
  1457. }
  1458. };
  1459. tokenTypes[143].updateContext = context => {
  1460. context.push(types.j_expr, types.j_oTag);
  1461. };
  1462. }
  1463. 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";
  1464. 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";
  1465. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1466. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1467. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1468. 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];
  1469. 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];
  1470. function isInAstralSet(code, set) {
  1471. let pos = 0x10000;
  1472. for (let i = 0, length = set.length; i < length; i += 2) {
  1473. pos += set[i];
  1474. if (pos > code) return false;
  1475. pos += set[i + 1];
  1476. if (pos >= code) return true;
  1477. }
  1478. return false;
  1479. }
  1480. function isIdentifierStart(code) {
  1481. if (code < 65) return code === 36;
  1482. if (code <= 90) return true;
  1483. if (code < 97) return code === 95;
  1484. if (code <= 122) return true;
  1485. if (code <= 0xffff) {
  1486. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1487. }
  1488. return isInAstralSet(code, astralIdentifierStartCodes);
  1489. }
  1490. function isIdentifierChar(code) {
  1491. if (code < 48) return code === 36;
  1492. if (code < 58) return true;
  1493. if (code < 65) return false;
  1494. if (code <= 90) return true;
  1495. if (code < 97) return code === 95;
  1496. if (code <= 122) return true;
  1497. if (code <= 0xffff) {
  1498. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1499. }
  1500. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1501. }
  1502. const reservedWords = {
  1503. 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"],
  1504. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1505. strictBind: ["eval", "arguments"]
  1506. };
  1507. const keywords = new Set(reservedWords.keyword);
  1508. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1509. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1510. function isReservedWord(word, inModule) {
  1511. return inModule && word === "await" || word === "enum";
  1512. }
  1513. function isStrictReservedWord(word, inModule) {
  1514. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1515. }
  1516. function isStrictBindOnlyReservedWord(word) {
  1517. return reservedWordsStrictBindSet.has(word);
  1518. }
  1519. function isStrictBindReservedWord(word, inModule) {
  1520. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1521. }
  1522. function isKeyword(word) {
  1523. return keywords.has(word);
  1524. }
  1525. function isIteratorStart(current, next, next2) {
  1526. return current === 64 && next === 64 && isIdentifierStart(next2);
  1527. }
  1528. 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"]);
  1529. function canBeReservedWord(word) {
  1530. return reservedWordLikeSet.has(word);
  1531. }
  1532. class Scope {
  1533. constructor(flags) {
  1534. this.flags = 0;
  1535. this.names = new Map();
  1536. this.firstLexicalName = "";
  1537. this.flags = flags;
  1538. }
  1539. }
  1540. class ScopeHandler {
  1541. constructor(parser, inModule) {
  1542. this.parser = void 0;
  1543. this.scopeStack = [];
  1544. this.inModule = void 0;
  1545. this.undefinedExports = new Map();
  1546. this.parser = parser;
  1547. this.inModule = inModule;
  1548. }
  1549. get inTopLevel() {
  1550. return (this.currentScope().flags & 1) > 0;
  1551. }
  1552. get inFunction() {
  1553. return (this.currentVarScopeFlags() & 2) > 0;
  1554. }
  1555. get allowSuper() {
  1556. return (this.currentThisScopeFlags() & 16) > 0;
  1557. }
  1558. get allowDirectSuper() {
  1559. return (this.currentThisScopeFlags() & 32) > 0;
  1560. }
  1561. get allowNewTarget() {
  1562. return (this.currentThisScopeFlags() & 512) > 0;
  1563. }
  1564. get inClass() {
  1565. return (this.currentThisScopeFlags() & 64) > 0;
  1566. }
  1567. get inClassAndNotInNonArrowFunction() {
  1568. const flags = this.currentThisScopeFlags();
  1569. return (flags & 64) > 0 && (flags & 2) === 0;
  1570. }
  1571. get inStaticBlock() {
  1572. for (let i = this.scopeStack.length - 1;; i--) {
  1573. const {
  1574. flags
  1575. } = this.scopeStack[i];
  1576. if (flags & 128) {
  1577. return true;
  1578. }
  1579. if (flags & (1667 | 64)) {
  1580. return false;
  1581. }
  1582. }
  1583. }
  1584. get inNonArrowFunction() {
  1585. return (this.currentThisScopeFlags() & 2) > 0;
  1586. }
  1587. get inBareCaseStatement() {
  1588. return (this.currentScope().flags & 256) > 0;
  1589. }
  1590. get treatFunctionsAsVar() {
  1591. return this.treatFunctionsAsVarInScope(this.currentScope());
  1592. }
  1593. createScope(flags) {
  1594. return new Scope(flags);
  1595. }
  1596. enter(flags) {
  1597. this.scopeStack.push(this.createScope(flags));
  1598. }
  1599. exit() {
  1600. const scope = this.scopeStack.pop();
  1601. return scope.flags;
  1602. }
  1603. treatFunctionsAsVarInScope(scope) {
  1604. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1605. }
  1606. declareName(name, bindingType, loc) {
  1607. let scope = this.currentScope();
  1608. if (bindingType & 8 || bindingType & 16) {
  1609. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1610. let type = scope.names.get(name) || 0;
  1611. if (bindingType & 16) {
  1612. type = type | 4;
  1613. } else {
  1614. if (!scope.firstLexicalName) {
  1615. scope.firstLexicalName = name;
  1616. }
  1617. type = type | 2;
  1618. }
  1619. scope.names.set(name, type);
  1620. if (bindingType & 8) {
  1621. this.maybeExportDefined(scope, name);
  1622. }
  1623. } else if (bindingType & 4) {
  1624. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1625. scope = this.scopeStack[i];
  1626. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1627. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1628. this.maybeExportDefined(scope, name);
  1629. if (scope.flags & 1667) break;
  1630. }
  1631. }
  1632. if (this.parser.inModule && scope.flags & 1) {
  1633. this.undefinedExports.delete(name);
  1634. }
  1635. }
  1636. maybeExportDefined(scope, name) {
  1637. if (this.parser.inModule && scope.flags & 1) {
  1638. this.undefinedExports.delete(name);
  1639. }
  1640. }
  1641. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1642. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1643. this.parser.raise(Errors.VarRedeclaration, loc, {
  1644. identifierName: name
  1645. });
  1646. }
  1647. }
  1648. isRedeclaredInScope(scope, name, bindingType) {
  1649. if (!(bindingType & 1)) return false;
  1650. if (bindingType & 8) {
  1651. return scope.names.has(name);
  1652. }
  1653. const type = scope.names.get(name);
  1654. if (bindingType & 16) {
  1655. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1656. }
  1657. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1658. }
  1659. checkLocalExport(id) {
  1660. const {
  1661. name
  1662. } = id;
  1663. const topLevelScope = this.scopeStack[0];
  1664. if (!topLevelScope.names.has(name)) {
  1665. this.undefinedExports.set(name, id.loc.start);
  1666. }
  1667. }
  1668. currentScope() {
  1669. return this.scopeStack[this.scopeStack.length - 1];
  1670. }
  1671. currentVarScopeFlags() {
  1672. for (let i = this.scopeStack.length - 1;; i--) {
  1673. const {
  1674. flags
  1675. } = this.scopeStack[i];
  1676. if (flags & 1667) {
  1677. return flags;
  1678. }
  1679. }
  1680. }
  1681. currentThisScopeFlags() {
  1682. for (let i = this.scopeStack.length - 1;; i--) {
  1683. const {
  1684. flags
  1685. } = this.scopeStack[i];
  1686. if (flags & (1667 | 64) && !(flags & 4)) {
  1687. return flags;
  1688. }
  1689. }
  1690. }
  1691. }
  1692. class FlowScope extends Scope {
  1693. constructor(...args) {
  1694. super(...args);
  1695. this.declareFunctions = new Set();
  1696. }
  1697. }
  1698. class FlowScopeHandler extends ScopeHandler {
  1699. createScope(flags) {
  1700. return new FlowScope(flags);
  1701. }
  1702. declareName(name, bindingType, loc) {
  1703. const scope = this.currentScope();
  1704. if (bindingType & 2048) {
  1705. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1706. this.maybeExportDefined(scope, name);
  1707. scope.declareFunctions.add(name);
  1708. return;
  1709. }
  1710. super.declareName(name, bindingType, loc);
  1711. }
  1712. isRedeclaredInScope(scope, name, bindingType) {
  1713. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1714. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1715. const type = scope.names.get(name);
  1716. return (type & 4) > 0 || (type & 2) > 0;
  1717. }
  1718. return false;
  1719. }
  1720. checkLocalExport(id) {
  1721. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1722. super.checkLocalExport(id);
  1723. }
  1724. }
  1725. }
  1726. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  1727. const FlowErrors = ParseErrorEnum`flow`({
  1728. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  1729. 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.",
  1730. AssignReservedType: ({
  1731. reservedType
  1732. }) => `Cannot overwrite reserved type ${reservedType}.`,
  1733. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  1734. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  1735. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  1736. EnumBooleanMemberNotInitialized: ({
  1737. memberName,
  1738. enumName
  1739. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  1740. EnumDuplicateMemberName: ({
  1741. memberName,
  1742. enumName
  1743. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  1744. EnumInconsistentMemberValues: ({
  1745. enumName
  1746. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  1747. EnumInvalidExplicitType: ({
  1748. invalidEnumType,
  1749. enumName
  1750. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1751. EnumInvalidExplicitTypeUnknownSupplied: ({
  1752. enumName
  1753. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1754. EnumInvalidMemberInitializerPrimaryType: ({
  1755. enumName,
  1756. memberName,
  1757. explicitType
  1758. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  1759. EnumInvalidMemberInitializerSymbolType: ({
  1760. enumName,
  1761. memberName
  1762. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  1763. EnumInvalidMemberInitializerUnknownType: ({
  1764. enumName,
  1765. memberName
  1766. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  1767. EnumInvalidMemberName: ({
  1768. enumName,
  1769. memberName,
  1770. suggestion
  1771. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  1772. EnumNumberMemberNotInitialized: ({
  1773. enumName,
  1774. memberName
  1775. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  1776. EnumStringMemberInconsistentlyInitialized: ({
  1777. enumName
  1778. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  1779. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  1780. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  1781. 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.",
  1782. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  1783. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  1784. InexactVariance: "Explicit inexact syntax cannot have variance.",
  1785. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  1786. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  1787. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  1788. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  1789. PatternIsOptional: Object.assign({
  1790. message: "A binding pattern parameter cannot be optional in an implementation signature."
  1791. }, {
  1792. reasonCode: "OptionalBindingPattern"
  1793. }),
  1794. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  1795. SpreadVariance: "Spread properties cannot have variance.",
  1796. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  1797. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  1798. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  1799. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  1800. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  1801. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  1802. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  1803. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  1804. UnexpectedReservedType: ({
  1805. reservedType
  1806. }) => `Unexpected reserved type ${reservedType}.`,
  1807. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  1808. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  1809. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  1810. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  1811. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  1812. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  1813. UnsupportedDeclareExportKind: ({
  1814. unsupportedExportKind,
  1815. suggestion
  1816. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  1817. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  1818. UnterminatedFlowComment: "Unterminated flow-comment."
  1819. });
  1820. function isEsModuleType(bodyElement) {
  1821. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  1822. }
  1823. function hasTypeImportKind(node) {
  1824. return node.importKind === "type" || node.importKind === "typeof";
  1825. }
  1826. const exportSuggestions = {
  1827. const: "declare export var",
  1828. let: "declare export var",
  1829. type: "export type",
  1830. interface: "export interface"
  1831. };
  1832. function partition(list, test) {
  1833. const list1 = [];
  1834. const list2 = [];
  1835. for (let i = 0; i < list.length; i++) {
  1836. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  1837. }
  1838. return [list1, list2];
  1839. }
  1840. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  1841. var flow = superClass => class FlowParserMixin extends superClass {
  1842. constructor(...args) {
  1843. super(...args);
  1844. this.flowPragma = undefined;
  1845. }
  1846. getScopeHandler() {
  1847. return FlowScopeHandler;
  1848. }
  1849. shouldParseTypes() {
  1850. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  1851. }
  1852. finishToken(type, val) {
  1853. if (type !== 134 && type !== 13 && type !== 28) {
  1854. if (this.flowPragma === undefined) {
  1855. this.flowPragma = null;
  1856. }
  1857. }
  1858. super.finishToken(type, val);
  1859. }
  1860. addComment(comment) {
  1861. if (this.flowPragma === undefined) {
  1862. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  1863. if (!matches) ;else if (matches[1] === "flow") {
  1864. this.flowPragma = "flow";
  1865. } else if (matches[1] === "noflow") {
  1866. this.flowPragma = "noflow";
  1867. } else {
  1868. throw new Error("Unexpected flow pragma");
  1869. }
  1870. }
  1871. super.addComment(comment);
  1872. }
  1873. flowParseTypeInitialiser(tok) {
  1874. const oldInType = this.state.inType;
  1875. this.state.inType = true;
  1876. this.expect(tok || 14);
  1877. const type = this.flowParseType();
  1878. this.state.inType = oldInType;
  1879. return type;
  1880. }
  1881. flowParsePredicate() {
  1882. const node = this.startNode();
  1883. const moduloLoc = this.state.startLoc;
  1884. this.next();
  1885. this.expectContextual(110);
  1886. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  1887. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  1888. }
  1889. if (this.eat(10)) {
  1890. node.value = super.parseExpression();
  1891. this.expect(11);
  1892. return this.finishNode(node, "DeclaredPredicate");
  1893. } else {
  1894. return this.finishNode(node, "InferredPredicate");
  1895. }
  1896. }
  1897. flowParseTypeAndPredicateInitialiser() {
  1898. const oldInType = this.state.inType;
  1899. this.state.inType = true;
  1900. this.expect(14);
  1901. let type = null;
  1902. let predicate = null;
  1903. if (this.match(54)) {
  1904. this.state.inType = oldInType;
  1905. predicate = this.flowParsePredicate();
  1906. } else {
  1907. type = this.flowParseType();
  1908. this.state.inType = oldInType;
  1909. if (this.match(54)) {
  1910. predicate = this.flowParsePredicate();
  1911. }
  1912. }
  1913. return [type, predicate];
  1914. }
  1915. flowParseDeclareClass(node) {
  1916. this.next();
  1917. this.flowParseInterfaceish(node, true);
  1918. return this.finishNode(node, "DeclareClass");
  1919. }
  1920. flowParseDeclareFunction(node) {
  1921. this.next();
  1922. const id = node.id = this.parseIdentifier();
  1923. const typeNode = this.startNode();
  1924. const typeContainer = this.startNode();
  1925. if (this.match(47)) {
  1926. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  1927. } else {
  1928. typeNode.typeParameters = null;
  1929. }
  1930. this.expect(10);
  1931. const tmp = this.flowParseFunctionTypeParams();
  1932. typeNode.params = tmp.params;
  1933. typeNode.rest = tmp.rest;
  1934. typeNode.this = tmp._this;
  1935. this.expect(11);
  1936. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  1937. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  1938. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  1939. this.resetEndLocation(id);
  1940. this.semicolon();
  1941. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  1942. return this.finishNode(node, "DeclareFunction");
  1943. }
  1944. flowParseDeclare(node, insideModule) {
  1945. if (this.match(80)) {
  1946. return this.flowParseDeclareClass(node);
  1947. } else if (this.match(68)) {
  1948. return this.flowParseDeclareFunction(node);
  1949. } else if (this.match(74)) {
  1950. return this.flowParseDeclareVariable(node);
  1951. } else if (this.eatContextual(127)) {
  1952. if (this.match(16)) {
  1953. return this.flowParseDeclareModuleExports(node);
  1954. } else {
  1955. if (insideModule) {
  1956. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  1957. }
  1958. return this.flowParseDeclareModule(node);
  1959. }
  1960. } else if (this.isContextual(130)) {
  1961. return this.flowParseDeclareTypeAlias(node);
  1962. } else if (this.isContextual(131)) {
  1963. return this.flowParseDeclareOpaqueType(node);
  1964. } else if (this.isContextual(129)) {
  1965. return this.flowParseDeclareInterface(node);
  1966. } else if (this.match(82)) {
  1967. return this.flowParseDeclareExportDeclaration(node, insideModule);
  1968. } else {
  1969. this.unexpected();
  1970. }
  1971. }
  1972. flowParseDeclareVariable(node) {
  1973. this.next();
  1974. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  1975. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  1976. this.semicolon();
  1977. return this.finishNode(node, "DeclareVariable");
  1978. }
  1979. flowParseDeclareModule(node) {
  1980. this.scope.enter(0);
  1981. if (this.match(134)) {
  1982. node.id = super.parseExprAtom();
  1983. } else {
  1984. node.id = this.parseIdentifier();
  1985. }
  1986. const bodyNode = node.body = this.startNode();
  1987. const body = bodyNode.body = [];
  1988. this.expect(5);
  1989. while (!this.match(8)) {
  1990. let bodyNode = this.startNode();
  1991. if (this.match(83)) {
  1992. this.next();
  1993. if (!this.isContextual(130) && !this.match(87)) {
  1994. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  1995. }
  1996. super.parseImport(bodyNode);
  1997. } else {
  1998. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  1999. bodyNode = this.flowParseDeclare(bodyNode, true);
  2000. }
  2001. body.push(bodyNode);
  2002. }
  2003. this.scope.exit();
  2004. this.expect(8);
  2005. this.finishNode(bodyNode, "BlockStatement");
  2006. let kind = null;
  2007. let hasModuleExport = false;
  2008. body.forEach(bodyElement => {
  2009. if (isEsModuleType(bodyElement)) {
  2010. if (kind === "CommonJS") {
  2011. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  2012. }
  2013. kind = "ES";
  2014. } else if (bodyElement.type === "DeclareModuleExports") {
  2015. if (hasModuleExport) {
  2016. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  2017. }
  2018. if (kind === "ES") {
  2019. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  2020. }
  2021. kind = "CommonJS";
  2022. hasModuleExport = true;
  2023. }
  2024. });
  2025. node.kind = kind || "CommonJS";
  2026. return this.finishNode(node, "DeclareModule");
  2027. }
  2028. flowParseDeclareExportDeclaration(node, insideModule) {
  2029. this.expect(82);
  2030. if (this.eat(65)) {
  2031. if (this.match(68) || this.match(80)) {
  2032. node.declaration = this.flowParseDeclare(this.startNode());
  2033. } else {
  2034. node.declaration = this.flowParseType();
  2035. this.semicolon();
  2036. }
  2037. node.default = true;
  2038. return this.finishNode(node, "DeclareExportDeclaration");
  2039. } else {
  2040. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  2041. const label = this.state.value;
  2042. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  2043. unsupportedExportKind: label,
  2044. suggestion: exportSuggestions[label]
  2045. });
  2046. }
  2047. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  2048. node.declaration = this.flowParseDeclare(this.startNode());
  2049. node.default = false;
  2050. return this.finishNode(node, "DeclareExportDeclaration");
  2051. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  2052. node = this.parseExport(node, null);
  2053. if (node.type === "ExportNamedDeclaration") {
  2054. node.default = false;
  2055. delete node.exportKind;
  2056. return this.castNodeTo(node, "DeclareExportDeclaration");
  2057. } else {
  2058. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  2059. }
  2060. }
  2061. }
  2062. this.unexpected();
  2063. }
  2064. flowParseDeclareModuleExports(node) {
  2065. this.next();
  2066. this.expectContextual(111);
  2067. node.typeAnnotation = this.flowParseTypeAnnotation();
  2068. this.semicolon();
  2069. return this.finishNode(node, "DeclareModuleExports");
  2070. }
  2071. flowParseDeclareTypeAlias(node) {
  2072. this.next();
  2073. const finished = this.flowParseTypeAlias(node);
  2074. this.castNodeTo(finished, "DeclareTypeAlias");
  2075. return finished;
  2076. }
  2077. flowParseDeclareOpaqueType(node) {
  2078. this.next();
  2079. const finished = this.flowParseOpaqueType(node, true);
  2080. this.castNodeTo(finished, "DeclareOpaqueType");
  2081. return finished;
  2082. }
  2083. flowParseDeclareInterface(node) {
  2084. this.next();
  2085. this.flowParseInterfaceish(node, false);
  2086. return this.finishNode(node, "DeclareInterface");
  2087. }
  2088. flowParseInterfaceish(node, isClass) {
  2089. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  2090. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  2091. if (this.match(47)) {
  2092. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2093. } else {
  2094. node.typeParameters = null;
  2095. }
  2096. node.extends = [];
  2097. if (this.eat(81)) {
  2098. do {
  2099. node.extends.push(this.flowParseInterfaceExtends());
  2100. } while (!isClass && this.eat(12));
  2101. }
  2102. if (isClass) {
  2103. node.implements = [];
  2104. node.mixins = [];
  2105. if (this.eatContextual(117)) {
  2106. do {
  2107. node.mixins.push(this.flowParseInterfaceExtends());
  2108. } while (this.eat(12));
  2109. }
  2110. if (this.eatContextual(113)) {
  2111. do {
  2112. node.implements.push(this.flowParseInterfaceExtends());
  2113. } while (this.eat(12));
  2114. }
  2115. }
  2116. node.body = this.flowParseObjectType({
  2117. allowStatic: isClass,
  2118. allowExact: false,
  2119. allowSpread: false,
  2120. allowProto: isClass,
  2121. allowInexact: false
  2122. });
  2123. }
  2124. flowParseInterfaceExtends() {
  2125. const node = this.startNode();
  2126. node.id = this.flowParseQualifiedTypeIdentifier();
  2127. if (this.match(47)) {
  2128. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2129. } else {
  2130. node.typeParameters = null;
  2131. }
  2132. return this.finishNode(node, "InterfaceExtends");
  2133. }
  2134. flowParseInterface(node) {
  2135. this.flowParseInterfaceish(node, false);
  2136. return this.finishNode(node, "InterfaceDeclaration");
  2137. }
  2138. checkNotUnderscore(word) {
  2139. if (word === "_") {
  2140. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  2141. }
  2142. }
  2143. checkReservedType(word, startLoc, declaration) {
  2144. if (!reservedTypes.has(word)) return;
  2145. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  2146. reservedType: word
  2147. });
  2148. }
  2149. flowParseRestrictedIdentifier(liberal, declaration) {
  2150. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  2151. return this.parseIdentifier(liberal);
  2152. }
  2153. flowParseTypeAlias(node) {
  2154. node.id = this.flowParseRestrictedIdentifier(false, true);
  2155. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2156. if (this.match(47)) {
  2157. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2158. } else {
  2159. node.typeParameters = null;
  2160. }
  2161. node.right = this.flowParseTypeInitialiser(29);
  2162. this.semicolon();
  2163. return this.finishNode(node, "TypeAlias");
  2164. }
  2165. flowParseOpaqueType(node, declare) {
  2166. this.expectContextual(130);
  2167. node.id = this.flowParseRestrictedIdentifier(true, true);
  2168. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2169. if (this.match(47)) {
  2170. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2171. } else {
  2172. node.typeParameters = null;
  2173. }
  2174. node.supertype = null;
  2175. if (this.match(14)) {
  2176. node.supertype = this.flowParseTypeInitialiser(14);
  2177. }
  2178. node.impltype = null;
  2179. if (!declare) {
  2180. node.impltype = this.flowParseTypeInitialiser(29);
  2181. }
  2182. this.semicolon();
  2183. return this.finishNode(node, "OpaqueType");
  2184. }
  2185. flowParseTypeParameter(requireDefault = false) {
  2186. const nodeStartLoc = this.state.startLoc;
  2187. const node = this.startNode();
  2188. const variance = this.flowParseVariance();
  2189. const ident = this.flowParseTypeAnnotatableIdentifier();
  2190. node.name = ident.name;
  2191. node.variance = variance;
  2192. node.bound = ident.typeAnnotation;
  2193. if (this.match(29)) {
  2194. this.eat(29);
  2195. node.default = this.flowParseType();
  2196. } else {
  2197. if (requireDefault) {
  2198. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  2199. }
  2200. }
  2201. return this.finishNode(node, "TypeParameter");
  2202. }
  2203. flowParseTypeParameterDeclaration() {
  2204. const oldInType = this.state.inType;
  2205. const node = this.startNode();
  2206. node.params = [];
  2207. this.state.inType = true;
  2208. if (this.match(47) || this.match(143)) {
  2209. this.next();
  2210. } else {
  2211. this.unexpected();
  2212. }
  2213. let defaultRequired = false;
  2214. do {
  2215. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  2216. node.params.push(typeParameter);
  2217. if (typeParameter.default) {
  2218. defaultRequired = true;
  2219. }
  2220. if (!this.match(48)) {
  2221. this.expect(12);
  2222. }
  2223. } while (!this.match(48));
  2224. this.expect(48);
  2225. this.state.inType = oldInType;
  2226. return this.finishNode(node, "TypeParameterDeclaration");
  2227. }
  2228. flowInTopLevelContext(cb) {
  2229. if (this.curContext() !== types.brace) {
  2230. const oldContext = this.state.context;
  2231. this.state.context = [oldContext[0]];
  2232. try {
  2233. return cb();
  2234. } finally {
  2235. this.state.context = oldContext;
  2236. }
  2237. } else {
  2238. return cb();
  2239. }
  2240. }
  2241. flowParseTypeParameterInstantiationInExpression() {
  2242. if (this.reScan_lt() !== 47) return;
  2243. return this.flowParseTypeParameterInstantiation();
  2244. }
  2245. flowParseTypeParameterInstantiation() {
  2246. const node = this.startNode();
  2247. const oldInType = this.state.inType;
  2248. this.state.inType = true;
  2249. node.params = [];
  2250. this.flowInTopLevelContext(() => {
  2251. this.expect(47);
  2252. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2253. this.state.noAnonFunctionType = false;
  2254. while (!this.match(48)) {
  2255. node.params.push(this.flowParseType());
  2256. if (!this.match(48)) {
  2257. this.expect(12);
  2258. }
  2259. }
  2260. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2261. });
  2262. this.state.inType = oldInType;
  2263. if (!this.state.inType && this.curContext() === types.brace) {
  2264. this.reScan_lt_gt();
  2265. }
  2266. this.expect(48);
  2267. return this.finishNode(node, "TypeParameterInstantiation");
  2268. }
  2269. flowParseTypeParameterInstantiationCallOrNew() {
  2270. if (this.reScan_lt() !== 47) return;
  2271. const node = this.startNode();
  2272. const oldInType = this.state.inType;
  2273. node.params = [];
  2274. this.state.inType = true;
  2275. this.expect(47);
  2276. while (!this.match(48)) {
  2277. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  2278. if (!this.match(48)) {
  2279. this.expect(12);
  2280. }
  2281. }
  2282. this.expect(48);
  2283. this.state.inType = oldInType;
  2284. return this.finishNode(node, "TypeParameterInstantiation");
  2285. }
  2286. flowParseInterfaceType() {
  2287. const node = this.startNode();
  2288. this.expectContextual(129);
  2289. node.extends = [];
  2290. if (this.eat(81)) {
  2291. do {
  2292. node.extends.push(this.flowParseInterfaceExtends());
  2293. } while (this.eat(12));
  2294. }
  2295. node.body = this.flowParseObjectType({
  2296. allowStatic: false,
  2297. allowExact: false,
  2298. allowSpread: false,
  2299. allowProto: false,
  2300. allowInexact: false
  2301. });
  2302. return this.finishNode(node, "InterfaceTypeAnnotation");
  2303. }
  2304. flowParseObjectPropertyKey() {
  2305. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  2306. }
  2307. flowParseObjectTypeIndexer(node, isStatic, variance) {
  2308. node.static = isStatic;
  2309. if (this.lookahead().type === 14) {
  2310. node.id = this.flowParseObjectPropertyKey();
  2311. node.key = this.flowParseTypeInitialiser();
  2312. } else {
  2313. node.id = null;
  2314. node.key = this.flowParseType();
  2315. }
  2316. this.expect(3);
  2317. node.value = this.flowParseTypeInitialiser();
  2318. node.variance = variance;
  2319. return this.finishNode(node, "ObjectTypeIndexer");
  2320. }
  2321. flowParseObjectTypeInternalSlot(node, isStatic) {
  2322. node.static = isStatic;
  2323. node.id = this.flowParseObjectPropertyKey();
  2324. this.expect(3);
  2325. this.expect(3);
  2326. if (this.match(47) || this.match(10)) {
  2327. node.method = true;
  2328. node.optional = false;
  2329. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2330. } else {
  2331. node.method = false;
  2332. if (this.eat(17)) {
  2333. node.optional = true;
  2334. }
  2335. node.value = this.flowParseTypeInitialiser();
  2336. }
  2337. return this.finishNode(node, "ObjectTypeInternalSlot");
  2338. }
  2339. flowParseObjectTypeMethodish(node) {
  2340. node.params = [];
  2341. node.rest = null;
  2342. node.typeParameters = null;
  2343. node.this = null;
  2344. if (this.match(47)) {
  2345. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2346. }
  2347. this.expect(10);
  2348. if (this.match(78)) {
  2349. node.this = this.flowParseFunctionTypeParam(true);
  2350. node.this.name = null;
  2351. if (!this.match(11)) {
  2352. this.expect(12);
  2353. }
  2354. }
  2355. while (!this.match(11) && !this.match(21)) {
  2356. node.params.push(this.flowParseFunctionTypeParam(false));
  2357. if (!this.match(11)) {
  2358. this.expect(12);
  2359. }
  2360. }
  2361. if (this.eat(21)) {
  2362. node.rest = this.flowParseFunctionTypeParam(false);
  2363. }
  2364. this.expect(11);
  2365. node.returnType = this.flowParseTypeInitialiser();
  2366. return this.finishNode(node, "FunctionTypeAnnotation");
  2367. }
  2368. flowParseObjectTypeCallProperty(node, isStatic) {
  2369. const valueNode = this.startNode();
  2370. node.static = isStatic;
  2371. node.value = this.flowParseObjectTypeMethodish(valueNode);
  2372. return this.finishNode(node, "ObjectTypeCallProperty");
  2373. }
  2374. flowParseObjectType({
  2375. allowStatic,
  2376. allowExact,
  2377. allowSpread,
  2378. allowProto,
  2379. allowInexact
  2380. }) {
  2381. const oldInType = this.state.inType;
  2382. this.state.inType = true;
  2383. const nodeStart = this.startNode();
  2384. nodeStart.callProperties = [];
  2385. nodeStart.properties = [];
  2386. nodeStart.indexers = [];
  2387. nodeStart.internalSlots = [];
  2388. let endDelim;
  2389. let exact;
  2390. let inexact = false;
  2391. if (allowExact && this.match(6)) {
  2392. this.expect(6);
  2393. endDelim = 9;
  2394. exact = true;
  2395. } else {
  2396. this.expect(5);
  2397. endDelim = 8;
  2398. exact = false;
  2399. }
  2400. nodeStart.exact = exact;
  2401. while (!this.match(endDelim)) {
  2402. let isStatic = false;
  2403. let protoStartLoc = null;
  2404. let inexactStartLoc = null;
  2405. const node = this.startNode();
  2406. if (allowProto && this.isContextual(118)) {
  2407. const lookahead = this.lookahead();
  2408. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2409. this.next();
  2410. protoStartLoc = this.state.startLoc;
  2411. allowStatic = false;
  2412. }
  2413. }
  2414. if (allowStatic && this.isContextual(106)) {
  2415. const lookahead = this.lookahead();
  2416. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2417. this.next();
  2418. isStatic = true;
  2419. }
  2420. }
  2421. const variance = this.flowParseVariance();
  2422. if (this.eat(0)) {
  2423. if (protoStartLoc != null) {
  2424. this.unexpected(protoStartLoc);
  2425. }
  2426. if (this.eat(0)) {
  2427. if (variance) {
  2428. this.unexpected(variance.loc.start);
  2429. }
  2430. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  2431. } else {
  2432. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  2433. }
  2434. } else if (this.match(10) || this.match(47)) {
  2435. if (protoStartLoc != null) {
  2436. this.unexpected(protoStartLoc);
  2437. }
  2438. if (variance) {
  2439. this.unexpected(variance.loc.start);
  2440. }
  2441. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  2442. } else {
  2443. let kind = "init";
  2444. if (this.isContextual(99) || this.isContextual(104)) {
  2445. const lookahead = this.lookahead();
  2446. if (tokenIsLiteralPropertyName(lookahead.type)) {
  2447. kind = this.state.value;
  2448. this.next();
  2449. }
  2450. }
  2451. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  2452. if (propOrInexact === null) {
  2453. inexact = true;
  2454. inexactStartLoc = this.state.lastTokStartLoc;
  2455. } else {
  2456. nodeStart.properties.push(propOrInexact);
  2457. }
  2458. }
  2459. this.flowObjectTypeSemicolon();
  2460. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  2461. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  2462. }
  2463. }
  2464. this.expect(endDelim);
  2465. if (allowSpread) {
  2466. nodeStart.inexact = inexact;
  2467. }
  2468. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  2469. this.state.inType = oldInType;
  2470. return out;
  2471. }
  2472. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  2473. if (this.eat(21)) {
  2474. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  2475. if (isInexactToken) {
  2476. if (!allowSpread) {
  2477. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  2478. } else if (!allowInexact) {
  2479. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  2480. }
  2481. if (variance) {
  2482. this.raise(FlowErrors.InexactVariance, variance);
  2483. }
  2484. return null;
  2485. }
  2486. if (!allowSpread) {
  2487. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  2488. }
  2489. if (protoStartLoc != null) {
  2490. this.unexpected(protoStartLoc);
  2491. }
  2492. if (variance) {
  2493. this.raise(FlowErrors.SpreadVariance, variance);
  2494. }
  2495. node.argument = this.flowParseType();
  2496. return this.finishNode(node, "ObjectTypeSpreadProperty");
  2497. } else {
  2498. node.key = this.flowParseObjectPropertyKey();
  2499. node.static = isStatic;
  2500. node.proto = protoStartLoc != null;
  2501. node.kind = kind;
  2502. let optional = false;
  2503. if (this.match(47) || this.match(10)) {
  2504. node.method = true;
  2505. if (protoStartLoc != null) {
  2506. this.unexpected(protoStartLoc);
  2507. }
  2508. if (variance) {
  2509. this.unexpected(variance.loc.start);
  2510. }
  2511. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2512. if (kind === "get" || kind === "set") {
  2513. this.flowCheckGetterSetterParams(node);
  2514. }
  2515. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  2516. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  2517. }
  2518. } else {
  2519. if (kind !== "init") this.unexpected();
  2520. node.method = false;
  2521. if (this.eat(17)) {
  2522. optional = true;
  2523. }
  2524. node.value = this.flowParseTypeInitialiser();
  2525. node.variance = variance;
  2526. }
  2527. node.optional = optional;
  2528. return this.finishNode(node, "ObjectTypeProperty");
  2529. }
  2530. }
  2531. flowCheckGetterSetterParams(property) {
  2532. const paramCount = property.kind === "get" ? 0 : 1;
  2533. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  2534. if (property.value.this) {
  2535. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  2536. }
  2537. if (length !== paramCount) {
  2538. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  2539. }
  2540. if (property.kind === "set" && property.value.rest) {
  2541. this.raise(Errors.BadSetterRestParameter, property);
  2542. }
  2543. }
  2544. flowObjectTypeSemicolon() {
  2545. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  2546. this.unexpected();
  2547. }
  2548. }
  2549. flowParseQualifiedTypeIdentifier(startLoc, id) {
  2550. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  2551. let node = id || this.flowParseRestrictedIdentifier(true);
  2552. while (this.eat(16)) {
  2553. const node2 = this.startNodeAt(startLoc);
  2554. node2.qualification = node;
  2555. node2.id = this.flowParseRestrictedIdentifier(true);
  2556. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  2557. }
  2558. return node;
  2559. }
  2560. flowParseGenericType(startLoc, id) {
  2561. const node = this.startNodeAt(startLoc);
  2562. node.typeParameters = null;
  2563. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  2564. if (this.match(47)) {
  2565. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2566. }
  2567. return this.finishNode(node, "GenericTypeAnnotation");
  2568. }
  2569. flowParseTypeofType() {
  2570. const node = this.startNode();
  2571. this.expect(87);
  2572. node.argument = this.flowParsePrimaryType();
  2573. return this.finishNode(node, "TypeofTypeAnnotation");
  2574. }
  2575. flowParseTupleType() {
  2576. const node = this.startNode();
  2577. node.types = [];
  2578. this.expect(0);
  2579. while (this.state.pos < this.length && !this.match(3)) {
  2580. node.types.push(this.flowParseType());
  2581. if (this.match(3)) break;
  2582. this.expect(12);
  2583. }
  2584. this.expect(3);
  2585. return this.finishNode(node, "TupleTypeAnnotation");
  2586. }
  2587. flowParseFunctionTypeParam(first) {
  2588. let name = null;
  2589. let optional = false;
  2590. let typeAnnotation = null;
  2591. const node = this.startNode();
  2592. const lh = this.lookahead();
  2593. const isThis = this.state.type === 78;
  2594. if (lh.type === 14 || lh.type === 17) {
  2595. if (isThis && !first) {
  2596. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  2597. }
  2598. name = this.parseIdentifier(isThis);
  2599. if (this.eat(17)) {
  2600. optional = true;
  2601. if (isThis) {
  2602. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  2603. }
  2604. }
  2605. typeAnnotation = this.flowParseTypeInitialiser();
  2606. } else {
  2607. typeAnnotation = this.flowParseType();
  2608. }
  2609. node.name = name;
  2610. node.optional = optional;
  2611. node.typeAnnotation = typeAnnotation;
  2612. return this.finishNode(node, "FunctionTypeParam");
  2613. }
  2614. reinterpretTypeAsFunctionTypeParam(type) {
  2615. const node = this.startNodeAt(type.loc.start);
  2616. node.name = null;
  2617. node.optional = false;
  2618. node.typeAnnotation = type;
  2619. return this.finishNode(node, "FunctionTypeParam");
  2620. }
  2621. flowParseFunctionTypeParams(params = []) {
  2622. let rest = null;
  2623. let _this = null;
  2624. if (this.match(78)) {
  2625. _this = this.flowParseFunctionTypeParam(true);
  2626. _this.name = null;
  2627. if (!this.match(11)) {
  2628. this.expect(12);
  2629. }
  2630. }
  2631. while (!this.match(11) && !this.match(21)) {
  2632. params.push(this.flowParseFunctionTypeParam(false));
  2633. if (!this.match(11)) {
  2634. this.expect(12);
  2635. }
  2636. }
  2637. if (this.eat(21)) {
  2638. rest = this.flowParseFunctionTypeParam(false);
  2639. }
  2640. return {
  2641. params,
  2642. rest,
  2643. _this
  2644. };
  2645. }
  2646. flowIdentToTypeAnnotation(startLoc, node, id) {
  2647. switch (id.name) {
  2648. case "any":
  2649. return this.finishNode(node, "AnyTypeAnnotation");
  2650. case "bool":
  2651. case "boolean":
  2652. return this.finishNode(node, "BooleanTypeAnnotation");
  2653. case "mixed":
  2654. return this.finishNode(node, "MixedTypeAnnotation");
  2655. case "empty":
  2656. return this.finishNode(node, "EmptyTypeAnnotation");
  2657. case "number":
  2658. return this.finishNode(node, "NumberTypeAnnotation");
  2659. case "string":
  2660. return this.finishNode(node, "StringTypeAnnotation");
  2661. case "symbol":
  2662. return this.finishNode(node, "SymbolTypeAnnotation");
  2663. default:
  2664. this.checkNotUnderscore(id.name);
  2665. return this.flowParseGenericType(startLoc, id);
  2666. }
  2667. }
  2668. flowParsePrimaryType() {
  2669. const startLoc = this.state.startLoc;
  2670. const node = this.startNode();
  2671. let tmp;
  2672. let type;
  2673. let isGroupedType = false;
  2674. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2675. switch (this.state.type) {
  2676. case 5:
  2677. return this.flowParseObjectType({
  2678. allowStatic: false,
  2679. allowExact: false,
  2680. allowSpread: true,
  2681. allowProto: false,
  2682. allowInexact: true
  2683. });
  2684. case 6:
  2685. return this.flowParseObjectType({
  2686. allowStatic: false,
  2687. allowExact: true,
  2688. allowSpread: true,
  2689. allowProto: false,
  2690. allowInexact: false
  2691. });
  2692. case 0:
  2693. this.state.noAnonFunctionType = false;
  2694. type = this.flowParseTupleType();
  2695. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2696. return type;
  2697. case 47:
  2698. {
  2699. const node = this.startNode();
  2700. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2701. this.expect(10);
  2702. tmp = this.flowParseFunctionTypeParams();
  2703. node.params = tmp.params;
  2704. node.rest = tmp.rest;
  2705. node.this = tmp._this;
  2706. this.expect(11);
  2707. this.expect(19);
  2708. node.returnType = this.flowParseType();
  2709. return this.finishNode(node, "FunctionTypeAnnotation");
  2710. }
  2711. case 10:
  2712. {
  2713. const node = this.startNode();
  2714. this.next();
  2715. if (!this.match(11) && !this.match(21)) {
  2716. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  2717. const token = this.lookahead().type;
  2718. isGroupedType = token !== 17 && token !== 14;
  2719. } else {
  2720. isGroupedType = true;
  2721. }
  2722. }
  2723. if (isGroupedType) {
  2724. this.state.noAnonFunctionType = false;
  2725. type = this.flowParseType();
  2726. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2727. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  2728. this.expect(11);
  2729. return type;
  2730. } else {
  2731. this.eat(12);
  2732. }
  2733. }
  2734. if (type) {
  2735. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  2736. } else {
  2737. tmp = this.flowParseFunctionTypeParams();
  2738. }
  2739. node.params = tmp.params;
  2740. node.rest = tmp.rest;
  2741. node.this = tmp._this;
  2742. this.expect(11);
  2743. this.expect(19);
  2744. node.returnType = this.flowParseType();
  2745. node.typeParameters = null;
  2746. return this.finishNode(node, "FunctionTypeAnnotation");
  2747. }
  2748. case 134:
  2749. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  2750. case 85:
  2751. case 86:
  2752. node.value = this.match(85);
  2753. this.next();
  2754. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  2755. case 53:
  2756. if (this.state.value === "-") {
  2757. this.next();
  2758. if (this.match(135)) {
  2759. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  2760. }
  2761. if (this.match(136)) {
  2762. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  2763. }
  2764. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  2765. }
  2766. this.unexpected();
  2767. return;
  2768. case 135:
  2769. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  2770. case 136:
  2771. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  2772. case 88:
  2773. this.next();
  2774. return this.finishNode(node, "VoidTypeAnnotation");
  2775. case 84:
  2776. this.next();
  2777. return this.finishNode(node, "NullLiteralTypeAnnotation");
  2778. case 78:
  2779. this.next();
  2780. return this.finishNode(node, "ThisTypeAnnotation");
  2781. case 55:
  2782. this.next();
  2783. return this.finishNode(node, "ExistsTypeAnnotation");
  2784. case 87:
  2785. return this.flowParseTypeofType();
  2786. default:
  2787. if (tokenIsKeyword(this.state.type)) {
  2788. const label = tokenLabelName(this.state.type);
  2789. this.next();
  2790. return super.createIdentifier(node, label);
  2791. } else if (tokenIsIdentifier(this.state.type)) {
  2792. if (this.isContextual(129)) {
  2793. return this.flowParseInterfaceType();
  2794. }
  2795. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  2796. }
  2797. }
  2798. this.unexpected();
  2799. }
  2800. flowParsePostfixType() {
  2801. const startLoc = this.state.startLoc;
  2802. let type = this.flowParsePrimaryType();
  2803. let seenOptionalIndexedAccess = false;
  2804. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  2805. const node = this.startNodeAt(startLoc);
  2806. const optional = this.eat(18);
  2807. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  2808. this.expect(0);
  2809. if (!optional && this.match(3)) {
  2810. node.elementType = type;
  2811. this.next();
  2812. type = this.finishNode(node, "ArrayTypeAnnotation");
  2813. } else {
  2814. node.objectType = type;
  2815. node.indexType = this.flowParseType();
  2816. this.expect(3);
  2817. if (seenOptionalIndexedAccess) {
  2818. node.optional = optional;
  2819. type = this.finishNode(node, "OptionalIndexedAccessType");
  2820. } else {
  2821. type = this.finishNode(node, "IndexedAccessType");
  2822. }
  2823. }
  2824. }
  2825. return type;
  2826. }
  2827. flowParsePrefixType() {
  2828. const node = this.startNode();
  2829. if (this.eat(17)) {
  2830. node.typeAnnotation = this.flowParsePrefixType();
  2831. return this.finishNode(node, "NullableTypeAnnotation");
  2832. } else {
  2833. return this.flowParsePostfixType();
  2834. }
  2835. }
  2836. flowParseAnonFunctionWithoutParens() {
  2837. const param = this.flowParsePrefixType();
  2838. if (!this.state.noAnonFunctionType && this.eat(19)) {
  2839. const node = this.startNodeAt(param.loc.start);
  2840. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  2841. node.rest = null;
  2842. node.this = null;
  2843. node.returnType = this.flowParseType();
  2844. node.typeParameters = null;
  2845. return this.finishNode(node, "FunctionTypeAnnotation");
  2846. }
  2847. return param;
  2848. }
  2849. flowParseIntersectionType() {
  2850. const node = this.startNode();
  2851. this.eat(45);
  2852. const type = this.flowParseAnonFunctionWithoutParens();
  2853. node.types = [type];
  2854. while (this.eat(45)) {
  2855. node.types.push(this.flowParseAnonFunctionWithoutParens());
  2856. }
  2857. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  2858. }
  2859. flowParseUnionType() {
  2860. const node = this.startNode();
  2861. this.eat(43);
  2862. const type = this.flowParseIntersectionType();
  2863. node.types = [type];
  2864. while (this.eat(43)) {
  2865. node.types.push(this.flowParseIntersectionType());
  2866. }
  2867. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  2868. }
  2869. flowParseType() {
  2870. const oldInType = this.state.inType;
  2871. this.state.inType = true;
  2872. const type = this.flowParseUnionType();
  2873. this.state.inType = oldInType;
  2874. return type;
  2875. }
  2876. flowParseTypeOrImplicitInstantiation() {
  2877. if (this.state.type === 132 && this.state.value === "_") {
  2878. const startLoc = this.state.startLoc;
  2879. const node = this.parseIdentifier();
  2880. return this.flowParseGenericType(startLoc, node);
  2881. } else {
  2882. return this.flowParseType();
  2883. }
  2884. }
  2885. flowParseTypeAnnotation() {
  2886. const node = this.startNode();
  2887. node.typeAnnotation = this.flowParseTypeInitialiser();
  2888. return this.finishNode(node, "TypeAnnotation");
  2889. }
  2890. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  2891. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  2892. if (this.match(14)) {
  2893. ident.typeAnnotation = this.flowParseTypeAnnotation();
  2894. this.resetEndLocation(ident);
  2895. }
  2896. return ident;
  2897. }
  2898. typeCastToParameter(node) {
  2899. node.expression.typeAnnotation = node.typeAnnotation;
  2900. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  2901. return node.expression;
  2902. }
  2903. flowParseVariance() {
  2904. let variance = null;
  2905. if (this.match(53)) {
  2906. variance = this.startNode();
  2907. if (this.state.value === "+") {
  2908. variance.kind = "plus";
  2909. } else {
  2910. variance.kind = "minus";
  2911. }
  2912. this.next();
  2913. return this.finishNode(variance, "Variance");
  2914. }
  2915. return variance;
  2916. }
  2917. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  2918. if (allowExpressionBody) {
  2919. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  2920. return;
  2921. }
  2922. super.parseFunctionBody(node, false, isMethod);
  2923. }
  2924. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  2925. if (this.match(14)) {
  2926. const typeNode = this.startNode();
  2927. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  2928. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  2929. }
  2930. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  2931. }
  2932. parseStatementLike(flags) {
  2933. if (this.state.strict && this.isContextual(129)) {
  2934. const lookahead = this.lookahead();
  2935. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  2936. const node = this.startNode();
  2937. this.next();
  2938. return this.flowParseInterface(node);
  2939. }
  2940. } else if (this.isContextual(126)) {
  2941. const node = this.startNode();
  2942. this.next();
  2943. return this.flowParseEnumDeclaration(node);
  2944. }
  2945. const stmt = super.parseStatementLike(flags);
  2946. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  2947. this.flowPragma = null;
  2948. }
  2949. return stmt;
  2950. }
  2951. parseExpressionStatement(node, expr, decorators) {
  2952. if (expr.type === "Identifier") {
  2953. if (expr.name === "declare") {
  2954. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  2955. return this.flowParseDeclare(node);
  2956. }
  2957. } else if (tokenIsIdentifier(this.state.type)) {
  2958. if (expr.name === "interface") {
  2959. return this.flowParseInterface(node);
  2960. } else if (expr.name === "type") {
  2961. return this.flowParseTypeAlias(node);
  2962. } else if (expr.name === "opaque") {
  2963. return this.flowParseOpaqueType(node, false);
  2964. }
  2965. }
  2966. }
  2967. return super.parseExpressionStatement(node, expr, decorators);
  2968. }
  2969. shouldParseExportDeclaration() {
  2970. const {
  2971. type
  2972. } = this.state;
  2973. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2974. return !this.state.containsEsc;
  2975. }
  2976. return super.shouldParseExportDeclaration();
  2977. }
  2978. isExportDefaultSpecifier() {
  2979. const {
  2980. type
  2981. } = this.state;
  2982. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2983. return this.state.containsEsc;
  2984. }
  2985. return super.isExportDefaultSpecifier();
  2986. }
  2987. parseExportDefaultExpression() {
  2988. if (this.isContextual(126)) {
  2989. const node = this.startNode();
  2990. this.next();
  2991. return this.flowParseEnumDeclaration(node);
  2992. }
  2993. return super.parseExportDefaultExpression();
  2994. }
  2995. parseConditional(expr, startLoc, refExpressionErrors) {
  2996. if (!this.match(17)) return expr;
  2997. if (this.state.maybeInArrowParameters) {
  2998. const nextCh = this.lookaheadCharCode();
  2999. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  3000. this.setOptionalParametersError(refExpressionErrors);
  3001. return expr;
  3002. }
  3003. }
  3004. this.expect(17);
  3005. const state = this.state.clone();
  3006. const originalNoArrowAt = this.state.noArrowAt;
  3007. const node = this.startNodeAt(startLoc);
  3008. let {
  3009. consequent,
  3010. failed
  3011. } = this.tryParseConditionalConsequent();
  3012. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  3013. if (failed || invalid.length > 0) {
  3014. const noArrowAt = [...originalNoArrowAt];
  3015. if (invalid.length > 0) {
  3016. this.state = state;
  3017. this.state.noArrowAt = noArrowAt;
  3018. for (let i = 0; i < invalid.length; i++) {
  3019. noArrowAt.push(invalid[i].start);
  3020. }
  3021. ({
  3022. consequent,
  3023. failed
  3024. } = this.tryParseConditionalConsequent());
  3025. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  3026. }
  3027. if (failed && valid.length > 1) {
  3028. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  3029. }
  3030. if (failed && valid.length === 1) {
  3031. this.state = state;
  3032. noArrowAt.push(valid[0].start);
  3033. this.state.noArrowAt = noArrowAt;
  3034. ({
  3035. consequent,
  3036. failed
  3037. } = this.tryParseConditionalConsequent());
  3038. }
  3039. }
  3040. this.getArrowLikeExpressions(consequent, true);
  3041. this.state.noArrowAt = originalNoArrowAt;
  3042. this.expect(14);
  3043. node.test = expr;
  3044. node.consequent = consequent;
  3045. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  3046. return this.finishNode(node, "ConditionalExpression");
  3047. }
  3048. tryParseConditionalConsequent() {
  3049. this.state.noArrowParamsConversionAt.push(this.state.start);
  3050. const consequent = this.parseMaybeAssignAllowIn();
  3051. const failed = !this.match(14);
  3052. this.state.noArrowParamsConversionAt.pop();
  3053. return {
  3054. consequent,
  3055. failed
  3056. };
  3057. }
  3058. getArrowLikeExpressions(node, disallowInvalid) {
  3059. const stack = [node];
  3060. const arrows = [];
  3061. while (stack.length !== 0) {
  3062. const node = stack.pop();
  3063. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  3064. if (node.typeParameters || !node.returnType) {
  3065. this.finishArrowValidation(node);
  3066. } else {
  3067. arrows.push(node);
  3068. }
  3069. stack.push(node.body);
  3070. } else if (node.type === "ConditionalExpression") {
  3071. stack.push(node.consequent);
  3072. stack.push(node.alternate);
  3073. }
  3074. }
  3075. if (disallowInvalid) {
  3076. arrows.forEach(node => this.finishArrowValidation(node));
  3077. return [arrows, []];
  3078. }
  3079. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  3080. }
  3081. finishArrowValidation(node) {
  3082. var _node$extra;
  3083. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  3084. this.scope.enter(514 | 4);
  3085. super.checkParams(node, false, true);
  3086. this.scope.exit();
  3087. }
  3088. forwardNoArrowParamsConversionAt(node, parse) {
  3089. let result;
  3090. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3091. this.state.noArrowParamsConversionAt.push(this.state.start);
  3092. result = parse();
  3093. this.state.noArrowParamsConversionAt.pop();
  3094. } else {
  3095. result = parse();
  3096. }
  3097. return result;
  3098. }
  3099. parseParenItem(node, startLoc) {
  3100. const newNode = super.parseParenItem(node, startLoc);
  3101. if (this.eat(17)) {
  3102. newNode.optional = true;
  3103. this.resetEndLocation(node);
  3104. }
  3105. if (this.match(14)) {
  3106. const typeCastNode = this.startNodeAt(startLoc);
  3107. typeCastNode.expression = newNode;
  3108. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  3109. return this.finishNode(typeCastNode, "TypeCastExpression");
  3110. }
  3111. return newNode;
  3112. }
  3113. assertModuleNodeAllowed(node) {
  3114. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  3115. return;
  3116. }
  3117. super.assertModuleNodeAllowed(node);
  3118. }
  3119. parseExportDeclaration(node) {
  3120. if (this.isContextual(130)) {
  3121. node.exportKind = "type";
  3122. const declarationNode = this.startNode();
  3123. this.next();
  3124. if (this.match(5)) {
  3125. node.specifiers = this.parseExportSpecifiers(true);
  3126. super.parseExportFrom(node);
  3127. return null;
  3128. } else {
  3129. return this.flowParseTypeAlias(declarationNode);
  3130. }
  3131. } else if (this.isContextual(131)) {
  3132. node.exportKind = "type";
  3133. const declarationNode = this.startNode();
  3134. this.next();
  3135. return this.flowParseOpaqueType(declarationNode, false);
  3136. } else if (this.isContextual(129)) {
  3137. node.exportKind = "type";
  3138. const declarationNode = this.startNode();
  3139. this.next();
  3140. return this.flowParseInterface(declarationNode);
  3141. } else if (this.isContextual(126)) {
  3142. node.exportKind = "value";
  3143. const declarationNode = this.startNode();
  3144. this.next();
  3145. return this.flowParseEnumDeclaration(declarationNode);
  3146. } else {
  3147. return super.parseExportDeclaration(node);
  3148. }
  3149. }
  3150. eatExportStar(node) {
  3151. if (super.eatExportStar(node)) return true;
  3152. if (this.isContextual(130) && this.lookahead().type === 55) {
  3153. node.exportKind = "type";
  3154. this.next();
  3155. this.next();
  3156. return true;
  3157. }
  3158. return false;
  3159. }
  3160. maybeParseExportNamespaceSpecifier(node) {
  3161. const {
  3162. startLoc
  3163. } = this.state;
  3164. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  3165. if (hasNamespace && node.exportKind === "type") {
  3166. this.unexpected(startLoc);
  3167. }
  3168. return hasNamespace;
  3169. }
  3170. parseClassId(node, isStatement, optionalId) {
  3171. super.parseClassId(node, isStatement, optionalId);
  3172. if (this.match(47)) {
  3173. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3174. }
  3175. }
  3176. parseClassMember(classBody, member, state) {
  3177. const {
  3178. startLoc
  3179. } = this.state;
  3180. if (this.isContextual(125)) {
  3181. if (super.parseClassMemberFromModifier(classBody, member)) {
  3182. return;
  3183. }
  3184. member.declare = true;
  3185. }
  3186. super.parseClassMember(classBody, member, state);
  3187. if (member.declare) {
  3188. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  3189. this.raise(FlowErrors.DeclareClassElement, startLoc);
  3190. } else if (member.value) {
  3191. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  3192. }
  3193. }
  3194. }
  3195. isIterator(word) {
  3196. return word === "iterator" || word === "asyncIterator";
  3197. }
  3198. readIterator() {
  3199. const word = super.readWord1();
  3200. const fullWord = "@@" + word;
  3201. if (!this.isIterator(word) || !this.state.inType) {
  3202. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  3203. identifierName: fullWord
  3204. });
  3205. }
  3206. this.finishToken(132, fullWord);
  3207. }
  3208. getTokenFromCode(code) {
  3209. const next = this.input.charCodeAt(this.state.pos + 1);
  3210. if (code === 123 && next === 124) {
  3211. this.finishOp(6, 2);
  3212. } else if (this.state.inType && (code === 62 || code === 60)) {
  3213. this.finishOp(code === 62 ? 48 : 47, 1);
  3214. } else if (this.state.inType && code === 63) {
  3215. if (next === 46) {
  3216. this.finishOp(18, 2);
  3217. } else {
  3218. this.finishOp(17, 1);
  3219. }
  3220. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  3221. this.state.pos += 2;
  3222. this.readIterator();
  3223. } else {
  3224. super.getTokenFromCode(code);
  3225. }
  3226. }
  3227. isAssignable(node, isBinding) {
  3228. if (node.type === "TypeCastExpression") {
  3229. return this.isAssignable(node.expression, isBinding);
  3230. } else {
  3231. return super.isAssignable(node, isBinding);
  3232. }
  3233. }
  3234. toAssignable(node, isLHS = false) {
  3235. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  3236. node.left = this.typeCastToParameter(node.left);
  3237. }
  3238. super.toAssignable(node, isLHS);
  3239. }
  3240. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  3241. for (let i = 0; i < exprList.length; i++) {
  3242. const expr = exprList[i];
  3243. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  3244. exprList[i] = this.typeCastToParameter(expr);
  3245. }
  3246. }
  3247. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  3248. }
  3249. toReferencedList(exprList, isParenthesizedExpr) {
  3250. for (let i = 0; i < exprList.length; i++) {
  3251. var _expr$extra;
  3252. const expr = exprList[i];
  3253. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  3254. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  3255. }
  3256. }
  3257. return exprList;
  3258. }
  3259. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  3260. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  3261. if (canBePattern && !this.state.maybeInArrowParameters) {
  3262. this.toReferencedList(node.elements);
  3263. }
  3264. return node;
  3265. }
  3266. isValidLVal(type, isParenthesized, binding) {
  3267. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  3268. }
  3269. parseClassProperty(node) {
  3270. if (this.match(14)) {
  3271. node.typeAnnotation = this.flowParseTypeAnnotation();
  3272. }
  3273. return super.parseClassProperty(node);
  3274. }
  3275. parseClassPrivateProperty(node) {
  3276. if (this.match(14)) {
  3277. node.typeAnnotation = this.flowParseTypeAnnotation();
  3278. }
  3279. return super.parseClassPrivateProperty(node);
  3280. }
  3281. isClassMethod() {
  3282. return this.match(47) || super.isClassMethod();
  3283. }
  3284. isClassProperty() {
  3285. return this.match(14) || super.isClassProperty();
  3286. }
  3287. isNonstaticConstructor(method) {
  3288. return !this.match(14) && super.isNonstaticConstructor(method);
  3289. }
  3290. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  3291. if (method.variance) {
  3292. this.unexpected(method.variance.loc.start);
  3293. }
  3294. delete method.variance;
  3295. if (this.match(47)) {
  3296. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3297. }
  3298. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  3299. if (method.params && isConstructor) {
  3300. const params = method.params;
  3301. if (params.length > 0 && this.isThisParam(params[0])) {
  3302. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3303. }
  3304. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  3305. const params = method.value.params;
  3306. if (params.length > 0 && this.isThisParam(params[0])) {
  3307. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3308. }
  3309. }
  3310. }
  3311. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  3312. if (method.variance) {
  3313. this.unexpected(method.variance.loc.start);
  3314. }
  3315. delete method.variance;
  3316. if (this.match(47)) {
  3317. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3318. }
  3319. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  3320. }
  3321. parseClassSuper(node) {
  3322. super.parseClassSuper(node);
  3323. if (node.superClass && (this.match(47) || this.match(51))) {
  3324. {
  3325. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  3326. }
  3327. }
  3328. if (this.isContextual(113)) {
  3329. this.next();
  3330. const implemented = node.implements = [];
  3331. do {
  3332. const node = this.startNode();
  3333. node.id = this.flowParseRestrictedIdentifier(true);
  3334. if (this.match(47)) {
  3335. node.typeParameters = this.flowParseTypeParameterInstantiation();
  3336. } else {
  3337. node.typeParameters = null;
  3338. }
  3339. implemented.push(this.finishNode(node, "ClassImplements"));
  3340. } while (this.eat(12));
  3341. }
  3342. }
  3343. checkGetterSetterParams(method) {
  3344. super.checkGetterSetterParams(method);
  3345. const params = this.getObjectOrClassMethodParams(method);
  3346. if (params.length > 0) {
  3347. const param = params[0];
  3348. if (this.isThisParam(param) && method.kind === "get") {
  3349. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  3350. } else if (this.isThisParam(param)) {
  3351. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  3352. }
  3353. }
  3354. }
  3355. parsePropertyNamePrefixOperator(node) {
  3356. node.variance = this.flowParseVariance();
  3357. }
  3358. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  3359. if (prop.variance) {
  3360. this.unexpected(prop.variance.loc.start);
  3361. }
  3362. delete prop.variance;
  3363. let typeParameters;
  3364. if (this.match(47) && !isAccessor) {
  3365. typeParameters = this.flowParseTypeParameterDeclaration();
  3366. if (!this.match(10)) this.unexpected();
  3367. }
  3368. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  3369. if (typeParameters) {
  3370. (result.value || result).typeParameters = typeParameters;
  3371. }
  3372. return result;
  3373. }
  3374. parseFunctionParamType(param) {
  3375. if (this.eat(17)) {
  3376. if (param.type !== "Identifier") {
  3377. this.raise(FlowErrors.PatternIsOptional, param);
  3378. }
  3379. if (this.isThisParam(param)) {
  3380. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  3381. }
  3382. param.optional = true;
  3383. }
  3384. if (this.match(14)) {
  3385. param.typeAnnotation = this.flowParseTypeAnnotation();
  3386. } else if (this.isThisParam(param)) {
  3387. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  3388. }
  3389. if (this.match(29) && this.isThisParam(param)) {
  3390. this.raise(FlowErrors.ThisParamNoDefault, param);
  3391. }
  3392. this.resetEndLocation(param);
  3393. return param;
  3394. }
  3395. parseMaybeDefault(startLoc, left) {
  3396. const node = super.parseMaybeDefault(startLoc, left);
  3397. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  3398. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  3399. }
  3400. return node;
  3401. }
  3402. checkImportReflection(node) {
  3403. super.checkImportReflection(node);
  3404. if (node.module && node.importKind !== "value") {
  3405. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  3406. }
  3407. }
  3408. parseImportSpecifierLocal(node, specifier, type) {
  3409. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  3410. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  3411. }
  3412. isPotentialImportPhase(isExport) {
  3413. if (super.isPotentialImportPhase(isExport)) return true;
  3414. if (this.isContextual(130)) {
  3415. if (!isExport) return true;
  3416. const ch = this.lookaheadCharCode();
  3417. return ch === 123 || ch === 42;
  3418. }
  3419. return !isExport && this.isContextual(87);
  3420. }
  3421. applyImportPhase(node, isExport, phase, loc) {
  3422. super.applyImportPhase(node, isExport, phase, loc);
  3423. if (isExport) {
  3424. if (!phase && this.match(65)) {
  3425. return;
  3426. }
  3427. node.exportKind = phase === "type" ? phase : "value";
  3428. } else {
  3429. if (phase === "type" && this.match(55)) this.unexpected();
  3430. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  3431. }
  3432. }
  3433. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  3434. const firstIdent = specifier.imported;
  3435. let specifierTypeKind = null;
  3436. if (firstIdent.type === "Identifier") {
  3437. if (firstIdent.name === "type") {
  3438. specifierTypeKind = "type";
  3439. } else if (firstIdent.name === "typeof") {
  3440. specifierTypeKind = "typeof";
  3441. }
  3442. }
  3443. let isBinding = false;
  3444. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  3445. const as_ident = this.parseIdentifier(true);
  3446. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  3447. specifier.imported = as_ident;
  3448. specifier.importKind = specifierTypeKind;
  3449. specifier.local = this.cloneIdentifier(as_ident);
  3450. } else {
  3451. specifier.imported = firstIdent;
  3452. specifier.importKind = null;
  3453. specifier.local = this.parseIdentifier();
  3454. }
  3455. } else {
  3456. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  3457. specifier.imported = this.parseIdentifier(true);
  3458. specifier.importKind = specifierTypeKind;
  3459. } else {
  3460. if (importedIsString) {
  3461. throw this.raise(Errors.ImportBindingIsString, specifier, {
  3462. importName: firstIdent.value
  3463. });
  3464. }
  3465. specifier.imported = firstIdent;
  3466. specifier.importKind = null;
  3467. }
  3468. if (this.eatContextual(93)) {
  3469. specifier.local = this.parseIdentifier();
  3470. } else {
  3471. isBinding = true;
  3472. specifier.local = this.cloneIdentifier(specifier.imported);
  3473. }
  3474. }
  3475. const specifierIsTypeImport = hasTypeImportKind(specifier);
  3476. if (isInTypeOnlyImport && specifierIsTypeImport) {
  3477. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  3478. }
  3479. if (isInTypeOnlyImport || specifierIsTypeImport) {
  3480. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  3481. }
  3482. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  3483. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  3484. }
  3485. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  3486. }
  3487. parseBindingAtom() {
  3488. switch (this.state.type) {
  3489. case 78:
  3490. return this.parseIdentifier(true);
  3491. default:
  3492. return super.parseBindingAtom();
  3493. }
  3494. }
  3495. parseFunctionParams(node, isConstructor) {
  3496. const kind = node.kind;
  3497. if (kind !== "get" && kind !== "set" && this.match(47)) {
  3498. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3499. }
  3500. super.parseFunctionParams(node, isConstructor);
  3501. }
  3502. parseVarId(decl, kind) {
  3503. super.parseVarId(decl, kind);
  3504. if (this.match(14)) {
  3505. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  3506. this.resetEndLocation(decl.id);
  3507. }
  3508. }
  3509. parseAsyncArrowFromCallExpression(node, call) {
  3510. if (this.match(14)) {
  3511. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3512. this.state.noAnonFunctionType = true;
  3513. node.returnType = this.flowParseTypeAnnotation();
  3514. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3515. }
  3516. return super.parseAsyncArrowFromCallExpression(node, call);
  3517. }
  3518. shouldParseAsyncArrow() {
  3519. return this.match(14) || super.shouldParseAsyncArrow();
  3520. }
  3521. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  3522. var _jsx;
  3523. let state = null;
  3524. let jsx;
  3525. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  3526. state = this.state.clone();
  3527. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  3528. if (!jsx.error) return jsx.node;
  3529. const {
  3530. context
  3531. } = this.state;
  3532. const currentContext = context[context.length - 1];
  3533. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  3534. context.pop();
  3535. }
  3536. }
  3537. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  3538. var _jsx2, _jsx3;
  3539. state = state || this.state.clone();
  3540. let typeParameters;
  3541. const arrow = this.tryParse(abort => {
  3542. var _arrowExpression$extr;
  3543. typeParameters = this.flowParseTypeParameterDeclaration();
  3544. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  3545. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3546. this.resetStartLocationFromNode(result, typeParameters);
  3547. return result;
  3548. });
  3549. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  3550. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  3551. if (expr.type !== "ArrowFunctionExpression") abort();
  3552. expr.typeParameters = typeParameters;
  3553. this.resetStartLocationFromNode(expr, typeParameters);
  3554. return arrowExpression;
  3555. }, state);
  3556. let arrowExpression = null;
  3557. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  3558. if (!arrow.error && !arrow.aborted) {
  3559. if (arrow.node.async) {
  3560. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  3561. }
  3562. return arrow.node;
  3563. }
  3564. arrowExpression = arrow.node;
  3565. }
  3566. if ((_jsx2 = jsx) != null && _jsx2.node) {
  3567. this.state = jsx.failState;
  3568. return jsx.node;
  3569. }
  3570. if (arrowExpression) {
  3571. this.state = arrow.failState;
  3572. return arrowExpression;
  3573. }
  3574. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  3575. if (arrow.thrown) throw arrow.error;
  3576. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  3577. }
  3578. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3579. }
  3580. parseArrow(node) {
  3581. if (this.match(14)) {
  3582. const result = this.tryParse(() => {
  3583. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3584. this.state.noAnonFunctionType = true;
  3585. const typeNode = this.startNode();
  3586. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  3587. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3588. if (this.canInsertSemicolon()) this.unexpected();
  3589. if (!this.match(19)) this.unexpected();
  3590. return typeNode;
  3591. });
  3592. if (result.thrown) return null;
  3593. if (result.error) this.state = result.failState;
  3594. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  3595. }
  3596. return super.parseArrow(node);
  3597. }
  3598. shouldParseArrow(params) {
  3599. return this.match(14) || super.shouldParseArrow(params);
  3600. }
  3601. setArrowFunctionParameters(node, params) {
  3602. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3603. node.params = params;
  3604. } else {
  3605. super.setArrowFunctionParameters(node, params);
  3606. }
  3607. }
  3608. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  3609. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3610. return;
  3611. }
  3612. for (let i = 0; i < node.params.length; i++) {
  3613. if (this.isThisParam(node.params[i]) && i > 0) {
  3614. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  3615. }
  3616. }
  3617. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  3618. }
  3619. parseParenAndDistinguishExpression(canBeArrow) {
  3620. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  3621. }
  3622. parseSubscripts(base, startLoc, noCalls) {
  3623. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  3624. this.next();
  3625. const node = this.startNodeAt(startLoc);
  3626. node.callee = base;
  3627. node.arguments = super.parseCallExpressionArguments();
  3628. base = this.finishNode(node, "CallExpression");
  3629. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  3630. const state = this.state.clone();
  3631. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  3632. if (!arrow.error && !arrow.aborted) return arrow.node;
  3633. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  3634. if (result.node && !result.error) return result.node;
  3635. if (arrow.node) {
  3636. this.state = arrow.failState;
  3637. return arrow.node;
  3638. }
  3639. if (result.node) {
  3640. this.state = result.failState;
  3641. return result.node;
  3642. }
  3643. throw arrow.error || result.error;
  3644. }
  3645. return super.parseSubscripts(base, startLoc, noCalls);
  3646. }
  3647. parseSubscript(base, startLoc, noCalls, subscriptState) {
  3648. if (this.match(18) && this.isLookaheadToken_lt()) {
  3649. subscriptState.optionalChainMember = true;
  3650. if (noCalls) {
  3651. subscriptState.stop = true;
  3652. return base;
  3653. }
  3654. this.next();
  3655. const node = this.startNodeAt(startLoc);
  3656. node.callee = base;
  3657. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  3658. this.expect(10);
  3659. node.arguments = this.parseCallExpressionArguments();
  3660. node.optional = true;
  3661. return this.finishCallExpression(node, true);
  3662. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  3663. const node = this.startNodeAt(startLoc);
  3664. node.callee = base;
  3665. const result = this.tryParse(() => {
  3666. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  3667. this.expect(10);
  3668. node.arguments = super.parseCallExpressionArguments();
  3669. if (subscriptState.optionalChainMember) {
  3670. node.optional = false;
  3671. }
  3672. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  3673. });
  3674. if (result.node) {
  3675. if (result.error) this.state = result.failState;
  3676. return result.node;
  3677. }
  3678. }
  3679. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  3680. }
  3681. parseNewCallee(node) {
  3682. super.parseNewCallee(node);
  3683. let targs = null;
  3684. if (this.shouldParseTypes() && this.match(47)) {
  3685. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  3686. }
  3687. node.typeArguments = targs;
  3688. }
  3689. parseAsyncArrowWithTypeParameters(startLoc) {
  3690. const node = this.startNodeAt(startLoc);
  3691. this.parseFunctionParams(node, false);
  3692. if (!this.parseArrow(node)) return;
  3693. return super.parseArrowExpression(node, undefined, true);
  3694. }
  3695. readToken_mult_modulo(code) {
  3696. const next = this.input.charCodeAt(this.state.pos + 1);
  3697. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  3698. this.state.hasFlowComment = false;
  3699. this.state.pos += 2;
  3700. this.nextToken();
  3701. return;
  3702. }
  3703. super.readToken_mult_modulo(code);
  3704. }
  3705. readToken_pipe_amp(code) {
  3706. const next = this.input.charCodeAt(this.state.pos + 1);
  3707. if (code === 124 && next === 125) {
  3708. this.finishOp(9, 2);
  3709. return;
  3710. }
  3711. super.readToken_pipe_amp(code);
  3712. }
  3713. parseTopLevel(file, program) {
  3714. const fileNode = super.parseTopLevel(file, program);
  3715. if (this.state.hasFlowComment) {
  3716. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  3717. }
  3718. return fileNode;
  3719. }
  3720. skipBlockComment() {
  3721. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  3722. if (this.state.hasFlowComment) {
  3723. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  3724. }
  3725. this.hasFlowCommentCompletion();
  3726. const commentSkip = this.skipFlowComment();
  3727. if (commentSkip) {
  3728. this.state.pos += commentSkip;
  3729. this.state.hasFlowComment = true;
  3730. }
  3731. return;
  3732. }
  3733. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  3734. }
  3735. skipFlowComment() {
  3736. const {
  3737. pos
  3738. } = this.state;
  3739. let shiftToFirstNonWhiteSpace = 2;
  3740. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  3741. shiftToFirstNonWhiteSpace++;
  3742. }
  3743. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  3744. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  3745. if (ch2 === 58 && ch3 === 58) {
  3746. return shiftToFirstNonWhiteSpace + 2;
  3747. }
  3748. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  3749. return shiftToFirstNonWhiteSpace + 12;
  3750. }
  3751. if (ch2 === 58 && ch3 !== 58) {
  3752. return shiftToFirstNonWhiteSpace;
  3753. }
  3754. return false;
  3755. }
  3756. hasFlowCommentCompletion() {
  3757. const end = this.input.indexOf("*/", this.state.pos);
  3758. if (end === -1) {
  3759. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  3760. }
  3761. }
  3762. flowEnumErrorBooleanMemberNotInitialized(loc, {
  3763. enumName,
  3764. memberName
  3765. }) {
  3766. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  3767. memberName,
  3768. enumName
  3769. });
  3770. }
  3771. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  3772. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  3773. }
  3774. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  3775. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  3776. }
  3777. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  3778. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  3779. }
  3780. flowEnumMemberInit() {
  3781. const startLoc = this.state.startLoc;
  3782. const endOfInit = () => this.match(12) || this.match(8);
  3783. switch (this.state.type) {
  3784. case 135:
  3785. {
  3786. const literal = this.parseNumericLiteral(this.state.value);
  3787. if (endOfInit()) {
  3788. return {
  3789. type: "number",
  3790. loc: literal.loc.start,
  3791. value: literal
  3792. };
  3793. }
  3794. return {
  3795. type: "invalid",
  3796. loc: startLoc
  3797. };
  3798. }
  3799. case 134:
  3800. {
  3801. const literal = this.parseStringLiteral(this.state.value);
  3802. if (endOfInit()) {
  3803. return {
  3804. type: "string",
  3805. loc: literal.loc.start,
  3806. value: literal
  3807. };
  3808. }
  3809. return {
  3810. type: "invalid",
  3811. loc: startLoc
  3812. };
  3813. }
  3814. case 85:
  3815. case 86:
  3816. {
  3817. const literal = this.parseBooleanLiteral(this.match(85));
  3818. if (endOfInit()) {
  3819. return {
  3820. type: "boolean",
  3821. loc: literal.loc.start,
  3822. value: literal
  3823. };
  3824. }
  3825. return {
  3826. type: "invalid",
  3827. loc: startLoc
  3828. };
  3829. }
  3830. default:
  3831. return {
  3832. type: "invalid",
  3833. loc: startLoc
  3834. };
  3835. }
  3836. }
  3837. flowEnumMemberRaw() {
  3838. const loc = this.state.startLoc;
  3839. const id = this.parseIdentifier(true);
  3840. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  3841. type: "none",
  3842. loc
  3843. };
  3844. return {
  3845. id,
  3846. init
  3847. };
  3848. }
  3849. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  3850. const {
  3851. explicitType
  3852. } = context;
  3853. if (explicitType === null) {
  3854. return;
  3855. }
  3856. if (explicitType !== expectedType) {
  3857. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  3858. }
  3859. }
  3860. flowEnumMembers({
  3861. enumName,
  3862. explicitType
  3863. }) {
  3864. const seenNames = new Set();
  3865. const members = {
  3866. booleanMembers: [],
  3867. numberMembers: [],
  3868. stringMembers: [],
  3869. defaultedMembers: []
  3870. };
  3871. let hasUnknownMembers = false;
  3872. while (!this.match(8)) {
  3873. if (this.eat(21)) {
  3874. hasUnknownMembers = true;
  3875. break;
  3876. }
  3877. const memberNode = this.startNode();
  3878. const {
  3879. id,
  3880. init
  3881. } = this.flowEnumMemberRaw();
  3882. const memberName = id.name;
  3883. if (memberName === "") {
  3884. continue;
  3885. }
  3886. if (/^[a-z]/.test(memberName)) {
  3887. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  3888. memberName,
  3889. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  3890. enumName
  3891. });
  3892. }
  3893. if (seenNames.has(memberName)) {
  3894. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  3895. memberName,
  3896. enumName
  3897. });
  3898. }
  3899. seenNames.add(memberName);
  3900. const context = {
  3901. enumName,
  3902. explicitType,
  3903. memberName
  3904. };
  3905. memberNode.id = id;
  3906. switch (init.type) {
  3907. case "boolean":
  3908. {
  3909. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  3910. memberNode.init = init.value;
  3911. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  3912. break;
  3913. }
  3914. case "number":
  3915. {
  3916. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  3917. memberNode.init = init.value;
  3918. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  3919. break;
  3920. }
  3921. case "string":
  3922. {
  3923. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  3924. memberNode.init = init.value;
  3925. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  3926. break;
  3927. }
  3928. case "invalid":
  3929. {
  3930. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  3931. }
  3932. case "none":
  3933. {
  3934. switch (explicitType) {
  3935. case "boolean":
  3936. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  3937. break;
  3938. case "number":
  3939. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  3940. break;
  3941. default:
  3942. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  3943. }
  3944. }
  3945. }
  3946. if (!this.match(8)) {
  3947. this.expect(12);
  3948. }
  3949. }
  3950. return {
  3951. members,
  3952. hasUnknownMembers
  3953. };
  3954. }
  3955. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  3956. enumName
  3957. }) {
  3958. if (initializedMembers.length === 0) {
  3959. return defaultedMembers;
  3960. } else if (defaultedMembers.length === 0) {
  3961. return initializedMembers;
  3962. } else if (defaultedMembers.length > initializedMembers.length) {
  3963. for (const member of initializedMembers) {
  3964. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3965. enumName
  3966. });
  3967. }
  3968. return defaultedMembers;
  3969. } else {
  3970. for (const member of defaultedMembers) {
  3971. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3972. enumName
  3973. });
  3974. }
  3975. return initializedMembers;
  3976. }
  3977. }
  3978. flowEnumParseExplicitType({
  3979. enumName
  3980. }) {
  3981. if (!this.eatContextual(102)) return null;
  3982. if (!tokenIsIdentifier(this.state.type)) {
  3983. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  3984. enumName
  3985. });
  3986. }
  3987. const {
  3988. value
  3989. } = this.state;
  3990. this.next();
  3991. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  3992. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  3993. enumName,
  3994. invalidEnumType: value
  3995. });
  3996. }
  3997. return value;
  3998. }
  3999. flowEnumBody(node, id) {
  4000. const enumName = id.name;
  4001. const nameLoc = id.loc.start;
  4002. const explicitType = this.flowEnumParseExplicitType({
  4003. enumName
  4004. });
  4005. this.expect(5);
  4006. const {
  4007. members,
  4008. hasUnknownMembers
  4009. } = this.flowEnumMembers({
  4010. enumName,
  4011. explicitType
  4012. });
  4013. node.hasUnknownMembers = hasUnknownMembers;
  4014. switch (explicitType) {
  4015. case "boolean":
  4016. node.explicitType = true;
  4017. node.members = members.booleanMembers;
  4018. this.expect(8);
  4019. return this.finishNode(node, "EnumBooleanBody");
  4020. case "number":
  4021. node.explicitType = true;
  4022. node.members = members.numberMembers;
  4023. this.expect(8);
  4024. return this.finishNode(node, "EnumNumberBody");
  4025. case "string":
  4026. node.explicitType = true;
  4027. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4028. enumName
  4029. });
  4030. this.expect(8);
  4031. return this.finishNode(node, "EnumStringBody");
  4032. case "symbol":
  4033. node.members = members.defaultedMembers;
  4034. this.expect(8);
  4035. return this.finishNode(node, "EnumSymbolBody");
  4036. default:
  4037. {
  4038. const empty = () => {
  4039. node.members = [];
  4040. this.expect(8);
  4041. return this.finishNode(node, "EnumStringBody");
  4042. };
  4043. node.explicitType = false;
  4044. const boolsLen = members.booleanMembers.length;
  4045. const numsLen = members.numberMembers.length;
  4046. const strsLen = members.stringMembers.length;
  4047. const defaultedLen = members.defaultedMembers.length;
  4048. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  4049. return empty();
  4050. } else if (!boolsLen && !numsLen) {
  4051. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4052. enumName
  4053. });
  4054. this.expect(8);
  4055. return this.finishNode(node, "EnumStringBody");
  4056. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  4057. for (const member of members.defaultedMembers) {
  4058. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  4059. enumName,
  4060. memberName: member.id.name
  4061. });
  4062. }
  4063. node.members = members.booleanMembers;
  4064. this.expect(8);
  4065. return this.finishNode(node, "EnumBooleanBody");
  4066. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  4067. for (const member of members.defaultedMembers) {
  4068. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  4069. enumName,
  4070. memberName: member.id.name
  4071. });
  4072. }
  4073. node.members = members.numberMembers;
  4074. this.expect(8);
  4075. return this.finishNode(node, "EnumNumberBody");
  4076. } else {
  4077. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  4078. enumName
  4079. });
  4080. return empty();
  4081. }
  4082. }
  4083. }
  4084. }
  4085. flowParseEnumDeclaration(node) {
  4086. const id = this.parseIdentifier();
  4087. node.id = id;
  4088. node.body = this.flowEnumBody(this.startNode(), id);
  4089. return this.finishNode(node, "EnumDeclaration");
  4090. }
  4091. jsxParseOpeningElementAfterName(node) {
  4092. if (this.shouldParseTypes()) {
  4093. if (this.match(47) || this.match(51)) {
  4094. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  4095. }
  4096. }
  4097. return super.jsxParseOpeningElementAfterName(node);
  4098. }
  4099. isLookaheadToken_lt() {
  4100. const next = this.nextTokenStart();
  4101. if (this.input.charCodeAt(next) === 60) {
  4102. const afterNext = this.input.charCodeAt(next + 1);
  4103. return afterNext !== 60 && afterNext !== 61;
  4104. }
  4105. return false;
  4106. }
  4107. reScan_lt_gt() {
  4108. const {
  4109. type
  4110. } = this.state;
  4111. if (type === 47) {
  4112. this.state.pos -= 1;
  4113. this.readToken_lt();
  4114. } else if (type === 48) {
  4115. this.state.pos -= 1;
  4116. this.readToken_gt();
  4117. }
  4118. }
  4119. reScan_lt() {
  4120. const {
  4121. type
  4122. } = this.state;
  4123. if (type === 51) {
  4124. this.state.pos -= 2;
  4125. this.finishOp(47, 1);
  4126. return 47;
  4127. }
  4128. return type;
  4129. }
  4130. maybeUnwrapTypeCastExpression(node) {
  4131. return node.type === "TypeCastExpression" ? node.expression : node;
  4132. }
  4133. };
  4134. const entities = {
  4135. __proto__: null,
  4136. quot: "\u0022",
  4137. amp: "&",
  4138. apos: "\u0027",
  4139. lt: "<",
  4140. gt: ">",
  4141. nbsp: "\u00A0",
  4142. iexcl: "\u00A1",
  4143. cent: "\u00A2",
  4144. pound: "\u00A3",
  4145. curren: "\u00A4",
  4146. yen: "\u00A5",
  4147. brvbar: "\u00A6",
  4148. sect: "\u00A7",
  4149. uml: "\u00A8",
  4150. copy: "\u00A9",
  4151. ordf: "\u00AA",
  4152. laquo: "\u00AB",
  4153. not: "\u00AC",
  4154. shy: "\u00AD",
  4155. reg: "\u00AE",
  4156. macr: "\u00AF",
  4157. deg: "\u00B0",
  4158. plusmn: "\u00B1",
  4159. sup2: "\u00B2",
  4160. sup3: "\u00B3",
  4161. acute: "\u00B4",
  4162. micro: "\u00B5",
  4163. para: "\u00B6",
  4164. middot: "\u00B7",
  4165. cedil: "\u00B8",
  4166. sup1: "\u00B9",
  4167. ordm: "\u00BA",
  4168. raquo: "\u00BB",
  4169. frac14: "\u00BC",
  4170. frac12: "\u00BD",
  4171. frac34: "\u00BE",
  4172. iquest: "\u00BF",
  4173. Agrave: "\u00C0",
  4174. Aacute: "\u00C1",
  4175. Acirc: "\u00C2",
  4176. Atilde: "\u00C3",
  4177. Auml: "\u00C4",
  4178. Aring: "\u00C5",
  4179. AElig: "\u00C6",
  4180. Ccedil: "\u00C7",
  4181. Egrave: "\u00C8",
  4182. Eacute: "\u00C9",
  4183. Ecirc: "\u00CA",
  4184. Euml: "\u00CB",
  4185. Igrave: "\u00CC",
  4186. Iacute: "\u00CD",
  4187. Icirc: "\u00CE",
  4188. Iuml: "\u00CF",
  4189. ETH: "\u00D0",
  4190. Ntilde: "\u00D1",
  4191. Ograve: "\u00D2",
  4192. Oacute: "\u00D3",
  4193. Ocirc: "\u00D4",
  4194. Otilde: "\u00D5",
  4195. Ouml: "\u00D6",
  4196. times: "\u00D7",
  4197. Oslash: "\u00D8",
  4198. Ugrave: "\u00D9",
  4199. Uacute: "\u00DA",
  4200. Ucirc: "\u00DB",
  4201. Uuml: "\u00DC",
  4202. Yacute: "\u00DD",
  4203. THORN: "\u00DE",
  4204. szlig: "\u00DF",
  4205. agrave: "\u00E0",
  4206. aacute: "\u00E1",
  4207. acirc: "\u00E2",
  4208. atilde: "\u00E3",
  4209. auml: "\u00E4",
  4210. aring: "\u00E5",
  4211. aelig: "\u00E6",
  4212. ccedil: "\u00E7",
  4213. egrave: "\u00E8",
  4214. eacute: "\u00E9",
  4215. ecirc: "\u00EA",
  4216. euml: "\u00EB",
  4217. igrave: "\u00EC",
  4218. iacute: "\u00ED",
  4219. icirc: "\u00EE",
  4220. iuml: "\u00EF",
  4221. eth: "\u00F0",
  4222. ntilde: "\u00F1",
  4223. ograve: "\u00F2",
  4224. oacute: "\u00F3",
  4225. ocirc: "\u00F4",
  4226. otilde: "\u00F5",
  4227. ouml: "\u00F6",
  4228. divide: "\u00F7",
  4229. oslash: "\u00F8",
  4230. ugrave: "\u00F9",
  4231. uacute: "\u00FA",
  4232. ucirc: "\u00FB",
  4233. uuml: "\u00FC",
  4234. yacute: "\u00FD",
  4235. thorn: "\u00FE",
  4236. yuml: "\u00FF",
  4237. OElig: "\u0152",
  4238. oelig: "\u0153",
  4239. Scaron: "\u0160",
  4240. scaron: "\u0161",
  4241. Yuml: "\u0178",
  4242. fnof: "\u0192",
  4243. circ: "\u02C6",
  4244. tilde: "\u02DC",
  4245. Alpha: "\u0391",
  4246. Beta: "\u0392",
  4247. Gamma: "\u0393",
  4248. Delta: "\u0394",
  4249. Epsilon: "\u0395",
  4250. Zeta: "\u0396",
  4251. Eta: "\u0397",
  4252. Theta: "\u0398",
  4253. Iota: "\u0399",
  4254. Kappa: "\u039A",
  4255. Lambda: "\u039B",
  4256. Mu: "\u039C",
  4257. Nu: "\u039D",
  4258. Xi: "\u039E",
  4259. Omicron: "\u039F",
  4260. Pi: "\u03A0",
  4261. Rho: "\u03A1",
  4262. Sigma: "\u03A3",
  4263. Tau: "\u03A4",
  4264. Upsilon: "\u03A5",
  4265. Phi: "\u03A6",
  4266. Chi: "\u03A7",
  4267. Psi: "\u03A8",
  4268. Omega: "\u03A9",
  4269. alpha: "\u03B1",
  4270. beta: "\u03B2",
  4271. gamma: "\u03B3",
  4272. delta: "\u03B4",
  4273. epsilon: "\u03B5",
  4274. zeta: "\u03B6",
  4275. eta: "\u03B7",
  4276. theta: "\u03B8",
  4277. iota: "\u03B9",
  4278. kappa: "\u03BA",
  4279. lambda: "\u03BB",
  4280. mu: "\u03BC",
  4281. nu: "\u03BD",
  4282. xi: "\u03BE",
  4283. omicron: "\u03BF",
  4284. pi: "\u03C0",
  4285. rho: "\u03C1",
  4286. sigmaf: "\u03C2",
  4287. sigma: "\u03C3",
  4288. tau: "\u03C4",
  4289. upsilon: "\u03C5",
  4290. phi: "\u03C6",
  4291. chi: "\u03C7",
  4292. psi: "\u03C8",
  4293. omega: "\u03C9",
  4294. thetasym: "\u03D1",
  4295. upsih: "\u03D2",
  4296. piv: "\u03D6",
  4297. ensp: "\u2002",
  4298. emsp: "\u2003",
  4299. thinsp: "\u2009",
  4300. zwnj: "\u200C",
  4301. zwj: "\u200D",
  4302. lrm: "\u200E",
  4303. rlm: "\u200F",
  4304. ndash: "\u2013",
  4305. mdash: "\u2014",
  4306. lsquo: "\u2018",
  4307. rsquo: "\u2019",
  4308. sbquo: "\u201A",
  4309. ldquo: "\u201C",
  4310. rdquo: "\u201D",
  4311. bdquo: "\u201E",
  4312. dagger: "\u2020",
  4313. Dagger: "\u2021",
  4314. bull: "\u2022",
  4315. hellip: "\u2026",
  4316. permil: "\u2030",
  4317. prime: "\u2032",
  4318. Prime: "\u2033",
  4319. lsaquo: "\u2039",
  4320. rsaquo: "\u203A",
  4321. oline: "\u203E",
  4322. frasl: "\u2044",
  4323. euro: "\u20AC",
  4324. image: "\u2111",
  4325. weierp: "\u2118",
  4326. real: "\u211C",
  4327. trade: "\u2122",
  4328. alefsym: "\u2135",
  4329. larr: "\u2190",
  4330. uarr: "\u2191",
  4331. rarr: "\u2192",
  4332. darr: "\u2193",
  4333. harr: "\u2194",
  4334. crarr: "\u21B5",
  4335. lArr: "\u21D0",
  4336. uArr: "\u21D1",
  4337. rArr: "\u21D2",
  4338. dArr: "\u21D3",
  4339. hArr: "\u21D4",
  4340. forall: "\u2200",
  4341. part: "\u2202",
  4342. exist: "\u2203",
  4343. empty: "\u2205",
  4344. nabla: "\u2207",
  4345. isin: "\u2208",
  4346. notin: "\u2209",
  4347. ni: "\u220B",
  4348. prod: "\u220F",
  4349. sum: "\u2211",
  4350. minus: "\u2212",
  4351. lowast: "\u2217",
  4352. radic: "\u221A",
  4353. prop: "\u221D",
  4354. infin: "\u221E",
  4355. ang: "\u2220",
  4356. and: "\u2227",
  4357. or: "\u2228",
  4358. cap: "\u2229",
  4359. cup: "\u222A",
  4360. int: "\u222B",
  4361. there4: "\u2234",
  4362. sim: "\u223C",
  4363. cong: "\u2245",
  4364. asymp: "\u2248",
  4365. ne: "\u2260",
  4366. equiv: "\u2261",
  4367. le: "\u2264",
  4368. ge: "\u2265",
  4369. sub: "\u2282",
  4370. sup: "\u2283",
  4371. nsub: "\u2284",
  4372. sube: "\u2286",
  4373. supe: "\u2287",
  4374. oplus: "\u2295",
  4375. otimes: "\u2297",
  4376. perp: "\u22A5",
  4377. sdot: "\u22C5",
  4378. lceil: "\u2308",
  4379. rceil: "\u2309",
  4380. lfloor: "\u230A",
  4381. rfloor: "\u230B",
  4382. lang: "\u2329",
  4383. rang: "\u232A",
  4384. loz: "\u25CA",
  4385. spades: "\u2660",
  4386. clubs: "\u2663",
  4387. hearts: "\u2665",
  4388. diams: "\u2666"
  4389. };
  4390. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  4391. const lineBreakG = new RegExp(lineBreak.source, "g");
  4392. function isNewLine(code) {
  4393. switch (code) {
  4394. case 10:
  4395. case 13:
  4396. case 8232:
  4397. case 8233:
  4398. return true;
  4399. default:
  4400. return false;
  4401. }
  4402. }
  4403. function hasNewLine(input, start, end) {
  4404. for (let i = start; i < end; i++) {
  4405. if (isNewLine(input.charCodeAt(i))) {
  4406. return true;
  4407. }
  4408. }
  4409. return false;
  4410. }
  4411. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  4412. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  4413. function isWhitespace(code) {
  4414. switch (code) {
  4415. case 0x0009:
  4416. case 0x000b:
  4417. case 0x000c:
  4418. case 32:
  4419. case 160:
  4420. case 5760:
  4421. case 0x2000:
  4422. case 0x2001:
  4423. case 0x2002:
  4424. case 0x2003:
  4425. case 0x2004:
  4426. case 0x2005:
  4427. case 0x2006:
  4428. case 0x2007:
  4429. case 0x2008:
  4430. case 0x2009:
  4431. case 0x200a:
  4432. case 0x202f:
  4433. case 0x205f:
  4434. case 0x3000:
  4435. case 0xfeff:
  4436. return true;
  4437. default:
  4438. return false;
  4439. }
  4440. }
  4441. const JsxErrors = ParseErrorEnum`jsx`({
  4442. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  4443. MissingClosingTagElement: ({
  4444. openingTagName
  4445. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  4446. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  4447. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  4448. UnexpectedToken: ({
  4449. unexpected,
  4450. HTMLEntity
  4451. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  4452. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  4453. UnterminatedJsxContent: "Unterminated JSX contents.",
  4454. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  4455. });
  4456. function isFragment(object) {
  4457. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  4458. }
  4459. function getQualifiedJSXName(object) {
  4460. if (object.type === "JSXIdentifier") {
  4461. return object.name;
  4462. }
  4463. if (object.type === "JSXNamespacedName") {
  4464. return object.namespace.name + ":" + object.name.name;
  4465. }
  4466. if (object.type === "JSXMemberExpression") {
  4467. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  4468. }
  4469. throw new Error("Node had unexpected type: " + object.type);
  4470. }
  4471. var jsx = superClass => class JSXParserMixin extends superClass {
  4472. jsxReadToken() {
  4473. let out = "";
  4474. let chunkStart = this.state.pos;
  4475. for (;;) {
  4476. if (this.state.pos >= this.length) {
  4477. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  4478. }
  4479. const ch = this.input.charCodeAt(this.state.pos);
  4480. switch (ch) {
  4481. case 60:
  4482. case 123:
  4483. if (this.state.pos === this.state.start) {
  4484. if (ch === 60 && this.state.canStartJSXElement) {
  4485. ++this.state.pos;
  4486. this.finishToken(143);
  4487. } else {
  4488. super.getTokenFromCode(ch);
  4489. }
  4490. return;
  4491. }
  4492. out += this.input.slice(chunkStart, this.state.pos);
  4493. this.finishToken(142, out);
  4494. return;
  4495. case 38:
  4496. out += this.input.slice(chunkStart, this.state.pos);
  4497. out += this.jsxReadEntity();
  4498. chunkStart = this.state.pos;
  4499. break;
  4500. case 62:
  4501. case 125:
  4502. default:
  4503. if (isNewLine(ch)) {
  4504. out += this.input.slice(chunkStart, this.state.pos);
  4505. out += this.jsxReadNewLine(true);
  4506. chunkStart = this.state.pos;
  4507. } else {
  4508. ++this.state.pos;
  4509. }
  4510. }
  4511. }
  4512. }
  4513. jsxReadNewLine(normalizeCRLF) {
  4514. const ch = this.input.charCodeAt(this.state.pos);
  4515. let out;
  4516. ++this.state.pos;
  4517. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  4518. ++this.state.pos;
  4519. out = normalizeCRLF ? "\n" : "\r\n";
  4520. } else {
  4521. out = String.fromCharCode(ch);
  4522. }
  4523. ++this.state.curLine;
  4524. this.state.lineStart = this.state.pos;
  4525. return out;
  4526. }
  4527. jsxReadString(quote) {
  4528. let out = "";
  4529. let chunkStart = ++this.state.pos;
  4530. for (;;) {
  4531. if (this.state.pos >= this.length) {
  4532. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  4533. }
  4534. const ch = this.input.charCodeAt(this.state.pos);
  4535. if (ch === quote) break;
  4536. if (ch === 38) {
  4537. out += this.input.slice(chunkStart, this.state.pos);
  4538. out += this.jsxReadEntity();
  4539. chunkStart = this.state.pos;
  4540. } else if (isNewLine(ch)) {
  4541. out += this.input.slice(chunkStart, this.state.pos);
  4542. out += this.jsxReadNewLine(false);
  4543. chunkStart = this.state.pos;
  4544. } else {
  4545. ++this.state.pos;
  4546. }
  4547. }
  4548. out += this.input.slice(chunkStart, this.state.pos++);
  4549. this.finishToken(134, out);
  4550. }
  4551. jsxReadEntity() {
  4552. const startPos = ++this.state.pos;
  4553. if (this.codePointAtPos(this.state.pos) === 35) {
  4554. ++this.state.pos;
  4555. let radix = 10;
  4556. if (this.codePointAtPos(this.state.pos) === 120) {
  4557. radix = 16;
  4558. ++this.state.pos;
  4559. }
  4560. const codePoint = this.readInt(radix, undefined, false, "bail");
  4561. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  4562. ++this.state.pos;
  4563. return String.fromCodePoint(codePoint);
  4564. }
  4565. } else {
  4566. let count = 0;
  4567. let semi = false;
  4568. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  4569. ++this.state.pos;
  4570. }
  4571. if (semi) {
  4572. const desc = this.input.slice(startPos, this.state.pos);
  4573. const entity = entities[desc];
  4574. ++this.state.pos;
  4575. if (entity) {
  4576. return entity;
  4577. }
  4578. }
  4579. }
  4580. this.state.pos = startPos;
  4581. return "&";
  4582. }
  4583. jsxReadWord() {
  4584. let ch;
  4585. const start = this.state.pos;
  4586. do {
  4587. ch = this.input.charCodeAt(++this.state.pos);
  4588. } while (isIdentifierChar(ch) || ch === 45);
  4589. this.finishToken(141, this.input.slice(start, this.state.pos));
  4590. }
  4591. jsxParseIdentifier() {
  4592. const node = this.startNode();
  4593. if (this.match(141)) {
  4594. node.name = this.state.value;
  4595. } else if (tokenIsKeyword(this.state.type)) {
  4596. node.name = tokenLabelName(this.state.type);
  4597. } else {
  4598. this.unexpected();
  4599. }
  4600. this.next();
  4601. return this.finishNode(node, "JSXIdentifier");
  4602. }
  4603. jsxParseNamespacedName() {
  4604. const startLoc = this.state.startLoc;
  4605. const name = this.jsxParseIdentifier();
  4606. if (!this.eat(14)) return name;
  4607. const node = this.startNodeAt(startLoc);
  4608. node.namespace = name;
  4609. node.name = this.jsxParseIdentifier();
  4610. return this.finishNode(node, "JSXNamespacedName");
  4611. }
  4612. jsxParseElementName() {
  4613. const startLoc = this.state.startLoc;
  4614. let node = this.jsxParseNamespacedName();
  4615. if (node.type === "JSXNamespacedName") {
  4616. return node;
  4617. }
  4618. while (this.eat(16)) {
  4619. const newNode = this.startNodeAt(startLoc);
  4620. newNode.object = node;
  4621. newNode.property = this.jsxParseIdentifier();
  4622. node = this.finishNode(newNode, "JSXMemberExpression");
  4623. }
  4624. return node;
  4625. }
  4626. jsxParseAttributeValue() {
  4627. let node;
  4628. switch (this.state.type) {
  4629. case 5:
  4630. node = this.startNode();
  4631. this.setContext(types.brace);
  4632. this.next();
  4633. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  4634. if (node.expression.type === "JSXEmptyExpression") {
  4635. this.raise(JsxErrors.AttributeIsEmpty, node);
  4636. }
  4637. return node;
  4638. case 143:
  4639. case 134:
  4640. return this.parseExprAtom();
  4641. default:
  4642. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  4643. }
  4644. }
  4645. jsxParseEmptyExpression() {
  4646. const node = this.startNodeAt(this.state.lastTokEndLoc);
  4647. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  4648. }
  4649. jsxParseSpreadChild(node) {
  4650. this.next();
  4651. node.expression = this.parseExpression();
  4652. this.setContext(types.j_expr);
  4653. this.state.canStartJSXElement = true;
  4654. this.expect(8);
  4655. return this.finishNode(node, "JSXSpreadChild");
  4656. }
  4657. jsxParseExpressionContainer(node, previousContext) {
  4658. if (this.match(8)) {
  4659. node.expression = this.jsxParseEmptyExpression();
  4660. } else {
  4661. const expression = this.parseExpression();
  4662. node.expression = expression;
  4663. }
  4664. this.setContext(previousContext);
  4665. this.state.canStartJSXElement = true;
  4666. this.expect(8);
  4667. return this.finishNode(node, "JSXExpressionContainer");
  4668. }
  4669. jsxParseAttribute() {
  4670. const node = this.startNode();
  4671. if (this.match(5)) {
  4672. this.setContext(types.brace);
  4673. this.next();
  4674. this.expect(21);
  4675. node.argument = this.parseMaybeAssignAllowIn();
  4676. this.setContext(types.j_oTag);
  4677. this.state.canStartJSXElement = true;
  4678. this.expect(8);
  4679. return this.finishNode(node, "JSXSpreadAttribute");
  4680. }
  4681. node.name = this.jsxParseNamespacedName();
  4682. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  4683. return this.finishNode(node, "JSXAttribute");
  4684. }
  4685. jsxParseOpeningElementAt(startLoc) {
  4686. const node = this.startNodeAt(startLoc);
  4687. if (this.eat(144)) {
  4688. return this.finishNode(node, "JSXOpeningFragment");
  4689. }
  4690. node.name = this.jsxParseElementName();
  4691. return this.jsxParseOpeningElementAfterName(node);
  4692. }
  4693. jsxParseOpeningElementAfterName(node) {
  4694. const attributes = [];
  4695. while (!this.match(56) && !this.match(144)) {
  4696. attributes.push(this.jsxParseAttribute());
  4697. }
  4698. node.attributes = attributes;
  4699. node.selfClosing = this.eat(56);
  4700. this.expect(144);
  4701. return this.finishNode(node, "JSXOpeningElement");
  4702. }
  4703. jsxParseClosingElementAt(startLoc) {
  4704. const node = this.startNodeAt(startLoc);
  4705. if (this.eat(144)) {
  4706. return this.finishNode(node, "JSXClosingFragment");
  4707. }
  4708. node.name = this.jsxParseElementName();
  4709. this.expect(144);
  4710. return this.finishNode(node, "JSXClosingElement");
  4711. }
  4712. jsxParseElementAt(startLoc) {
  4713. const node = this.startNodeAt(startLoc);
  4714. const children = [];
  4715. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  4716. let closingElement = null;
  4717. if (!openingElement.selfClosing) {
  4718. contents: for (;;) {
  4719. switch (this.state.type) {
  4720. case 143:
  4721. startLoc = this.state.startLoc;
  4722. this.next();
  4723. if (this.eat(56)) {
  4724. closingElement = this.jsxParseClosingElementAt(startLoc);
  4725. break contents;
  4726. }
  4727. children.push(this.jsxParseElementAt(startLoc));
  4728. break;
  4729. case 142:
  4730. children.push(this.parseLiteral(this.state.value, "JSXText"));
  4731. break;
  4732. case 5:
  4733. {
  4734. const node = this.startNode();
  4735. this.setContext(types.brace);
  4736. this.next();
  4737. if (this.match(21)) {
  4738. children.push(this.jsxParseSpreadChild(node));
  4739. } else {
  4740. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  4741. }
  4742. break;
  4743. }
  4744. default:
  4745. this.unexpected();
  4746. }
  4747. }
  4748. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  4749. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  4750. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  4751. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4752. openingTagName: getQualifiedJSXName(openingElement.name)
  4753. });
  4754. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  4755. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  4756. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4757. openingTagName: getQualifiedJSXName(openingElement.name)
  4758. });
  4759. }
  4760. }
  4761. }
  4762. if (isFragment(openingElement)) {
  4763. node.openingFragment = openingElement;
  4764. node.closingFragment = closingElement;
  4765. } else {
  4766. node.openingElement = openingElement;
  4767. node.closingElement = closingElement;
  4768. }
  4769. node.children = children;
  4770. if (this.match(47)) {
  4771. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  4772. }
  4773. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  4774. }
  4775. jsxParseElement() {
  4776. const startLoc = this.state.startLoc;
  4777. this.next();
  4778. return this.jsxParseElementAt(startLoc);
  4779. }
  4780. setContext(newContext) {
  4781. const {
  4782. context
  4783. } = this.state;
  4784. context[context.length - 1] = newContext;
  4785. }
  4786. parseExprAtom(refExpressionErrors) {
  4787. if (this.match(143)) {
  4788. return this.jsxParseElement();
  4789. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  4790. this.replaceToken(143);
  4791. return this.jsxParseElement();
  4792. } else {
  4793. return super.parseExprAtom(refExpressionErrors);
  4794. }
  4795. }
  4796. skipSpace() {
  4797. const curContext = this.curContext();
  4798. if (!curContext.preserveSpace) super.skipSpace();
  4799. }
  4800. getTokenFromCode(code) {
  4801. const context = this.curContext();
  4802. if (context === types.j_expr) {
  4803. this.jsxReadToken();
  4804. return;
  4805. }
  4806. if (context === types.j_oTag || context === types.j_cTag) {
  4807. if (isIdentifierStart(code)) {
  4808. this.jsxReadWord();
  4809. return;
  4810. }
  4811. if (code === 62) {
  4812. ++this.state.pos;
  4813. this.finishToken(144);
  4814. return;
  4815. }
  4816. if ((code === 34 || code === 39) && context === types.j_oTag) {
  4817. this.jsxReadString(code);
  4818. return;
  4819. }
  4820. }
  4821. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  4822. ++this.state.pos;
  4823. this.finishToken(143);
  4824. return;
  4825. }
  4826. super.getTokenFromCode(code);
  4827. }
  4828. updateContext(prevType) {
  4829. const {
  4830. context,
  4831. type
  4832. } = this.state;
  4833. if (type === 56 && prevType === 143) {
  4834. context.splice(-2, 2, types.j_cTag);
  4835. this.state.canStartJSXElement = false;
  4836. } else if (type === 143) {
  4837. context.push(types.j_oTag);
  4838. } else if (type === 144) {
  4839. const out = context[context.length - 1];
  4840. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  4841. context.pop();
  4842. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  4843. } else {
  4844. this.setContext(types.j_expr);
  4845. this.state.canStartJSXElement = true;
  4846. }
  4847. } else {
  4848. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  4849. }
  4850. }
  4851. };
  4852. class TypeScriptScope extends Scope {
  4853. constructor(...args) {
  4854. super(...args);
  4855. this.tsNames = new Map();
  4856. }
  4857. }
  4858. class TypeScriptScopeHandler extends ScopeHandler {
  4859. constructor(...args) {
  4860. super(...args);
  4861. this.importsStack = [];
  4862. }
  4863. createScope(flags) {
  4864. this.importsStack.push(new Set());
  4865. return new TypeScriptScope(flags);
  4866. }
  4867. enter(flags) {
  4868. if (flags === 1024) {
  4869. this.importsStack.push(new Set());
  4870. }
  4871. super.enter(flags);
  4872. }
  4873. exit() {
  4874. const flags = super.exit();
  4875. if (flags === 1024) {
  4876. this.importsStack.pop();
  4877. }
  4878. return flags;
  4879. }
  4880. hasImport(name, allowShadow) {
  4881. const len = this.importsStack.length;
  4882. if (this.importsStack[len - 1].has(name)) {
  4883. return true;
  4884. }
  4885. if (!allowShadow && len > 1) {
  4886. for (let i = 0; i < len - 1; i++) {
  4887. if (this.importsStack[i].has(name)) return true;
  4888. }
  4889. }
  4890. return false;
  4891. }
  4892. declareName(name, bindingType, loc) {
  4893. if (bindingType & 4096) {
  4894. if (this.hasImport(name, true)) {
  4895. this.parser.raise(Errors.VarRedeclaration, loc, {
  4896. identifierName: name
  4897. });
  4898. }
  4899. this.importsStack[this.importsStack.length - 1].add(name);
  4900. return;
  4901. }
  4902. const scope = this.currentScope();
  4903. let type = scope.tsNames.get(name) || 0;
  4904. if (bindingType & 1024) {
  4905. this.maybeExportDefined(scope, name);
  4906. scope.tsNames.set(name, type | 16);
  4907. return;
  4908. }
  4909. super.declareName(name, bindingType, loc);
  4910. if (bindingType & 2) {
  4911. if (!(bindingType & 1)) {
  4912. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4913. this.maybeExportDefined(scope, name);
  4914. }
  4915. type = type | 1;
  4916. }
  4917. if (bindingType & 256) {
  4918. type = type | 2;
  4919. }
  4920. if (bindingType & 512) {
  4921. type = type | 4;
  4922. }
  4923. if (bindingType & 128) {
  4924. type = type | 8;
  4925. }
  4926. if (type) scope.tsNames.set(name, type);
  4927. }
  4928. isRedeclaredInScope(scope, name, bindingType) {
  4929. const type = scope.tsNames.get(name);
  4930. if ((type & 2) > 0) {
  4931. if (bindingType & 256) {
  4932. const isConst = !!(bindingType & 512);
  4933. const wasConst = (type & 4) > 0;
  4934. return isConst !== wasConst;
  4935. }
  4936. return true;
  4937. }
  4938. if (bindingType & 128 && (type & 8) > 0) {
  4939. if (scope.names.get(name) & 2) {
  4940. return !!(bindingType & 1);
  4941. } else {
  4942. return false;
  4943. }
  4944. }
  4945. if (bindingType & 2 && (type & 1) > 0) {
  4946. return true;
  4947. }
  4948. return super.isRedeclaredInScope(scope, name, bindingType);
  4949. }
  4950. checkLocalExport(id) {
  4951. const {
  4952. name
  4953. } = id;
  4954. if (this.hasImport(name)) return;
  4955. const len = this.scopeStack.length;
  4956. for (let i = len - 1; i >= 0; i--) {
  4957. const scope = this.scopeStack[i];
  4958. const type = scope.tsNames.get(name);
  4959. if ((type & 1) > 0 || (type & 16) > 0) {
  4960. return;
  4961. }
  4962. }
  4963. super.checkLocalExport(id);
  4964. }
  4965. }
  4966. class ProductionParameterHandler {
  4967. constructor() {
  4968. this.stacks = [];
  4969. }
  4970. enter(flags) {
  4971. this.stacks.push(flags);
  4972. }
  4973. exit() {
  4974. this.stacks.pop();
  4975. }
  4976. currentFlags() {
  4977. return this.stacks[this.stacks.length - 1];
  4978. }
  4979. get hasAwait() {
  4980. return (this.currentFlags() & 2) > 0;
  4981. }
  4982. get hasYield() {
  4983. return (this.currentFlags() & 1) > 0;
  4984. }
  4985. get hasReturn() {
  4986. return (this.currentFlags() & 4) > 0;
  4987. }
  4988. get hasIn() {
  4989. return (this.currentFlags() & 8) > 0;
  4990. }
  4991. }
  4992. function functionFlags(isAsync, isGenerator) {
  4993. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  4994. }
  4995. class BaseParser {
  4996. constructor() {
  4997. this.sawUnambiguousESM = false;
  4998. this.ambiguousScriptDifferentAst = false;
  4999. }
  5000. sourceToOffsetPos(sourcePos) {
  5001. return sourcePos + this.startIndex;
  5002. }
  5003. offsetToSourcePos(offsetPos) {
  5004. return offsetPos - this.startIndex;
  5005. }
  5006. hasPlugin(pluginConfig) {
  5007. if (typeof pluginConfig === "string") {
  5008. return this.plugins.has(pluginConfig);
  5009. } else {
  5010. const [pluginName, pluginOptions] = pluginConfig;
  5011. if (!this.hasPlugin(pluginName)) {
  5012. return false;
  5013. }
  5014. const actualOptions = this.plugins.get(pluginName);
  5015. for (const key of Object.keys(pluginOptions)) {
  5016. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  5017. return false;
  5018. }
  5019. }
  5020. return true;
  5021. }
  5022. }
  5023. getPluginOption(plugin, name) {
  5024. var _this$plugins$get;
  5025. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  5026. }
  5027. }
  5028. function setTrailingComments(node, comments) {
  5029. if (node.trailingComments === undefined) {
  5030. node.trailingComments = comments;
  5031. } else {
  5032. node.trailingComments.unshift(...comments);
  5033. }
  5034. }
  5035. function setLeadingComments(node, comments) {
  5036. if (node.leadingComments === undefined) {
  5037. node.leadingComments = comments;
  5038. } else {
  5039. node.leadingComments.unshift(...comments);
  5040. }
  5041. }
  5042. function setInnerComments(node, comments) {
  5043. if (node.innerComments === undefined) {
  5044. node.innerComments = comments;
  5045. } else {
  5046. node.innerComments.unshift(...comments);
  5047. }
  5048. }
  5049. function adjustInnerComments(node, elements, commentWS) {
  5050. let lastElement = null;
  5051. let i = elements.length;
  5052. while (lastElement === null && i > 0) {
  5053. lastElement = elements[--i];
  5054. }
  5055. if (lastElement === null || lastElement.start > commentWS.start) {
  5056. setInnerComments(node, commentWS.comments);
  5057. } else {
  5058. setTrailingComments(lastElement, commentWS.comments);
  5059. }
  5060. }
  5061. class CommentsParser extends BaseParser {
  5062. addComment(comment) {
  5063. if (this.filename) comment.loc.filename = this.filename;
  5064. const {
  5065. commentsLen
  5066. } = this.state;
  5067. if (this.comments.length !== commentsLen) {
  5068. this.comments.length = commentsLen;
  5069. }
  5070. this.comments.push(comment);
  5071. this.state.commentsLen++;
  5072. }
  5073. processComment(node) {
  5074. const {
  5075. commentStack
  5076. } = this.state;
  5077. const commentStackLength = commentStack.length;
  5078. if (commentStackLength === 0) return;
  5079. let i = commentStackLength - 1;
  5080. const lastCommentWS = commentStack[i];
  5081. if (lastCommentWS.start === node.end) {
  5082. lastCommentWS.leadingNode = node;
  5083. i--;
  5084. }
  5085. const {
  5086. start: nodeStart
  5087. } = node;
  5088. for (; i >= 0; i--) {
  5089. const commentWS = commentStack[i];
  5090. const commentEnd = commentWS.end;
  5091. if (commentEnd > nodeStart) {
  5092. commentWS.containingNode = node;
  5093. this.finalizeComment(commentWS);
  5094. commentStack.splice(i, 1);
  5095. } else {
  5096. if (commentEnd === nodeStart) {
  5097. commentWS.trailingNode = node;
  5098. }
  5099. break;
  5100. }
  5101. }
  5102. }
  5103. finalizeComment(commentWS) {
  5104. var _node$options;
  5105. const {
  5106. comments
  5107. } = commentWS;
  5108. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  5109. if (commentWS.leadingNode !== null) {
  5110. setTrailingComments(commentWS.leadingNode, comments);
  5111. }
  5112. if (commentWS.trailingNode !== null) {
  5113. setLeadingComments(commentWS.trailingNode, comments);
  5114. }
  5115. } else {
  5116. const {
  5117. containingNode: node,
  5118. start: commentStart
  5119. } = commentWS;
  5120. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  5121. switch (node.type) {
  5122. case "ObjectExpression":
  5123. case "ObjectPattern":
  5124. case "RecordExpression":
  5125. adjustInnerComments(node, node.properties, commentWS);
  5126. break;
  5127. case "CallExpression":
  5128. case "OptionalCallExpression":
  5129. adjustInnerComments(node, node.arguments, commentWS);
  5130. break;
  5131. case "ImportExpression":
  5132. adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
  5133. break;
  5134. case "FunctionDeclaration":
  5135. case "FunctionExpression":
  5136. case "ArrowFunctionExpression":
  5137. case "ObjectMethod":
  5138. case "ClassMethod":
  5139. case "ClassPrivateMethod":
  5140. adjustInnerComments(node, node.params, commentWS);
  5141. break;
  5142. case "ArrayExpression":
  5143. case "ArrayPattern":
  5144. case "TupleExpression":
  5145. adjustInnerComments(node, node.elements, commentWS);
  5146. break;
  5147. case "ExportNamedDeclaration":
  5148. case "ImportDeclaration":
  5149. adjustInnerComments(node, node.specifiers, commentWS);
  5150. break;
  5151. case "TSEnumDeclaration":
  5152. {
  5153. adjustInnerComments(node, node.members, commentWS);
  5154. }
  5155. break;
  5156. case "TSEnumBody":
  5157. adjustInnerComments(node, node.members, commentWS);
  5158. break;
  5159. default:
  5160. {
  5161. setInnerComments(node, comments);
  5162. }
  5163. }
  5164. } else {
  5165. setInnerComments(node, comments);
  5166. }
  5167. }
  5168. }
  5169. finalizeRemainingComments() {
  5170. const {
  5171. commentStack
  5172. } = this.state;
  5173. for (let i = commentStack.length - 1; i >= 0; i--) {
  5174. this.finalizeComment(commentStack[i]);
  5175. }
  5176. this.state.commentStack = [];
  5177. }
  5178. resetPreviousNodeTrailingComments(node) {
  5179. const {
  5180. commentStack
  5181. } = this.state;
  5182. const {
  5183. length
  5184. } = commentStack;
  5185. if (length === 0) return;
  5186. const commentWS = commentStack[length - 1];
  5187. if (commentWS.leadingNode === node) {
  5188. commentWS.leadingNode = null;
  5189. }
  5190. }
  5191. takeSurroundingComments(node, start, end) {
  5192. const {
  5193. commentStack
  5194. } = this.state;
  5195. const commentStackLength = commentStack.length;
  5196. if (commentStackLength === 0) return;
  5197. let i = commentStackLength - 1;
  5198. for (; i >= 0; i--) {
  5199. const commentWS = commentStack[i];
  5200. const commentEnd = commentWS.end;
  5201. const commentStart = commentWS.start;
  5202. if (commentStart === end) {
  5203. commentWS.leadingNode = node;
  5204. } else if (commentEnd === start) {
  5205. commentWS.trailingNode = node;
  5206. } else if (commentEnd < start) {
  5207. break;
  5208. }
  5209. }
  5210. }
  5211. }
  5212. class State {
  5213. constructor() {
  5214. this.flags = 1024;
  5215. this.startIndex = void 0;
  5216. this.curLine = void 0;
  5217. this.lineStart = void 0;
  5218. this.startLoc = void 0;
  5219. this.endLoc = void 0;
  5220. this.errors = [];
  5221. this.potentialArrowAt = -1;
  5222. this.noArrowAt = [];
  5223. this.noArrowParamsConversionAt = [];
  5224. this.topicContext = {
  5225. maxNumOfResolvableTopics: 0,
  5226. maxTopicIndex: null
  5227. };
  5228. this.labels = [];
  5229. this.commentsLen = 0;
  5230. this.commentStack = [];
  5231. this.pos = 0;
  5232. this.type = 140;
  5233. this.value = null;
  5234. this.start = 0;
  5235. this.end = 0;
  5236. this.lastTokEndLoc = null;
  5237. this.lastTokStartLoc = null;
  5238. this.context = [types.brace];
  5239. this.firstInvalidTemplateEscapePos = null;
  5240. this.strictErrors = new Map();
  5241. this.tokensLength = 0;
  5242. }
  5243. get strict() {
  5244. return (this.flags & 1) > 0;
  5245. }
  5246. set strict(v) {
  5247. if (v) this.flags |= 1;else this.flags &= -2;
  5248. }
  5249. init({
  5250. strictMode,
  5251. sourceType,
  5252. startIndex,
  5253. startLine,
  5254. startColumn
  5255. }) {
  5256. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  5257. this.startIndex = startIndex;
  5258. this.curLine = startLine;
  5259. this.lineStart = -startColumn;
  5260. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  5261. }
  5262. get maybeInArrowParameters() {
  5263. return (this.flags & 2) > 0;
  5264. }
  5265. set maybeInArrowParameters(v) {
  5266. if (v) this.flags |= 2;else this.flags &= -3;
  5267. }
  5268. get inType() {
  5269. return (this.flags & 4) > 0;
  5270. }
  5271. set inType(v) {
  5272. if (v) this.flags |= 4;else this.flags &= -5;
  5273. }
  5274. get noAnonFunctionType() {
  5275. return (this.flags & 8) > 0;
  5276. }
  5277. set noAnonFunctionType(v) {
  5278. if (v) this.flags |= 8;else this.flags &= -9;
  5279. }
  5280. get hasFlowComment() {
  5281. return (this.flags & 16) > 0;
  5282. }
  5283. set hasFlowComment(v) {
  5284. if (v) this.flags |= 16;else this.flags &= -17;
  5285. }
  5286. get isAmbientContext() {
  5287. return (this.flags & 32) > 0;
  5288. }
  5289. set isAmbientContext(v) {
  5290. if (v) this.flags |= 32;else this.flags &= -33;
  5291. }
  5292. get inAbstractClass() {
  5293. return (this.flags & 64) > 0;
  5294. }
  5295. set inAbstractClass(v) {
  5296. if (v) this.flags |= 64;else this.flags &= -65;
  5297. }
  5298. get inDisallowConditionalTypesContext() {
  5299. return (this.flags & 128) > 0;
  5300. }
  5301. set inDisallowConditionalTypesContext(v) {
  5302. if (v) this.flags |= 128;else this.flags &= -129;
  5303. }
  5304. get soloAwait() {
  5305. return (this.flags & 256) > 0;
  5306. }
  5307. set soloAwait(v) {
  5308. if (v) this.flags |= 256;else this.flags &= -257;
  5309. }
  5310. get inFSharpPipelineDirectBody() {
  5311. return (this.flags & 512) > 0;
  5312. }
  5313. set inFSharpPipelineDirectBody(v) {
  5314. if (v) this.flags |= 512;else this.flags &= -513;
  5315. }
  5316. get canStartJSXElement() {
  5317. return (this.flags & 1024) > 0;
  5318. }
  5319. set canStartJSXElement(v) {
  5320. if (v) this.flags |= 1024;else this.flags &= -1025;
  5321. }
  5322. get containsEsc() {
  5323. return (this.flags & 2048) > 0;
  5324. }
  5325. set containsEsc(v) {
  5326. if (v) this.flags |= 2048;else this.flags &= -2049;
  5327. }
  5328. get hasTopLevelAwait() {
  5329. return (this.flags & 4096) > 0;
  5330. }
  5331. set hasTopLevelAwait(v) {
  5332. if (v) this.flags |= 4096;else this.flags &= -4097;
  5333. }
  5334. curPosition() {
  5335. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  5336. }
  5337. clone() {
  5338. const state = new State();
  5339. state.flags = this.flags;
  5340. state.startIndex = this.startIndex;
  5341. state.curLine = this.curLine;
  5342. state.lineStart = this.lineStart;
  5343. state.startLoc = this.startLoc;
  5344. state.endLoc = this.endLoc;
  5345. state.errors = this.errors.slice();
  5346. state.potentialArrowAt = this.potentialArrowAt;
  5347. state.noArrowAt = this.noArrowAt.slice();
  5348. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  5349. state.topicContext = this.topicContext;
  5350. state.labels = this.labels.slice();
  5351. state.commentsLen = this.commentsLen;
  5352. state.commentStack = this.commentStack.slice();
  5353. state.pos = this.pos;
  5354. state.type = this.type;
  5355. state.value = this.value;
  5356. state.start = this.start;
  5357. state.end = this.end;
  5358. state.lastTokEndLoc = this.lastTokEndLoc;
  5359. state.lastTokStartLoc = this.lastTokStartLoc;
  5360. state.context = this.context.slice();
  5361. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  5362. state.strictErrors = this.strictErrors;
  5363. state.tokensLength = this.tokensLength;
  5364. return state;
  5365. }
  5366. }
  5367. var _isDigit = function isDigit(code) {
  5368. return code >= 48 && code <= 57;
  5369. };
  5370. const forbiddenNumericSeparatorSiblings = {
  5371. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  5372. hex: new Set([46, 88, 95, 120])
  5373. };
  5374. const isAllowedNumericSeparatorSibling = {
  5375. bin: ch => ch === 48 || ch === 49,
  5376. oct: ch => ch >= 48 && ch <= 55,
  5377. dec: ch => ch >= 48 && ch <= 57,
  5378. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  5379. };
  5380. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  5381. const initialPos = pos;
  5382. const initialLineStart = lineStart;
  5383. const initialCurLine = curLine;
  5384. let out = "";
  5385. let firstInvalidLoc = null;
  5386. let chunkStart = pos;
  5387. const {
  5388. length
  5389. } = input;
  5390. for (;;) {
  5391. if (pos >= length) {
  5392. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5393. out += input.slice(chunkStart, pos);
  5394. break;
  5395. }
  5396. const ch = input.charCodeAt(pos);
  5397. if (isStringEnd(type, ch, input, pos)) {
  5398. out += input.slice(chunkStart, pos);
  5399. break;
  5400. }
  5401. if (ch === 92) {
  5402. out += input.slice(chunkStart, pos);
  5403. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  5404. if (res.ch === null && !firstInvalidLoc) {
  5405. firstInvalidLoc = {
  5406. pos,
  5407. lineStart,
  5408. curLine
  5409. };
  5410. } else {
  5411. out += res.ch;
  5412. }
  5413. ({
  5414. pos,
  5415. lineStart,
  5416. curLine
  5417. } = res);
  5418. chunkStart = pos;
  5419. } else if (ch === 8232 || ch === 8233) {
  5420. ++pos;
  5421. ++curLine;
  5422. lineStart = pos;
  5423. } else if (ch === 10 || ch === 13) {
  5424. if (type === "template") {
  5425. out += input.slice(chunkStart, pos) + "\n";
  5426. ++pos;
  5427. if (ch === 13 && input.charCodeAt(pos) === 10) {
  5428. ++pos;
  5429. }
  5430. ++curLine;
  5431. chunkStart = lineStart = pos;
  5432. } else {
  5433. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5434. }
  5435. } else {
  5436. ++pos;
  5437. }
  5438. }
  5439. return {
  5440. pos,
  5441. str: out,
  5442. firstInvalidLoc,
  5443. lineStart,
  5444. curLine,
  5445. containsInvalid: !!firstInvalidLoc
  5446. };
  5447. }
  5448. function isStringEnd(type, ch, input, pos) {
  5449. if (type === "template") {
  5450. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  5451. }
  5452. return ch === (type === "double" ? 34 : 39);
  5453. }
  5454. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  5455. const throwOnInvalid = !inTemplate;
  5456. pos++;
  5457. const res = ch => ({
  5458. pos,
  5459. ch,
  5460. lineStart,
  5461. curLine
  5462. });
  5463. const ch = input.charCodeAt(pos++);
  5464. switch (ch) {
  5465. case 110:
  5466. return res("\n");
  5467. case 114:
  5468. return res("\r");
  5469. case 120:
  5470. {
  5471. let code;
  5472. ({
  5473. code,
  5474. pos
  5475. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  5476. return res(code === null ? null : String.fromCharCode(code));
  5477. }
  5478. case 117:
  5479. {
  5480. let code;
  5481. ({
  5482. code,
  5483. pos
  5484. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  5485. return res(code === null ? null : String.fromCodePoint(code));
  5486. }
  5487. case 116:
  5488. return res("\t");
  5489. case 98:
  5490. return res("\b");
  5491. case 118:
  5492. return res("\u000b");
  5493. case 102:
  5494. return res("\f");
  5495. case 13:
  5496. if (input.charCodeAt(pos) === 10) {
  5497. ++pos;
  5498. }
  5499. case 10:
  5500. lineStart = pos;
  5501. ++curLine;
  5502. case 8232:
  5503. case 8233:
  5504. return res("");
  5505. case 56:
  5506. case 57:
  5507. if (inTemplate) {
  5508. return res(null);
  5509. } else {
  5510. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  5511. }
  5512. default:
  5513. if (ch >= 48 && ch <= 55) {
  5514. const startPos = pos - 1;
  5515. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  5516. let octalStr = match[0];
  5517. let octal = parseInt(octalStr, 8);
  5518. if (octal > 255) {
  5519. octalStr = octalStr.slice(0, -1);
  5520. octal = parseInt(octalStr, 8);
  5521. }
  5522. pos += octalStr.length - 1;
  5523. const next = input.charCodeAt(pos);
  5524. if (octalStr !== "0" || next === 56 || next === 57) {
  5525. if (inTemplate) {
  5526. return res(null);
  5527. } else {
  5528. errors.strictNumericEscape(startPos, lineStart, curLine);
  5529. }
  5530. }
  5531. return res(String.fromCharCode(octal));
  5532. }
  5533. return res(String.fromCharCode(ch));
  5534. }
  5535. }
  5536. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  5537. const initialPos = pos;
  5538. let n;
  5539. ({
  5540. n,
  5541. pos
  5542. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  5543. if (n === null) {
  5544. if (throwOnInvalid) {
  5545. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  5546. } else {
  5547. pos = initialPos - 1;
  5548. }
  5549. }
  5550. return {
  5551. code: n,
  5552. pos
  5553. };
  5554. }
  5555. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  5556. const start = pos;
  5557. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  5558. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  5559. let invalid = false;
  5560. let total = 0;
  5561. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  5562. const code = input.charCodeAt(pos);
  5563. let val;
  5564. if (code === 95 && allowNumSeparator !== "bail") {
  5565. const prev = input.charCodeAt(pos - 1);
  5566. const next = input.charCodeAt(pos + 1);
  5567. if (!allowNumSeparator) {
  5568. if (bailOnError) return {
  5569. n: null,
  5570. pos
  5571. };
  5572. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  5573. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  5574. if (bailOnError) return {
  5575. n: null,
  5576. pos
  5577. };
  5578. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  5579. }
  5580. ++pos;
  5581. continue;
  5582. }
  5583. if (code >= 97) {
  5584. val = code - 97 + 10;
  5585. } else if (code >= 65) {
  5586. val = code - 65 + 10;
  5587. } else if (_isDigit(code)) {
  5588. val = code - 48;
  5589. } else {
  5590. val = Infinity;
  5591. }
  5592. if (val >= radix) {
  5593. if (val <= 9 && bailOnError) {
  5594. return {
  5595. n: null,
  5596. pos
  5597. };
  5598. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  5599. val = 0;
  5600. } else if (forceLen) {
  5601. val = 0;
  5602. invalid = true;
  5603. } else {
  5604. break;
  5605. }
  5606. }
  5607. ++pos;
  5608. total = total * radix + val;
  5609. }
  5610. if (pos === start || len != null && pos - start !== len || invalid) {
  5611. return {
  5612. n: null,
  5613. pos
  5614. };
  5615. }
  5616. return {
  5617. n: total,
  5618. pos
  5619. };
  5620. }
  5621. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  5622. const ch = input.charCodeAt(pos);
  5623. let code;
  5624. if (ch === 123) {
  5625. ++pos;
  5626. ({
  5627. code,
  5628. pos
  5629. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  5630. ++pos;
  5631. if (code !== null && code > 0x10ffff) {
  5632. if (throwOnInvalid) {
  5633. errors.invalidCodePoint(pos, lineStart, curLine);
  5634. } else {
  5635. return {
  5636. code: null,
  5637. pos
  5638. };
  5639. }
  5640. }
  5641. } else {
  5642. ({
  5643. code,
  5644. pos
  5645. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  5646. }
  5647. return {
  5648. code,
  5649. pos
  5650. };
  5651. }
  5652. function buildPosition(pos, lineStart, curLine) {
  5653. return new Position(curLine, pos - lineStart, pos);
  5654. }
  5655. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  5656. class Token {
  5657. constructor(state) {
  5658. const startIndex = state.startIndex || 0;
  5659. this.type = state.type;
  5660. this.value = state.value;
  5661. this.start = startIndex + state.start;
  5662. this.end = startIndex + state.end;
  5663. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  5664. }
  5665. }
  5666. class Tokenizer extends CommentsParser {
  5667. constructor(options, input) {
  5668. super();
  5669. this.isLookahead = void 0;
  5670. this.tokens = [];
  5671. this.errorHandlers_readInt = {
  5672. invalidDigit: (pos, lineStart, curLine, radix) => {
  5673. if (!(this.optionFlags & 2048)) return false;
  5674. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  5675. radix
  5676. });
  5677. return true;
  5678. },
  5679. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  5680. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  5681. };
  5682. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  5683. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  5684. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  5685. });
  5686. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  5687. strictNumericEscape: (pos, lineStart, curLine) => {
  5688. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  5689. },
  5690. unterminated: (pos, lineStart, curLine) => {
  5691. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  5692. }
  5693. });
  5694. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  5695. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  5696. unterminated: (pos, lineStart, curLine) => {
  5697. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  5698. }
  5699. });
  5700. this.state = new State();
  5701. this.state.init(options);
  5702. this.input = input;
  5703. this.length = input.length;
  5704. this.comments = [];
  5705. this.isLookahead = false;
  5706. }
  5707. pushToken(token) {
  5708. this.tokens.length = this.state.tokensLength;
  5709. this.tokens.push(token);
  5710. ++this.state.tokensLength;
  5711. }
  5712. next() {
  5713. this.checkKeywordEscapes();
  5714. if (this.optionFlags & 256) {
  5715. this.pushToken(new Token(this.state));
  5716. }
  5717. this.state.lastTokEndLoc = this.state.endLoc;
  5718. this.state.lastTokStartLoc = this.state.startLoc;
  5719. this.nextToken();
  5720. }
  5721. eat(type) {
  5722. if (this.match(type)) {
  5723. this.next();
  5724. return true;
  5725. } else {
  5726. return false;
  5727. }
  5728. }
  5729. match(type) {
  5730. return this.state.type === type;
  5731. }
  5732. createLookaheadState(state) {
  5733. return {
  5734. pos: state.pos,
  5735. value: null,
  5736. type: state.type,
  5737. start: state.start,
  5738. end: state.end,
  5739. context: [this.curContext()],
  5740. inType: state.inType,
  5741. startLoc: state.startLoc,
  5742. lastTokEndLoc: state.lastTokEndLoc,
  5743. curLine: state.curLine,
  5744. lineStart: state.lineStart,
  5745. curPosition: state.curPosition
  5746. };
  5747. }
  5748. lookahead() {
  5749. const old = this.state;
  5750. this.state = this.createLookaheadState(old);
  5751. this.isLookahead = true;
  5752. this.nextToken();
  5753. this.isLookahead = false;
  5754. const curr = this.state;
  5755. this.state = old;
  5756. return curr;
  5757. }
  5758. nextTokenStart() {
  5759. return this.nextTokenStartSince(this.state.pos);
  5760. }
  5761. nextTokenStartSince(pos) {
  5762. skipWhiteSpace.lastIndex = pos;
  5763. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  5764. }
  5765. lookaheadCharCode() {
  5766. return this.lookaheadCharCodeSince(this.state.pos);
  5767. }
  5768. lookaheadCharCodeSince(pos) {
  5769. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  5770. }
  5771. nextTokenInLineStart() {
  5772. return this.nextTokenInLineStartSince(this.state.pos);
  5773. }
  5774. nextTokenInLineStartSince(pos) {
  5775. skipWhiteSpaceInLine.lastIndex = pos;
  5776. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  5777. }
  5778. lookaheadInLineCharCode() {
  5779. return this.input.charCodeAt(this.nextTokenInLineStart());
  5780. }
  5781. codePointAtPos(pos) {
  5782. let cp = this.input.charCodeAt(pos);
  5783. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  5784. const trail = this.input.charCodeAt(pos);
  5785. if ((trail & 0xfc00) === 0xdc00) {
  5786. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  5787. }
  5788. }
  5789. return cp;
  5790. }
  5791. setStrict(strict) {
  5792. this.state.strict = strict;
  5793. if (strict) {
  5794. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  5795. this.state.strictErrors.clear();
  5796. }
  5797. }
  5798. curContext() {
  5799. return this.state.context[this.state.context.length - 1];
  5800. }
  5801. nextToken() {
  5802. this.skipSpace();
  5803. this.state.start = this.state.pos;
  5804. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  5805. if (this.state.pos >= this.length) {
  5806. this.finishToken(140);
  5807. return;
  5808. }
  5809. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  5810. }
  5811. skipBlockComment(commentEnd) {
  5812. let startLoc;
  5813. if (!this.isLookahead) startLoc = this.state.curPosition();
  5814. const start = this.state.pos;
  5815. const end = this.input.indexOf(commentEnd, start + 2);
  5816. if (end === -1) {
  5817. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5818. }
  5819. this.state.pos = end + commentEnd.length;
  5820. lineBreakG.lastIndex = start + 2;
  5821. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  5822. ++this.state.curLine;
  5823. this.state.lineStart = lineBreakG.lastIndex;
  5824. }
  5825. if (this.isLookahead) return;
  5826. const comment = {
  5827. type: "CommentBlock",
  5828. value: this.input.slice(start + 2, end),
  5829. start: this.sourceToOffsetPos(start),
  5830. end: this.sourceToOffsetPos(end + commentEnd.length),
  5831. loc: new SourceLocation(startLoc, this.state.curPosition())
  5832. };
  5833. if (this.optionFlags & 256) this.pushToken(comment);
  5834. return comment;
  5835. }
  5836. skipLineComment(startSkip) {
  5837. const start = this.state.pos;
  5838. let startLoc;
  5839. if (!this.isLookahead) startLoc = this.state.curPosition();
  5840. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  5841. if (this.state.pos < this.length) {
  5842. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  5843. ch = this.input.charCodeAt(this.state.pos);
  5844. }
  5845. }
  5846. if (this.isLookahead) return;
  5847. const end = this.state.pos;
  5848. const value = this.input.slice(start + startSkip, end);
  5849. const comment = {
  5850. type: "CommentLine",
  5851. value,
  5852. start: this.sourceToOffsetPos(start),
  5853. end: this.sourceToOffsetPos(end),
  5854. loc: new SourceLocation(startLoc, this.state.curPosition())
  5855. };
  5856. if (this.optionFlags & 256) this.pushToken(comment);
  5857. return comment;
  5858. }
  5859. skipSpace() {
  5860. const spaceStart = this.state.pos;
  5861. const comments = this.optionFlags & 4096 ? [] : null;
  5862. loop: while (this.state.pos < this.length) {
  5863. const ch = this.input.charCodeAt(this.state.pos);
  5864. switch (ch) {
  5865. case 32:
  5866. case 160:
  5867. case 9:
  5868. ++this.state.pos;
  5869. break;
  5870. case 13:
  5871. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  5872. ++this.state.pos;
  5873. }
  5874. case 10:
  5875. case 8232:
  5876. case 8233:
  5877. ++this.state.pos;
  5878. ++this.state.curLine;
  5879. this.state.lineStart = this.state.pos;
  5880. break;
  5881. case 47:
  5882. switch (this.input.charCodeAt(this.state.pos + 1)) {
  5883. case 42:
  5884. {
  5885. const comment = this.skipBlockComment("*/");
  5886. if (comment !== undefined) {
  5887. this.addComment(comment);
  5888. comments == null || comments.push(comment);
  5889. }
  5890. break;
  5891. }
  5892. case 47:
  5893. {
  5894. const comment = this.skipLineComment(2);
  5895. if (comment !== undefined) {
  5896. this.addComment(comment);
  5897. comments == null || comments.push(comment);
  5898. }
  5899. break;
  5900. }
  5901. default:
  5902. break loop;
  5903. }
  5904. break;
  5905. default:
  5906. if (isWhitespace(ch)) {
  5907. ++this.state.pos;
  5908. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  5909. const pos = this.state.pos;
  5910. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  5911. const comment = this.skipLineComment(3);
  5912. if (comment !== undefined) {
  5913. this.addComment(comment);
  5914. comments == null || comments.push(comment);
  5915. }
  5916. } else {
  5917. break loop;
  5918. }
  5919. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  5920. const pos = this.state.pos;
  5921. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  5922. const comment = this.skipLineComment(4);
  5923. if (comment !== undefined) {
  5924. this.addComment(comment);
  5925. comments == null || comments.push(comment);
  5926. }
  5927. } else {
  5928. break loop;
  5929. }
  5930. } else {
  5931. break loop;
  5932. }
  5933. }
  5934. }
  5935. if ((comments == null ? void 0 : comments.length) > 0) {
  5936. const end = this.state.pos;
  5937. const commentWhitespace = {
  5938. start: this.sourceToOffsetPos(spaceStart),
  5939. end: this.sourceToOffsetPos(end),
  5940. comments,
  5941. leadingNode: null,
  5942. trailingNode: null,
  5943. containingNode: null
  5944. };
  5945. this.state.commentStack.push(commentWhitespace);
  5946. }
  5947. }
  5948. finishToken(type, val) {
  5949. this.state.end = this.state.pos;
  5950. this.state.endLoc = this.state.curPosition();
  5951. const prevType = this.state.type;
  5952. this.state.type = type;
  5953. this.state.value = val;
  5954. if (!this.isLookahead) {
  5955. this.updateContext(prevType);
  5956. }
  5957. }
  5958. replaceToken(type) {
  5959. this.state.type = type;
  5960. this.updateContext();
  5961. }
  5962. readToken_numberSign() {
  5963. if (this.state.pos === 0 && this.readToken_interpreter()) {
  5964. return;
  5965. }
  5966. const nextPos = this.state.pos + 1;
  5967. const next = this.codePointAtPos(nextPos);
  5968. if (next >= 48 && next <= 57) {
  5969. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  5970. }
  5971. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  5972. this.expectPlugin("recordAndTuple");
  5973. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  5974. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  5975. }
  5976. this.state.pos += 2;
  5977. if (next === 123) {
  5978. this.finishToken(7);
  5979. } else {
  5980. this.finishToken(1);
  5981. }
  5982. } else if (isIdentifierStart(next)) {
  5983. ++this.state.pos;
  5984. this.finishToken(139, this.readWord1(next));
  5985. } else if (next === 92) {
  5986. ++this.state.pos;
  5987. this.finishToken(139, this.readWord1());
  5988. } else {
  5989. this.finishOp(27, 1);
  5990. }
  5991. }
  5992. readToken_dot() {
  5993. const next = this.input.charCodeAt(this.state.pos + 1);
  5994. if (next >= 48 && next <= 57) {
  5995. this.readNumber(true);
  5996. return;
  5997. }
  5998. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  5999. this.state.pos += 3;
  6000. this.finishToken(21);
  6001. } else {
  6002. ++this.state.pos;
  6003. this.finishToken(16);
  6004. }
  6005. }
  6006. readToken_slash() {
  6007. const next = this.input.charCodeAt(this.state.pos + 1);
  6008. if (next === 61) {
  6009. this.finishOp(31, 2);
  6010. } else {
  6011. this.finishOp(56, 1);
  6012. }
  6013. }
  6014. readToken_interpreter() {
  6015. if (this.state.pos !== 0 || this.length < 2) return false;
  6016. let ch = this.input.charCodeAt(this.state.pos + 1);
  6017. if (ch !== 33) return false;
  6018. const start = this.state.pos;
  6019. this.state.pos += 1;
  6020. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  6021. ch = this.input.charCodeAt(this.state.pos);
  6022. }
  6023. const value = this.input.slice(start + 2, this.state.pos);
  6024. this.finishToken(28, value);
  6025. return true;
  6026. }
  6027. readToken_mult_modulo(code) {
  6028. let type = code === 42 ? 55 : 54;
  6029. let width = 1;
  6030. let next = this.input.charCodeAt(this.state.pos + 1);
  6031. if (code === 42 && next === 42) {
  6032. width++;
  6033. next = this.input.charCodeAt(this.state.pos + 2);
  6034. type = 57;
  6035. }
  6036. if (next === 61 && !this.state.inType) {
  6037. width++;
  6038. type = code === 37 ? 33 : 30;
  6039. }
  6040. this.finishOp(type, width);
  6041. }
  6042. readToken_pipe_amp(code) {
  6043. const next = this.input.charCodeAt(this.state.pos + 1);
  6044. if (next === code) {
  6045. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  6046. this.finishOp(30, 3);
  6047. } else {
  6048. this.finishOp(code === 124 ? 41 : 42, 2);
  6049. }
  6050. return;
  6051. }
  6052. if (code === 124) {
  6053. if (next === 62) {
  6054. this.finishOp(39, 2);
  6055. return;
  6056. }
  6057. if (this.hasPlugin("recordAndTuple") && next === 125) {
  6058. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6059. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6060. }
  6061. this.state.pos += 2;
  6062. this.finishToken(9);
  6063. return;
  6064. }
  6065. if (this.hasPlugin("recordAndTuple") && next === 93) {
  6066. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6067. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6068. }
  6069. this.state.pos += 2;
  6070. this.finishToken(4);
  6071. return;
  6072. }
  6073. }
  6074. if (next === 61) {
  6075. this.finishOp(30, 2);
  6076. return;
  6077. }
  6078. this.finishOp(code === 124 ? 43 : 45, 1);
  6079. }
  6080. readToken_caret() {
  6081. const next = this.input.charCodeAt(this.state.pos + 1);
  6082. if (next === 61 && !this.state.inType) {
  6083. this.finishOp(32, 2);
  6084. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  6085. proposal: "hack",
  6086. topicToken: "^^"
  6087. }])) {
  6088. this.finishOp(37, 2);
  6089. const lookaheadCh = this.input.codePointAt(this.state.pos);
  6090. if (lookaheadCh === 94) {
  6091. this.unexpected();
  6092. }
  6093. } else {
  6094. this.finishOp(44, 1);
  6095. }
  6096. }
  6097. readToken_atSign() {
  6098. const next = this.input.charCodeAt(this.state.pos + 1);
  6099. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  6100. proposal: "hack",
  6101. topicToken: "@@"
  6102. }])) {
  6103. this.finishOp(38, 2);
  6104. } else {
  6105. this.finishOp(26, 1);
  6106. }
  6107. }
  6108. readToken_plus_min(code) {
  6109. const next = this.input.charCodeAt(this.state.pos + 1);
  6110. if (next === code) {
  6111. this.finishOp(34, 2);
  6112. return;
  6113. }
  6114. if (next === 61) {
  6115. this.finishOp(30, 2);
  6116. } else {
  6117. this.finishOp(53, 1);
  6118. }
  6119. }
  6120. readToken_lt() {
  6121. const {
  6122. pos
  6123. } = this.state;
  6124. const next = this.input.charCodeAt(pos + 1);
  6125. if (next === 60) {
  6126. if (this.input.charCodeAt(pos + 2) === 61) {
  6127. this.finishOp(30, 3);
  6128. return;
  6129. }
  6130. this.finishOp(51, 2);
  6131. return;
  6132. }
  6133. if (next === 61) {
  6134. this.finishOp(49, 2);
  6135. return;
  6136. }
  6137. this.finishOp(47, 1);
  6138. }
  6139. readToken_gt() {
  6140. const {
  6141. pos
  6142. } = this.state;
  6143. const next = this.input.charCodeAt(pos + 1);
  6144. if (next === 62) {
  6145. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  6146. if (this.input.charCodeAt(pos + size) === 61) {
  6147. this.finishOp(30, size + 1);
  6148. return;
  6149. }
  6150. this.finishOp(52, size);
  6151. return;
  6152. }
  6153. if (next === 61) {
  6154. this.finishOp(49, 2);
  6155. return;
  6156. }
  6157. this.finishOp(48, 1);
  6158. }
  6159. readToken_eq_excl(code) {
  6160. const next = this.input.charCodeAt(this.state.pos + 1);
  6161. if (next === 61) {
  6162. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  6163. return;
  6164. }
  6165. if (code === 61 && next === 62) {
  6166. this.state.pos += 2;
  6167. this.finishToken(19);
  6168. return;
  6169. }
  6170. this.finishOp(code === 61 ? 29 : 35, 1);
  6171. }
  6172. readToken_question() {
  6173. const next = this.input.charCodeAt(this.state.pos + 1);
  6174. const next2 = this.input.charCodeAt(this.state.pos + 2);
  6175. if (next === 63) {
  6176. if (next2 === 61) {
  6177. this.finishOp(30, 3);
  6178. } else {
  6179. this.finishOp(40, 2);
  6180. }
  6181. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  6182. this.state.pos += 2;
  6183. this.finishToken(18);
  6184. } else {
  6185. ++this.state.pos;
  6186. this.finishToken(17);
  6187. }
  6188. }
  6189. getTokenFromCode(code) {
  6190. switch (code) {
  6191. case 46:
  6192. this.readToken_dot();
  6193. return;
  6194. case 40:
  6195. ++this.state.pos;
  6196. this.finishToken(10);
  6197. return;
  6198. case 41:
  6199. ++this.state.pos;
  6200. this.finishToken(11);
  6201. return;
  6202. case 59:
  6203. ++this.state.pos;
  6204. this.finishToken(13);
  6205. return;
  6206. case 44:
  6207. ++this.state.pos;
  6208. this.finishToken(12);
  6209. return;
  6210. case 91:
  6211. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6212. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6213. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6214. }
  6215. this.state.pos += 2;
  6216. this.finishToken(2);
  6217. } else {
  6218. ++this.state.pos;
  6219. this.finishToken(0);
  6220. }
  6221. return;
  6222. case 93:
  6223. ++this.state.pos;
  6224. this.finishToken(3);
  6225. return;
  6226. case 123:
  6227. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6228. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6229. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6230. }
  6231. this.state.pos += 2;
  6232. this.finishToken(6);
  6233. } else {
  6234. ++this.state.pos;
  6235. this.finishToken(5);
  6236. }
  6237. return;
  6238. case 125:
  6239. ++this.state.pos;
  6240. this.finishToken(8);
  6241. return;
  6242. case 58:
  6243. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  6244. this.finishOp(15, 2);
  6245. } else {
  6246. ++this.state.pos;
  6247. this.finishToken(14);
  6248. }
  6249. return;
  6250. case 63:
  6251. this.readToken_question();
  6252. return;
  6253. case 96:
  6254. this.readTemplateToken();
  6255. return;
  6256. case 48:
  6257. {
  6258. const next = this.input.charCodeAt(this.state.pos + 1);
  6259. if (next === 120 || next === 88) {
  6260. this.readRadixNumber(16);
  6261. return;
  6262. }
  6263. if (next === 111 || next === 79) {
  6264. this.readRadixNumber(8);
  6265. return;
  6266. }
  6267. if (next === 98 || next === 66) {
  6268. this.readRadixNumber(2);
  6269. return;
  6270. }
  6271. }
  6272. case 49:
  6273. case 50:
  6274. case 51:
  6275. case 52:
  6276. case 53:
  6277. case 54:
  6278. case 55:
  6279. case 56:
  6280. case 57:
  6281. this.readNumber(false);
  6282. return;
  6283. case 34:
  6284. case 39:
  6285. this.readString(code);
  6286. return;
  6287. case 47:
  6288. this.readToken_slash();
  6289. return;
  6290. case 37:
  6291. case 42:
  6292. this.readToken_mult_modulo(code);
  6293. return;
  6294. case 124:
  6295. case 38:
  6296. this.readToken_pipe_amp(code);
  6297. return;
  6298. case 94:
  6299. this.readToken_caret();
  6300. return;
  6301. case 43:
  6302. case 45:
  6303. this.readToken_plus_min(code);
  6304. return;
  6305. case 60:
  6306. this.readToken_lt();
  6307. return;
  6308. case 62:
  6309. this.readToken_gt();
  6310. return;
  6311. case 61:
  6312. case 33:
  6313. this.readToken_eq_excl(code);
  6314. return;
  6315. case 126:
  6316. this.finishOp(36, 1);
  6317. return;
  6318. case 64:
  6319. this.readToken_atSign();
  6320. return;
  6321. case 35:
  6322. this.readToken_numberSign();
  6323. return;
  6324. case 92:
  6325. this.readWord();
  6326. return;
  6327. default:
  6328. if (isIdentifierStart(code)) {
  6329. this.readWord(code);
  6330. return;
  6331. }
  6332. }
  6333. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  6334. unexpected: String.fromCodePoint(code)
  6335. });
  6336. }
  6337. finishOp(type, size) {
  6338. const str = this.input.slice(this.state.pos, this.state.pos + size);
  6339. this.state.pos += size;
  6340. this.finishToken(type, str);
  6341. }
  6342. readRegexp() {
  6343. const startLoc = this.state.startLoc;
  6344. const start = this.state.start + 1;
  6345. let escaped, inClass;
  6346. let {
  6347. pos
  6348. } = this.state;
  6349. for (;; ++pos) {
  6350. if (pos >= this.length) {
  6351. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6352. }
  6353. const ch = this.input.charCodeAt(pos);
  6354. if (isNewLine(ch)) {
  6355. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6356. }
  6357. if (escaped) {
  6358. escaped = false;
  6359. } else {
  6360. if (ch === 91) {
  6361. inClass = true;
  6362. } else if (ch === 93 && inClass) {
  6363. inClass = false;
  6364. } else if (ch === 47 && !inClass) {
  6365. break;
  6366. }
  6367. escaped = ch === 92;
  6368. }
  6369. }
  6370. const content = this.input.slice(start, pos);
  6371. ++pos;
  6372. let mods = "";
  6373. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  6374. while (pos < this.length) {
  6375. const cp = this.codePointAtPos(pos);
  6376. const char = String.fromCharCode(cp);
  6377. if (VALID_REGEX_FLAGS.has(cp)) {
  6378. if (cp === 118) {
  6379. if (mods.includes("u")) {
  6380. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6381. }
  6382. } else if (cp === 117) {
  6383. if (mods.includes("v")) {
  6384. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6385. }
  6386. }
  6387. if (mods.includes(char)) {
  6388. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  6389. }
  6390. } else if (isIdentifierChar(cp) || cp === 92) {
  6391. this.raise(Errors.MalformedRegExpFlags, nextPos());
  6392. } else {
  6393. break;
  6394. }
  6395. ++pos;
  6396. mods += char;
  6397. }
  6398. this.state.pos = pos;
  6399. this.finishToken(138, {
  6400. pattern: content,
  6401. flags: mods
  6402. });
  6403. }
  6404. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  6405. const {
  6406. n,
  6407. pos
  6408. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  6409. this.state.pos = pos;
  6410. return n;
  6411. }
  6412. readRadixNumber(radix) {
  6413. const start = this.state.pos;
  6414. const startLoc = this.state.curPosition();
  6415. let isBigInt = false;
  6416. this.state.pos += 2;
  6417. const val = this.readInt(radix);
  6418. if (val == null) {
  6419. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  6420. radix
  6421. });
  6422. }
  6423. const next = this.input.charCodeAt(this.state.pos);
  6424. if (next === 110) {
  6425. ++this.state.pos;
  6426. isBigInt = true;
  6427. } else if (next === 109) {
  6428. throw this.raise(Errors.InvalidDecimal, startLoc);
  6429. }
  6430. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6431. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6432. }
  6433. if (isBigInt) {
  6434. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  6435. this.finishToken(136, str);
  6436. return;
  6437. }
  6438. this.finishToken(135, val);
  6439. }
  6440. readNumber(startsWithDot) {
  6441. const start = this.state.pos;
  6442. const startLoc = this.state.curPosition();
  6443. let isFloat = false;
  6444. let isBigInt = false;
  6445. let hasExponent = false;
  6446. let isOctal = false;
  6447. if (!startsWithDot && this.readInt(10) === null) {
  6448. this.raise(Errors.InvalidNumber, this.state.curPosition());
  6449. }
  6450. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  6451. if (hasLeadingZero) {
  6452. const integer = this.input.slice(start, this.state.pos);
  6453. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  6454. if (!this.state.strict) {
  6455. const underscorePos = integer.indexOf("_");
  6456. if (underscorePos > 0) {
  6457. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  6458. }
  6459. }
  6460. isOctal = hasLeadingZero && !/[89]/.test(integer);
  6461. }
  6462. let next = this.input.charCodeAt(this.state.pos);
  6463. if (next === 46 && !isOctal) {
  6464. ++this.state.pos;
  6465. this.readInt(10);
  6466. isFloat = true;
  6467. next = this.input.charCodeAt(this.state.pos);
  6468. }
  6469. if ((next === 69 || next === 101) && !isOctal) {
  6470. next = this.input.charCodeAt(++this.state.pos);
  6471. if (next === 43 || next === 45) {
  6472. ++this.state.pos;
  6473. }
  6474. if (this.readInt(10) === null) {
  6475. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  6476. }
  6477. isFloat = true;
  6478. hasExponent = true;
  6479. next = this.input.charCodeAt(this.state.pos);
  6480. }
  6481. if (next === 110) {
  6482. if (isFloat || hasLeadingZero) {
  6483. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  6484. }
  6485. ++this.state.pos;
  6486. isBigInt = true;
  6487. }
  6488. if (next === 109) {
  6489. this.expectPlugin("decimal", this.state.curPosition());
  6490. if (hasExponent || hasLeadingZero) {
  6491. this.raise(Errors.InvalidDecimal, startLoc);
  6492. }
  6493. ++this.state.pos;
  6494. var isDecimal = true;
  6495. }
  6496. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6497. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6498. }
  6499. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  6500. if (isBigInt) {
  6501. this.finishToken(136, str);
  6502. return;
  6503. }
  6504. if (isDecimal) {
  6505. this.finishToken(137, str);
  6506. return;
  6507. }
  6508. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  6509. this.finishToken(135, val);
  6510. }
  6511. readCodePoint(throwOnInvalid) {
  6512. const {
  6513. code,
  6514. pos
  6515. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  6516. this.state.pos = pos;
  6517. return code;
  6518. }
  6519. readString(quote) {
  6520. const {
  6521. str,
  6522. pos,
  6523. curLine,
  6524. lineStart
  6525. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  6526. this.state.pos = pos + 1;
  6527. this.state.lineStart = lineStart;
  6528. this.state.curLine = curLine;
  6529. this.finishToken(134, str);
  6530. }
  6531. readTemplateContinuation() {
  6532. if (!this.match(8)) {
  6533. this.unexpected(null, 8);
  6534. }
  6535. this.state.pos--;
  6536. this.readTemplateToken();
  6537. }
  6538. readTemplateToken() {
  6539. const opening = this.input[this.state.pos];
  6540. const {
  6541. str,
  6542. firstInvalidLoc,
  6543. pos,
  6544. curLine,
  6545. lineStart
  6546. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  6547. this.state.pos = pos + 1;
  6548. this.state.lineStart = lineStart;
  6549. this.state.curLine = curLine;
  6550. if (firstInvalidLoc) {
  6551. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  6552. }
  6553. if (this.input.codePointAt(pos) === 96) {
  6554. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  6555. } else {
  6556. this.state.pos++;
  6557. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  6558. }
  6559. }
  6560. recordStrictModeErrors(toParseError, at) {
  6561. const index = at.index;
  6562. if (this.state.strict && !this.state.strictErrors.has(index)) {
  6563. this.raise(toParseError, at);
  6564. } else {
  6565. this.state.strictErrors.set(index, [toParseError, at]);
  6566. }
  6567. }
  6568. readWord1(firstCode) {
  6569. this.state.containsEsc = false;
  6570. let word = "";
  6571. const start = this.state.pos;
  6572. let chunkStart = this.state.pos;
  6573. if (firstCode !== undefined) {
  6574. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  6575. }
  6576. while (this.state.pos < this.length) {
  6577. const ch = this.codePointAtPos(this.state.pos);
  6578. if (isIdentifierChar(ch)) {
  6579. this.state.pos += ch <= 0xffff ? 1 : 2;
  6580. } else if (ch === 92) {
  6581. this.state.containsEsc = true;
  6582. word += this.input.slice(chunkStart, this.state.pos);
  6583. const escStart = this.state.curPosition();
  6584. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  6585. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  6586. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  6587. chunkStart = this.state.pos - 1;
  6588. continue;
  6589. }
  6590. ++this.state.pos;
  6591. const esc = this.readCodePoint(true);
  6592. if (esc !== null) {
  6593. if (!identifierCheck(esc)) {
  6594. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  6595. }
  6596. word += String.fromCodePoint(esc);
  6597. }
  6598. chunkStart = this.state.pos;
  6599. } else {
  6600. break;
  6601. }
  6602. }
  6603. return word + this.input.slice(chunkStart, this.state.pos);
  6604. }
  6605. readWord(firstCode) {
  6606. const word = this.readWord1(firstCode);
  6607. const type = keywords$1.get(word);
  6608. if (type !== undefined) {
  6609. this.finishToken(type, tokenLabelName(type));
  6610. } else {
  6611. this.finishToken(132, word);
  6612. }
  6613. }
  6614. checkKeywordEscapes() {
  6615. const {
  6616. type
  6617. } = this.state;
  6618. if (tokenIsKeyword(type) && this.state.containsEsc) {
  6619. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  6620. reservedWord: tokenLabelName(type)
  6621. });
  6622. }
  6623. }
  6624. raise(toParseError, at, details = {}) {
  6625. const loc = at instanceof Position ? at : at.loc.start;
  6626. const error = toParseError(loc, details);
  6627. if (!(this.optionFlags & 2048)) throw error;
  6628. if (!this.isLookahead) this.state.errors.push(error);
  6629. return error;
  6630. }
  6631. raiseOverwrite(toParseError, at, details = {}) {
  6632. const loc = at instanceof Position ? at : at.loc.start;
  6633. const pos = loc.index;
  6634. const errors = this.state.errors;
  6635. for (let i = errors.length - 1; i >= 0; i--) {
  6636. const error = errors[i];
  6637. if (error.loc.index === pos) {
  6638. return errors[i] = toParseError(loc, details);
  6639. }
  6640. if (error.loc.index < pos) break;
  6641. }
  6642. return this.raise(toParseError, at, details);
  6643. }
  6644. updateContext(prevType) {}
  6645. unexpected(loc, type) {
  6646. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  6647. expected: type ? tokenLabelName(type) : null
  6648. });
  6649. }
  6650. expectPlugin(pluginName, loc) {
  6651. if (this.hasPlugin(pluginName)) {
  6652. return true;
  6653. }
  6654. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  6655. missingPlugin: [pluginName]
  6656. });
  6657. }
  6658. expectOnePlugin(pluginNames) {
  6659. if (!pluginNames.some(name => this.hasPlugin(name))) {
  6660. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  6661. missingPlugin: pluginNames
  6662. });
  6663. }
  6664. }
  6665. errorBuilder(error) {
  6666. return (pos, lineStart, curLine) => {
  6667. this.raise(error, buildPosition(pos, lineStart, curLine));
  6668. };
  6669. }
  6670. }
  6671. class ClassScope {
  6672. constructor() {
  6673. this.privateNames = new Set();
  6674. this.loneAccessors = new Map();
  6675. this.undefinedPrivateNames = new Map();
  6676. }
  6677. }
  6678. class ClassScopeHandler {
  6679. constructor(parser) {
  6680. this.parser = void 0;
  6681. this.stack = [];
  6682. this.undefinedPrivateNames = new Map();
  6683. this.parser = parser;
  6684. }
  6685. current() {
  6686. return this.stack[this.stack.length - 1];
  6687. }
  6688. enter() {
  6689. this.stack.push(new ClassScope());
  6690. }
  6691. exit() {
  6692. const oldClassScope = this.stack.pop();
  6693. const current = this.current();
  6694. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  6695. if (current) {
  6696. if (!current.undefinedPrivateNames.has(name)) {
  6697. current.undefinedPrivateNames.set(name, loc);
  6698. }
  6699. } else {
  6700. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6701. identifierName: name
  6702. });
  6703. }
  6704. }
  6705. }
  6706. declarePrivateName(name, elementType, loc) {
  6707. const {
  6708. privateNames,
  6709. loneAccessors,
  6710. undefinedPrivateNames
  6711. } = this.current();
  6712. let redefined = privateNames.has(name);
  6713. if (elementType & 3) {
  6714. const accessor = redefined && loneAccessors.get(name);
  6715. if (accessor) {
  6716. const oldStatic = accessor & 4;
  6717. const newStatic = elementType & 4;
  6718. const oldKind = accessor & 3;
  6719. const newKind = elementType & 3;
  6720. redefined = oldKind === newKind || oldStatic !== newStatic;
  6721. if (!redefined) loneAccessors.delete(name);
  6722. } else if (!redefined) {
  6723. loneAccessors.set(name, elementType);
  6724. }
  6725. }
  6726. if (redefined) {
  6727. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  6728. identifierName: name
  6729. });
  6730. }
  6731. privateNames.add(name);
  6732. undefinedPrivateNames.delete(name);
  6733. }
  6734. usePrivateName(name, loc) {
  6735. let classScope;
  6736. for (classScope of this.stack) {
  6737. if (classScope.privateNames.has(name)) return;
  6738. }
  6739. if (classScope) {
  6740. classScope.undefinedPrivateNames.set(name, loc);
  6741. } else {
  6742. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6743. identifierName: name
  6744. });
  6745. }
  6746. }
  6747. }
  6748. class ExpressionScope {
  6749. constructor(type = 0) {
  6750. this.type = type;
  6751. }
  6752. canBeArrowParameterDeclaration() {
  6753. return this.type === 2 || this.type === 1;
  6754. }
  6755. isCertainlyParameterDeclaration() {
  6756. return this.type === 3;
  6757. }
  6758. }
  6759. class ArrowHeadParsingScope extends ExpressionScope {
  6760. constructor(type) {
  6761. super(type);
  6762. this.declarationErrors = new Map();
  6763. }
  6764. recordDeclarationError(ParsingErrorClass, at) {
  6765. const index = at.index;
  6766. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  6767. }
  6768. clearDeclarationError(index) {
  6769. this.declarationErrors.delete(index);
  6770. }
  6771. iterateErrors(iterator) {
  6772. this.declarationErrors.forEach(iterator);
  6773. }
  6774. }
  6775. class ExpressionScopeHandler {
  6776. constructor(parser) {
  6777. this.parser = void 0;
  6778. this.stack = [new ExpressionScope()];
  6779. this.parser = parser;
  6780. }
  6781. enter(scope) {
  6782. this.stack.push(scope);
  6783. }
  6784. exit() {
  6785. this.stack.pop();
  6786. }
  6787. recordParameterInitializerError(toParseError, node) {
  6788. const origin = node.loc.start;
  6789. const {
  6790. stack
  6791. } = this;
  6792. let i = stack.length - 1;
  6793. let scope = stack[i];
  6794. while (!scope.isCertainlyParameterDeclaration()) {
  6795. if (scope.canBeArrowParameterDeclaration()) {
  6796. scope.recordDeclarationError(toParseError, origin);
  6797. } else {
  6798. return;
  6799. }
  6800. scope = stack[--i];
  6801. }
  6802. this.parser.raise(toParseError, origin);
  6803. }
  6804. recordArrowParameterBindingError(error, node) {
  6805. const {
  6806. stack
  6807. } = this;
  6808. const scope = stack[stack.length - 1];
  6809. const origin = node.loc.start;
  6810. if (scope.isCertainlyParameterDeclaration()) {
  6811. this.parser.raise(error, origin);
  6812. } else if (scope.canBeArrowParameterDeclaration()) {
  6813. scope.recordDeclarationError(error, origin);
  6814. } else {
  6815. return;
  6816. }
  6817. }
  6818. recordAsyncArrowParametersError(at) {
  6819. const {
  6820. stack
  6821. } = this;
  6822. let i = stack.length - 1;
  6823. let scope = stack[i];
  6824. while (scope.canBeArrowParameterDeclaration()) {
  6825. if (scope.type === 2) {
  6826. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  6827. }
  6828. scope = stack[--i];
  6829. }
  6830. }
  6831. validateAsPattern() {
  6832. const {
  6833. stack
  6834. } = this;
  6835. const currentScope = stack[stack.length - 1];
  6836. if (!currentScope.canBeArrowParameterDeclaration()) return;
  6837. currentScope.iterateErrors(([toParseError, loc]) => {
  6838. this.parser.raise(toParseError, loc);
  6839. let i = stack.length - 2;
  6840. let scope = stack[i];
  6841. while (scope.canBeArrowParameterDeclaration()) {
  6842. scope.clearDeclarationError(loc.index);
  6843. scope = stack[--i];
  6844. }
  6845. });
  6846. }
  6847. }
  6848. function newParameterDeclarationScope() {
  6849. return new ExpressionScope(3);
  6850. }
  6851. function newArrowHeadScope() {
  6852. return new ArrowHeadParsingScope(1);
  6853. }
  6854. function newAsyncArrowScope() {
  6855. return new ArrowHeadParsingScope(2);
  6856. }
  6857. function newExpressionScope() {
  6858. return new ExpressionScope();
  6859. }
  6860. class UtilParser extends Tokenizer {
  6861. addExtra(node, key, value, enumerable = true) {
  6862. if (!node) return;
  6863. let {
  6864. extra
  6865. } = node;
  6866. if (extra == null) {
  6867. extra = {};
  6868. node.extra = extra;
  6869. }
  6870. if (enumerable) {
  6871. extra[key] = value;
  6872. } else {
  6873. Object.defineProperty(extra, key, {
  6874. enumerable,
  6875. value
  6876. });
  6877. }
  6878. }
  6879. isContextual(token) {
  6880. return this.state.type === token && !this.state.containsEsc;
  6881. }
  6882. isUnparsedContextual(nameStart, name) {
  6883. if (this.input.startsWith(name, nameStart)) {
  6884. const nextCh = this.input.charCodeAt(nameStart + name.length);
  6885. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  6886. }
  6887. return false;
  6888. }
  6889. isLookaheadContextual(name) {
  6890. const next = this.nextTokenStart();
  6891. return this.isUnparsedContextual(next, name);
  6892. }
  6893. eatContextual(token) {
  6894. if (this.isContextual(token)) {
  6895. this.next();
  6896. return true;
  6897. }
  6898. return false;
  6899. }
  6900. expectContextual(token, toParseError) {
  6901. if (!this.eatContextual(token)) {
  6902. if (toParseError != null) {
  6903. throw this.raise(toParseError, this.state.startLoc);
  6904. }
  6905. this.unexpected(null, token);
  6906. }
  6907. }
  6908. canInsertSemicolon() {
  6909. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  6910. }
  6911. hasPrecedingLineBreak() {
  6912. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  6913. }
  6914. hasFollowingLineBreak() {
  6915. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  6916. }
  6917. isLineTerminator() {
  6918. return this.eat(13) || this.canInsertSemicolon();
  6919. }
  6920. semicolon(allowAsi = true) {
  6921. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  6922. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  6923. }
  6924. expect(type, loc) {
  6925. if (!this.eat(type)) {
  6926. this.unexpected(loc, type);
  6927. }
  6928. }
  6929. tryParse(fn, oldState = this.state.clone()) {
  6930. const abortSignal = {
  6931. node: null
  6932. };
  6933. try {
  6934. const node = fn((node = null) => {
  6935. abortSignal.node = node;
  6936. throw abortSignal;
  6937. });
  6938. if (this.state.errors.length > oldState.errors.length) {
  6939. const failState = this.state;
  6940. this.state = oldState;
  6941. this.state.tokensLength = failState.tokensLength;
  6942. return {
  6943. node,
  6944. error: failState.errors[oldState.errors.length],
  6945. thrown: false,
  6946. aborted: false,
  6947. failState
  6948. };
  6949. }
  6950. return {
  6951. node,
  6952. error: null,
  6953. thrown: false,
  6954. aborted: false,
  6955. failState: null
  6956. };
  6957. } catch (error) {
  6958. const failState = this.state;
  6959. this.state = oldState;
  6960. if (error instanceof SyntaxError) {
  6961. return {
  6962. node: null,
  6963. error,
  6964. thrown: true,
  6965. aborted: false,
  6966. failState
  6967. };
  6968. }
  6969. if (error === abortSignal) {
  6970. return {
  6971. node: abortSignal.node,
  6972. error: null,
  6973. thrown: false,
  6974. aborted: true,
  6975. failState
  6976. };
  6977. }
  6978. throw error;
  6979. }
  6980. }
  6981. checkExpressionErrors(refExpressionErrors, andThrow) {
  6982. if (!refExpressionErrors) return false;
  6983. const {
  6984. shorthandAssignLoc,
  6985. doubleProtoLoc,
  6986. privateKeyLoc,
  6987. optionalParametersLoc,
  6988. voidPatternLoc
  6989. } = refExpressionErrors;
  6990. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
  6991. if (!andThrow) {
  6992. return hasErrors;
  6993. }
  6994. if (shorthandAssignLoc != null) {
  6995. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  6996. }
  6997. if (doubleProtoLoc != null) {
  6998. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  6999. }
  7000. if (privateKeyLoc != null) {
  7001. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  7002. }
  7003. if (optionalParametersLoc != null) {
  7004. this.unexpected(optionalParametersLoc);
  7005. }
  7006. if (voidPatternLoc != null) {
  7007. this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
  7008. }
  7009. }
  7010. isLiteralPropertyName() {
  7011. return tokenIsLiteralPropertyName(this.state.type);
  7012. }
  7013. isPrivateName(node) {
  7014. return node.type === "PrivateName";
  7015. }
  7016. getPrivateNameSV(node) {
  7017. return node.id.name;
  7018. }
  7019. hasPropertyAsPrivateName(node) {
  7020. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  7021. }
  7022. isObjectProperty(node) {
  7023. return node.type === "ObjectProperty";
  7024. }
  7025. isObjectMethod(node) {
  7026. return node.type === "ObjectMethod";
  7027. }
  7028. initializeScopes(inModule = this.options.sourceType === "module") {
  7029. const oldLabels = this.state.labels;
  7030. this.state.labels = [];
  7031. const oldExportedIdentifiers = this.exportedIdentifiers;
  7032. this.exportedIdentifiers = new Set();
  7033. const oldInModule = this.inModule;
  7034. this.inModule = inModule;
  7035. const oldScope = this.scope;
  7036. const ScopeHandler = this.getScopeHandler();
  7037. this.scope = new ScopeHandler(this, inModule);
  7038. const oldProdParam = this.prodParam;
  7039. this.prodParam = new ProductionParameterHandler();
  7040. const oldClassScope = this.classScope;
  7041. this.classScope = new ClassScopeHandler(this);
  7042. const oldExpressionScope = this.expressionScope;
  7043. this.expressionScope = new ExpressionScopeHandler(this);
  7044. return () => {
  7045. this.state.labels = oldLabels;
  7046. this.exportedIdentifiers = oldExportedIdentifiers;
  7047. this.inModule = oldInModule;
  7048. this.scope = oldScope;
  7049. this.prodParam = oldProdParam;
  7050. this.classScope = oldClassScope;
  7051. this.expressionScope = oldExpressionScope;
  7052. };
  7053. }
  7054. enterInitialScopes() {
  7055. let paramFlags = 0;
  7056. if (this.inModule || this.optionFlags & 1) {
  7057. paramFlags |= 2;
  7058. }
  7059. if (this.optionFlags & 32) {
  7060. paramFlags |= 1;
  7061. }
  7062. const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
  7063. if (isCommonJS || this.optionFlags & 2) {
  7064. paramFlags |= 4;
  7065. }
  7066. this.prodParam.enter(paramFlags);
  7067. let scopeFlags = isCommonJS ? 514 : 1;
  7068. if (this.optionFlags & 4) {
  7069. scopeFlags |= 512;
  7070. }
  7071. this.scope.enter(scopeFlags);
  7072. }
  7073. checkDestructuringPrivate(refExpressionErrors) {
  7074. const {
  7075. privateKeyLoc
  7076. } = refExpressionErrors;
  7077. if (privateKeyLoc !== null) {
  7078. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  7079. }
  7080. }
  7081. }
  7082. class ExpressionErrors {
  7083. constructor() {
  7084. this.shorthandAssignLoc = null;
  7085. this.doubleProtoLoc = null;
  7086. this.privateKeyLoc = null;
  7087. this.optionalParametersLoc = null;
  7088. this.voidPatternLoc = null;
  7089. }
  7090. }
  7091. class Node {
  7092. constructor(parser, pos, loc) {
  7093. this.type = "";
  7094. this.start = pos;
  7095. this.end = 0;
  7096. this.loc = new SourceLocation(loc);
  7097. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  7098. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  7099. }
  7100. }
  7101. const NodePrototype = Node.prototype;
  7102. {
  7103. NodePrototype.__clone = function () {
  7104. const newNode = new Node(undefined, this.start, this.loc.start);
  7105. const keys = Object.keys(this);
  7106. for (let i = 0, length = keys.length; i < length; i++) {
  7107. const key = keys[i];
  7108. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  7109. newNode[key] = this[key];
  7110. }
  7111. }
  7112. return newNode;
  7113. };
  7114. }
  7115. class NodeUtils extends UtilParser {
  7116. startNode() {
  7117. const loc = this.state.startLoc;
  7118. return new Node(this, loc.index, loc);
  7119. }
  7120. startNodeAt(loc) {
  7121. return new Node(this, loc.index, loc);
  7122. }
  7123. startNodeAtNode(type) {
  7124. return this.startNodeAt(type.loc.start);
  7125. }
  7126. finishNode(node, type) {
  7127. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  7128. }
  7129. finishNodeAt(node, type, endLoc) {
  7130. node.type = type;
  7131. node.end = endLoc.index;
  7132. node.loc.end = endLoc;
  7133. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7134. if (this.optionFlags & 4096) {
  7135. this.processComment(node);
  7136. }
  7137. return node;
  7138. }
  7139. resetStartLocation(node, startLoc) {
  7140. node.start = startLoc.index;
  7141. node.loc.start = startLoc;
  7142. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  7143. }
  7144. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  7145. node.end = endLoc.index;
  7146. node.loc.end = endLoc;
  7147. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7148. }
  7149. resetStartLocationFromNode(node, locationNode) {
  7150. this.resetStartLocation(node, locationNode.loc.start);
  7151. }
  7152. castNodeTo(node, type) {
  7153. node.type = type;
  7154. return node;
  7155. }
  7156. cloneIdentifier(node) {
  7157. const {
  7158. type,
  7159. start,
  7160. end,
  7161. loc,
  7162. range,
  7163. name
  7164. } = node;
  7165. const cloned = Object.create(NodePrototype);
  7166. cloned.type = type;
  7167. cloned.start = start;
  7168. cloned.end = end;
  7169. cloned.loc = loc;
  7170. cloned.range = range;
  7171. cloned.name = name;
  7172. if (node.extra) cloned.extra = node.extra;
  7173. return cloned;
  7174. }
  7175. cloneStringLiteral(node) {
  7176. const {
  7177. type,
  7178. start,
  7179. end,
  7180. loc,
  7181. range,
  7182. extra
  7183. } = node;
  7184. const cloned = Object.create(NodePrototype);
  7185. cloned.type = type;
  7186. cloned.start = start;
  7187. cloned.end = end;
  7188. cloned.loc = loc;
  7189. cloned.range = range;
  7190. cloned.extra = extra;
  7191. cloned.value = node.value;
  7192. return cloned;
  7193. }
  7194. }
  7195. const unwrapParenthesizedExpression = node => {
  7196. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7197. };
  7198. class LValParser extends NodeUtils {
  7199. toAssignable(node, isLHS = false) {
  7200. var _node$extra, _node$extra3;
  7201. let parenthesized = undefined;
  7202. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7203. parenthesized = unwrapParenthesizedExpression(node);
  7204. if (isLHS) {
  7205. if (parenthesized.type === "Identifier") {
  7206. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7207. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7208. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7209. }
  7210. } else {
  7211. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7212. }
  7213. }
  7214. switch (node.type) {
  7215. case "Identifier":
  7216. case "ObjectPattern":
  7217. case "ArrayPattern":
  7218. case "AssignmentPattern":
  7219. case "RestElement":
  7220. case "VoidPattern":
  7221. break;
  7222. case "ObjectExpression":
  7223. this.castNodeTo(node, "ObjectPattern");
  7224. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7225. var _node$extra2;
  7226. const prop = node.properties[i];
  7227. const isLast = i === last;
  7228. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7229. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7230. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7231. }
  7232. }
  7233. break;
  7234. case "ObjectProperty":
  7235. {
  7236. const {
  7237. key,
  7238. value
  7239. } = node;
  7240. if (this.isPrivateName(key)) {
  7241. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7242. }
  7243. this.toAssignable(value, isLHS);
  7244. break;
  7245. }
  7246. case "SpreadElement":
  7247. {
  7248. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7249. }
  7250. case "ArrayExpression":
  7251. this.castNodeTo(node, "ArrayPattern");
  7252. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7253. break;
  7254. case "AssignmentExpression":
  7255. if (node.operator !== "=") {
  7256. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7257. }
  7258. this.castNodeTo(node, "AssignmentPattern");
  7259. delete node.operator;
  7260. if (node.left.type === "VoidPattern") {
  7261. this.raise(Errors.VoidPatternInitializer, node.left);
  7262. }
  7263. this.toAssignable(node.left, isLHS);
  7264. break;
  7265. case "ParenthesizedExpression":
  7266. this.toAssignable(parenthesized, isLHS);
  7267. break;
  7268. }
  7269. }
  7270. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7271. if (prop.type === "ObjectMethod") {
  7272. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7273. } else if (prop.type === "SpreadElement") {
  7274. this.castNodeTo(prop, "RestElement");
  7275. const arg = prop.argument;
  7276. this.checkToRestConversion(arg, false);
  7277. this.toAssignable(arg, isLHS);
  7278. if (!isLast) {
  7279. this.raise(Errors.RestTrailingComma, prop);
  7280. }
  7281. } else {
  7282. this.toAssignable(prop, isLHS);
  7283. }
  7284. }
  7285. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7286. const end = exprList.length - 1;
  7287. for (let i = 0; i <= end; i++) {
  7288. const elt = exprList[i];
  7289. if (!elt) continue;
  7290. this.toAssignableListItem(exprList, i, isLHS);
  7291. if (elt.type === "RestElement") {
  7292. if (i < end) {
  7293. this.raise(Errors.RestTrailingComma, elt);
  7294. } else if (trailingCommaLoc) {
  7295. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7296. }
  7297. }
  7298. }
  7299. }
  7300. toAssignableListItem(exprList, index, isLHS) {
  7301. const node = exprList[index];
  7302. if (node.type === "SpreadElement") {
  7303. this.castNodeTo(node, "RestElement");
  7304. const arg = node.argument;
  7305. this.checkToRestConversion(arg, true);
  7306. this.toAssignable(arg, isLHS);
  7307. } else {
  7308. this.toAssignable(node, isLHS);
  7309. }
  7310. }
  7311. isAssignable(node, isBinding) {
  7312. switch (node.type) {
  7313. case "Identifier":
  7314. case "ObjectPattern":
  7315. case "ArrayPattern":
  7316. case "AssignmentPattern":
  7317. case "RestElement":
  7318. case "VoidPattern":
  7319. return true;
  7320. case "ObjectExpression":
  7321. {
  7322. const last = node.properties.length - 1;
  7323. return node.properties.every((prop, i) => {
  7324. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7325. });
  7326. }
  7327. case "ObjectProperty":
  7328. return this.isAssignable(node.value);
  7329. case "SpreadElement":
  7330. return this.isAssignable(node.argument);
  7331. case "ArrayExpression":
  7332. return node.elements.every(element => element === null || this.isAssignable(element));
  7333. case "AssignmentExpression":
  7334. return node.operator === "=";
  7335. case "ParenthesizedExpression":
  7336. return this.isAssignable(node.expression);
  7337. case "MemberExpression":
  7338. case "OptionalMemberExpression":
  7339. return !isBinding;
  7340. default:
  7341. return false;
  7342. }
  7343. }
  7344. toReferencedList(exprList, isParenthesizedExpr) {
  7345. return exprList;
  7346. }
  7347. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7348. this.toReferencedList(exprList, isParenthesizedExpr);
  7349. for (const expr of exprList) {
  7350. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7351. this.toReferencedListDeep(expr.elements);
  7352. }
  7353. }
  7354. }
  7355. parseSpread(refExpressionErrors) {
  7356. const node = this.startNode();
  7357. this.next();
  7358. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7359. return this.finishNode(node, "SpreadElement");
  7360. }
  7361. parseRestBinding() {
  7362. const node = this.startNode();
  7363. this.next();
  7364. const argument = this.parseBindingAtom();
  7365. if (argument.type === "VoidPattern") {
  7366. this.raise(Errors.UnexpectedVoidPattern, argument);
  7367. }
  7368. node.argument = argument;
  7369. return this.finishNode(node, "RestElement");
  7370. }
  7371. parseBindingAtom() {
  7372. switch (this.state.type) {
  7373. case 0:
  7374. {
  7375. const node = this.startNode();
  7376. this.next();
  7377. node.elements = this.parseBindingList(3, 93, 1);
  7378. return this.finishNode(node, "ArrayPattern");
  7379. }
  7380. case 5:
  7381. return this.parseObjectLike(8, true);
  7382. case 88:
  7383. return this.parseVoidPattern(null);
  7384. }
  7385. return this.parseIdentifier();
  7386. }
  7387. parseBindingList(close, closeCharCode, flags) {
  7388. const allowEmpty = flags & 1;
  7389. const elts = [];
  7390. let first = true;
  7391. while (!this.eat(close)) {
  7392. if (first) {
  7393. first = false;
  7394. } else {
  7395. this.expect(12);
  7396. }
  7397. if (allowEmpty && this.match(12)) {
  7398. elts.push(null);
  7399. } else if (this.eat(close)) {
  7400. break;
  7401. } else if (this.match(21)) {
  7402. let rest = this.parseRestBinding();
  7403. if (this.hasPlugin("flow") || flags & 2) {
  7404. rest = this.parseFunctionParamType(rest);
  7405. }
  7406. elts.push(rest);
  7407. if (!this.checkCommaAfterRest(closeCharCode)) {
  7408. this.expect(close);
  7409. break;
  7410. }
  7411. } else {
  7412. const decorators = [];
  7413. if (flags & 2) {
  7414. if (this.match(26) && this.hasPlugin("decorators")) {
  7415. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7416. }
  7417. while (this.match(26)) {
  7418. decorators.push(this.parseDecorator());
  7419. }
  7420. }
  7421. elts.push(this.parseBindingElement(flags, decorators));
  7422. }
  7423. }
  7424. return elts;
  7425. }
  7426. parseBindingRestProperty(prop) {
  7427. this.next();
  7428. if (this.hasPlugin("discardBinding") && this.match(88)) {
  7429. prop.argument = this.parseVoidPattern(null);
  7430. this.raise(Errors.UnexpectedVoidPattern, prop.argument);
  7431. } else {
  7432. prop.argument = this.parseIdentifier();
  7433. }
  7434. this.checkCommaAfterRest(125);
  7435. return this.finishNode(prop, "RestElement");
  7436. }
  7437. parseBindingProperty() {
  7438. const {
  7439. type,
  7440. startLoc
  7441. } = this.state;
  7442. if (type === 21) {
  7443. return this.parseBindingRestProperty(this.startNode());
  7444. }
  7445. const prop = this.startNode();
  7446. if (type === 139) {
  7447. this.expectPlugin("destructuringPrivate", startLoc);
  7448. this.classScope.usePrivateName(this.state.value, startLoc);
  7449. prop.key = this.parsePrivateName();
  7450. } else {
  7451. this.parsePropertyName(prop);
  7452. }
  7453. prop.method = false;
  7454. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7455. }
  7456. parseBindingElement(flags, decorators) {
  7457. const left = this.parseMaybeDefault();
  7458. if (this.hasPlugin("flow") || flags & 2) {
  7459. this.parseFunctionParamType(left);
  7460. }
  7461. if (decorators.length) {
  7462. left.decorators = decorators;
  7463. this.resetStartLocationFromNode(left, decorators[0]);
  7464. }
  7465. const elt = this.parseMaybeDefault(left.loc.start, left);
  7466. return elt;
  7467. }
  7468. parseFunctionParamType(param) {
  7469. return param;
  7470. }
  7471. parseMaybeDefault(startLoc, left) {
  7472. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  7473. left = left != null ? left : this.parseBindingAtom();
  7474. if (!this.eat(29)) return left;
  7475. const node = this.startNodeAt(startLoc);
  7476. if (left.type === "VoidPattern") {
  7477. this.raise(Errors.VoidPatternInitializer, left);
  7478. }
  7479. node.left = left;
  7480. node.right = this.parseMaybeAssignAllowIn();
  7481. return this.finishNode(node, "AssignmentPattern");
  7482. }
  7483. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7484. switch (type) {
  7485. case "AssignmentPattern":
  7486. return "left";
  7487. case "RestElement":
  7488. return "argument";
  7489. case "ObjectProperty":
  7490. return "value";
  7491. case "ParenthesizedExpression":
  7492. return "expression";
  7493. case "ArrayPattern":
  7494. return "elements";
  7495. case "ObjectPattern":
  7496. return "properties";
  7497. case "VoidPattern":
  7498. return true;
  7499. }
  7500. return false;
  7501. }
  7502. isOptionalMemberExpression(expression) {
  7503. return expression.type === "OptionalMemberExpression";
  7504. }
  7505. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false) {
  7506. var _expression$extra;
  7507. const type = expression.type;
  7508. if (this.isObjectMethod(expression)) return;
  7509. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7510. if (isOptionalMemberExpression || type === "MemberExpression") {
  7511. if (isOptionalMemberExpression) {
  7512. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7513. if (ancestor.type !== "AssignmentExpression") {
  7514. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7515. ancestor
  7516. });
  7517. }
  7518. }
  7519. if (binding !== 64) {
  7520. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7521. }
  7522. return;
  7523. }
  7524. if (type === "Identifier") {
  7525. this.checkIdentifier(expression, binding, strictModeChanged);
  7526. const {
  7527. name
  7528. } = expression;
  7529. if (checkClashes) {
  7530. if (checkClashes.has(name)) {
  7531. this.raise(Errors.ParamDupe, expression);
  7532. } else {
  7533. checkClashes.add(name);
  7534. }
  7535. }
  7536. return;
  7537. } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
  7538. this.raise(Errors.VoidPatternCatchClauseParam, expression);
  7539. }
  7540. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7541. if (validity === true) return;
  7542. if (validity === false) {
  7543. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7544. this.raise(ParseErrorClass, expression, {
  7545. ancestor
  7546. });
  7547. return;
  7548. }
  7549. let key, isParenthesizedExpression;
  7550. if (typeof validity === "string") {
  7551. key = validity;
  7552. isParenthesizedExpression = type === "ParenthesizedExpression";
  7553. } else {
  7554. [key, isParenthesizedExpression] = validity;
  7555. }
  7556. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7557. type
  7558. } : ancestor;
  7559. const val = expression[key];
  7560. if (Array.isArray(val)) {
  7561. for (const child of val) {
  7562. if (child) {
  7563. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  7564. }
  7565. }
  7566. } else if (val) {
  7567. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  7568. }
  7569. }
  7570. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7571. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7572. if (bindingType === 64) {
  7573. this.raise(Errors.StrictEvalArguments, at, {
  7574. referenceName: at.name
  7575. });
  7576. } else {
  7577. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  7578. bindingName: at.name
  7579. });
  7580. }
  7581. }
  7582. if (bindingType & 8192 && at.name === "let") {
  7583. this.raise(Errors.LetInLexicalBinding, at);
  7584. }
  7585. if (!(bindingType & 64)) {
  7586. this.declareNameFromIdentifier(at, bindingType);
  7587. }
  7588. }
  7589. declareNameFromIdentifier(identifier, binding) {
  7590. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7591. }
  7592. checkToRestConversion(node, allowPattern) {
  7593. switch (node.type) {
  7594. case "ParenthesizedExpression":
  7595. this.checkToRestConversion(node.expression, allowPattern);
  7596. break;
  7597. case "Identifier":
  7598. case "MemberExpression":
  7599. break;
  7600. case "ArrayExpression":
  7601. case "ObjectExpression":
  7602. if (allowPattern) break;
  7603. default:
  7604. this.raise(Errors.InvalidRestAssignmentPattern, node);
  7605. }
  7606. }
  7607. checkCommaAfterRest(close) {
  7608. if (!this.match(12)) {
  7609. return false;
  7610. }
  7611. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  7612. return true;
  7613. }
  7614. }
  7615. function nonNull(x) {
  7616. if (x == null) {
  7617. throw new Error(`Unexpected ${x} value.`);
  7618. }
  7619. return x;
  7620. }
  7621. function assert(x) {
  7622. if (!x) {
  7623. throw new Error("Assert fail");
  7624. }
  7625. }
  7626. const TSErrors = ParseErrorEnum`typescript`({
  7627. AbstractMethodHasImplementation: ({
  7628. methodName
  7629. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7630. AbstractPropertyHasInitializer: ({
  7631. propertyName
  7632. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7633. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7634. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7635. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7636. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7637. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7638. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7639. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7640. DeclareAccessor: ({
  7641. kind
  7642. }) => `'declare' is not allowed in ${kind}ters.`,
  7643. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7644. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7645. DuplicateAccessibilityModifier: ({
  7646. modifier
  7647. }) => `Accessibility modifier already seen: '${modifier}'.`,
  7648. DuplicateModifier: ({
  7649. modifier
  7650. }) => `Duplicate modifier: '${modifier}'.`,
  7651. EmptyHeritageClauseType: ({
  7652. token
  7653. }) => `'${token}' list cannot be empty.`,
  7654. EmptyTypeArguments: "Type argument list cannot be empty.",
  7655. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7656. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7657. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7658. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7659. IncompatibleModifiers: ({
  7660. modifiers
  7661. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7662. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7663. IndexSignatureHasAccessibility: ({
  7664. modifier
  7665. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7666. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7667. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7668. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7669. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7670. InvalidHeritageClauseType: ({
  7671. token
  7672. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  7673. InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
  7674. InvalidModifierOnTypeMember: ({
  7675. modifier
  7676. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7677. InvalidModifierOnTypeParameter: ({
  7678. modifier
  7679. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7680. InvalidModifierOnTypeParameterPositions: ({
  7681. modifier
  7682. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7683. InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
  7684. InvalidModifiersOrder: ({
  7685. orderedModifiers
  7686. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7687. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7688. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7689. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7690. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7691. NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7692. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7693. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7694. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7695. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7696. PrivateElementHasAccessibility: ({
  7697. modifier
  7698. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7699. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7700. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7701. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7702. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7703. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7704. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7705. SingleTypeParameterWithoutTrailingComma: ({
  7706. typeParameterName
  7707. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7708. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7709. 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?`).",
  7710. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7711. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7712. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7713. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7714. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7715. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7716. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7717. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7718. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7719. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7720. UnsupportedSignatureParameterKind: ({
  7721. type
  7722. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
  7723. UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
  7724. });
  7725. function keywordTypeFromName(value) {
  7726. switch (value) {
  7727. case "any":
  7728. return "TSAnyKeyword";
  7729. case "boolean":
  7730. return "TSBooleanKeyword";
  7731. case "bigint":
  7732. return "TSBigIntKeyword";
  7733. case "never":
  7734. return "TSNeverKeyword";
  7735. case "number":
  7736. return "TSNumberKeyword";
  7737. case "object":
  7738. return "TSObjectKeyword";
  7739. case "string":
  7740. return "TSStringKeyword";
  7741. case "symbol":
  7742. return "TSSymbolKeyword";
  7743. case "undefined":
  7744. return "TSUndefinedKeyword";
  7745. case "unknown":
  7746. return "TSUnknownKeyword";
  7747. default:
  7748. return undefined;
  7749. }
  7750. }
  7751. function tsIsAccessModifier(modifier) {
  7752. return modifier === "private" || modifier === "public" || modifier === "protected";
  7753. }
  7754. function tsIsVarianceAnnotations(modifier) {
  7755. return modifier === "in" || modifier === "out";
  7756. }
  7757. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7758. constructor(...args) {
  7759. super(...args);
  7760. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7761. allowedModifiers: ["in", "out"],
  7762. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7763. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7764. });
  7765. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7766. allowedModifiers: ["const"],
  7767. disallowedModifiers: ["in", "out"],
  7768. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7769. });
  7770. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7771. allowedModifiers: ["in", "out", "const"],
  7772. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7773. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7774. });
  7775. }
  7776. getScopeHandler() {
  7777. return TypeScriptScopeHandler;
  7778. }
  7779. tsIsIdentifier() {
  7780. return tokenIsIdentifier(this.state.type);
  7781. }
  7782. tsTokenCanFollowModifier() {
  7783. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  7784. }
  7785. tsNextTokenOnSameLineAndCanFollowModifier() {
  7786. this.next();
  7787. if (this.hasPrecedingLineBreak()) {
  7788. return false;
  7789. }
  7790. return this.tsTokenCanFollowModifier();
  7791. }
  7792. tsNextTokenCanFollowModifier() {
  7793. if (this.match(106)) {
  7794. this.next();
  7795. return this.tsTokenCanFollowModifier();
  7796. }
  7797. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  7798. }
  7799. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
  7800. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7801. return undefined;
  7802. }
  7803. const modifier = this.state.value;
  7804. if (allowedModifiers.includes(modifier)) {
  7805. if (hasSeenStaticModifier && this.match(106)) {
  7806. return undefined;
  7807. }
  7808. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7809. return undefined;
  7810. }
  7811. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7812. return modifier;
  7813. }
  7814. }
  7815. return undefined;
  7816. }
  7817. tsParseModifiers({
  7818. allowedModifiers,
  7819. disallowedModifiers,
  7820. stopOnStartOfClassStaticBlock,
  7821. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7822. }, modified) {
  7823. const enforceOrder = (loc, modifier, before, after) => {
  7824. if (modifier === before && modified[after]) {
  7825. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7826. orderedModifiers: [before, after]
  7827. });
  7828. }
  7829. };
  7830. const incompatible = (loc, modifier, mod1, mod2) => {
  7831. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7832. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7833. modifiers: [mod1, mod2]
  7834. });
  7835. }
  7836. };
  7837. for (;;) {
  7838. const {
  7839. startLoc
  7840. } = this.state;
  7841. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
  7842. if (!modifier) break;
  7843. if (tsIsAccessModifier(modifier)) {
  7844. if (modified.accessibility) {
  7845. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7846. modifier
  7847. });
  7848. } else {
  7849. enforceOrder(startLoc, modifier, modifier, "override");
  7850. enforceOrder(startLoc, modifier, modifier, "static");
  7851. enforceOrder(startLoc, modifier, modifier, "readonly");
  7852. modified.accessibility = modifier;
  7853. }
  7854. } else if (tsIsVarianceAnnotations(modifier)) {
  7855. if (modified[modifier]) {
  7856. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7857. modifier
  7858. });
  7859. }
  7860. modified[modifier] = true;
  7861. enforceOrder(startLoc, modifier, "in", "out");
  7862. } else {
  7863. if (hasOwnProperty.call(modified, modifier)) {
  7864. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7865. modifier
  7866. });
  7867. } else {
  7868. enforceOrder(startLoc, modifier, "static", "readonly");
  7869. enforceOrder(startLoc, modifier, "static", "override");
  7870. enforceOrder(startLoc, modifier, "override", "readonly");
  7871. enforceOrder(startLoc, modifier, "abstract", "override");
  7872. incompatible(startLoc, modifier, "declare", "override");
  7873. incompatible(startLoc, modifier, "static", "abstract");
  7874. }
  7875. modified[modifier] = true;
  7876. }
  7877. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7878. this.raise(errorTemplate, startLoc, {
  7879. modifier
  7880. });
  7881. }
  7882. }
  7883. }
  7884. tsIsListTerminator(kind) {
  7885. switch (kind) {
  7886. case "EnumMembers":
  7887. case "TypeMembers":
  7888. return this.match(8);
  7889. case "HeritageClauseElement":
  7890. return this.match(5);
  7891. case "TupleElementTypes":
  7892. return this.match(3);
  7893. case "TypeParametersOrArguments":
  7894. return this.match(48);
  7895. }
  7896. }
  7897. tsParseList(kind, parseElement) {
  7898. const result = [];
  7899. while (!this.tsIsListTerminator(kind)) {
  7900. result.push(parseElement());
  7901. }
  7902. return result;
  7903. }
  7904. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7905. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7906. }
  7907. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7908. const result = [];
  7909. let trailingCommaPos = -1;
  7910. for (;;) {
  7911. if (this.tsIsListTerminator(kind)) {
  7912. break;
  7913. }
  7914. trailingCommaPos = -1;
  7915. const element = parseElement();
  7916. if (element == null) {
  7917. return undefined;
  7918. }
  7919. result.push(element);
  7920. if (this.eat(12)) {
  7921. trailingCommaPos = this.state.lastTokStartLoc.index;
  7922. continue;
  7923. }
  7924. if (this.tsIsListTerminator(kind)) {
  7925. break;
  7926. }
  7927. if (expectSuccess) {
  7928. this.expect(12);
  7929. }
  7930. return undefined;
  7931. }
  7932. if (refTrailingCommaPos) {
  7933. refTrailingCommaPos.value = trailingCommaPos;
  7934. }
  7935. return result;
  7936. }
  7937. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7938. if (!skipFirstToken) {
  7939. if (bracket) {
  7940. this.expect(0);
  7941. } else {
  7942. this.expect(47);
  7943. }
  7944. }
  7945. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7946. if (bracket) {
  7947. this.expect(3);
  7948. } else {
  7949. this.expect(48);
  7950. }
  7951. return result;
  7952. }
  7953. tsParseImportType() {
  7954. const node = this.startNode();
  7955. this.expect(83);
  7956. this.expect(10);
  7957. if (!this.match(134)) {
  7958. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7959. {
  7960. node.argument = super.parseExprAtom();
  7961. }
  7962. } else {
  7963. {
  7964. node.argument = this.parseStringLiteral(this.state.value);
  7965. }
  7966. }
  7967. if (this.eat(12)) {
  7968. node.options = this.tsParseImportTypeOptions();
  7969. } else {
  7970. node.options = null;
  7971. }
  7972. this.expect(11);
  7973. if (this.eat(16)) {
  7974. node.qualifier = this.tsParseEntityName(1 | 2);
  7975. }
  7976. if (this.match(47)) {
  7977. {
  7978. node.typeParameters = this.tsParseTypeArguments();
  7979. }
  7980. }
  7981. return this.finishNode(node, "TSImportType");
  7982. }
  7983. tsParseImportTypeOptions() {
  7984. const node = this.startNode();
  7985. this.expect(5);
  7986. const withProperty = this.startNode();
  7987. if (this.isContextual(76)) {
  7988. withProperty.method = false;
  7989. withProperty.key = this.parseIdentifier(true);
  7990. withProperty.computed = false;
  7991. withProperty.shorthand = false;
  7992. } else {
  7993. this.unexpected(null, 76);
  7994. }
  7995. this.expect(14);
  7996. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  7997. node.properties = [this.finishObjectProperty(withProperty)];
  7998. this.expect(8);
  7999. return this.finishNode(node, "ObjectExpression");
  8000. }
  8001. tsParseImportTypeWithPropertyValue() {
  8002. const node = this.startNode();
  8003. const properties = [];
  8004. this.expect(5);
  8005. while (!this.match(8)) {
  8006. const type = this.state.type;
  8007. if (tokenIsIdentifier(type) || type === 134) {
  8008. properties.push(super.parsePropertyDefinition(null));
  8009. } else {
  8010. this.unexpected();
  8011. }
  8012. this.eat(12);
  8013. }
  8014. node.properties = properties;
  8015. this.next();
  8016. return this.finishNode(node, "ObjectExpression");
  8017. }
  8018. tsParseEntityName(flags) {
  8019. let entity;
  8020. if (flags & 1 && this.match(78)) {
  8021. if (flags & 2) {
  8022. entity = this.parseIdentifier(true);
  8023. } else {
  8024. const node = this.startNode();
  8025. this.next();
  8026. entity = this.finishNode(node, "ThisExpression");
  8027. }
  8028. } else {
  8029. entity = this.parseIdentifier(!!(flags & 1));
  8030. }
  8031. while (this.eat(16)) {
  8032. const node = this.startNodeAtNode(entity);
  8033. node.left = entity;
  8034. node.right = this.parseIdentifier(!!(flags & 1));
  8035. entity = this.finishNode(node, "TSQualifiedName");
  8036. }
  8037. return entity;
  8038. }
  8039. tsParseTypeReference() {
  8040. const node = this.startNode();
  8041. node.typeName = this.tsParseEntityName(1);
  8042. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8043. {
  8044. node.typeParameters = this.tsParseTypeArguments();
  8045. }
  8046. }
  8047. return this.finishNode(node, "TSTypeReference");
  8048. }
  8049. tsParseThisTypePredicate(lhs) {
  8050. this.next();
  8051. const node = this.startNodeAtNode(lhs);
  8052. node.parameterName = lhs;
  8053. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  8054. node.asserts = false;
  8055. return this.finishNode(node, "TSTypePredicate");
  8056. }
  8057. tsParseThisTypeNode() {
  8058. const node = this.startNode();
  8059. this.next();
  8060. return this.finishNode(node, "TSThisType");
  8061. }
  8062. tsParseTypeQuery() {
  8063. const node = this.startNode();
  8064. this.expect(87);
  8065. if (this.match(83)) {
  8066. node.exprName = this.tsParseImportType();
  8067. } else {
  8068. {
  8069. node.exprName = this.tsParseEntityName(1 | 2);
  8070. }
  8071. }
  8072. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8073. {
  8074. node.typeParameters = this.tsParseTypeArguments();
  8075. }
  8076. }
  8077. return this.finishNode(node, "TSTypeQuery");
  8078. }
  8079. tsParseTypeParameter(parseModifiers) {
  8080. const node = this.startNode();
  8081. parseModifiers(node);
  8082. node.name = this.tsParseTypeParameterName();
  8083. node.constraint = this.tsEatThenParseType(81);
  8084. node.default = this.tsEatThenParseType(29);
  8085. return this.finishNode(node, "TSTypeParameter");
  8086. }
  8087. tsTryParseTypeParameters(parseModifiers) {
  8088. if (this.match(47)) {
  8089. return this.tsParseTypeParameters(parseModifiers);
  8090. }
  8091. }
  8092. tsParseTypeParameters(parseModifiers) {
  8093. const node = this.startNode();
  8094. if (this.match(47) || this.match(143)) {
  8095. this.next();
  8096. } else {
  8097. this.unexpected();
  8098. }
  8099. const refTrailingCommaPos = {
  8100. value: -1
  8101. };
  8102. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  8103. if (node.params.length === 0) {
  8104. this.raise(TSErrors.EmptyTypeParameters, node);
  8105. }
  8106. if (refTrailingCommaPos.value !== -1) {
  8107. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  8108. }
  8109. return this.finishNode(node, "TSTypeParameterDeclaration");
  8110. }
  8111. tsFillSignature(returnToken, signature) {
  8112. const returnTokenRequired = returnToken === 19;
  8113. const paramsKey = "parameters";
  8114. const returnTypeKey = "typeAnnotation";
  8115. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  8116. this.expect(10);
  8117. signature[paramsKey] = this.tsParseBindingListForSignature();
  8118. if (returnTokenRequired) {
  8119. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8120. } else if (this.match(returnToken)) {
  8121. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8122. }
  8123. }
  8124. tsParseBindingListForSignature() {
  8125. const list = super.parseBindingList(11, 41, 2);
  8126. for (const pattern of list) {
  8127. const {
  8128. type
  8129. } = pattern;
  8130. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  8131. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  8132. type
  8133. });
  8134. }
  8135. }
  8136. return list;
  8137. }
  8138. tsParseTypeMemberSemicolon() {
  8139. if (!this.eat(12) && !this.isLineTerminator()) {
  8140. this.expect(13);
  8141. }
  8142. }
  8143. tsParseSignatureMember(kind, node) {
  8144. this.tsFillSignature(14, node);
  8145. this.tsParseTypeMemberSemicolon();
  8146. return this.finishNode(node, kind);
  8147. }
  8148. tsIsUnambiguouslyIndexSignature() {
  8149. this.next();
  8150. if (tokenIsIdentifier(this.state.type)) {
  8151. this.next();
  8152. return this.match(14);
  8153. }
  8154. return false;
  8155. }
  8156. tsTryParseIndexSignature(node) {
  8157. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8158. return;
  8159. }
  8160. this.expect(0);
  8161. const id = this.parseIdentifier();
  8162. id.typeAnnotation = this.tsParseTypeAnnotation();
  8163. this.resetEndLocation(id);
  8164. this.expect(3);
  8165. node.parameters = [id];
  8166. const type = this.tsTryParseTypeAnnotation();
  8167. if (type) node.typeAnnotation = type;
  8168. this.tsParseTypeMemberSemicolon();
  8169. return this.finishNode(node, "TSIndexSignature");
  8170. }
  8171. tsParsePropertyOrMethodSignature(node, readonly) {
  8172. if (this.eat(17)) node.optional = true;
  8173. if (this.match(10) || this.match(47)) {
  8174. if (readonly) {
  8175. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  8176. }
  8177. const method = node;
  8178. if (method.kind && this.match(47)) {
  8179. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  8180. }
  8181. this.tsFillSignature(14, method);
  8182. this.tsParseTypeMemberSemicolon();
  8183. const paramsKey = "parameters";
  8184. const returnTypeKey = "typeAnnotation";
  8185. if (method.kind === "get") {
  8186. if (method[paramsKey].length > 0) {
  8187. this.raise(Errors.BadGetterArity, this.state.curPosition());
  8188. if (this.isThisParam(method[paramsKey][0])) {
  8189. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8190. }
  8191. }
  8192. } else if (method.kind === "set") {
  8193. if (method[paramsKey].length !== 1) {
  8194. this.raise(Errors.BadSetterArity, this.state.curPosition());
  8195. } else {
  8196. const firstParameter = method[paramsKey][0];
  8197. if (this.isThisParam(firstParameter)) {
  8198. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8199. }
  8200. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8201. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  8202. }
  8203. if (firstParameter.type === "RestElement") {
  8204. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  8205. }
  8206. }
  8207. if (method[returnTypeKey]) {
  8208. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  8209. }
  8210. } else {
  8211. method.kind = "method";
  8212. }
  8213. return this.finishNode(method, "TSMethodSignature");
  8214. } else {
  8215. const property = node;
  8216. if (readonly) property.readonly = true;
  8217. const type = this.tsTryParseTypeAnnotation();
  8218. if (type) property.typeAnnotation = type;
  8219. this.tsParseTypeMemberSemicolon();
  8220. return this.finishNode(property, "TSPropertySignature");
  8221. }
  8222. }
  8223. tsParseTypeMember() {
  8224. const node = this.startNode();
  8225. if (this.match(10) || this.match(47)) {
  8226. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8227. }
  8228. if (this.match(77)) {
  8229. const id = this.startNode();
  8230. this.next();
  8231. if (this.match(10) || this.match(47)) {
  8232. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8233. } else {
  8234. node.key = this.createIdentifier(id, "new");
  8235. return this.tsParsePropertyOrMethodSignature(node, false);
  8236. }
  8237. }
  8238. this.tsParseModifiers({
  8239. allowedModifiers: ["readonly"],
  8240. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8241. }, node);
  8242. const idx = this.tsTryParseIndexSignature(node);
  8243. if (idx) {
  8244. return idx;
  8245. }
  8246. super.parsePropertyName(node);
  8247. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8248. node.kind = node.key.name;
  8249. super.parsePropertyName(node);
  8250. if (!this.match(10) && !this.match(47)) {
  8251. this.unexpected(null, 10);
  8252. }
  8253. }
  8254. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8255. }
  8256. tsParseTypeLiteral() {
  8257. const node = this.startNode();
  8258. node.members = this.tsParseObjectTypeMembers();
  8259. return this.finishNode(node, "TSTypeLiteral");
  8260. }
  8261. tsParseObjectTypeMembers() {
  8262. this.expect(5);
  8263. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8264. this.expect(8);
  8265. return members;
  8266. }
  8267. tsIsStartOfMappedType() {
  8268. this.next();
  8269. if (this.eat(53)) {
  8270. return this.isContextual(122);
  8271. }
  8272. if (this.isContextual(122)) {
  8273. this.next();
  8274. }
  8275. if (!this.match(0)) {
  8276. return false;
  8277. }
  8278. this.next();
  8279. if (!this.tsIsIdentifier()) {
  8280. return false;
  8281. }
  8282. this.next();
  8283. return this.match(58);
  8284. }
  8285. tsParseMappedType() {
  8286. const node = this.startNode();
  8287. this.expect(5);
  8288. if (this.match(53)) {
  8289. node.readonly = this.state.value;
  8290. this.next();
  8291. this.expectContextual(122);
  8292. } else if (this.eatContextual(122)) {
  8293. node.readonly = true;
  8294. }
  8295. this.expect(0);
  8296. {
  8297. const typeParameter = this.startNode();
  8298. typeParameter.name = this.tsParseTypeParameterName();
  8299. typeParameter.constraint = this.tsExpectThenParseType(58);
  8300. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8301. }
  8302. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8303. this.expect(3);
  8304. if (this.match(53)) {
  8305. node.optional = this.state.value;
  8306. this.next();
  8307. this.expect(17);
  8308. } else if (this.eat(17)) {
  8309. node.optional = true;
  8310. }
  8311. node.typeAnnotation = this.tsTryParseType();
  8312. this.semicolon();
  8313. this.expect(8);
  8314. return this.finishNode(node, "TSMappedType");
  8315. }
  8316. tsParseTupleType() {
  8317. const node = this.startNode();
  8318. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8319. let seenOptionalElement = false;
  8320. node.elementTypes.forEach(elementNode => {
  8321. const {
  8322. type
  8323. } = elementNode;
  8324. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8325. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8326. }
  8327. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8328. });
  8329. return this.finishNode(node, "TSTupleType");
  8330. }
  8331. tsParseTupleElementType() {
  8332. const restStartLoc = this.state.startLoc;
  8333. const rest = this.eat(21);
  8334. const {
  8335. startLoc
  8336. } = this.state;
  8337. let labeled;
  8338. let label;
  8339. let optional;
  8340. let type;
  8341. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8342. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8343. if (chAfterWord === 58) {
  8344. labeled = true;
  8345. optional = false;
  8346. label = this.parseIdentifier(true);
  8347. this.expect(14);
  8348. type = this.tsParseType();
  8349. } else if (chAfterWord === 63) {
  8350. optional = true;
  8351. const wordName = this.state.value;
  8352. const typeOrLabel = this.tsParseNonArrayType();
  8353. if (this.lookaheadCharCode() === 58) {
  8354. labeled = true;
  8355. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8356. this.expect(17);
  8357. this.expect(14);
  8358. type = this.tsParseType();
  8359. } else {
  8360. labeled = false;
  8361. type = typeOrLabel;
  8362. this.expect(17);
  8363. }
  8364. } else {
  8365. type = this.tsParseType();
  8366. optional = this.eat(17);
  8367. labeled = this.eat(14);
  8368. }
  8369. if (labeled) {
  8370. let labeledNode;
  8371. if (label) {
  8372. labeledNode = this.startNodeAt(startLoc);
  8373. labeledNode.optional = optional;
  8374. labeledNode.label = label;
  8375. labeledNode.elementType = type;
  8376. if (this.eat(17)) {
  8377. labeledNode.optional = true;
  8378. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8379. }
  8380. } else {
  8381. labeledNode = this.startNodeAt(startLoc);
  8382. labeledNode.optional = optional;
  8383. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8384. labeledNode.label = type;
  8385. labeledNode.elementType = this.tsParseType();
  8386. }
  8387. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8388. } else if (optional) {
  8389. const optionalTypeNode = this.startNodeAt(startLoc);
  8390. optionalTypeNode.typeAnnotation = type;
  8391. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8392. }
  8393. if (rest) {
  8394. const restNode = this.startNodeAt(restStartLoc);
  8395. restNode.typeAnnotation = type;
  8396. type = this.finishNode(restNode, "TSRestType");
  8397. }
  8398. return type;
  8399. }
  8400. tsParseParenthesizedType() {
  8401. const node = this.startNode();
  8402. this.expect(10);
  8403. node.typeAnnotation = this.tsParseType();
  8404. this.expect(11);
  8405. return this.finishNode(node, "TSParenthesizedType");
  8406. }
  8407. tsParseFunctionOrConstructorType(type, abstract) {
  8408. const node = this.startNode();
  8409. if (type === "TSConstructorType") {
  8410. node.abstract = !!abstract;
  8411. if (abstract) this.next();
  8412. this.next();
  8413. }
  8414. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8415. return this.finishNode(node, type);
  8416. }
  8417. tsParseLiteralTypeNode() {
  8418. const node = this.startNode();
  8419. switch (this.state.type) {
  8420. case 135:
  8421. case 136:
  8422. case 134:
  8423. case 85:
  8424. case 86:
  8425. node.literal = super.parseExprAtom();
  8426. break;
  8427. default:
  8428. this.unexpected();
  8429. }
  8430. return this.finishNode(node, "TSLiteralType");
  8431. }
  8432. tsParseTemplateLiteralType() {
  8433. {
  8434. const node = this.startNode();
  8435. node.literal = super.parseTemplate(false);
  8436. return this.finishNode(node, "TSLiteralType");
  8437. }
  8438. }
  8439. parseTemplateSubstitution() {
  8440. if (this.state.inType) return this.tsParseType();
  8441. return super.parseTemplateSubstitution();
  8442. }
  8443. tsParseThisTypeOrThisTypePredicate() {
  8444. const thisKeyword = this.tsParseThisTypeNode();
  8445. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8446. return this.tsParseThisTypePredicate(thisKeyword);
  8447. } else {
  8448. return thisKeyword;
  8449. }
  8450. }
  8451. tsParseNonArrayType() {
  8452. switch (this.state.type) {
  8453. case 134:
  8454. case 135:
  8455. case 136:
  8456. case 85:
  8457. case 86:
  8458. return this.tsParseLiteralTypeNode();
  8459. case 53:
  8460. if (this.state.value === "-") {
  8461. const node = this.startNode();
  8462. const nextToken = this.lookahead();
  8463. if (nextToken.type !== 135 && nextToken.type !== 136) {
  8464. this.unexpected();
  8465. }
  8466. node.literal = this.parseMaybeUnary();
  8467. return this.finishNode(node, "TSLiteralType");
  8468. }
  8469. break;
  8470. case 78:
  8471. return this.tsParseThisTypeOrThisTypePredicate();
  8472. case 87:
  8473. return this.tsParseTypeQuery();
  8474. case 83:
  8475. return this.tsParseImportType();
  8476. case 5:
  8477. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8478. case 0:
  8479. return this.tsParseTupleType();
  8480. case 10:
  8481. return this.tsParseParenthesizedType();
  8482. case 25:
  8483. case 24:
  8484. return this.tsParseTemplateLiteralType();
  8485. default:
  8486. {
  8487. const {
  8488. type
  8489. } = this.state;
  8490. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8491. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8492. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8493. const node = this.startNode();
  8494. this.next();
  8495. return this.finishNode(node, nodeType);
  8496. }
  8497. return this.tsParseTypeReference();
  8498. }
  8499. }
  8500. }
  8501. this.unexpected();
  8502. }
  8503. tsParseArrayTypeOrHigher() {
  8504. const {
  8505. startLoc
  8506. } = this.state;
  8507. let type = this.tsParseNonArrayType();
  8508. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8509. if (this.match(3)) {
  8510. const node = this.startNodeAt(startLoc);
  8511. node.elementType = type;
  8512. this.expect(3);
  8513. type = this.finishNode(node, "TSArrayType");
  8514. } else {
  8515. const node = this.startNodeAt(startLoc);
  8516. node.objectType = type;
  8517. node.indexType = this.tsParseType();
  8518. this.expect(3);
  8519. type = this.finishNode(node, "TSIndexedAccessType");
  8520. }
  8521. }
  8522. return type;
  8523. }
  8524. tsParseTypeOperator() {
  8525. const node = this.startNode();
  8526. const operator = this.state.value;
  8527. this.next();
  8528. node.operator = operator;
  8529. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8530. if (operator === "readonly") {
  8531. this.tsCheckTypeAnnotationForReadOnly(node);
  8532. }
  8533. return this.finishNode(node, "TSTypeOperator");
  8534. }
  8535. tsCheckTypeAnnotationForReadOnly(node) {
  8536. switch (node.typeAnnotation.type) {
  8537. case "TSTupleType":
  8538. case "TSArrayType":
  8539. return;
  8540. default:
  8541. this.raise(TSErrors.UnexpectedReadonly, node);
  8542. }
  8543. }
  8544. tsParseInferType() {
  8545. const node = this.startNode();
  8546. this.expectContextual(115);
  8547. const typeParameter = this.startNode();
  8548. typeParameter.name = this.tsParseTypeParameterName();
  8549. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8550. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8551. return this.finishNode(node, "TSInferType");
  8552. }
  8553. tsParseConstraintForInferType() {
  8554. if (this.eat(81)) {
  8555. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8556. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8557. return constraint;
  8558. }
  8559. }
  8560. }
  8561. tsParseTypeOperatorOrHigher() {
  8562. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8563. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8564. }
  8565. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8566. const node = this.startNode();
  8567. const hasLeadingOperator = this.eat(operator);
  8568. const types = [];
  8569. do {
  8570. types.push(parseConstituentType());
  8571. } while (this.eat(operator));
  8572. if (types.length === 1 && !hasLeadingOperator) {
  8573. return types[0];
  8574. }
  8575. node.types = types;
  8576. return this.finishNode(node, kind);
  8577. }
  8578. tsParseIntersectionTypeOrHigher() {
  8579. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8580. }
  8581. tsParseUnionTypeOrHigher() {
  8582. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8583. }
  8584. tsIsStartOfFunctionType() {
  8585. if (this.match(47)) {
  8586. return true;
  8587. }
  8588. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8589. }
  8590. tsSkipParameterStart() {
  8591. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8592. this.next();
  8593. return true;
  8594. }
  8595. if (this.match(5)) {
  8596. const {
  8597. errors
  8598. } = this.state;
  8599. const previousErrorCount = errors.length;
  8600. try {
  8601. this.parseObjectLike(8, true);
  8602. return errors.length === previousErrorCount;
  8603. } catch (_unused) {
  8604. return false;
  8605. }
  8606. }
  8607. if (this.match(0)) {
  8608. this.next();
  8609. const {
  8610. errors
  8611. } = this.state;
  8612. const previousErrorCount = errors.length;
  8613. try {
  8614. super.parseBindingList(3, 93, 1);
  8615. return errors.length === previousErrorCount;
  8616. } catch (_unused2) {
  8617. return false;
  8618. }
  8619. }
  8620. return false;
  8621. }
  8622. tsIsUnambiguouslyStartOfFunctionType() {
  8623. this.next();
  8624. if (this.match(11) || this.match(21)) {
  8625. return true;
  8626. }
  8627. if (this.tsSkipParameterStart()) {
  8628. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8629. return true;
  8630. }
  8631. if (this.match(11)) {
  8632. this.next();
  8633. if (this.match(19)) {
  8634. return true;
  8635. }
  8636. }
  8637. }
  8638. return false;
  8639. }
  8640. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8641. return this.tsInType(() => {
  8642. const t = this.startNode();
  8643. this.expect(returnToken);
  8644. const node = this.startNode();
  8645. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8646. if (asserts && this.match(78)) {
  8647. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8648. if (thisTypePredicate.type === "TSThisType") {
  8649. node.parameterName = thisTypePredicate;
  8650. node.asserts = true;
  8651. node.typeAnnotation = null;
  8652. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8653. } else {
  8654. this.resetStartLocationFromNode(thisTypePredicate, node);
  8655. thisTypePredicate.asserts = true;
  8656. }
  8657. t.typeAnnotation = thisTypePredicate;
  8658. return this.finishNode(t, "TSTypeAnnotation");
  8659. }
  8660. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8661. if (!typePredicateVariable) {
  8662. if (!asserts) {
  8663. return this.tsParseTypeAnnotation(false, t);
  8664. }
  8665. node.parameterName = this.parseIdentifier();
  8666. node.asserts = asserts;
  8667. node.typeAnnotation = null;
  8668. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8669. return this.finishNode(t, "TSTypeAnnotation");
  8670. }
  8671. const type = this.tsParseTypeAnnotation(false);
  8672. node.parameterName = typePredicateVariable;
  8673. node.typeAnnotation = type;
  8674. node.asserts = asserts;
  8675. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8676. return this.finishNode(t, "TSTypeAnnotation");
  8677. });
  8678. }
  8679. tsTryParseTypeOrTypePredicateAnnotation() {
  8680. if (this.match(14)) {
  8681. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8682. }
  8683. }
  8684. tsTryParseTypeAnnotation() {
  8685. if (this.match(14)) {
  8686. return this.tsParseTypeAnnotation();
  8687. }
  8688. }
  8689. tsTryParseType() {
  8690. return this.tsEatThenParseType(14);
  8691. }
  8692. tsParseTypePredicatePrefix() {
  8693. const id = this.parseIdentifier();
  8694. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8695. this.next();
  8696. return id;
  8697. }
  8698. }
  8699. tsParseTypePredicateAsserts() {
  8700. if (this.state.type !== 109) {
  8701. return false;
  8702. }
  8703. const containsEsc = this.state.containsEsc;
  8704. this.next();
  8705. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8706. return false;
  8707. }
  8708. if (containsEsc) {
  8709. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8710. reservedWord: "asserts"
  8711. });
  8712. }
  8713. return true;
  8714. }
  8715. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8716. this.tsInType(() => {
  8717. if (eatColon) this.expect(14);
  8718. t.typeAnnotation = this.tsParseType();
  8719. });
  8720. return this.finishNode(t, "TSTypeAnnotation");
  8721. }
  8722. tsParseType() {
  8723. assert(this.state.inType);
  8724. const type = this.tsParseNonConditionalType();
  8725. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8726. return type;
  8727. }
  8728. const node = this.startNodeAtNode(type);
  8729. node.checkType = type;
  8730. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8731. this.expect(17);
  8732. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8733. this.expect(14);
  8734. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8735. return this.finishNode(node, "TSConditionalType");
  8736. }
  8737. isAbstractConstructorSignature() {
  8738. return this.isContextual(124) && this.isLookaheadContextual("new");
  8739. }
  8740. tsParseNonConditionalType() {
  8741. if (this.tsIsStartOfFunctionType()) {
  8742. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8743. }
  8744. if (this.match(77)) {
  8745. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8746. } else if (this.isAbstractConstructorSignature()) {
  8747. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8748. }
  8749. return this.tsParseUnionTypeOrHigher();
  8750. }
  8751. tsParseTypeAssertion() {
  8752. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8753. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8754. }
  8755. const node = this.startNode();
  8756. node.typeAnnotation = this.tsInType(() => {
  8757. this.next();
  8758. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8759. });
  8760. this.expect(48);
  8761. node.expression = this.parseMaybeUnary();
  8762. return this.finishNode(node, "TSTypeAssertion");
  8763. }
  8764. tsParseHeritageClause(token) {
  8765. const originalStartLoc = this.state.startLoc;
  8766. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8767. {
  8768. const node = this.startNode();
  8769. node.expression = this.tsParseEntityName(1 | 2);
  8770. if (this.match(47)) {
  8771. node.typeParameters = this.tsParseTypeArguments();
  8772. }
  8773. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8774. }
  8775. });
  8776. if (!delimitedList.length) {
  8777. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8778. token
  8779. });
  8780. }
  8781. return delimitedList;
  8782. }
  8783. tsParseInterfaceDeclaration(node, properties = {}) {
  8784. if (this.hasFollowingLineBreak()) return null;
  8785. this.expectContextual(129);
  8786. if (properties.declare) node.declare = true;
  8787. if (tokenIsIdentifier(this.state.type)) {
  8788. node.id = this.parseIdentifier();
  8789. this.checkIdentifier(node.id, 130);
  8790. } else {
  8791. node.id = null;
  8792. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8793. }
  8794. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8795. if (this.eat(81)) {
  8796. node.extends = this.tsParseHeritageClause("extends");
  8797. }
  8798. const body = this.startNode();
  8799. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8800. node.body = this.finishNode(body, "TSInterfaceBody");
  8801. return this.finishNode(node, "TSInterfaceDeclaration");
  8802. }
  8803. tsParseTypeAliasDeclaration(node) {
  8804. node.id = this.parseIdentifier();
  8805. this.checkIdentifier(node.id, 2);
  8806. node.typeAnnotation = this.tsInType(() => {
  8807. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8808. this.expect(29);
  8809. if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
  8810. const node = this.startNode();
  8811. this.next();
  8812. return this.finishNode(node, "TSIntrinsicKeyword");
  8813. }
  8814. return this.tsParseType();
  8815. });
  8816. this.semicolon();
  8817. return this.finishNode(node, "TSTypeAliasDeclaration");
  8818. }
  8819. tsInTopLevelContext(cb) {
  8820. if (this.curContext() !== types.brace) {
  8821. const oldContext = this.state.context;
  8822. this.state.context = [oldContext[0]];
  8823. try {
  8824. return cb();
  8825. } finally {
  8826. this.state.context = oldContext;
  8827. }
  8828. } else {
  8829. return cb();
  8830. }
  8831. }
  8832. tsInType(cb) {
  8833. const oldInType = this.state.inType;
  8834. this.state.inType = true;
  8835. try {
  8836. return cb();
  8837. } finally {
  8838. this.state.inType = oldInType;
  8839. }
  8840. }
  8841. tsInDisallowConditionalTypesContext(cb) {
  8842. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8843. this.state.inDisallowConditionalTypesContext = true;
  8844. try {
  8845. return cb();
  8846. } finally {
  8847. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8848. }
  8849. }
  8850. tsInAllowConditionalTypesContext(cb) {
  8851. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8852. this.state.inDisallowConditionalTypesContext = false;
  8853. try {
  8854. return cb();
  8855. } finally {
  8856. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8857. }
  8858. }
  8859. tsEatThenParseType(token) {
  8860. if (this.match(token)) {
  8861. return this.tsNextThenParseType();
  8862. }
  8863. }
  8864. tsExpectThenParseType(token) {
  8865. return this.tsInType(() => {
  8866. this.expect(token);
  8867. return this.tsParseType();
  8868. });
  8869. }
  8870. tsNextThenParseType() {
  8871. return this.tsInType(() => {
  8872. this.next();
  8873. return this.tsParseType();
  8874. });
  8875. }
  8876. tsParseEnumMember() {
  8877. const node = this.startNode();
  8878. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8879. if (this.eat(29)) {
  8880. node.initializer = super.parseMaybeAssignAllowIn();
  8881. }
  8882. return this.finishNode(node, "TSEnumMember");
  8883. }
  8884. tsParseEnumDeclaration(node, properties = {}) {
  8885. if (properties.const) node.const = true;
  8886. if (properties.declare) node.declare = true;
  8887. this.expectContextual(126);
  8888. node.id = this.parseIdentifier();
  8889. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8890. {
  8891. this.expect(5);
  8892. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8893. this.expect(8);
  8894. }
  8895. return this.finishNode(node, "TSEnumDeclaration");
  8896. }
  8897. tsParseEnumBody() {
  8898. const node = this.startNode();
  8899. this.expect(5);
  8900. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8901. this.expect(8);
  8902. return this.finishNode(node, "TSEnumBody");
  8903. }
  8904. tsParseModuleBlock() {
  8905. const node = this.startNode();
  8906. this.scope.enter(0);
  8907. this.expect(5);
  8908. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8909. this.scope.exit();
  8910. return this.finishNode(node, "TSModuleBlock");
  8911. }
  8912. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8913. node.id = this.parseIdentifier();
  8914. if (!nested) {
  8915. this.checkIdentifier(node.id, 1024);
  8916. }
  8917. if (this.eat(16)) {
  8918. const inner = this.startNode();
  8919. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8920. node.body = inner;
  8921. } else {
  8922. this.scope.enter(1024);
  8923. this.prodParam.enter(0);
  8924. node.body = this.tsParseModuleBlock();
  8925. this.prodParam.exit();
  8926. this.scope.exit();
  8927. }
  8928. return this.finishNode(node, "TSModuleDeclaration");
  8929. }
  8930. tsParseAmbientExternalModuleDeclaration(node) {
  8931. if (this.isContextual(112)) {
  8932. node.kind = "global";
  8933. {
  8934. node.global = true;
  8935. }
  8936. node.id = this.parseIdentifier();
  8937. } else if (this.match(134)) {
  8938. node.kind = "module";
  8939. node.id = super.parseStringLiteral(this.state.value);
  8940. } else {
  8941. this.unexpected();
  8942. }
  8943. if (this.match(5)) {
  8944. this.scope.enter(1024);
  8945. this.prodParam.enter(0);
  8946. node.body = this.tsParseModuleBlock();
  8947. this.prodParam.exit();
  8948. this.scope.exit();
  8949. } else {
  8950. this.semicolon();
  8951. }
  8952. return this.finishNode(node, "TSModuleDeclaration");
  8953. }
  8954. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8955. {
  8956. node.isExport = isExport || false;
  8957. }
  8958. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8959. this.checkIdentifier(node.id, 4096);
  8960. this.expect(29);
  8961. const moduleReference = this.tsParseModuleReference();
  8962. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8963. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8964. }
  8965. node.moduleReference = moduleReference;
  8966. this.semicolon();
  8967. return this.finishNode(node, "TSImportEqualsDeclaration");
  8968. }
  8969. tsIsExternalModuleReference() {
  8970. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8971. }
  8972. tsParseModuleReference() {
  8973. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  8974. }
  8975. tsParseExternalModuleReference() {
  8976. const node = this.startNode();
  8977. this.expectContextual(119);
  8978. this.expect(10);
  8979. if (!this.match(134)) {
  8980. this.unexpected();
  8981. }
  8982. node.expression = super.parseExprAtom();
  8983. this.expect(11);
  8984. this.sawUnambiguousESM = true;
  8985. return this.finishNode(node, "TSExternalModuleReference");
  8986. }
  8987. tsLookAhead(f) {
  8988. const state = this.state.clone();
  8989. const res = f();
  8990. this.state = state;
  8991. return res;
  8992. }
  8993. tsTryParseAndCatch(f) {
  8994. const result = this.tryParse(abort => f() || abort());
  8995. if (result.aborted || !result.node) return;
  8996. if (result.error) this.state = result.failState;
  8997. return result.node;
  8998. }
  8999. tsTryParse(f) {
  9000. const state = this.state.clone();
  9001. const result = f();
  9002. if (result !== undefined && result !== false) {
  9003. return result;
  9004. }
  9005. this.state = state;
  9006. }
  9007. tsTryParseDeclare(node) {
  9008. if (this.isLineTerminator()) {
  9009. return;
  9010. }
  9011. const startType = this.state.type;
  9012. return this.tsInAmbientContext(() => {
  9013. switch (startType) {
  9014. case 68:
  9015. node.declare = true;
  9016. return super.parseFunctionStatement(node, false, false);
  9017. case 80:
  9018. node.declare = true;
  9019. return this.parseClass(node, true, false);
  9020. case 126:
  9021. return this.tsParseEnumDeclaration(node, {
  9022. declare: true
  9023. });
  9024. case 112:
  9025. return this.tsParseAmbientExternalModuleDeclaration(node);
  9026. case 100:
  9027. if (this.state.containsEsc) {
  9028. return;
  9029. }
  9030. case 75:
  9031. case 74:
  9032. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  9033. node.declare = true;
  9034. return this.parseVarStatement(node, this.state.value, true);
  9035. }
  9036. this.expect(75);
  9037. return this.tsParseEnumDeclaration(node, {
  9038. const: true,
  9039. declare: true
  9040. });
  9041. case 107:
  9042. if (this.isUsing()) {
  9043. this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
  9044. node.declare = true;
  9045. return this.parseVarStatement(node, "using", true);
  9046. }
  9047. break;
  9048. case 96:
  9049. if (this.isAwaitUsing()) {
  9050. this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
  9051. node.declare = true;
  9052. this.next();
  9053. return this.parseVarStatement(node, "await using", true);
  9054. }
  9055. break;
  9056. case 129:
  9057. {
  9058. const result = this.tsParseInterfaceDeclaration(node, {
  9059. declare: true
  9060. });
  9061. if (result) return result;
  9062. }
  9063. default:
  9064. if (tokenIsIdentifier(startType)) {
  9065. return this.tsParseDeclaration(node, this.state.value, true, null);
  9066. }
  9067. }
  9068. });
  9069. }
  9070. tsTryParseExportDeclaration() {
  9071. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  9072. }
  9073. tsParseExpressionStatement(node, expr, decorators) {
  9074. switch (expr.name) {
  9075. case "declare":
  9076. {
  9077. const declaration = this.tsTryParseDeclare(node);
  9078. if (declaration) {
  9079. declaration.declare = true;
  9080. }
  9081. return declaration;
  9082. }
  9083. case "global":
  9084. if (this.match(5)) {
  9085. this.scope.enter(1024);
  9086. this.prodParam.enter(0);
  9087. const mod = node;
  9088. mod.kind = "global";
  9089. {
  9090. node.global = true;
  9091. }
  9092. mod.id = expr;
  9093. mod.body = this.tsParseModuleBlock();
  9094. this.scope.exit();
  9095. this.prodParam.exit();
  9096. return this.finishNode(mod, "TSModuleDeclaration");
  9097. }
  9098. break;
  9099. default:
  9100. return this.tsParseDeclaration(node, expr.name, false, decorators);
  9101. }
  9102. }
  9103. tsParseDeclaration(node, value, next, decorators) {
  9104. switch (value) {
  9105. case "abstract":
  9106. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  9107. return this.tsParseAbstractDeclaration(node, decorators);
  9108. }
  9109. break;
  9110. case "module":
  9111. if (this.tsCheckLineTerminator(next)) {
  9112. if (this.match(134)) {
  9113. return this.tsParseAmbientExternalModuleDeclaration(node);
  9114. } else if (tokenIsIdentifier(this.state.type)) {
  9115. node.kind = "module";
  9116. return this.tsParseModuleOrNamespaceDeclaration(node);
  9117. }
  9118. }
  9119. break;
  9120. case "namespace":
  9121. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9122. node.kind = "namespace";
  9123. return this.tsParseModuleOrNamespaceDeclaration(node);
  9124. }
  9125. break;
  9126. case "type":
  9127. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9128. return this.tsParseTypeAliasDeclaration(node);
  9129. }
  9130. break;
  9131. }
  9132. }
  9133. tsCheckLineTerminator(next) {
  9134. if (next) {
  9135. if (this.hasFollowingLineBreak()) return false;
  9136. this.next();
  9137. return true;
  9138. }
  9139. return !this.isLineTerminator();
  9140. }
  9141. tsTryParseGenericAsyncArrowFunction(startLoc) {
  9142. if (!this.match(47)) return;
  9143. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9144. this.state.maybeInArrowParameters = true;
  9145. const res = this.tsTryParseAndCatch(() => {
  9146. const node = this.startNodeAt(startLoc);
  9147. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9148. super.parseFunctionParams(node);
  9149. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9150. this.expect(19);
  9151. return node;
  9152. });
  9153. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9154. if (!res) return;
  9155. return super.parseArrowExpression(res, null, true);
  9156. }
  9157. tsParseTypeArgumentsInExpression() {
  9158. if (this.reScan_lt() !== 47) return;
  9159. return this.tsParseTypeArguments();
  9160. }
  9161. tsParseTypeArguments() {
  9162. const node = this.startNode();
  9163. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  9164. this.expect(47);
  9165. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9166. }));
  9167. if (node.params.length === 0) {
  9168. this.raise(TSErrors.EmptyTypeArguments, node);
  9169. } else if (!this.state.inType && this.curContext() === types.brace) {
  9170. this.reScan_lt_gt();
  9171. }
  9172. this.expect(48);
  9173. return this.finishNode(node, "TSTypeParameterInstantiation");
  9174. }
  9175. tsIsDeclarationStart() {
  9176. return tokenIsTSDeclarationStart(this.state.type);
  9177. }
  9178. isExportDefaultSpecifier() {
  9179. if (this.tsIsDeclarationStart()) return false;
  9180. return super.isExportDefaultSpecifier();
  9181. }
  9182. parseBindingElement(flags, decorators) {
  9183. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  9184. const modified = {};
  9185. this.tsParseModifiers({
  9186. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9187. }, modified);
  9188. const accessibility = modified.accessibility;
  9189. const override = modified.override;
  9190. const readonly = modified.readonly;
  9191. if (!(flags & 4) && (accessibility || readonly || override)) {
  9192. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  9193. }
  9194. const left = this.parseMaybeDefault();
  9195. if (flags & 2) {
  9196. this.parseFunctionParamType(left);
  9197. }
  9198. const elt = this.parseMaybeDefault(left.loc.start, left);
  9199. if (accessibility || readonly || override) {
  9200. const pp = this.startNodeAt(startLoc);
  9201. if (decorators.length) {
  9202. pp.decorators = decorators;
  9203. }
  9204. if (accessibility) pp.accessibility = accessibility;
  9205. if (readonly) pp.readonly = readonly;
  9206. if (override) pp.override = override;
  9207. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9208. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  9209. }
  9210. pp.parameter = elt;
  9211. return this.finishNode(pp, "TSParameterProperty");
  9212. }
  9213. if (decorators.length) {
  9214. left.decorators = decorators;
  9215. }
  9216. return elt;
  9217. }
  9218. isSimpleParameter(node) {
  9219. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9220. }
  9221. tsDisallowOptionalPattern(node) {
  9222. for (const param of node.params) {
  9223. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9224. this.raise(TSErrors.PatternIsOptional, param);
  9225. }
  9226. }
  9227. }
  9228. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9229. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9230. this.tsDisallowOptionalPattern(node);
  9231. }
  9232. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9233. if (this.match(14)) {
  9234. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9235. }
  9236. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9237. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9238. return this.finishNode(node, bodilessType);
  9239. }
  9240. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9241. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  9242. if (node.declare) {
  9243. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9244. }
  9245. }
  9246. this.tsDisallowOptionalPattern(node);
  9247. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9248. }
  9249. registerFunctionStatementId(node) {
  9250. if (!node.body && node.id) {
  9251. this.checkIdentifier(node.id, 1024);
  9252. } else {
  9253. super.registerFunctionStatementId(node);
  9254. }
  9255. }
  9256. tsCheckForInvalidTypeCasts(items) {
  9257. items.forEach(node => {
  9258. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9259. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  9260. }
  9261. });
  9262. }
  9263. toReferencedList(exprList, isInParens) {
  9264. this.tsCheckForInvalidTypeCasts(exprList);
  9265. return exprList;
  9266. }
  9267. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9268. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9269. if (node.type === "ArrayExpression") {
  9270. this.tsCheckForInvalidTypeCasts(node.elements);
  9271. }
  9272. return node;
  9273. }
  9274. parseSubscript(base, startLoc, noCalls, state) {
  9275. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9276. this.state.canStartJSXElement = false;
  9277. this.next();
  9278. const nonNullExpression = this.startNodeAt(startLoc);
  9279. nonNullExpression.expression = base;
  9280. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9281. }
  9282. let isOptionalCall = false;
  9283. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9284. if (noCalls) {
  9285. state.stop = true;
  9286. return base;
  9287. }
  9288. state.optionalChainMember = isOptionalCall = true;
  9289. this.next();
  9290. }
  9291. if (this.match(47) || this.match(51)) {
  9292. let missingParenErrorLoc;
  9293. const result = this.tsTryParseAndCatch(() => {
  9294. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9295. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9296. if (asyncArrowFn) {
  9297. return asyncArrowFn;
  9298. }
  9299. }
  9300. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9301. if (!typeArguments) return;
  9302. if (isOptionalCall && !this.match(10)) {
  9303. missingParenErrorLoc = this.state.curPosition();
  9304. return;
  9305. }
  9306. if (tokenIsTemplate(this.state.type)) {
  9307. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9308. {
  9309. result.typeParameters = typeArguments;
  9310. }
  9311. return result;
  9312. }
  9313. if (!noCalls && this.eat(10)) {
  9314. const node = this.startNodeAt(startLoc);
  9315. node.callee = base;
  9316. node.arguments = this.parseCallExpressionArguments();
  9317. this.tsCheckForInvalidTypeCasts(node.arguments);
  9318. {
  9319. node.typeParameters = typeArguments;
  9320. }
  9321. if (state.optionalChainMember) {
  9322. node.optional = isOptionalCall;
  9323. }
  9324. return this.finishCallExpression(node, state.optionalChainMember);
  9325. }
  9326. const tokenType = this.state.type;
  9327. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9328. return;
  9329. }
  9330. const node = this.startNodeAt(startLoc);
  9331. node.expression = base;
  9332. {
  9333. node.typeParameters = typeArguments;
  9334. }
  9335. return this.finishNode(node, "TSInstantiationExpression");
  9336. });
  9337. if (missingParenErrorLoc) {
  9338. this.unexpected(missingParenErrorLoc, 10);
  9339. }
  9340. if (result) {
  9341. if (result.type === "TSInstantiationExpression") {
  9342. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  9343. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  9344. }
  9345. if (!this.match(16) && !this.match(18)) {
  9346. result.expression = super.stopParseSubscript(base, state);
  9347. }
  9348. }
  9349. return result;
  9350. }
  9351. }
  9352. return super.parseSubscript(base, startLoc, noCalls, state);
  9353. }
  9354. parseNewCallee(node) {
  9355. var _callee$extra;
  9356. super.parseNewCallee(node);
  9357. const {
  9358. callee
  9359. } = node;
  9360. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9361. {
  9362. node.typeParameters = callee.typeParameters;
  9363. }
  9364. node.callee = callee.expression;
  9365. }
  9366. }
  9367. parseExprOp(left, leftStartLoc, minPrec) {
  9368. let isSatisfies;
  9369. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9370. const node = this.startNodeAt(leftStartLoc);
  9371. node.expression = left;
  9372. node.typeAnnotation = this.tsInType(() => {
  9373. this.next();
  9374. if (this.match(75)) {
  9375. if (isSatisfies) {
  9376. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9377. keyword: "const"
  9378. });
  9379. }
  9380. return this.tsParseTypeReference();
  9381. }
  9382. return this.tsParseType();
  9383. });
  9384. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9385. this.reScan_lt_gt();
  9386. return this.parseExprOp(node, leftStartLoc, minPrec);
  9387. }
  9388. return super.parseExprOp(left, leftStartLoc, minPrec);
  9389. }
  9390. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9391. if (!this.state.isAmbientContext) {
  9392. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9393. }
  9394. }
  9395. checkImportReflection(node) {
  9396. super.checkImportReflection(node);
  9397. if (node.module && node.importKind !== "value") {
  9398. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9399. }
  9400. }
  9401. checkDuplicateExports() {}
  9402. isPotentialImportPhase(isExport) {
  9403. if (super.isPotentialImportPhase(isExport)) return true;
  9404. if (this.isContextual(130)) {
  9405. const ch = this.lookaheadCharCode();
  9406. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9407. }
  9408. return !isExport && this.isContextual(87);
  9409. }
  9410. applyImportPhase(node, isExport, phase, loc) {
  9411. super.applyImportPhase(node, isExport, phase, loc);
  9412. if (isExport) {
  9413. node.exportKind = phase === "type" ? "type" : "value";
  9414. } else {
  9415. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9416. }
  9417. }
  9418. parseImport(node) {
  9419. if (this.match(134)) {
  9420. node.importKind = "value";
  9421. return super.parseImport(node);
  9422. }
  9423. let importNode;
  9424. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9425. node.importKind = "value";
  9426. return this.tsParseImportEqualsDeclaration(node);
  9427. } else if (this.isContextual(130)) {
  9428. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9429. if (this.lookaheadCharCode() === 61) {
  9430. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9431. } else {
  9432. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9433. }
  9434. } else {
  9435. importNode = super.parseImport(node);
  9436. }
  9437. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9438. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9439. }
  9440. return importNode;
  9441. }
  9442. parseExport(node, decorators) {
  9443. if (this.match(83)) {
  9444. const nodeImportEquals = node;
  9445. this.next();
  9446. let maybeDefaultIdentifier = null;
  9447. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9448. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9449. } else {
  9450. nodeImportEquals.importKind = "value";
  9451. }
  9452. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9453. {
  9454. return declaration;
  9455. }
  9456. } else if (this.eat(29)) {
  9457. const assign = node;
  9458. assign.expression = super.parseExpression();
  9459. this.semicolon();
  9460. this.sawUnambiguousESM = true;
  9461. return this.finishNode(assign, "TSExportAssignment");
  9462. } else if (this.eatContextual(93)) {
  9463. const decl = node;
  9464. this.expectContextual(128);
  9465. decl.id = this.parseIdentifier();
  9466. this.semicolon();
  9467. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9468. } else {
  9469. return super.parseExport(node, decorators);
  9470. }
  9471. }
  9472. isAbstractClass() {
  9473. return this.isContextual(124) && this.isLookaheadContextual("class");
  9474. }
  9475. parseExportDefaultExpression() {
  9476. if (this.isAbstractClass()) {
  9477. const cls = this.startNode();
  9478. this.next();
  9479. cls.abstract = true;
  9480. return this.parseClass(cls, true, true);
  9481. }
  9482. if (this.match(129)) {
  9483. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9484. if (result) return result;
  9485. }
  9486. return super.parseExportDefaultExpression();
  9487. }
  9488. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9489. const {
  9490. isAmbientContext
  9491. } = this.state;
  9492. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9493. if (!isAmbientContext) return declaration;
  9494. if (!node.declare && (kind === "using" || kind === "await using")) {
  9495. this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
  9496. return declaration;
  9497. }
  9498. for (const {
  9499. id,
  9500. init
  9501. } of declaration.declarations) {
  9502. if (!init) continue;
  9503. if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
  9504. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9505. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9506. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9507. }
  9508. }
  9509. return declaration;
  9510. }
  9511. parseStatementContent(flags, decorators) {
  9512. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9513. const node = this.startNode();
  9514. this.expect(75);
  9515. return this.tsParseEnumDeclaration(node, {
  9516. const: true
  9517. });
  9518. }
  9519. if (this.isContextual(126)) {
  9520. return this.tsParseEnumDeclaration(this.startNode());
  9521. }
  9522. if (this.isContextual(129)) {
  9523. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9524. if (result) return result;
  9525. }
  9526. return super.parseStatementContent(flags, decorators);
  9527. }
  9528. parseAccessModifier() {
  9529. return this.tsParseModifier(["public", "protected", "private"]);
  9530. }
  9531. tsHasSomeModifiers(member, modifiers) {
  9532. return modifiers.some(modifier => {
  9533. if (tsIsAccessModifier(modifier)) {
  9534. return member.accessibility === modifier;
  9535. }
  9536. return !!member[modifier];
  9537. });
  9538. }
  9539. tsIsStartOfStaticBlocks() {
  9540. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9541. }
  9542. parseClassMember(classBody, member, state) {
  9543. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9544. this.tsParseModifiers({
  9545. allowedModifiers: modifiers,
  9546. disallowedModifiers: ["in", "out"],
  9547. stopOnStartOfClassStaticBlock: true,
  9548. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9549. }, member);
  9550. const callParseClassMemberWithIsStatic = () => {
  9551. if (this.tsIsStartOfStaticBlocks()) {
  9552. this.next();
  9553. this.next();
  9554. if (this.tsHasSomeModifiers(member, modifiers)) {
  9555. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9556. }
  9557. super.parseClassStaticBlock(classBody, member);
  9558. } else {
  9559. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9560. }
  9561. };
  9562. if (member.declare) {
  9563. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9564. } else {
  9565. callParseClassMemberWithIsStatic();
  9566. }
  9567. }
  9568. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9569. const idx = this.tsTryParseIndexSignature(member);
  9570. if (idx) {
  9571. classBody.body.push(idx);
  9572. if (member.abstract) {
  9573. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9574. }
  9575. if (member.accessibility) {
  9576. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9577. modifier: member.accessibility
  9578. });
  9579. }
  9580. if (member.declare) {
  9581. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9582. }
  9583. if (member.override) {
  9584. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9585. }
  9586. return;
  9587. }
  9588. if (!this.state.inAbstractClass && member.abstract) {
  9589. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9590. }
  9591. if (member.override) {
  9592. if (!state.hadSuperClass) {
  9593. this.raise(TSErrors.OverrideNotInSubClass, member);
  9594. }
  9595. }
  9596. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9597. }
  9598. parsePostMemberNameModifiers(methodOrProp) {
  9599. const optional = this.eat(17);
  9600. if (optional) methodOrProp.optional = true;
  9601. if (methodOrProp.readonly && this.match(10)) {
  9602. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9603. }
  9604. if (methodOrProp.declare && this.match(10)) {
  9605. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9606. }
  9607. }
  9608. parseExpressionStatement(node, expr, decorators) {
  9609. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9610. return decl || super.parseExpressionStatement(node, expr, decorators);
  9611. }
  9612. shouldParseExportDeclaration() {
  9613. if (this.tsIsDeclarationStart()) return true;
  9614. return super.shouldParseExportDeclaration();
  9615. }
  9616. parseConditional(expr, startLoc, refExpressionErrors) {
  9617. if (!this.match(17)) return expr;
  9618. if (this.state.maybeInArrowParameters) {
  9619. const nextCh = this.lookaheadCharCode();
  9620. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  9621. this.setOptionalParametersError(refExpressionErrors);
  9622. return expr;
  9623. }
  9624. }
  9625. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9626. }
  9627. parseParenItem(node, startLoc) {
  9628. const newNode = super.parseParenItem(node, startLoc);
  9629. if (this.eat(17)) {
  9630. newNode.optional = true;
  9631. this.resetEndLocation(node);
  9632. }
  9633. if (this.match(14)) {
  9634. const typeCastNode = this.startNodeAt(startLoc);
  9635. typeCastNode.expression = node;
  9636. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9637. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9638. }
  9639. return node;
  9640. }
  9641. parseExportDeclaration(node) {
  9642. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9643. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9644. }
  9645. const startLoc = this.state.startLoc;
  9646. const isDeclare = this.eatContextual(125);
  9647. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9648. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9649. }
  9650. const isIdentifier = tokenIsIdentifier(this.state.type);
  9651. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9652. if (!declaration) return null;
  9653. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9654. node.exportKind = "type";
  9655. }
  9656. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  9657. this.resetStartLocation(declaration, startLoc);
  9658. declaration.declare = true;
  9659. }
  9660. return declaration;
  9661. }
  9662. parseClassId(node, isStatement, optionalId, bindingType) {
  9663. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9664. return;
  9665. }
  9666. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9667. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9668. if (typeParameters) node.typeParameters = typeParameters;
  9669. }
  9670. parseClassPropertyAnnotation(node) {
  9671. if (!node.optional) {
  9672. if (this.eat(35)) {
  9673. node.definite = true;
  9674. } else if (this.eat(17)) {
  9675. node.optional = true;
  9676. }
  9677. }
  9678. const type = this.tsTryParseTypeAnnotation();
  9679. if (type) node.typeAnnotation = type;
  9680. }
  9681. parseClassProperty(node) {
  9682. this.parseClassPropertyAnnotation(node);
  9683. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9684. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9685. }
  9686. if (node.abstract && this.match(29)) {
  9687. const {
  9688. key
  9689. } = node;
  9690. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9691. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9692. });
  9693. }
  9694. return super.parseClassProperty(node);
  9695. }
  9696. parseClassPrivateProperty(node) {
  9697. if (node.abstract) {
  9698. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9699. }
  9700. if (node.accessibility) {
  9701. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9702. modifier: node.accessibility
  9703. });
  9704. }
  9705. this.parseClassPropertyAnnotation(node);
  9706. return super.parseClassPrivateProperty(node);
  9707. }
  9708. parseClassAccessorProperty(node) {
  9709. this.parseClassPropertyAnnotation(node);
  9710. if (node.optional) {
  9711. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9712. }
  9713. return super.parseClassAccessorProperty(node);
  9714. }
  9715. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9716. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9717. if (typeParameters && isConstructor) {
  9718. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9719. }
  9720. const {
  9721. declare = false,
  9722. kind
  9723. } = method;
  9724. if (declare && (kind === "get" || kind === "set")) {
  9725. this.raise(TSErrors.DeclareAccessor, method, {
  9726. kind
  9727. });
  9728. }
  9729. if (typeParameters) method.typeParameters = typeParameters;
  9730. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9731. }
  9732. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9733. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9734. if (typeParameters) method.typeParameters = typeParameters;
  9735. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9736. }
  9737. declareClassPrivateMethodInScope(node, kind) {
  9738. if (node.type === "TSDeclareMethod") return;
  9739. if (node.type === "MethodDefinition" && node.value.body == null) {
  9740. return;
  9741. }
  9742. super.declareClassPrivateMethodInScope(node, kind);
  9743. }
  9744. parseClassSuper(node) {
  9745. super.parseClassSuper(node);
  9746. if (node.superClass && (this.match(47) || this.match(51))) {
  9747. {
  9748. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9749. }
  9750. }
  9751. if (this.eatContextual(113)) {
  9752. node.implements = this.tsParseHeritageClause("implements");
  9753. }
  9754. }
  9755. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9756. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9757. if (typeParameters) prop.typeParameters = typeParameters;
  9758. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9759. }
  9760. parseFunctionParams(node, isConstructor) {
  9761. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9762. if (typeParameters) node.typeParameters = typeParameters;
  9763. super.parseFunctionParams(node, isConstructor);
  9764. }
  9765. parseVarId(decl, kind) {
  9766. super.parseVarId(decl, kind);
  9767. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9768. decl.definite = true;
  9769. }
  9770. const type = this.tsTryParseTypeAnnotation();
  9771. if (type) {
  9772. decl.id.typeAnnotation = type;
  9773. this.resetEndLocation(decl.id);
  9774. }
  9775. }
  9776. parseAsyncArrowFromCallExpression(node, call) {
  9777. if (this.match(14)) {
  9778. node.returnType = this.tsParseTypeAnnotation();
  9779. }
  9780. return super.parseAsyncArrowFromCallExpression(node, call);
  9781. }
  9782. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9783. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9784. let state;
  9785. let jsx;
  9786. let typeCast;
  9787. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  9788. state = this.state.clone();
  9789. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9790. if (!jsx.error) return jsx.node;
  9791. const {
  9792. context
  9793. } = this.state;
  9794. const currentContext = context[context.length - 1];
  9795. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9796. context.pop();
  9797. }
  9798. }
  9799. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9800. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9801. }
  9802. if (!state || state === this.state) state = this.state.clone();
  9803. let typeParameters;
  9804. const arrow = this.tryParse(abort => {
  9805. var _expr$extra, _typeParameters;
  9806. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9807. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9808. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9809. abort();
  9810. }
  9811. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9812. this.resetStartLocationFromNode(expr, typeParameters);
  9813. }
  9814. expr.typeParameters = typeParameters;
  9815. return expr;
  9816. }, state);
  9817. if (!arrow.error && !arrow.aborted) {
  9818. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9819. return arrow.node;
  9820. }
  9821. if (!jsx) {
  9822. assert(!this.hasPlugin("jsx"));
  9823. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9824. if (!typeCast.error) return typeCast.node;
  9825. }
  9826. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9827. this.state = jsx.failState;
  9828. return jsx.node;
  9829. }
  9830. if (arrow.node) {
  9831. this.state = arrow.failState;
  9832. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9833. return arrow.node;
  9834. }
  9835. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9836. this.state = typeCast.failState;
  9837. return typeCast.node;
  9838. }
  9839. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9840. }
  9841. reportReservedArrowTypeParam(node) {
  9842. var _node$extra2;
  9843. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9844. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9845. }
  9846. }
  9847. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9848. if (!this.hasPlugin("jsx") && this.match(47)) {
  9849. return this.tsParseTypeAssertion();
  9850. }
  9851. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9852. }
  9853. parseArrow(node) {
  9854. if (this.match(14)) {
  9855. const result = this.tryParse(abort => {
  9856. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9857. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9858. return returnType;
  9859. });
  9860. if (result.aborted) return;
  9861. if (!result.thrown) {
  9862. if (result.error) this.state = result.failState;
  9863. node.returnType = result.node;
  9864. }
  9865. }
  9866. return super.parseArrow(node);
  9867. }
  9868. parseFunctionParamType(param) {
  9869. if (this.eat(17)) {
  9870. param.optional = true;
  9871. }
  9872. const type = this.tsTryParseTypeAnnotation();
  9873. if (type) param.typeAnnotation = type;
  9874. this.resetEndLocation(param);
  9875. return param;
  9876. }
  9877. isAssignable(node, isBinding) {
  9878. switch (node.type) {
  9879. case "TSTypeCastExpression":
  9880. return this.isAssignable(node.expression, isBinding);
  9881. case "TSParameterProperty":
  9882. return true;
  9883. default:
  9884. return super.isAssignable(node, isBinding);
  9885. }
  9886. }
  9887. toAssignable(node, isLHS = false) {
  9888. switch (node.type) {
  9889. case "ParenthesizedExpression":
  9890. this.toAssignableParenthesizedExpression(node, isLHS);
  9891. break;
  9892. case "TSAsExpression":
  9893. case "TSSatisfiesExpression":
  9894. case "TSNonNullExpression":
  9895. case "TSTypeAssertion":
  9896. if (isLHS) {
  9897. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9898. } else {
  9899. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9900. }
  9901. this.toAssignable(node.expression, isLHS);
  9902. break;
  9903. case "AssignmentExpression":
  9904. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9905. node.left = this.typeCastToParameter(node.left);
  9906. }
  9907. default:
  9908. super.toAssignable(node, isLHS);
  9909. }
  9910. }
  9911. toAssignableParenthesizedExpression(node, isLHS) {
  9912. switch (node.expression.type) {
  9913. case "TSAsExpression":
  9914. case "TSSatisfiesExpression":
  9915. case "TSNonNullExpression":
  9916. case "TSTypeAssertion":
  9917. case "ParenthesizedExpression":
  9918. this.toAssignable(node.expression, isLHS);
  9919. break;
  9920. default:
  9921. super.toAssignable(node, isLHS);
  9922. }
  9923. }
  9924. checkToRestConversion(node, allowPattern) {
  9925. switch (node.type) {
  9926. case "TSAsExpression":
  9927. case "TSSatisfiesExpression":
  9928. case "TSTypeAssertion":
  9929. case "TSNonNullExpression":
  9930. this.checkToRestConversion(node.expression, false);
  9931. break;
  9932. default:
  9933. super.checkToRestConversion(node, allowPattern);
  9934. }
  9935. }
  9936. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9937. switch (type) {
  9938. case "TSTypeCastExpression":
  9939. return true;
  9940. case "TSParameterProperty":
  9941. return "parameter";
  9942. case "TSNonNullExpression":
  9943. return "expression";
  9944. case "TSAsExpression":
  9945. case "TSSatisfiesExpression":
  9946. case "TSTypeAssertion":
  9947. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  9948. default:
  9949. return super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9950. }
  9951. }
  9952. parseBindingAtom() {
  9953. if (this.state.type === 78) {
  9954. return this.parseIdentifier(true);
  9955. }
  9956. return super.parseBindingAtom();
  9957. }
  9958. parseMaybeDecoratorArguments(expr, startLoc) {
  9959. if (this.match(47) || this.match(51)) {
  9960. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9961. if (this.match(10)) {
  9962. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  9963. {
  9964. call.typeParameters = typeArguments;
  9965. }
  9966. return call;
  9967. }
  9968. this.unexpected(null, 10);
  9969. }
  9970. return super.parseMaybeDecoratorArguments(expr, startLoc);
  9971. }
  9972. checkCommaAfterRest(close) {
  9973. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9974. this.next();
  9975. return false;
  9976. }
  9977. return super.checkCommaAfterRest(close);
  9978. }
  9979. isClassMethod() {
  9980. return this.match(47) || super.isClassMethod();
  9981. }
  9982. isClassProperty() {
  9983. return this.match(35) || this.match(14) || super.isClassProperty();
  9984. }
  9985. parseMaybeDefault(startLoc, left) {
  9986. const node = super.parseMaybeDefault(startLoc, left);
  9987. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9988. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  9989. }
  9990. return node;
  9991. }
  9992. getTokenFromCode(code) {
  9993. if (this.state.inType) {
  9994. if (code === 62) {
  9995. this.finishOp(48, 1);
  9996. return;
  9997. }
  9998. if (code === 60) {
  9999. this.finishOp(47, 1);
  10000. return;
  10001. }
  10002. }
  10003. super.getTokenFromCode(code);
  10004. }
  10005. reScan_lt_gt() {
  10006. const {
  10007. type
  10008. } = this.state;
  10009. if (type === 47) {
  10010. this.state.pos -= 1;
  10011. this.readToken_lt();
  10012. } else if (type === 48) {
  10013. this.state.pos -= 1;
  10014. this.readToken_gt();
  10015. }
  10016. }
  10017. reScan_lt() {
  10018. const {
  10019. type
  10020. } = this.state;
  10021. if (type === 51) {
  10022. this.state.pos -= 2;
  10023. this.finishOp(47, 1);
  10024. return 47;
  10025. }
  10026. return type;
  10027. }
  10028. toAssignableListItem(exprList, index, isLHS) {
  10029. const node = exprList[index];
  10030. if (node.type === "TSTypeCastExpression") {
  10031. exprList[index] = this.typeCastToParameter(node);
  10032. }
  10033. super.toAssignableListItem(exprList, index, isLHS);
  10034. }
  10035. typeCastToParameter(node) {
  10036. node.expression.typeAnnotation = node.typeAnnotation;
  10037. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  10038. return node.expression;
  10039. }
  10040. shouldParseArrow(params) {
  10041. if (this.match(14)) {
  10042. return params.every(expr => this.isAssignable(expr, true));
  10043. }
  10044. return super.shouldParseArrow(params);
  10045. }
  10046. shouldParseAsyncArrow() {
  10047. return this.match(14) || super.shouldParseAsyncArrow();
  10048. }
  10049. canHaveLeadingDecorator() {
  10050. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  10051. }
  10052. jsxParseOpeningElementAfterName(node) {
  10053. if (this.match(47) || this.match(51)) {
  10054. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  10055. if (typeArguments) {
  10056. {
  10057. node.typeParameters = typeArguments;
  10058. }
  10059. }
  10060. }
  10061. return super.jsxParseOpeningElementAfterName(node);
  10062. }
  10063. getGetterSetterExpectedParamCount(method) {
  10064. const baseCount = super.getGetterSetterExpectedParamCount(method);
  10065. const params = this.getObjectOrClassMethodParams(method);
  10066. const firstParam = params[0];
  10067. const hasContextParam = firstParam && this.isThisParam(firstParam);
  10068. return hasContextParam ? baseCount + 1 : baseCount;
  10069. }
  10070. parseCatchClauseParam() {
  10071. const param = super.parseCatchClauseParam();
  10072. const type = this.tsTryParseTypeAnnotation();
  10073. if (type) {
  10074. param.typeAnnotation = type;
  10075. this.resetEndLocation(param);
  10076. }
  10077. return param;
  10078. }
  10079. tsInAmbientContext(cb) {
  10080. const {
  10081. isAmbientContext: oldIsAmbientContext,
  10082. strict: oldStrict
  10083. } = this.state;
  10084. this.state.isAmbientContext = true;
  10085. this.state.strict = false;
  10086. try {
  10087. return cb();
  10088. } finally {
  10089. this.state.isAmbientContext = oldIsAmbientContext;
  10090. this.state.strict = oldStrict;
  10091. }
  10092. }
  10093. parseClass(node, isStatement, optionalId) {
  10094. const oldInAbstractClass = this.state.inAbstractClass;
  10095. this.state.inAbstractClass = !!node.abstract;
  10096. try {
  10097. return super.parseClass(node, isStatement, optionalId);
  10098. } finally {
  10099. this.state.inAbstractClass = oldInAbstractClass;
  10100. }
  10101. }
  10102. tsParseAbstractDeclaration(node, decorators) {
  10103. if (this.match(80)) {
  10104. node.abstract = true;
  10105. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  10106. } else if (this.isContextual(129)) {
  10107. if (!this.hasFollowingLineBreak()) {
  10108. node.abstract = true;
  10109. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
  10110. return this.tsParseInterfaceDeclaration(node);
  10111. }
  10112. } else {
  10113. this.unexpected(null, 80);
  10114. }
  10115. }
  10116. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  10117. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  10118. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  10119. const hasEstreePlugin = this.hasPlugin("estree");
  10120. const methodFn = hasEstreePlugin ? method.value : method;
  10121. if (methodFn.body) {
  10122. const {
  10123. key
  10124. } = method;
  10125. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  10126. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  10127. });
  10128. }
  10129. }
  10130. return method;
  10131. }
  10132. tsParseTypeParameterName() {
  10133. const typeName = this.parseIdentifier();
  10134. return typeName.name;
  10135. }
  10136. shouldParseAsAmbientContext() {
  10137. return !!this.getPluginOption("typescript", "dts");
  10138. }
  10139. parse() {
  10140. if (this.shouldParseAsAmbientContext()) {
  10141. this.state.isAmbientContext = true;
  10142. }
  10143. return super.parse();
  10144. }
  10145. getExpression() {
  10146. if (this.shouldParseAsAmbientContext()) {
  10147. this.state.isAmbientContext = true;
  10148. }
  10149. return super.getExpression();
  10150. }
  10151. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10152. if (!isString && isMaybeTypeOnly) {
  10153. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10154. return this.finishNode(node, "ExportSpecifier");
  10155. }
  10156. node.exportKind = "value";
  10157. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10158. }
  10159. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10160. if (!importedIsString && isMaybeTypeOnly) {
  10161. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10162. return this.finishNode(specifier, "ImportSpecifier");
  10163. }
  10164. specifier.importKind = "value";
  10165. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  10166. }
  10167. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10168. const leftOfAsKey = isImport ? "imported" : "local";
  10169. const rightOfAsKey = isImport ? "local" : "exported";
  10170. let leftOfAs = node[leftOfAsKey];
  10171. let rightOfAs;
  10172. let hasTypeSpecifier = false;
  10173. let canParseAsKeyword = true;
  10174. const loc = leftOfAs.loc.start;
  10175. if (this.isContextual(93)) {
  10176. const firstAs = this.parseIdentifier();
  10177. if (this.isContextual(93)) {
  10178. const secondAs = this.parseIdentifier();
  10179. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10180. hasTypeSpecifier = true;
  10181. leftOfAs = firstAs;
  10182. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10183. canParseAsKeyword = false;
  10184. } else {
  10185. rightOfAs = secondAs;
  10186. canParseAsKeyword = false;
  10187. }
  10188. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10189. canParseAsKeyword = false;
  10190. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10191. } else {
  10192. hasTypeSpecifier = true;
  10193. leftOfAs = firstAs;
  10194. }
  10195. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10196. hasTypeSpecifier = true;
  10197. if (isImport) {
  10198. leftOfAs = this.parseIdentifier(true);
  10199. if (!this.isContextual(93)) {
  10200. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10201. }
  10202. } else {
  10203. leftOfAs = this.parseModuleExportName();
  10204. }
  10205. }
  10206. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10207. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  10208. }
  10209. node[leftOfAsKey] = leftOfAs;
  10210. node[rightOfAsKey] = rightOfAs;
  10211. const kindKey = isImport ? "importKind" : "exportKind";
  10212. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10213. if (canParseAsKeyword && this.eatContextual(93)) {
  10214. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10215. }
  10216. if (!node[rightOfAsKey]) {
  10217. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  10218. }
  10219. if (isImport) {
  10220. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10221. }
  10222. }
  10223. fillOptionalPropertiesForTSESLint(node) {
  10224. 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;
  10225. switch (node.type) {
  10226. case "ExpressionStatement":
  10227. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  10228. return;
  10229. case "RestElement":
  10230. node.value = undefined;
  10231. case "Identifier":
  10232. case "ArrayPattern":
  10233. case "AssignmentPattern":
  10234. case "ObjectPattern":
  10235. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  10236. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  10237. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  10238. return;
  10239. case "TSParameterProperty":
  10240. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  10241. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  10242. (_node$override = node.override) != null ? _node$override : node.override = false;
  10243. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  10244. (_node$static = node.static) != null ? _node$static : node.static = false;
  10245. return;
  10246. case "TSEmptyBodyFunctionExpression":
  10247. node.body = null;
  10248. case "TSDeclareFunction":
  10249. case "FunctionDeclaration":
  10250. case "FunctionExpression":
  10251. case "ClassMethod":
  10252. case "ClassPrivateMethod":
  10253. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  10254. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  10255. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  10256. return;
  10257. case "Property":
  10258. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  10259. return;
  10260. case "TSMethodSignature":
  10261. case "TSPropertySignature":
  10262. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  10263. case "TSIndexSignature":
  10264. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  10265. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  10266. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  10267. return;
  10268. case "TSAbstractPropertyDefinition":
  10269. case "PropertyDefinition":
  10270. case "TSAbstractAccessorProperty":
  10271. case "AccessorProperty":
  10272. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  10273. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  10274. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  10275. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  10276. case "TSAbstractMethodDefinition":
  10277. case "MethodDefinition":
  10278. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  10279. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  10280. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  10281. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  10282. return;
  10283. case "ClassExpression":
  10284. (_node$id = node.id) != null ? _node$id : node.id = null;
  10285. case "ClassDeclaration":
  10286. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  10287. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  10288. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  10289. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  10290. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  10291. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  10292. return;
  10293. case "TSTypeAliasDeclaration":
  10294. case "VariableDeclaration":
  10295. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  10296. return;
  10297. case "VariableDeclarator":
  10298. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  10299. return;
  10300. case "TSEnumDeclaration":
  10301. (_node$const = node.const) != null ? _node$const : node.const = false;
  10302. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  10303. return;
  10304. case "TSEnumMember":
  10305. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  10306. return;
  10307. case "TSImportType":
  10308. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  10309. (_node$options = node.options) != null ? _node$options : node.options = null;
  10310. return;
  10311. case "TSInterfaceDeclaration":
  10312. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  10313. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  10314. return;
  10315. case "TSModuleDeclaration":
  10316. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  10317. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  10318. return;
  10319. case "TSTypeParameter":
  10320. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  10321. (_node$in = node.in) != null ? _node$in : node.in = false;
  10322. (_node$out = node.out) != null ? _node$out : node.out = false;
  10323. return;
  10324. }
  10325. }
  10326. };
  10327. function isPossiblyLiteralEnum(expression) {
  10328. if (expression.type !== "MemberExpression") return false;
  10329. const {
  10330. computed,
  10331. property
  10332. } = expression;
  10333. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10334. return false;
  10335. }
  10336. return isUncomputedMemberExpressionChain(expression.object);
  10337. }
  10338. function isValidAmbientConstInitializer(expression, estree) {
  10339. var _expression$extra;
  10340. const {
  10341. type
  10342. } = expression;
  10343. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10344. return false;
  10345. }
  10346. if (estree) {
  10347. if (type === "Literal") {
  10348. const {
  10349. value
  10350. } = expression;
  10351. if (typeof value === "string" || typeof value === "boolean") {
  10352. return true;
  10353. }
  10354. }
  10355. } else {
  10356. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10357. return true;
  10358. }
  10359. }
  10360. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10361. return true;
  10362. }
  10363. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10364. return true;
  10365. }
  10366. if (isPossiblyLiteralEnum(expression)) {
  10367. return true;
  10368. }
  10369. return false;
  10370. }
  10371. function isNumber(expression, estree) {
  10372. if (estree) {
  10373. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10374. }
  10375. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10376. }
  10377. function isNegativeNumber(expression, estree) {
  10378. if (expression.type === "UnaryExpression") {
  10379. const {
  10380. operator,
  10381. argument
  10382. } = expression;
  10383. if (operator === "-" && isNumber(argument, estree)) {
  10384. return true;
  10385. }
  10386. }
  10387. return false;
  10388. }
  10389. function isUncomputedMemberExpressionChain(expression) {
  10390. if (expression.type === "Identifier") return true;
  10391. if (expression.type !== "MemberExpression" || expression.computed) {
  10392. return false;
  10393. }
  10394. return isUncomputedMemberExpressionChain(expression.object);
  10395. }
  10396. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10397. ClassNameIsRequired: "A class name is required.",
  10398. UnexpectedSpace: "Unexpected space in placeholder."
  10399. });
  10400. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10401. parsePlaceholder(expectedNode) {
  10402. if (this.match(133)) {
  10403. const node = this.startNode();
  10404. this.next();
  10405. this.assertNoSpace();
  10406. node.name = super.parseIdentifier(true);
  10407. this.assertNoSpace();
  10408. this.expect(133);
  10409. return this.finishPlaceholder(node, expectedNode);
  10410. }
  10411. }
  10412. finishPlaceholder(node, expectedNode) {
  10413. let placeholder = node;
  10414. if (!placeholder.expectedNode || !placeholder.type) {
  10415. placeholder = this.finishNode(placeholder, "Placeholder");
  10416. }
  10417. placeholder.expectedNode = expectedNode;
  10418. return placeholder;
  10419. }
  10420. getTokenFromCode(code) {
  10421. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10422. this.finishOp(133, 2);
  10423. } else {
  10424. super.getTokenFromCode(code);
  10425. }
  10426. }
  10427. parseExprAtom(refExpressionErrors) {
  10428. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10429. }
  10430. parseIdentifier(liberal) {
  10431. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10432. }
  10433. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10434. if (word !== undefined) {
  10435. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10436. }
  10437. }
  10438. cloneIdentifier(node) {
  10439. const cloned = super.cloneIdentifier(node);
  10440. if (cloned.type === "Placeholder") {
  10441. cloned.expectedNode = node.expectedNode;
  10442. }
  10443. return cloned;
  10444. }
  10445. cloneStringLiteral(node) {
  10446. if (node.type === "Placeholder") {
  10447. return this.cloneIdentifier(node);
  10448. }
  10449. return super.cloneStringLiteral(node);
  10450. }
  10451. parseBindingAtom() {
  10452. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10453. }
  10454. isValidLVal(type, isParenthesized, binding) {
  10455. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10456. }
  10457. toAssignable(node, isLHS) {
  10458. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10459. node.expectedNode = "Pattern";
  10460. } else {
  10461. super.toAssignable(node, isLHS);
  10462. }
  10463. }
  10464. chStartsBindingIdentifier(ch, pos) {
  10465. if (super.chStartsBindingIdentifier(ch, pos)) {
  10466. return true;
  10467. }
  10468. const next = this.nextTokenStart();
  10469. if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
  10470. return true;
  10471. }
  10472. return false;
  10473. }
  10474. verifyBreakContinue(node, isBreak) {
  10475. if (node.label && node.label.type === "Placeholder") return;
  10476. super.verifyBreakContinue(node, isBreak);
  10477. }
  10478. parseExpressionStatement(node, expr) {
  10479. var _expr$extra;
  10480. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10481. return super.parseExpressionStatement(node, expr);
  10482. }
  10483. if (this.match(14)) {
  10484. const stmt = node;
  10485. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10486. this.next();
  10487. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10488. return this.finishNode(stmt, "LabeledStatement");
  10489. }
  10490. this.semicolon();
  10491. const stmtPlaceholder = node;
  10492. stmtPlaceholder.name = expr.name;
  10493. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  10494. }
  10495. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10496. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10497. }
  10498. parseFunctionId(requireId) {
  10499. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10500. }
  10501. parseClass(node, isStatement, optionalId) {
  10502. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10503. this.next();
  10504. const oldStrict = this.state.strict;
  10505. const placeholder = this.parsePlaceholder("Identifier");
  10506. if (placeholder) {
  10507. if (this.match(81) || this.match(133) || this.match(5)) {
  10508. node.id = placeholder;
  10509. } else if (optionalId || !isStatement) {
  10510. node.id = null;
  10511. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10512. return this.finishNode(node, type);
  10513. } else {
  10514. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10515. }
  10516. } else {
  10517. this.parseClassId(node, isStatement, optionalId);
  10518. }
  10519. super.parseClassSuper(node);
  10520. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10521. return this.finishNode(node, type);
  10522. }
  10523. parseExport(node, decorators) {
  10524. const placeholder = this.parsePlaceholder("Identifier");
  10525. if (!placeholder) return super.parseExport(node, decorators);
  10526. const node2 = node;
  10527. if (!this.isContextual(98) && !this.match(12)) {
  10528. node2.specifiers = [];
  10529. node2.source = null;
  10530. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10531. return this.finishNode(node2, "ExportNamedDeclaration");
  10532. }
  10533. this.expectPlugin("exportDefaultFrom");
  10534. const specifier = this.startNode();
  10535. specifier.exported = placeholder;
  10536. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10537. return super.parseExport(node2, decorators);
  10538. }
  10539. isExportDefaultSpecifier() {
  10540. if (this.match(65)) {
  10541. const next = this.nextTokenStart();
  10542. if (this.isUnparsedContextual(next, "from")) {
  10543. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  10544. return true;
  10545. }
  10546. }
  10547. }
  10548. return super.isExportDefaultSpecifier();
  10549. }
  10550. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10551. var _specifiers;
  10552. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10553. return true;
  10554. }
  10555. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10556. }
  10557. checkExport(node) {
  10558. const {
  10559. specifiers
  10560. } = node;
  10561. if (specifiers != null && specifiers.length) {
  10562. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10563. }
  10564. super.checkExport(node);
  10565. node.specifiers = specifiers;
  10566. }
  10567. parseImport(node) {
  10568. const placeholder = this.parsePlaceholder("Identifier");
  10569. if (!placeholder) return super.parseImport(node);
  10570. node.specifiers = [];
  10571. if (!this.isContextual(98) && !this.match(12)) {
  10572. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10573. this.semicolon();
  10574. return this.finishNode(node, "ImportDeclaration");
  10575. }
  10576. const specifier = this.startNodeAtNode(placeholder);
  10577. specifier.local = placeholder;
  10578. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10579. if (this.eat(12)) {
  10580. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10581. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10582. }
  10583. this.expectContextual(98);
  10584. node.source = this.parseImportSource();
  10585. this.semicolon();
  10586. return this.finishNode(node, "ImportDeclaration");
  10587. }
  10588. parseImportSource() {
  10589. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10590. }
  10591. assertNoSpace() {
  10592. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  10593. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10594. }
  10595. }
  10596. };
  10597. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10598. parseV8Intrinsic() {
  10599. if (this.match(54)) {
  10600. const v8IntrinsicStartLoc = this.state.startLoc;
  10601. const node = this.startNode();
  10602. this.next();
  10603. if (tokenIsIdentifier(this.state.type)) {
  10604. const name = this.parseIdentifierName();
  10605. const identifier = this.createIdentifier(node, name);
  10606. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  10607. if (this.match(10)) {
  10608. return identifier;
  10609. }
  10610. }
  10611. this.unexpected(v8IntrinsicStartLoc);
  10612. }
  10613. }
  10614. parseExprAtom(refExpressionErrors) {
  10615. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10616. }
  10617. };
  10618. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10619. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10620. function validatePlugins(pluginsMap) {
  10621. if (pluginsMap.has("decorators")) {
  10622. if (pluginsMap.has("decorators-legacy")) {
  10623. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10624. }
  10625. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  10626. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10627. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10628. }
  10629. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  10630. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10631. throw new Error("'allowCallParenthesized' must be a boolean.");
  10632. }
  10633. }
  10634. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  10635. throw new Error("Cannot combine flow and typescript plugins.");
  10636. }
  10637. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  10638. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10639. }
  10640. if (pluginsMap.has("pipelineOperator")) {
  10641. var _pluginsMap$get2;
  10642. const proposal = pluginsMap.get("pipelineOperator").proposal;
  10643. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10644. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10645. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10646. }
  10647. if (proposal === "hack") {
  10648. if (pluginsMap.has("placeholders")) {
  10649. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10650. }
  10651. if (pluginsMap.has("v8intrinsic")) {
  10652. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10653. }
  10654. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  10655. if (!TOPIC_TOKENS.includes(topicToken)) {
  10656. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10657. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10658. }
  10659. {
  10660. var _pluginsMap$get;
  10661. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  10662. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10663. }
  10664. }
  10665. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  10666. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10667. }
  10668. }
  10669. if (pluginsMap.has("moduleAttributes")) {
  10670. {
  10671. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  10672. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  10673. }
  10674. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  10675. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10676. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10677. }
  10678. }
  10679. }
  10680. if (pluginsMap.has("importAssertions")) {
  10681. if (pluginsMap.has("deprecatedImportAssert")) {
  10682. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  10683. }
  10684. }
  10685. if (!pluginsMap.has("deprecatedImportAssert") && pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  10686. {
  10687. pluginsMap.set("deprecatedImportAssert", {});
  10688. }
  10689. }
  10690. if (pluginsMap.has("recordAndTuple")) {
  10691. {
  10692. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  10693. if (syntaxType != null) {
  10694. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10695. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  10696. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10697. }
  10698. }
  10699. }
  10700. }
  10701. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  10702. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10703. error.missingPlugins = "doExpressions";
  10704. throw error;
  10705. }
  10706. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  10707. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10708. }
  10709. if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
  10710. throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
  10711. }
  10712. }
  10713. const mixinPlugins = {
  10714. estree,
  10715. jsx,
  10716. flow,
  10717. typescript,
  10718. v8intrinsic,
  10719. placeholders
  10720. };
  10721. const mixinPluginNames = Object.keys(mixinPlugins);
  10722. class ExpressionParser extends LValParser {
  10723. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  10724. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10725. return sawProto;
  10726. }
  10727. const key = prop.key;
  10728. const name = key.type === "Identifier" ? key.name : key.value;
  10729. if (name === "__proto__") {
  10730. if (isRecord) {
  10731. this.raise(Errors.RecordNoProto, key);
  10732. return true;
  10733. }
  10734. if (sawProto) {
  10735. if (refExpressionErrors) {
  10736. if (refExpressionErrors.doubleProtoLoc === null) {
  10737. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10738. }
  10739. } else {
  10740. this.raise(Errors.DuplicateProto, key);
  10741. }
  10742. }
  10743. return true;
  10744. }
  10745. return sawProto;
  10746. }
  10747. shouldExitDescending(expr, potentialArrowAt) {
  10748. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  10749. }
  10750. getExpression() {
  10751. this.enterInitialScopes();
  10752. this.nextToken();
  10753. if (this.match(140)) {
  10754. throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
  10755. }
  10756. const expr = this.parseExpression();
  10757. if (!this.match(140)) {
  10758. throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
  10759. unexpected: this.input.codePointAt(this.state.start)
  10760. });
  10761. }
  10762. this.finalizeRemainingComments();
  10763. expr.comments = this.comments;
  10764. expr.errors = this.state.errors;
  10765. if (this.optionFlags & 256) {
  10766. expr.tokens = this.tokens;
  10767. }
  10768. return expr;
  10769. }
  10770. parseExpression(disallowIn, refExpressionErrors) {
  10771. if (disallowIn) {
  10772. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10773. }
  10774. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10775. }
  10776. parseExpressionBase(refExpressionErrors) {
  10777. const startLoc = this.state.startLoc;
  10778. const expr = this.parseMaybeAssign(refExpressionErrors);
  10779. if (this.match(12)) {
  10780. const node = this.startNodeAt(startLoc);
  10781. node.expressions = [expr];
  10782. while (this.eat(12)) {
  10783. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10784. }
  10785. this.toReferencedList(node.expressions);
  10786. return this.finishNode(node, "SequenceExpression");
  10787. }
  10788. return expr;
  10789. }
  10790. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10791. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10792. }
  10793. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10794. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10795. }
  10796. setOptionalParametersError(refExpressionErrors) {
  10797. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  10798. }
  10799. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10800. const startLoc = this.state.startLoc;
  10801. const isYield = this.isContextual(108);
  10802. if (isYield) {
  10803. if (this.prodParam.hasYield) {
  10804. this.next();
  10805. let left = this.parseYield(startLoc);
  10806. if (afterLeftParse) {
  10807. left = afterLeftParse.call(this, left, startLoc);
  10808. }
  10809. return left;
  10810. }
  10811. }
  10812. let ownExpressionErrors;
  10813. if (refExpressionErrors) {
  10814. ownExpressionErrors = false;
  10815. } else {
  10816. refExpressionErrors = new ExpressionErrors();
  10817. ownExpressionErrors = true;
  10818. }
  10819. const {
  10820. type
  10821. } = this.state;
  10822. if (type === 10 || tokenIsIdentifier(type)) {
  10823. this.state.potentialArrowAt = this.state.start;
  10824. }
  10825. let left = this.parseMaybeConditional(refExpressionErrors);
  10826. if (afterLeftParse) {
  10827. left = afterLeftParse.call(this, left, startLoc);
  10828. }
  10829. if (tokenIsAssignment(this.state.type)) {
  10830. const node = this.startNodeAt(startLoc);
  10831. const operator = this.state.value;
  10832. node.operator = operator;
  10833. if (this.match(29)) {
  10834. this.toAssignable(left, true);
  10835. node.left = left;
  10836. const startIndex = startLoc.index;
  10837. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10838. refExpressionErrors.doubleProtoLoc = null;
  10839. }
  10840. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10841. refExpressionErrors.shorthandAssignLoc = null;
  10842. }
  10843. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10844. this.checkDestructuringPrivate(refExpressionErrors);
  10845. refExpressionErrors.privateKeyLoc = null;
  10846. }
  10847. if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
  10848. refExpressionErrors.voidPatternLoc = null;
  10849. }
  10850. } else {
  10851. node.left = left;
  10852. }
  10853. this.next();
  10854. node.right = this.parseMaybeAssign();
  10855. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"));
  10856. return node;
  10857. } else if (ownExpressionErrors) {
  10858. this.checkExpressionErrors(refExpressionErrors, true);
  10859. }
  10860. if (isYield) {
  10861. const {
  10862. type
  10863. } = this.state;
  10864. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10865. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  10866. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  10867. return this.parseYield(startLoc);
  10868. }
  10869. }
  10870. return left;
  10871. }
  10872. parseMaybeConditional(refExpressionErrors) {
  10873. const startLoc = this.state.startLoc;
  10874. const potentialArrowAt = this.state.potentialArrowAt;
  10875. const expr = this.parseExprOps(refExpressionErrors);
  10876. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10877. return expr;
  10878. }
  10879. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10880. }
  10881. parseConditional(expr, startLoc, refExpressionErrors) {
  10882. if (this.eat(17)) {
  10883. const node = this.startNodeAt(startLoc);
  10884. node.test = expr;
  10885. node.consequent = this.parseMaybeAssignAllowIn();
  10886. this.expect(14);
  10887. node.alternate = this.parseMaybeAssign();
  10888. return this.finishNode(node, "ConditionalExpression");
  10889. }
  10890. return expr;
  10891. }
  10892. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10893. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10894. }
  10895. parseExprOps(refExpressionErrors) {
  10896. const startLoc = this.state.startLoc;
  10897. const potentialArrowAt = this.state.potentialArrowAt;
  10898. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10899. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10900. return expr;
  10901. }
  10902. return this.parseExprOp(expr, startLoc, -1);
  10903. }
  10904. parseExprOp(left, leftStartLoc, minPrec) {
  10905. if (this.isPrivateName(left)) {
  10906. const value = this.getPrivateNameSV(left);
  10907. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10908. this.raise(Errors.PrivateInExpectedIn, left, {
  10909. identifierName: value
  10910. });
  10911. }
  10912. this.classScope.usePrivateName(value, left.loc.start);
  10913. }
  10914. const op = this.state.type;
  10915. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10916. let prec = tokenOperatorPrecedence(op);
  10917. if (prec > minPrec) {
  10918. if (op === 39) {
  10919. this.expectPlugin("pipelineOperator");
  10920. if (this.state.inFSharpPipelineDirectBody) {
  10921. return left;
  10922. }
  10923. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10924. }
  10925. const node = this.startNodeAt(leftStartLoc);
  10926. node.left = left;
  10927. node.operator = this.state.value;
  10928. const logical = op === 41 || op === 42;
  10929. const coalesce = op === 40;
  10930. if (coalesce) {
  10931. prec = tokenOperatorPrecedence(42);
  10932. }
  10933. this.next();
  10934. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10935. proposal: "minimal"
  10936. }])) {
  10937. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10938. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  10939. }
  10940. }
  10941. node.right = this.parseExprOpRightExpr(op, prec);
  10942. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10943. const nextOp = this.state.type;
  10944. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10945. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  10946. }
  10947. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10948. }
  10949. }
  10950. return left;
  10951. }
  10952. parseExprOpRightExpr(op, prec) {
  10953. const startLoc = this.state.startLoc;
  10954. switch (op) {
  10955. case 39:
  10956. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10957. case "hack":
  10958. return this.withTopicBindingContext(() => {
  10959. return this.parseHackPipeBody();
  10960. });
  10961. case "fsharp":
  10962. return this.withSoloAwaitPermittingContext(() => {
  10963. return this.parseFSharpPipelineBody(prec);
  10964. });
  10965. }
  10966. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  10967. return this.withTopicBindingContext(() => {
  10968. if (this.prodParam.hasYield && this.isContextual(108)) {
  10969. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  10970. }
  10971. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10972. });
  10973. }
  10974. default:
  10975. return this.parseExprOpBaseRightExpr(op, prec);
  10976. }
  10977. }
  10978. parseExprOpBaseRightExpr(op, prec) {
  10979. const startLoc = this.state.startLoc;
  10980. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10981. }
  10982. parseHackPipeBody() {
  10983. var _body$extra;
  10984. const {
  10985. startLoc
  10986. } = this.state;
  10987. const body = this.parseMaybeAssign();
  10988. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10989. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10990. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  10991. type: body.type
  10992. });
  10993. }
  10994. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10995. this.raise(Errors.PipeTopicUnused, startLoc);
  10996. }
  10997. return body;
  10998. }
  10999. checkExponentialAfterUnary(node) {
  11000. if (this.match(57)) {
  11001. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  11002. }
  11003. }
  11004. parseMaybeUnary(refExpressionErrors, sawUnary) {
  11005. const startLoc = this.state.startLoc;
  11006. const isAwait = this.isContextual(96);
  11007. if (isAwait && this.recordAwaitIfAllowed()) {
  11008. this.next();
  11009. const expr = this.parseAwait(startLoc);
  11010. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  11011. return expr;
  11012. }
  11013. const update = this.match(34);
  11014. const node = this.startNode();
  11015. if (tokenIsPrefix(this.state.type)) {
  11016. node.operator = this.state.value;
  11017. node.prefix = true;
  11018. if (this.match(72)) {
  11019. this.expectPlugin("throwExpressions");
  11020. }
  11021. const isDelete = this.match(89);
  11022. this.next();
  11023. node.argument = this.parseMaybeUnary(null, true);
  11024. this.checkExpressionErrors(refExpressionErrors, true);
  11025. if (this.state.strict && isDelete) {
  11026. const arg = node.argument;
  11027. if (arg.type === "Identifier") {
  11028. this.raise(Errors.StrictDelete, node);
  11029. } else if (this.hasPropertyAsPrivateName(arg)) {
  11030. this.raise(Errors.DeletePrivateField, node);
  11031. }
  11032. }
  11033. if (!update) {
  11034. if (!sawUnary) {
  11035. this.checkExponentialAfterUnary(node);
  11036. }
  11037. return this.finishNode(node, "UnaryExpression");
  11038. }
  11039. }
  11040. const expr = this.parseUpdate(node, update, refExpressionErrors);
  11041. if (isAwait) {
  11042. const {
  11043. type
  11044. } = this.state;
  11045. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  11046. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  11047. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  11048. return this.parseAwait(startLoc);
  11049. }
  11050. }
  11051. return expr;
  11052. }
  11053. parseUpdate(node, update, refExpressionErrors) {
  11054. if (update) {
  11055. const updateExpressionNode = node;
  11056. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  11057. return node;
  11058. }
  11059. const startLoc = this.state.startLoc;
  11060. let expr = this.parseExprSubscripts(refExpressionErrors);
  11061. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  11062. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  11063. const node = this.startNodeAt(startLoc);
  11064. node.operator = this.state.value;
  11065. node.prefix = false;
  11066. node.argument = expr;
  11067. this.next();
  11068. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  11069. }
  11070. return expr;
  11071. }
  11072. parseExprSubscripts(refExpressionErrors) {
  11073. const startLoc = this.state.startLoc;
  11074. const potentialArrowAt = this.state.potentialArrowAt;
  11075. const expr = this.parseExprAtom(refExpressionErrors);
  11076. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11077. return expr;
  11078. }
  11079. return this.parseSubscripts(expr, startLoc);
  11080. }
  11081. parseSubscripts(base, startLoc, noCalls) {
  11082. const state = {
  11083. optionalChainMember: false,
  11084. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  11085. stop: false
  11086. };
  11087. do {
  11088. base = this.parseSubscript(base, startLoc, noCalls, state);
  11089. state.maybeAsyncArrow = false;
  11090. } while (!state.stop);
  11091. return base;
  11092. }
  11093. parseSubscript(base, startLoc, noCalls, state) {
  11094. const {
  11095. type
  11096. } = this.state;
  11097. if (!noCalls && type === 15) {
  11098. return this.parseBind(base, startLoc, noCalls, state);
  11099. } else if (tokenIsTemplate(type)) {
  11100. return this.parseTaggedTemplateExpression(base, startLoc, state);
  11101. }
  11102. let optional = false;
  11103. if (type === 18) {
  11104. if (noCalls) {
  11105. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  11106. if (this.lookaheadCharCode() === 40) {
  11107. return this.stopParseSubscript(base, state);
  11108. }
  11109. }
  11110. state.optionalChainMember = optional = true;
  11111. this.next();
  11112. }
  11113. if (!noCalls && this.match(10)) {
  11114. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  11115. } else {
  11116. const computed = this.eat(0);
  11117. if (computed || optional || this.eat(16)) {
  11118. return this.parseMember(base, startLoc, state, computed, optional);
  11119. } else {
  11120. return this.stopParseSubscript(base, state);
  11121. }
  11122. }
  11123. }
  11124. stopParseSubscript(base, state) {
  11125. state.stop = true;
  11126. return base;
  11127. }
  11128. parseMember(base, startLoc, state, computed, optional) {
  11129. const node = this.startNodeAt(startLoc);
  11130. node.object = base;
  11131. node.computed = computed;
  11132. if (computed) {
  11133. node.property = this.parseExpression();
  11134. this.expect(3);
  11135. } else if (this.match(139)) {
  11136. if (base.type === "Super") {
  11137. this.raise(Errors.SuperPrivateField, startLoc);
  11138. }
  11139. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  11140. node.property = this.parsePrivateName();
  11141. } else {
  11142. node.property = this.parseIdentifier(true);
  11143. }
  11144. if (state.optionalChainMember) {
  11145. node.optional = optional;
  11146. return this.finishNode(node, "OptionalMemberExpression");
  11147. } else {
  11148. return this.finishNode(node, "MemberExpression");
  11149. }
  11150. }
  11151. parseBind(base, startLoc, noCalls, state) {
  11152. const node = this.startNodeAt(startLoc);
  11153. node.object = base;
  11154. this.next();
  11155. node.callee = this.parseNoCallExpr();
  11156. state.stop = true;
  11157. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  11158. }
  11159. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  11160. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11161. let refExpressionErrors = null;
  11162. this.state.maybeInArrowParameters = true;
  11163. this.next();
  11164. const node = this.startNodeAt(startLoc);
  11165. node.callee = base;
  11166. const {
  11167. maybeAsyncArrow,
  11168. optionalChainMember
  11169. } = state;
  11170. if (maybeAsyncArrow) {
  11171. this.expressionScope.enter(newAsyncArrowScope());
  11172. refExpressionErrors = new ExpressionErrors();
  11173. }
  11174. if (optionalChainMember) {
  11175. node.optional = optional;
  11176. }
  11177. if (optional) {
  11178. node.arguments = this.parseCallExpressionArguments();
  11179. } else {
  11180. node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
  11181. }
  11182. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  11183. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  11184. state.stop = true;
  11185. this.checkDestructuringPrivate(refExpressionErrors);
  11186. this.expressionScope.validateAsPattern();
  11187. this.expressionScope.exit();
  11188. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  11189. } else {
  11190. if (maybeAsyncArrow) {
  11191. this.checkExpressionErrors(refExpressionErrors, true);
  11192. this.expressionScope.exit();
  11193. }
  11194. this.toReferencedArguments(finishedNode);
  11195. }
  11196. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11197. return finishedNode;
  11198. }
  11199. toReferencedArguments(node, isParenthesizedExpr) {
  11200. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11201. }
  11202. parseTaggedTemplateExpression(base, startLoc, state) {
  11203. const node = this.startNodeAt(startLoc);
  11204. node.tag = base;
  11205. node.quasi = this.parseTemplate(true);
  11206. if (state.optionalChainMember) {
  11207. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  11208. }
  11209. return this.finishNode(node, "TaggedTemplateExpression");
  11210. }
  11211. atPossibleAsyncArrow(base) {
  11212. 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;
  11213. }
  11214. finishCallExpression(node, optional) {
  11215. if (node.callee.type === "Import") {
  11216. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11217. this.raise(Errors.ImportCallArity, node);
  11218. } else {
  11219. for (const arg of node.arguments) {
  11220. if (arg.type === "SpreadElement") {
  11221. this.raise(Errors.ImportCallSpreadArgument, arg);
  11222. }
  11223. }
  11224. }
  11225. }
  11226. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11227. }
  11228. parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11229. const elts = [];
  11230. let first = true;
  11231. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11232. this.state.inFSharpPipelineDirectBody = false;
  11233. while (!this.eat(11)) {
  11234. if (first) {
  11235. first = false;
  11236. } else {
  11237. this.expect(12);
  11238. if (this.match(11)) {
  11239. if (nodeForExtra) {
  11240. this.addTrailingCommaExtraToNode(nodeForExtra);
  11241. }
  11242. this.next();
  11243. break;
  11244. }
  11245. }
  11246. elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
  11247. }
  11248. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11249. return elts;
  11250. }
  11251. shouldParseAsyncArrow() {
  11252. return this.match(19) && !this.canInsertSemicolon();
  11253. }
  11254. parseAsyncArrowFromCallExpression(node, call) {
  11255. var _call$extra;
  11256. this.resetPreviousNodeTrailingComments(call);
  11257. this.expect(19);
  11258. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11259. if (call.innerComments) {
  11260. setInnerComments(node, call.innerComments);
  11261. }
  11262. if (call.callee.trailingComments) {
  11263. setInnerComments(node, call.callee.trailingComments);
  11264. }
  11265. return node;
  11266. }
  11267. parseNoCallExpr() {
  11268. const startLoc = this.state.startLoc;
  11269. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11270. }
  11271. parseExprAtom(refExpressionErrors) {
  11272. let node;
  11273. let decorators = null;
  11274. const {
  11275. type
  11276. } = this.state;
  11277. switch (type) {
  11278. case 79:
  11279. return this.parseSuper();
  11280. case 83:
  11281. node = this.startNode();
  11282. this.next();
  11283. if (this.match(16)) {
  11284. return this.parseImportMetaPropertyOrPhaseCall(node);
  11285. }
  11286. if (this.match(10)) {
  11287. if (this.optionFlags & 512) {
  11288. return this.parseImportCall(node);
  11289. } else {
  11290. return this.finishNode(node, "Import");
  11291. }
  11292. } else {
  11293. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  11294. return this.finishNode(node, "Import");
  11295. }
  11296. case 78:
  11297. node = this.startNode();
  11298. this.next();
  11299. return this.finishNode(node, "ThisExpression");
  11300. case 90:
  11301. {
  11302. return this.parseDo(this.startNode(), false);
  11303. }
  11304. case 56:
  11305. case 31:
  11306. {
  11307. this.readRegexp();
  11308. return this.parseRegExpLiteral(this.state.value);
  11309. }
  11310. case 135:
  11311. return this.parseNumericLiteral(this.state.value);
  11312. case 136:
  11313. return this.parseBigIntLiteral(this.state.value);
  11314. case 134:
  11315. return this.parseStringLiteral(this.state.value);
  11316. case 84:
  11317. return this.parseNullLiteral();
  11318. case 85:
  11319. return this.parseBooleanLiteral(true);
  11320. case 86:
  11321. return this.parseBooleanLiteral(false);
  11322. case 10:
  11323. {
  11324. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11325. return this.parseParenAndDistinguishExpression(canBeArrow);
  11326. }
  11327. case 0:
  11328. {
  11329. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11330. }
  11331. case 5:
  11332. {
  11333. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11334. }
  11335. case 68:
  11336. return this.parseFunctionOrFunctionSent();
  11337. case 26:
  11338. decorators = this.parseDecorators();
  11339. case 80:
  11340. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11341. case 77:
  11342. return this.parseNewOrNewTarget();
  11343. case 25:
  11344. case 24:
  11345. return this.parseTemplate(false);
  11346. case 15:
  11347. {
  11348. node = this.startNode();
  11349. this.next();
  11350. node.object = null;
  11351. const callee = node.callee = this.parseNoCallExpr();
  11352. if (callee.type === "MemberExpression") {
  11353. return this.finishNode(node, "BindExpression");
  11354. } else {
  11355. throw this.raise(Errors.UnsupportedBind, callee);
  11356. }
  11357. }
  11358. case 139:
  11359. {
  11360. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  11361. identifierName: this.state.value
  11362. });
  11363. return this.parsePrivateName();
  11364. }
  11365. case 33:
  11366. {
  11367. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11368. }
  11369. case 32:
  11370. {
  11371. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11372. }
  11373. case 37:
  11374. case 38:
  11375. {
  11376. return this.parseTopicReference("hack");
  11377. }
  11378. case 44:
  11379. case 54:
  11380. case 27:
  11381. {
  11382. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11383. if (pipeProposal) {
  11384. return this.parseTopicReference(pipeProposal);
  11385. }
  11386. this.unexpected();
  11387. break;
  11388. }
  11389. case 47:
  11390. {
  11391. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11392. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11393. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11394. } else {
  11395. this.unexpected();
  11396. }
  11397. break;
  11398. }
  11399. default:
  11400. {
  11401. if (type === 137) {
  11402. return this.parseDecimalLiteral(this.state.value);
  11403. } else if (type === 2 || type === 1) {
  11404. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11405. } else if (type === 6 || type === 7) {
  11406. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11407. }
  11408. }
  11409. if (tokenIsIdentifier(type)) {
  11410. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11411. return this.parseModuleExpression();
  11412. }
  11413. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11414. const containsEsc = this.state.containsEsc;
  11415. const id = this.parseIdentifier();
  11416. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11417. const {
  11418. type
  11419. } = this.state;
  11420. if (type === 68) {
  11421. this.resetPreviousNodeTrailingComments(id);
  11422. this.next();
  11423. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11424. } else if (tokenIsIdentifier(type)) {
  11425. if (this.lookaheadCharCode() === 61) {
  11426. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11427. } else {
  11428. return id;
  11429. }
  11430. } else if (type === 90) {
  11431. this.resetPreviousNodeTrailingComments(id);
  11432. return this.parseDo(this.startNodeAtNode(id), true);
  11433. }
  11434. }
  11435. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11436. this.next();
  11437. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11438. }
  11439. return id;
  11440. } else {
  11441. this.unexpected();
  11442. }
  11443. }
  11444. }
  11445. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11446. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11447. if (pipeProposal) {
  11448. this.state.type = topicTokenType;
  11449. this.state.value = topicTokenValue;
  11450. this.state.pos--;
  11451. this.state.end--;
  11452. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11453. return this.parseTopicReference(pipeProposal);
  11454. } else {
  11455. this.unexpected();
  11456. }
  11457. }
  11458. parseTopicReference(pipeProposal) {
  11459. const node = this.startNode();
  11460. const startLoc = this.state.startLoc;
  11461. const tokenType = this.state.type;
  11462. this.next();
  11463. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11464. }
  11465. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11466. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11467. if (pipeProposal === "hack") {
  11468. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11469. this.raise(Errors.PipeTopicUnbound, startLoc);
  11470. }
  11471. this.registerTopicReference();
  11472. return this.finishNode(node, "TopicReference");
  11473. } else {
  11474. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11475. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  11476. }
  11477. this.registerTopicReference();
  11478. return this.finishNode(node, "PipelinePrimaryTopicReference");
  11479. }
  11480. } else {
  11481. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11482. token: tokenLabelName(tokenType)
  11483. });
  11484. }
  11485. }
  11486. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11487. switch (pipeProposal) {
  11488. case "hack":
  11489. {
  11490. return this.hasPlugin(["pipelineOperator", {
  11491. topicToken: tokenLabelName(tokenType)
  11492. }]);
  11493. }
  11494. case "smart":
  11495. return tokenType === 27;
  11496. default:
  11497. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11498. }
  11499. }
  11500. parseAsyncArrowUnaryFunction(node) {
  11501. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11502. const params = [this.parseIdentifier()];
  11503. this.prodParam.exit();
  11504. if (this.hasPrecedingLineBreak()) {
  11505. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11506. }
  11507. this.expect(19);
  11508. return this.parseArrowExpression(node, params, true);
  11509. }
  11510. parseDo(node, isAsync) {
  11511. this.expectPlugin("doExpressions");
  11512. if (isAsync) {
  11513. this.expectPlugin("asyncDoExpressions");
  11514. }
  11515. node.async = isAsync;
  11516. this.next();
  11517. const oldLabels = this.state.labels;
  11518. this.state.labels = [];
  11519. if (isAsync) {
  11520. this.prodParam.enter(2);
  11521. node.body = this.parseBlock();
  11522. this.prodParam.exit();
  11523. } else {
  11524. node.body = this.parseBlock();
  11525. }
  11526. this.state.labels = oldLabels;
  11527. return this.finishNode(node, "DoExpression");
  11528. }
  11529. parseSuper() {
  11530. const node = this.startNode();
  11531. this.next();
  11532. if (this.match(10) && !this.scope.allowDirectSuper && !(this.optionFlags & 16)) {
  11533. this.raise(Errors.SuperNotAllowed, node);
  11534. } else if (!this.scope.allowSuper && !(this.optionFlags & 16)) {
  11535. this.raise(Errors.UnexpectedSuper, node);
  11536. }
  11537. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11538. this.raise(Errors.UnsupportedSuper, node);
  11539. }
  11540. return this.finishNode(node, "Super");
  11541. }
  11542. parsePrivateName() {
  11543. const node = this.startNode();
  11544. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11545. const name = this.state.value;
  11546. this.next();
  11547. node.id = this.createIdentifier(id, name);
  11548. return this.finishNode(node, "PrivateName");
  11549. }
  11550. parseFunctionOrFunctionSent() {
  11551. const node = this.startNode();
  11552. this.next();
  11553. if (this.prodParam.hasYield && this.match(16)) {
  11554. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11555. this.next();
  11556. if (this.match(103)) {
  11557. this.expectPlugin("functionSent");
  11558. } else if (!this.hasPlugin("functionSent")) {
  11559. this.unexpected();
  11560. }
  11561. return this.parseMetaProperty(node, meta, "sent");
  11562. }
  11563. return this.parseFunction(node);
  11564. }
  11565. parseMetaProperty(node, meta, propertyName) {
  11566. node.meta = meta;
  11567. const containsEsc = this.state.containsEsc;
  11568. node.property = this.parseIdentifier(true);
  11569. if (node.property.name !== propertyName || containsEsc) {
  11570. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11571. target: meta.name,
  11572. onlyValidPropertyName: propertyName
  11573. });
  11574. }
  11575. return this.finishNode(node, "MetaProperty");
  11576. }
  11577. parseImportMetaPropertyOrPhaseCall(node) {
  11578. this.next();
  11579. if (this.isContextual(105) || this.isContextual(97)) {
  11580. const isSource = this.isContextual(105);
  11581. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11582. this.next();
  11583. node.phase = isSource ? "source" : "defer";
  11584. return this.parseImportCall(node);
  11585. } else {
  11586. const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
  11587. if (this.isContextual(101)) {
  11588. if (!this.inModule) {
  11589. this.raise(Errors.ImportMetaOutsideModule, id);
  11590. }
  11591. this.sawUnambiguousESM = true;
  11592. }
  11593. return this.parseMetaProperty(node, id, "meta");
  11594. }
  11595. }
  11596. parseLiteralAtNode(value, type, node) {
  11597. this.addExtra(node, "rawValue", value);
  11598. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11599. node.value = value;
  11600. this.next();
  11601. return this.finishNode(node, type);
  11602. }
  11603. parseLiteral(value, type) {
  11604. const node = this.startNode();
  11605. return this.parseLiteralAtNode(value, type, node);
  11606. }
  11607. parseStringLiteral(value) {
  11608. return this.parseLiteral(value, "StringLiteral");
  11609. }
  11610. parseNumericLiteral(value) {
  11611. return this.parseLiteral(value, "NumericLiteral");
  11612. }
  11613. parseBigIntLiteral(value) {
  11614. {
  11615. return this.parseLiteral(value, "BigIntLiteral");
  11616. }
  11617. }
  11618. parseDecimalLiteral(value) {
  11619. return this.parseLiteral(value, "DecimalLiteral");
  11620. }
  11621. parseRegExpLiteral(value) {
  11622. const node = this.startNode();
  11623. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11624. node.pattern = value.pattern;
  11625. node.flags = value.flags;
  11626. this.next();
  11627. return this.finishNode(node, "RegExpLiteral");
  11628. }
  11629. parseBooleanLiteral(value) {
  11630. const node = this.startNode();
  11631. node.value = value;
  11632. this.next();
  11633. return this.finishNode(node, "BooleanLiteral");
  11634. }
  11635. parseNullLiteral() {
  11636. const node = this.startNode();
  11637. this.next();
  11638. return this.finishNode(node, "NullLiteral");
  11639. }
  11640. parseParenAndDistinguishExpression(canBeArrow) {
  11641. const startLoc = this.state.startLoc;
  11642. let val;
  11643. this.next();
  11644. this.expressionScope.enter(newArrowHeadScope());
  11645. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11646. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11647. this.state.maybeInArrowParameters = true;
  11648. this.state.inFSharpPipelineDirectBody = false;
  11649. const innerStartLoc = this.state.startLoc;
  11650. const exprList = [];
  11651. const refExpressionErrors = new ExpressionErrors();
  11652. let first = true;
  11653. let spreadStartLoc;
  11654. let optionalCommaStartLoc;
  11655. while (!this.match(11)) {
  11656. if (first) {
  11657. first = false;
  11658. } else {
  11659. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11660. if (this.match(11)) {
  11661. optionalCommaStartLoc = this.state.startLoc;
  11662. break;
  11663. }
  11664. }
  11665. if (this.match(21)) {
  11666. const spreadNodeStartLoc = this.state.startLoc;
  11667. spreadStartLoc = this.state.startLoc;
  11668. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11669. if (!this.checkCommaAfterRest(41)) {
  11670. break;
  11671. }
  11672. } else {
  11673. exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
  11674. }
  11675. }
  11676. const innerEndLoc = this.state.lastTokEndLoc;
  11677. this.expect(11);
  11678. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11679. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11680. let arrowNode = this.startNodeAt(startLoc);
  11681. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11682. this.checkDestructuringPrivate(refExpressionErrors);
  11683. this.expressionScope.validateAsPattern();
  11684. this.expressionScope.exit();
  11685. this.parseArrowExpression(arrowNode, exprList, false);
  11686. return arrowNode;
  11687. }
  11688. this.expressionScope.exit();
  11689. if (!exprList.length) {
  11690. this.unexpected(this.state.lastTokStartLoc);
  11691. }
  11692. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11693. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11694. this.checkExpressionErrors(refExpressionErrors, true);
  11695. this.toReferencedListDeep(exprList, true);
  11696. if (exprList.length > 1) {
  11697. val = this.startNodeAt(innerStartLoc);
  11698. val.expressions = exprList;
  11699. this.finishNode(val, "SequenceExpression");
  11700. this.resetEndLocation(val, innerEndLoc);
  11701. } else {
  11702. val = exprList[0];
  11703. }
  11704. return this.wrapParenthesis(startLoc, val);
  11705. }
  11706. wrapParenthesis(startLoc, expression) {
  11707. if (!(this.optionFlags & 1024)) {
  11708. this.addExtra(expression, "parenthesized", true);
  11709. this.addExtra(expression, "parenStart", startLoc.index);
  11710. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11711. return expression;
  11712. }
  11713. const parenExpression = this.startNodeAt(startLoc);
  11714. parenExpression.expression = expression;
  11715. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11716. }
  11717. shouldParseArrow(params) {
  11718. return !this.canInsertSemicolon();
  11719. }
  11720. parseArrow(node) {
  11721. if (this.eat(19)) {
  11722. return node;
  11723. }
  11724. }
  11725. parseParenItem(node, startLoc) {
  11726. return node;
  11727. }
  11728. parseNewOrNewTarget() {
  11729. const node = this.startNode();
  11730. this.next();
  11731. if (this.match(16)) {
  11732. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11733. this.next();
  11734. const metaProp = this.parseMetaProperty(node, meta, "target");
  11735. if (!this.scope.allowNewTarget) {
  11736. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11737. }
  11738. return metaProp;
  11739. }
  11740. return this.parseNew(node);
  11741. }
  11742. parseNew(node) {
  11743. this.parseNewCallee(node);
  11744. if (this.eat(10)) {
  11745. const args = this.parseExprList(11);
  11746. this.toReferencedList(args);
  11747. node.arguments = args;
  11748. } else {
  11749. node.arguments = [];
  11750. }
  11751. return this.finishNode(node, "NewExpression");
  11752. }
  11753. parseNewCallee(node) {
  11754. const isImport = this.match(83);
  11755. const callee = this.parseNoCallExpr();
  11756. node.callee = callee;
  11757. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11758. this.raise(Errors.ImportCallNotNewExpression, callee);
  11759. }
  11760. }
  11761. parseTemplateElement(isTagged) {
  11762. const {
  11763. start,
  11764. startLoc,
  11765. end,
  11766. value
  11767. } = this.state;
  11768. const elemStart = start + 1;
  11769. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11770. if (value === null) {
  11771. if (!isTagged) {
  11772. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11773. }
  11774. }
  11775. const isTail = this.match(24);
  11776. const endOffset = isTail ? -1 : -2;
  11777. const elemEnd = end + endOffset;
  11778. elem.value = {
  11779. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11780. cooked: value === null ? null : value.slice(1, endOffset)
  11781. };
  11782. elem.tail = isTail;
  11783. this.next();
  11784. const finishedNode = this.finishNode(elem, "TemplateElement");
  11785. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11786. return finishedNode;
  11787. }
  11788. parseTemplate(isTagged) {
  11789. const node = this.startNode();
  11790. let curElt = this.parseTemplateElement(isTagged);
  11791. const quasis = [curElt];
  11792. const substitutions = [];
  11793. while (!curElt.tail) {
  11794. substitutions.push(this.parseTemplateSubstitution());
  11795. this.readTemplateContinuation();
  11796. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11797. }
  11798. node.expressions = substitutions;
  11799. node.quasis = quasis;
  11800. return this.finishNode(node, "TemplateLiteral");
  11801. }
  11802. parseTemplateSubstitution() {
  11803. return this.parseExpression();
  11804. }
  11805. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11806. if (isRecord) {
  11807. this.expectPlugin("recordAndTuple");
  11808. }
  11809. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11810. this.state.inFSharpPipelineDirectBody = false;
  11811. let sawProto = false;
  11812. let first = true;
  11813. const node = this.startNode();
  11814. node.properties = [];
  11815. this.next();
  11816. while (!this.match(close)) {
  11817. if (first) {
  11818. first = false;
  11819. } else {
  11820. this.expect(12);
  11821. if (this.match(close)) {
  11822. this.addTrailingCommaExtraToNode(node);
  11823. break;
  11824. }
  11825. }
  11826. let prop;
  11827. if (isPattern) {
  11828. prop = this.parseBindingProperty();
  11829. } else {
  11830. prop = this.parsePropertyDefinition(refExpressionErrors);
  11831. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  11832. }
  11833. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11834. this.raise(Errors.InvalidRecordProperty, prop);
  11835. }
  11836. {
  11837. if (prop.shorthand) {
  11838. this.addExtra(prop, "shorthand", true);
  11839. }
  11840. }
  11841. node.properties.push(prop);
  11842. }
  11843. this.next();
  11844. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11845. let type = "ObjectExpression";
  11846. if (isPattern) {
  11847. type = "ObjectPattern";
  11848. } else if (isRecord) {
  11849. type = "RecordExpression";
  11850. }
  11851. return this.finishNode(node, type);
  11852. }
  11853. addTrailingCommaExtraToNode(node) {
  11854. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11855. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11856. }
  11857. maybeAsyncOrAccessorProp(prop) {
  11858. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11859. }
  11860. parsePropertyDefinition(refExpressionErrors) {
  11861. let decorators = [];
  11862. if (this.match(26)) {
  11863. if (this.hasPlugin("decorators")) {
  11864. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11865. }
  11866. while (this.match(26)) {
  11867. decorators.push(this.parseDecorator());
  11868. }
  11869. }
  11870. const prop = this.startNode();
  11871. let isAsync = false;
  11872. let isAccessor = false;
  11873. let startLoc;
  11874. if (this.match(21)) {
  11875. if (decorators.length) this.unexpected();
  11876. return this.parseSpread();
  11877. }
  11878. if (decorators.length) {
  11879. prop.decorators = decorators;
  11880. decorators = [];
  11881. }
  11882. prop.method = false;
  11883. if (refExpressionErrors) {
  11884. startLoc = this.state.startLoc;
  11885. }
  11886. let isGenerator = this.eat(55);
  11887. this.parsePropertyNamePrefixOperator(prop);
  11888. const containsEsc = this.state.containsEsc;
  11889. this.parsePropertyName(prop, refExpressionErrors);
  11890. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11891. const {
  11892. key
  11893. } = prop;
  11894. const keyName = key.name;
  11895. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11896. isAsync = true;
  11897. this.resetPreviousNodeTrailingComments(key);
  11898. isGenerator = this.eat(55);
  11899. this.parsePropertyName(prop);
  11900. }
  11901. if (keyName === "get" || keyName === "set") {
  11902. isAccessor = true;
  11903. this.resetPreviousNodeTrailingComments(key);
  11904. prop.kind = keyName;
  11905. if (this.match(55)) {
  11906. isGenerator = true;
  11907. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11908. kind: keyName
  11909. });
  11910. this.next();
  11911. }
  11912. this.parsePropertyName(prop);
  11913. }
  11914. }
  11915. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11916. }
  11917. getGetterSetterExpectedParamCount(method) {
  11918. return method.kind === "get" ? 0 : 1;
  11919. }
  11920. getObjectOrClassMethodParams(method) {
  11921. return method.params;
  11922. }
  11923. checkGetterSetterParams(method) {
  11924. var _params;
  11925. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11926. const params = this.getObjectOrClassMethodParams(method);
  11927. if (params.length !== paramCount) {
  11928. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  11929. }
  11930. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11931. this.raise(Errors.BadSetterRestParameter, method);
  11932. }
  11933. }
  11934. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11935. if (isAccessor) {
  11936. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11937. this.checkGetterSetterParams(finishedProp);
  11938. return finishedProp;
  11939. }
  11940. if (isAsync || isGenerator || this.match(10)) {
  11941. if (isPattern) this.unexpected();
  11942. prop.kind = "method";
  11943. prop.method = true;
  11944. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11945. }
  11946. }
  11947. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11948. prop.shorthand = false;
  11949. if (this.eat(14)) {
  11950. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
  11951. return this.finishObjectProperty(prop);
  11952. }
  11953. if (!prop.computed && prop.key.type === "Identifier") {
  11954. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11955. if (isPattern) {
  11956. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  11957. } else if (this.match(29)) {
  11958. const shorthandAssignLoc = this.state.startLoc;
  11959. if (refExpressionErrors != null) {
  11960. if (refExpressionErrors.shorthandAssignLoc === null) {
  11961. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11962. }
  11963. } else {
  11964. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11965. }
  11966. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  11967. } else {
  11968. prop.value = this.cloneIdentifier(prop.key);
  11969. }
  11970. prop.shorthand = true;
  11971. return this.finishObjectProperty(prop);
  11972. }
  11973. }
  11974. finishObjectProperty(node) {
  11975. return this.finishNode(node, "ObjectProperty");
  11976. }
  11977. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11978. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11979. if (!node) this.unexpected();
  11980. return node;
  11981. }
  11982. parsePropertyName(prop, refExpressionErrors) {
  11983. if (this.eat(0)) {
  11984. prop.computed = true;
  11985. prop.key = this.parseMaybeAssignAllowIn();
  11986. this.expect(3);
  11987. } else {
  11988. const {
  11989. type,
  11990. value
  11991. } = this.state;
  11992. let key;
  11993. if (tokenIsKeywordOrIdentifier(type)) {
  11994. key = this.parseIdentifier(true);
  11995. } else {
  11996. switch (type) {
  11997. case 135:
  11998. key = this.parseNumericLiteral(value);
  11999. break;
  12000. case 134:
  12001. key = this.parseStringLiteral(value);
  12002. break;
  12003. case 136:
  12004. key = this.parseBigIntLiteral(value);
  12005. break;
  12006. case 139:
  12007. {
  12008. const privateKeyLoc = this.state.startLoc;
  12009. if (refExpressionErrors != null) {
  12010. if (refExpressionErrors.privateKeyLoc === null) {
  12011. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  12012. }
  12013. } else {
  12014. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  12015. }
  12016. key = this.parsePrivateName();
  12017. break;
  12018. }
  12019. default:
  12020. if (type === 137) {
  12021. key = this.parseDecimalLiteral(value);
  12022. break;
  12023. }
  12024. this.unexpected();
  12025. }
  12026. }
  12027. prop.key = key;
  12028. if (type !== 139) {
  12029. prop.computed = false;
  12030. }
  12031. }
  12032. }
  12033. initFunction(node, isAsync) {
  12034. node.id = null;
  12035. node.generator = false;
  12036. node.async = isAsync;
  12037. }
  12038. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  12039. this.initFunction(node, isAsync);
  12040. node.generator = isGenerator;
  12041. this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
  12042. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12043. this.parseFunctionParams(node, isConstructor);
  12044. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  12045. this.prodParam.exit();
  12046. this.scope.exit();
  12047. return finishedNode;
  12048. }
  12049. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  12050. if (isTuple) {
  12051. this.expectPlugin("recordAndTuple");
  12052. }
  12053. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12054. this.state.inFSharpPipelineDirectBody = false;
  12055. const node = this.startNode();
  12056. this.next();
  12057. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  12058. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12059. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  12060. }
  12061. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  12062. this.scope.enter(514 | 4);
  12063. let flags = functionFlags(isAsync, false);
  12064. if (!this.match(5) && this.prodParam.hasIn) {
  12065. flags |= 8;
  12066. }
  12067. this.prodParam.enter(flags);
  12068. this.initFunction(node, isAsync);
  12069. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12070. if (params) {
  12071. this.state.maybeInArrowParameters = true;
  12072. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  12073. }
  12074. this.state.maybeInArrowParameters = false;
  12075. this.parseFunctionBody(node, true);
  12076. this.prodParam.exit();
  12077. this.scope.exit();
  12078. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12079. return this.finishNode(node, "ArrowFunctionExpression");
  12080. }
  12081. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  12082. this.toAssignableList(params, trailingCommaLoc, false);
  12083. node.params = params;
  12084. }
  12085. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  12086. this.parseFunctionBody(node, false, isMethod);
  12087. return this.finishNode(node, type);
  12088. }
  12089. parseFunctionBody(node, allowExpression, isMethod = false) {
  12090. const isExpression = allowExpression && !this.match(5);
  12091. this.expressionScope.enter(newExpressionScope());
  12092. if (isExpression) {
  12093. node.body = this.parseMaybeAssign();
  12094. this.checkParams(node, false, allowExpression, false);
  12095. } else {
  12096. const oldStrict = this.state.strict;
  12097. const oldLabels = this.state.labels;
  12098. this.state.labels = [];
  12099. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  12100. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  12101. const nonSimple = !this.isSimpleParamList(node.params);
  12102. if (hasStrictModeDirective && nonSimple) {
  12103. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  12104. }
  12105. const strictModeChanged = !oldStrict && this.state.strict;
  12106. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  12107. if (this.state.strict && node.id) {
  12108. this.checkIdentifier(node.id, 65, strictModeChanged);
  12109. }
  12110. });
  12111. this.prodParam.exit();
  12112. this.state.labels = oldLabels;
  12113. }
  12114. this.expressionScope.exit();
  12115. }
  12116. isSimpleParameter(node) {
  12117. return node.type === "Identifier";
  12118. }
  12119. isSimpleParamList(params) {
  12120. for (let i = 0, len = params.length; i < len; i++) {
  12121. if (!this.isSimpleParameter(params[i])) return false;
  12122. }
  12123. return true;
  12124. }
  12125. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  12126. const checkClashes = !allowDuplicates && new Set();
  12127. const formalParameters = {
  12128. type: "FormalParameters"
  12129. };
  12130. for (const param of node.params) {
  12131. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  12132. }
  12133. }
  12134. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  12135. const elts = [];
  12136. let first = true;
  12137. while (!this.eat(close)) {
  12138. if (first) {
  12139. first = false;
  12140. } else {
  12141. this.expect(12);
  12142. if (this.match(close)) {
  12143. if (nodeForExtra) {
  12144. this.addTrailingCommaExtraToNode(nodeForExtra);
  12145. }
  12146. this.next();
  12147. break;
  12148. }
  12149. }
  12150. elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
  12151. }
  12152. return elts;
  12153. }
  12154. parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
  12155. let elt;
  12156. if (this.match(12)) {
  12157. if (!allowEmpty) {
  12158. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  12159. unexpected: ","
  12160. });
  12161. }
  12162. elt = null;
  12163. } else if (this.match(21)) {
  12164. const spreadNodeStartLoc = this.state.startLoc;
  12165. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12166. } else if (this.match(17)) {
  12167. this.expectPlugin("partialApplication");
  12168. if (!allowPlaceholder) {
  12169. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  12170. }
  12171. const node = this.startNode();
  12172. this.next();
  12173. elt = this.finishNode(node, "ArgumentPlaceholder");
  12174. } else {
  12175. elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
  12176. }
  12177. return elt;
  12178. }
  12179. parseIdentifier(liberal) {
  12180. const node = this.startNode();
  12181. const name = this.parseIdentifierName(liberal);
  12182. return this.createIdentifier(node, name);
  12183. }
  12184. createIdentifier(node, name) {
  12185. node.name = name;
  12186. node.loc.identifierName = name;
  12187. return this.finishNode(node, "Identifier");
  12188. }
  12189. createIdentifierAt(node, name, endLoc) {
  12190. node.name = name;
  12191. node.loc.identifierName = name;
  12192. return this.finishNodeAt(node, "Identifier", endLoc);
  12193. }
  12194. parseIdentifierName(liberal) {
  12195. let name;
  12196. const {
  12197. startLoc,
  12198. type
  12199. } = this.state;
  12200. if (tokenIsKeywordOrIdentifier(type)) {
  12201. name = this.state.value;
  12202. } else {
  12203. this.unexpected();
  12204. }
  12205. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12206. if (liberal) {
  12207. if (tokenIsKeyword) {
  12208. this.replaceToken(132);
  12209. }
  12210. } else {
  12211. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12212. }
  12213. this.next();
  12214. return name;
  12215. }
  12216. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12217. if (word.length > 10) {
  12218. return;
  12219. }
  12220. if (!canBeReservedWord(word)) {
  12221. return;
  12222. }
  12223. if (checkKeywords && isKeyword(word)) {
  12224. this.raise(Errors.UnexpectedKeyword, startLoc, {
  12225. keyword: word
  12226. });
  12227. return;
  12228. }
  12229. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12230. if (reservedTest(word, this.inModule)) {
  12231. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  12232. reservedWord: word
  12233. });
  12234. return;
  12235. } else if (word === "yield") {
  12236. if (this.prodParam.hasYield) {
  12237. this.raise(Errors.YieldBindingIdentifier, startLoc);
  12238. return;
  12239. }
  12240. } else if (word === "await") {
  12241. if (this.prodParam.hasAwait) {
  12242. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  12243. return;
  12244. }
  12245. if (this.scope.inStaticBlock) {
  12246. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  12247. return;
  12248. }
  12249. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  12250. } else if (word === "arguments") {
  12251. if (this.scope.inClassAndNotInNonArrowFunction) {
  12252. this.raise(Errors.ArgumentsInClass, startLoc);
  12253. return;
  12254. }
  12255. }
  12256. }
  12257. recordAwaitIfAllowed() {
  12258. const isAwaitAllowed = this.prodParam.hasAwait;
  12259. if (isAwaitAllowed && !this.scope.inFunction) {
  12260. this.state.hasTopLevelAwait = true;
  12261. }
  12262. return isAwaitAllowed;
  12263. }
  12264. parseAwait(startLoc) {
  12265. const node = this.startNodeAt(startLoc);
  12266. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  12267. if (this.eat(55)) {
  12268. this.raise(Errors.ObsoleteAwaitStar, node);
  12269. }
  12270. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  12271. if (this.isAmbiguousPrefixOrIdentifier()) {
  12272. this.ambiguousScriptDifferentAst = true;
  12273. } else {
  12274. this.sawUnambiguousESM = true;
  12275. }
  12276. }
  12277. if (!this.state.soloAwait) {
  12278. node.argument = this.parseMaybeUnary(null, true);
  12279. }
  12280. return this.finishNode(node, "AwaitExpression");
  12281. }
  12282. isAmbiguousPrefixOrIdentifier() {
  12283. if (this.hasPrecedingLineBreak()) return true;
  12284. const {
  12285. type
  12286. } = this.state;
  12287. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12288. }
  12289. parseYield(startLoc) {
  12290. const node = this.startNodeAt(startLoc);
  12291. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  12292. let delegating = false;
  12293. let argument = null;
  12294. if (!this.hasPrecedingLineBreak()) {
  12295. delegating = this.eat(55);
  12296. switch (this.state.type) {
  12297. case 13:
  12298. case 140:
  12299. case 8:
  12300. case 11:
  12301. case 3:
  12302. case 9:
  12303. case 14:
  12304. case 12:
  12305. if (!delegating) break;
  12306. default:
  12307. argument = this.parseMaybeAssign();
  12308. }
  12309. }
  12310. node.delegate = delegating;
  12311. node.argument = argument;
  12312. return this.finishNode(node, "YieldExpression");
  12313. }
  12314. parseImportCall(node) {
  12315. this.next();
  12316. node.source = this.parseMaybeAssignAllowIn();
  12317. node.options = null;
  12318. if (this.eat(12)) {
  12319. if (!this.match(11)) {
  12320. node.options = this.parseMaybeAssignAllowIn();
  12321. if (this.eat(12)) {
  12322. this.addTrailingCommaExtraToNode(node.options);
  12323. if (!this.match(11)) {
  12324. do {
  12325. this.parseMaybeAssignAllowIn();
  12326. } while (this.eat(12) && !this.match(11));
  12327. this.raise(Errors.ImportCallArity, node);
  12328. }
  12329. }
  12330. } else {
  12331. this.addTrailingCommaExtraToNode(node.source);
  12332. }
  12333. }
  12334. this.expect(11);
  12335. return this.finishNode(node, "ImportExpression");
  12336. }
  12337. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12338. if (this.hasPlugin(["pipelineOperator", {
  12339. proposal: "smart"
  12340. }])) {
  12341. if (left.type === "SequenceExpression") {
  12342. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  12343. }
  12344. }
  12345. }
  12346. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12347. if (this.isSimpleReference(childExpr)) {
  12348. const bodyNode = this.startNodeAt(startLoc);
  12349. bodyNode.callee = childExpr;
  12350. return this.finishNode(bodyNode, "PipelineBareFunction");
  12351. } else {
  12352. const bodyNode = this.startNodeAt(startLoc);
  12353. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12354. bodyNode.expression = childExpr;
  12355. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12356. }
  12357. }
  12358. isSimpleReference(expression) {
  12359. switch (expression.type) {
  12360. case "MemberExpression":
  12361. return !expression.computed && this.isSimpleReference(expression.object);
  12362. case "Identifier":
  12363. return true;
  12364. default:
  12365. return false;
  12366. }
  12367. }
  12368. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12369. if (this.match(19)) {
  12370. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  12371. }
  12372. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12373. this.raise(Errors.PipelineTopicUnused, startLoc);
  12374. }
  12375. }
  12376. withTopicBindingContext(callback) {
  12377. const outerContextTopicState = this.state.topicContext;
  12378. this.state.topicContext = {
  12379. maxNumOfResolvableTopics: 1,
  12380. maxTopicIndex: null
  12381. };
  12382. try {
  12383. return callback();
  12384. } finally {
  12385. this.state.topicContext = outerContextTopicState;
  12386. }
  12387. }
  12388. withSmartMixTopicForbiddingContext(callback) {
  12389. if (this.hasPlugin(["pipelineOperator", {
  12390. proposal: "smart"
  12391. }])) {
  12392. const outerContextTopicState = this.state.topicContext;
  12393. this.state.topicContext = {
  12394. maxNumOfResolvableTopics: 0,
  12395. maxTopicIndex: null
  12396. };
  12397. try {
  12398. return callback();
  12399. } finally {
  12400. this.state.topicContext = outerContextTopicState;
  12401. }
  12402. } else {
  12403. return callback();
  12404. }
  12405. }
  12406. withSoloAwaitPermittingContext(callback) {
  12407. const outerContextSoloAwaitState = this.state.soloAwait;
  12408. this.state.soloAwait = true;
  12409. try {
  12410. return callback();
  12411. } finally {
  12412. this.state.soloAwait = outerContextSoloAwaitState;
  12413. }
  12414. }
  12415. allowInAnd(callback) {
  12416. const flags = this.prodParam.currentFlags();
  12417. const prodParamToSet = 8 & ~flags;
  12418. if (prodParamToSet) {
  12419. this.prodParam.enter(flags | 8);
  12420. try {
  12421. return callback();
  12422. } finally {
  12423. this.prodParam.exit();
  12424. }
  12425. }
  12426. return callback();
  12427. }
  12428. disallowInAnd(callback) {
  12429. const flags = this.prodParam.currentFlags();
  12430. const prodParamToClear = 8 & flags;
  12431. if (prodParamToClear) {
  12432. this.prodParam.enter(flags & ~8);
  12433. try {
  12434. return callback();
  12435. } finally {
  12436. this.prodParam.exit();
  12437. }
  12438. }
  12439. return callback();
  12440. }
  12441. registerTopicReference() {
  12442. this.state.topicContext.maxTopicIndex = 0;
  12443. }
  12444. topicReferenceIsAllowedInCurrentContext() {
  12445. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12446. }
  12447. topicReferenceWasUsedInCurrentContext() {
  12448. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12449. }
  12450. parseFSharpPipelineBody(prec) {
  12451. const startLoc = this.state.startLoc;
  12452. this.state.potentialArrowAt = this.state.start;
  12453. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12454. this.state.inFSharpPipelineDirectBody = true;
  12455. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12456. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12457. return ret;
  12458. }
  12459. parseModuleExpression() {
  12460. this.expectPlugin("moduleBlocks");
  12461. const node = this.startNode();
  12462. this.next();
  12463. if (!this.match(5)) {
  12464. this.unexpected(null, 5);
  12465. }
  12466. const program = this.startNodeAt(this.state.endLoc);
  12467. this.next();
  12468. const revertScopes = this.initializeScopes(true);
  12469. this.enterInitialScopes();
  12470. try {
  12471. node.body = this.parseProgram(program, 8, "module");
  12472. } finally {
  12473. revertScopes();
  12474. }
  12475. return this.finishNode(node, "ModuleExpression");
  12476. }
  12477. parseVoidPattern(refExpressionErrors) {
  12478. this.expectPlugin("discardBinding");
  12479. const node = this.startNode();
  12480. if (refExpressionErrors != null) {
  12481. refExpressionErrors.voidPatternLoc = this.state.startLoc;
  12482. }
  12483. this.next();
  12484. return this.finishNode(node, "VoidPattern");
  12485. }
  12486. parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
  12487. if (refExpressionErrors != null && this.match(88)) {
  12488. const nextCode = this.lookaheadCharCode();
  12489. if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
  12490. return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
  12491. }
  12492. }
  12493. return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
  12494. }
  12495. parsePropertyNamePrefixOperator(prop) {}
  12496. }
  12497. const loopLabel = {
  12498. kind: 1
  12499. },
  12500. switchLabel = {
  12501. kind: 2
  12502. };
  12503. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12504. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12505. function babel7CompatTokens(tokens, input, startIndex) {
  12506. for (let i = 0; i < tokens.length; i++) {
  12507. const token = tokens[i];
  12508. const {
  12509. type
  12510. } = token;
  12511. if (typeof type === "number") {
  12512. {
  12513. if (type === 139) {
  12514. const {
  12515. loc,
  12516. start,
  12517. value,
  12518. end
  12519. } = token;
  12520. const hashEndPos = start + 1;
  12521. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12522. tokens.splice(i, 1, new Token({
  12523. type: getExportedToken(27),
  12524. value: "#",
  12525. start: start,
  12526. end: hashEndPos,
  12527. startLoc: loc.start,
  12528. endLoc: hashEndLoc
  12529. }), new Token({
  12530. type: getExportedToken(132),
  12531. value: value,
  12532. start: hashEndPos,
  12533. end: end,
  12534. startLoc: hashEndLoc,
  12535. endLoc: loc.end
  12536. }));
  12537. i++;
  12538. continue;
  12539. }
  12540. if (tokenIsTemplate(type)) {
  12541. const {
  12542. loc,
  12543. start,
  12544. value,
  12545. end
  12546. } = token;
  12547. const backquoteEnd = start + 1;
  12548. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12549. let startToken;
  12550. if (input.charCodeAt(start - startIndex) === 96) {
  12551. startToken = new Token({
  12552. type: getExportedToken(22),
  12553. value: "`",
  12554. start: start,
  12555. end: backquoteEnd,
  12556. startLoc: loc.start,
  12557. endLoc: backquoteEndLoc
  12558. });
  12559. } else {
  12560. startToken = new Token({
  12561. type: getExportedToken(8),
  12562. value: "}",
  12563. start: start,
  12564. end: backquoteEnd,
  12565. startLoc: loc.start,
  12566. endLoc: backquoteEndLoc
  12567. });
  12568. }
  12569. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12570. if (type === 24) {
  12571. templateElementEnd = end - 1;
  12572. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12573. templateValue = value === null ? null : value.slice(1, -1);
  12574. endToken = new Token({
  12575. type: getExportedToken(22),
  12576. value: "`",
  12577. start: templateElementEnd,
  12578. end: end,
  12579. startLoc: templateElementEndLoc,
  12580. endLoc: loc.end
  12581. });
  12582. } else {
  12583. templateElementEnd = end - 2;
  12584. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12585. templateValue = value === null ? null : value.slice(1, -2);
  12586. endToken = new Token({
  12587. type: getExportedToken(23),
  12588. value: "${",
  12589. start: templateElementEnd,
  12590. end: end,
  12591. startLoc: templateElementEndLoc,
  12592. endLoc: loc.end
  12593. });
  12594. }
  12595. tokens.splice(i, 1, startToken, new Token({
  12596. type: getExportedToken(20),
  12597. value: templateValue,
  12598. start: backquoteEnd,
  12599. end: templateElementEnd,
  12600. startLoc: backquoteEndLoc,
  12601. endLoc: templateElementEndLoc
  12602. }), endToken);
  12603. i += 2;
  12604. continue;
  12605. }
  12606. }
  12607. token.type = getExportedToken(type);
  12608. }
  12609. }
  12610. return tokens;
  12611. }
  12612. class StatementParser extends ExpressionParser {
  12613. parseTopLevel(file, program) {
  12614. file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
  12615. file.comments = this.comments;
  12616. if (this.optionFlags & 256) {
  12617. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  12618. }
  12619. return this.finishNode(file, "File");
  12620. }
  12621. parseProgram(program, end, sourceType) {
  12622. program.sourceType = sourceType;
  12623. program.interpreter = this.parseInterpreterDirective();
  12624. this.parseBlockBody(program, true, true, end);
  12625. if (this.inModule) {
  12626. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  12627. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12628. this.raise(Errors.ModuleExportUndefined, at, {
  12629. localName
  12630. });
  12631. }
  12632. }
  12633. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  12634. }
  12635. let finishedProgram;
  12636. if (end === 140) {
  12637. finishedProgram = this.finishNode(program, "Program");
  12638. } else {
  12639. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12640. }
  12641. return finishedProgram;
  12642. }
  12643. stmtToDirective(stmt) {
  12644. const directive = this.castNodeTo(stmt, "Directive");
  12645. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  12646. const expressionValue = directiveLiteral.value;
  12647. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  12648. const val = directiveLiteral.value = raw.slice(1, -1);
  12649. this.addExtra(directiveLiteral, "raw", raw);
  12650. this.addExtra(directiveLiteral, "rawValue", val);
  12651. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12652. directive.value = directiveLiteral;
  12653. delete stmt.expression;
  12654. return directive;
  12655. }
  12656. parseInterpreterDirective() {
  12657. if (!this.match(28)) {
  12658. return null;
  12659. }
  12660. const node = this.startNode();
  12661. node.value = this.state.value;
  12662. this.next();
  12663. return this.finishNode(node, "InterpreterDirective");
  12664. }
  12665. isLet() {
  12666. if (!this.isContextual(100)) {
  12667. return false;
  12668. }
  12669. return this.hasFollowingBindingAtom();
  12670. }
  12671. isUsing() {
  12672. if (!this.isContextual(107)) {
  12673. return false;
  12674. }
  12675. const next = this.nextTokenInLineStart();
  12676. const nextCh = this.codePointAtPos(next);
  12677. return this.chStartsBindingIdentifier(nextCh, next);
  12678. }
  12679. isForUsing() {
  12680. if (!this.isContextual(107)) {
  12681. return false;
  12682. }
  12683. const next = this.nextTokenInLineStart();
  12684. const nextCh = this.codePointAtPos(next);
  12685. if (this.isUnparsedContextual(next, "of")) {
  12686. const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
  12687. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  12688. return false;
  12689. }
  12690. }
  12691. if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
  12692. return true;
  12693. }
  12694. return false;
  12695. }
  12696. isAwaitUsing() {
  12697. if (!this.isContextual(96)) {
  12698. return false;
  12699. }
  12700. let next = this.nextTokenInLineStart();
  12701. if (this.isUnparsedContextual(next, "using")) {
  12702. next = this.nextTokenInLineStartSince(next + 5);
  12703. const nextCh = this.codePointAtPos(next);
  12704. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12705. return true;
  12706. }
  12707. }
  12708. return false;
  12709. }
  12710. chStartsBindingIdentifier(ch, pos) {
  12711. if (isIdentifierStart(ch)) {
  12712. keywordRelationalOperator.lastIndex = pos;
  12713. if (keywordRelationalOperator.test(this.input)) {
  12714. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12715. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12716. return false;
  12717. }
  12718. }
  12719. return true;
  12720. } else if (ch === 92) {
  12721. return true;
  12722. } else {
  12723. return false;
  12724. }
  12725. }
  12726. chStartsBindingPattern(ch) {
  12727. return ch === 91 || ch === 123;
  12728. }
  12729. hasFollowingBindingAtom() {
  12730. const next = this.nextTokenStart();
  12731. const nextCh = this.codePointAtPos(next);
  12732. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12733. }
  12734. hasInLineFollowingBindingIdentifierOrBrace() {
  12735. const next = this.nextTokenInLineStart();
  12736. const nextCh = this.codePointAtPos(next);
  12737. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  12738. }
  12739. allowsUsing() {
  12740. return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
  12741. }
  12742. parseModuleItem() {
  12743. return this.parseStatementLike(1 | 2 | 4 | 8);
  12744. }
  12745. parseStatementListItem() {
  12746. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12747. }
  12748. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12749. let flags = 0;
  12750. if (this.options.annexB && !this.state.strict) {
  12751. flags |= 4;
  12752. if (allowLabeledFunction) {
  12753. flags |= 8;
  12754. }
  12755. }
  12756. return this.parseStatementLike(flags);
  12757. }
  12758. parseStatement() {
  12759. return this.parseStatementLike(0);
  12760. }
  12761. parseStatementLike(flags) {
  12762. let decorators = null;
  12763. if (this.match(26)) {
  12764. decorators = this.parseDecorators(true);
  12765. }
  12766. return this.parseStatementContent(flags, decorators);
  12767. }
  12768. parseStatementContent(flags, decorators) {
  12769. const startType = this.state.type;
  12770. const node = this.startNode();
  12771. const allowDeclaration = !!(flags & 2);
  12772. const allowFunctionDeclaration = !!(flags & 4);
  12773. const topLevel = flags & 1;
  12774. switch (startType) {
  12775. case 60:
  12776. return this.parseBreakContinueStatement(node, true);
  12777. case 63:
  12778. return this.parseBreakContinueStatement(node, false);
  12779. case 64:
  12780. return this.parseDebuggerStatement(node);
  12781. case 90:
  12782. return this.parseDoWhileStatement(node);
  12783. case 91:
  12784. return this.parseForStatement(node);
  12785. case 68:
  12786. if (this.lookaheadCharCode() === 46) break;
  12787. if (!allowFunctionDeclaration) {
  12788. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12789. }
  12790. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12791. case 80:
  12792. if (!allowDeclaration) this.unexpected();
  12793. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12794. case 69:
  12795. return this.parseIfStatement(node);
  12796. case 70:
  12797. return this.parseReturnStatement(node);
  12798. case 71:
  12799. return this.parseSwitchStatement(node);
  12800. case 72:
  12801. return this.parseThrowStatement(node);
  12802. case 73:
  12803. return this.parseTryStatement(node);
  12804. case 96:
  12805. if (this.isAwaitUsing()) {
  12806. if (!this.allowsUsing()) {
  12807. this.raise(Errors.UnexpectedUsingDeclaration, node);
  12808. } else if (!allowDeclaration) {
  12809. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12810. } else if (!this.recordAwaitIfAllowed()) {
  12811. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12812. }
  12813. this.next();
  12814. return this.parseVarStatement(node, "await using");
  12815. }
  12816. break;
  12817. case 107:
  12818. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  12819. break;
  12820. }
  12821. if (!this.allowsUsing()) {
  12822. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12823. } else if (!allowDeclaration) {
  12824. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12825. }
  12826. return this.parseVarStatement(node, "using");
  12827. case 100:
  12828. {
  12829. if (this.state.containsEsc) {
  12830. break;
  12831. }
  12832. const next = this.nextTokenStart();
  12833. const nextCh = this.codePointAtPos(next);
  12834. if (nextCh !== 91) {
  12835. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12836. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12837. break;
  12838. }
  12839. }
  12840. }
  12841. case 75:
  12842. {
  12843. if (!allowDeclaration) {
  12844. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12845. }
  12846. }
  12847. case 74:
  12848. {
  12849. const kind = this.state.value;
  12850. return this.parseVarStatement(node, kind);
  12851. }
  12852. case 92:
  12853. return this.parseWhileStatement(node);
  12854. case 76:
  12855. return this.parseWithStatement(node);
  12856. case 5:
  12857. return this.parseBlock();
  12858. case 13:
  12859. return this.parseEmptyStatement(node);
  12860. case 83:
  12861. {
  12862. const nextTokenCharCode = this.lookaheadCharCode();
  12863. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12864. break;
  12865. }
  12866. }
  12867. case 82:
  12868. {
  12869. if (!(this.optionFlags & 8) && !topLevel) {
  12870. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12871. }
  12872. this.next();
  12873. let result;
  12874. if (startType === 83) {
  12875. result = this.parseImport(node);
  12876. } else {
  12877. result = this.parseExport(node, decorators);
  12878. }
  12879. this.assertModuleNodeAllowed(result);
  12880. return result;
  12881. }
  12882. default:
  12883. {
  12884. if (this.isAsyncFunction()) {
  12885. if (!allowDeclaration) {
  12886. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12887. }
  12888. this.next();
  12889. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12890. }
  12891. }
  12892. }
  12893. const maybeName = this.state.value;
  12894. const expr = this.parseExpression();
  12895. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  12896. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12897. } else {
  12898. return this.parseExpressionStatement(node, expr, decorators);
  12899. }
  12900. }
  12901. assertModuleNodeAllowed(node) {
  12902. if (!(this.optionFlags & 8) && !this.inModule) {
  12903. this.raise(Errors.ImportOutsideModule, node);
  12904. }
  12905. }
  12906. decoratorsEnabledBeforeExport() {
  12907. if (this.hasPlugin("decorators-legacy")) return true;
  12908. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12909. }
  12910. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12911. if (maybeDecorators) {
  12912. var _classNode$decorators;
  12913. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  12914. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12915. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12916. }
  12917. classNode.decorators.unshift(...maybeDecorators);
  12918. } else {
  12919. classNode.decorators = maybeDecorators;
  12920. }
  12921. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12922. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12923. }
  12924. return classNode;
  12925. }
  12926. canHaveLeadingDecorator() {
  12927. return this.match(80);
  12928. }
  12929. parseDecorators(allowExport) {
  12930. const decorators = [];
  12931. do {
  12932. decorators.push(this.parseDecorator());
  12933. } while (this.match(26));
  12934. if (this.match(82)) {
  12935. if (!allowExport) {
  12936. this.unexpected();
  12937. }
  12938. if (!this.decoratorsEnabledBeforeExport()) {
  12939. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  12940. }
  12941. } else if (!this.canHaveLeadingDecorator()) {
  12942. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  12943. }
  12944. return decorators;
  12945. }
  12946. parseDecorator() {
  12947. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12948. const node = this.startNode();
  12949. this.next();
  12950. if (this.hasPlugin("decorators")) {
  12951. const startLoc = this.state.startLoc;
  12952. let expr;
  12953. if (this.match(10)) {
  12954. const startLoc = this.state.startLoc;
  12955. this.next();
  12956. expr = this.parseExpression();
  12957. this.expect(11);
  12958. expr = this.wrapParenthesis(startLoc, expr);
  12959. const paramsStartLoc = this.state.startLoc;
  12960. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12961. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12962. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  12963. }
  12964. } else {
  12965. expr = this.parseIdentifier(false);
  12966. while (this.eat(16)) {
  12967. const node = this.startNodeAt(startLoc);
  12968. node.object = expr;
  12969. if (this.match(139)) {
  12970. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12971. node.property = this.parsePrivateName();
  12972. } else {
  12973. node.property = this.parseIdentifier(true);
  12974. }
  12975. node.computed = false;
  12976. expr = this.finishNode(node, "MemberExpression");
  12977. }
  12978. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12979. }
  12980. } else {
  12981. node.expression = this.parseExprSubscripts();
  12982. }
  12983. return this.finishNode(node, "Decorator");
  12984. }
  12985. parseMaybeDecoratorArguments(expr, startLoc) {
  12986. if (this.eat(10)) {
  12987. const node = this.startNodeAt(startLoc);
  12988. node.callee = expr;
  12989. node.arguments = this.parseCallExpressionArguments();
  12990. this.toReferencedList(node.arguments);
  12991. return this.finishNode(node, "CallExpression");
  12992. }
  12993. return expr;
  12994. }
  12995. parseBreakContinueStatement(node, isBreak) {
  12996. this.next();
  12997. if (this.isLineTerminator()) {
  12998. node.label = null;
  12999. } else {
  13000. node.label = this.parseIdentifier();
  13001. this.semicolon();
  13002. }
  13003. this.verifyBreakContinue(node, isBreak);
  13004. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  13005. }
  13006. verifyBreakContinue(node, isBreak) {
  13007. let i;
  13008. for (i = 0; i < this.state.labels.length; ++i) {
  13009. const lab = this.state.labels[i];
  13010. if (node.label == null || lab.name === node.label.name) {
  13011. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  13012. break;
  13013. }
  13014. if (node.label && isBreak) break;
  13015. }
  13016. }
  13017. if (i === this.state.labels.length) {
  13018. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  13019. this.raise(Errors.IllegalBreakContinue, node, {
  13020. type
  13021. });
  13022. }
  13023. }
  13024. parseDebuggerStatement(node) {
  13025. this.next();
  13026. this.semicolon();
  13027. return this.finishNode(node, "DebuggerStatement");
  13028. }
  13029. parseHeaderExpression() {
  13030. this.expect(10);
  13031. const val = this.parseExpression();
  13032. this.expect(11);
  13033. return val;
  13034. }
  13035. parseDoWhileStatement(node) {
  13036. this.next();
  13037. this.state.labels.push(loopLabel);
  13038. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13039. this.state.labels.pop();
  13040. this.expect(92);
  13041. node.test = this.parseHeaderExpression();
  13042. this.eat(13);
  13043. return this.finishNode(node, "DoWhileStatement");
  13044. }
  13045. parseForStatement(node) {
  13046. this.next();
  13047. this.state.labels.push(loopLabel);
  13048. let awaitAt = null;
  13049. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  13050. awaitAt = this.state.startLoc;
  13051. this.next();
  13052. }
  13053. this.scope.enter(0);
  13054. this.expect(10);
  13055. if (this.match(13)) {
  13056. if (awaitAt !== null) {
  13057. this.unexpected(awaitAt);
  13058. }
  13059. return this.parseFor(node, null);
  13060. }
  13061. const startsWithLet = this.isContextual(100);
  13062. {
  13063. const startsWithAwaitUsing = this.isAwaitUsing();
  13064. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
  13065. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  13066. if (this.match(74) || this.match(75) || isLetOrUsing) {
  13067. const initNode = this.startNode();
  13068. let kind;
  13069. if (startsWithAwaitUsing) {
  13070. kind = "await using";
  13071. if (!this.recordAwaitIfAllowed()) {
  13072. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  13073. }
  13074. this.next();
  13075. } else {
  13076. kind = this.state.value;
  13077. }
  13078. this.next();
  13079. this.parseVar(initNode, true, kind);
  13080. const init = this.finishNode(initNode, "VariableDeclaration");
  13081. const isForIn = this.match(58);
  13082. if (isForIn && starsWithUsingDeclaration) {
  13083. this.raise(Errors.ForInUsing, init);
  13084. }
  13085. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  13086. return this.parseForIn(node, init, awaitAt);
  13087. }
  13088. if (awaitAt !== null) {
  13089. this.unexpected(awaitAt);
  13090. }
  13091. return this.parseFor(node, init);
  13092. }
  13093. }
  13094. const startsWithAsync = this.isContextual(95);
  13095. const refExpressionErrors = new ExpressionErrors();
  13096. const init = this.parseExpression(true, refExpressionErrors);
  13097. const isForOf = this.isContextual(102);
  13098. if (isForOf) {
  13099. if (startsWithLet) {
  13100. this.raise(Errors.ForOfLet, init);
  13101. }
  13102. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  13103. this.raise(Errors.ForOfAsync, init);
  13104. }
  13105. }
  13106. if (isForOf || this.match(58)) {
  13107. this.checkDestructuringPrivate(refExpressionErrors);
  13108. this.toAssignable(init, true);
  13109. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  13110. this.checkLVal(init, {
  13111. type
  13112. });
  13113. return this.parseForIn(node, init, awaitAt);
  13114. } else {
  13115. this.checkExpressionErrors(refExpressionErrors, true);
  13116. }
  13117. if (awaitAt !== null) {
  13118. this.unexpected(awaitAt);
  13119. }
  13120. return this.parseFor(node, init);
  13121. }
  13122. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  13123. this.next();
  13124. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  13125. }
  13126. parseIfStatement(node) {
  13127. this.next();
  13128. node.test = this.parseHeaderExpression();
  13129. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  13130. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  13131. return this.finishNode(node, "IfStatement");
  13132. }
  13133. parseReturnStatement(node) {
  13134. if (!this.prodParam.hasReturn) {
  13135. this.raise(Errors.IllegalReturn, this.state.startLoc);
  13136. }
  13137. this.next();
  13138. if (this.isLineTerminator()) {
  13139. node.argument = null;
  13140. } else {
  13141. node.argument = this.parseExpression();
  13142. this.semicolon();
  13143. }
  13144. return this.finishNode(node, "ReturnStatement");
  13145. }
  13146. parseSwitchStatement(node) {
  13147. this.next();
  13148. node.discriminant = this.parseHeaderExpression();
  13149. const cases = node.cases = [];
  13150. this.expect(5);
  13151. this.state.labels.push(switchLabel);
  13152. this.scope.enter(256);
  13153. let cur;
  13154. for (let sawDefault; !this.match(8);) {
  13155. if (this.match(61) || this.match(65)) {
  13156. const isCase = this.match(61);
  13157. if (cur) this.finishNode(cur, "SwitchCase");
  13158. cases.push(cur = this.startNode());
  13159. cur.consequent = [];
  13160. this.next();
  13161. if (isCase) {
  13162. cur.test = this.parseExpression();
  13163. } else {
  13164. if (sawDefault) {
  13165. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  13166. }
  13167. sawDefault = true;
  13168. cur.test = null;
  13169. }
  13170. this.expect(14);
  13171. } else {
  13172. if (cur) {
  13173. cur.consequent.push(this.parseStatementListItem());
  13174. } else {
  13175. this.unexpected();
  13176. }
  13177. }
  13178. }
  13179. this.scope.exit();
  13180. if (cur) this.finishNode(cur, "SwitchCase");
  13181. this.next();
  13182. this.state.labels.pop();
  13183. return this.finishNode(node, "SwitchStatement");
  13184. }
  13185. parseThrowStatement(node) {
  13186. this.next();
  13187. if (this.hasPrecedingLineBreak()) {
  13188. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  13189. }
  13190. node.argument = this.parseExpression();
  13191. this.semicolon();
  13192. return this.finishNode(node, "ThrowStatement");
  13193. }
  13194. parseCatchClauseParam() {
  13195. const param = this.parseBindingAtom();
  13196. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13197. this.checkLVal(param, {
  13198. type: "CatchClause"
  13199. }, 9);
  13200. return param;
  13201. }
  13202. parseTryStatement(node) {
  13203. this.next();
  13204. node.block = this.parseBlock();
  13205. node.handler = null;
  13206. if (this.match(62)) {
  13207. const clause = this.startNode();
  13208. this.next();
  13209. if (this.match(10)) {
  13210. this.expect(10);
  13211. clause.param = this.parseCatchClauseParam();
  13212. this.expect(11);
  13213. } else {
  13214. clause.param = null;
  13215. this.scope.enter(0);
  13216. }
  13217. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13218. this.scope.exit();
  13219. node.handler = this.finishNode(clause, "CatchClause");
  13220. }
  13221. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13222. if (!node.handler && !node.finalizer) {
  13223. this.raise(Errors.NoCatchOrFinally, node);
  13224. }
  13225. return this.finishNode(node, "TryStatement");
  13226. }
  13227. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13228. this.next();
  13229. this.parseVar(node, false, kind, allowMissingInitializer);
  13230. this.semicolon();
  13231. return this.finishNode(node, "VariableDeclaration");
  13232. }
  13233. parseWhileStatement(node) {
  13234. this.next();
  13235. node.test = this.parseHeaderExpression();
  13236. this.state.labels.push(loopLabel);
  13237. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13238. this.state.labels.pop();
  13239. return this.finishNode(node, "WhileStatement");
  13240. }
  13241. parseWithStatement(node) {
  13242. if (this.state.strict) {
  13243. this.raise(Errors.StrictWith, this.state.startLoc);
  13244. }
  13245. this.next();
  13246. node.object = this.parseHeaderExpression();
  13247. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13248. return this.finishNode(node, "WithStatement");
  13249. }
  13250. parseEmptyStatement(node) {
  13251. this.next();
  13252. return this.finishNode(node, "EmptyStatement");
  13253. }
  13254. parseLabeledStatement(node, maybeName, expr, flags) {
  13255. for (const label of this.state.labels) {
  13256. if (label.name === maybeName) {
  13257. this.raise(Errors.LabelRedeclaration, expr, {
  13258. labelName: maybeName
  13259. });
  13260. }
  13261. }
  13262. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  13263. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13264. const label = this.state.labels[i];
  13265. if (label.statementStart === node.start) {
  13266. label.statementStart = this.sourceToOffsetPos(this.state.start);
  13267. label.kind = kind;
  13268. } else {
  13269. break;
  13270. }
  13271. }
  13272. this.state.labels.push({
  13273. name: maybeName,
  13274. kind: kind,
  13275. statementStart: this.sourceToOffsetPos(this.state.start)
  13276. });
  13277. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13278. this.state.labels.pop();
  13279. node.label = expr;
  13280. return this.finishNode(node, "LabeledStatement");
  13281. }
  13282. parseExpressionStatement(node, expr, decorators) {
  13283. node.expression = expr;
  13284. this.semicolon();
  13285. return this.finishNode(node, "ExpressionStatement");
  13286. }
  13287. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13288. const node = this.startNode();
  13289. if (allowDirectives) {
  13290. this.state.strictErrors.clear();
  13291. }
  13292. this.expect(5);
  13293. if (createNewLexicalScope) {
  13294. this.scope.enter(0);
  13295. }
  13296. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13297. if (createNewLexicalScope) {
  13298. this.scope.exit();
  13299. }
  13300. return this.finishNode(node, "BlockStatement");
  13301. }
  13302. isValidDirective(stmt) {
  13303. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13304. }
  13305. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13306. const body = node.body = [];
  13307. const directives = node.directives = [];
  13308. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13309. }
  13310. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13311. const oldStrict = this.state.strict;
  13312. let hasStrictModeDirective = false;
  13313. let parsedNonDirective = false;
  13314. while (!this.match(end)) {
  13315. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13316. if (directives && !parsedNonDirective) {
  13317. if (this.isValidDirective(stmt)) {
  13318. const directive = this.stmtToDirective(stmt);
  13319. directives.push(directive);
  13320. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13321. hasStrictModeDirective = true;
  13322. this.setStrict(true);
  13323. }
  13324. continue;
  13325. }
  13326. parsedNonDirective = true;
  13327. this.state.strictErrors.clear();
  13328. }
  13329. body.push(stmt);
  13330. }
  13331. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  13332. if (!oldStrict) {
  13333. this.setStrict(false);
  13334. }
  13335. this.next();
  13336. }
  13337. parseFor(node, init) {
  13338. node.init = init;
  13339. this.semicolon(false);
  13340. node.test = this.match(13) ? null : this.parseExpression();
  13341. this.semicolon(false);
  13342. node.update = this.match(11) ? null : this.parseExpression();
  13343. this.expect(11);
  13344. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13345. this.scope.exit();
  13346. this.state.labels.pop();
  13347. return this.finishNode(node, "ForStatement");
  13348. }
  13349. parseForIn(node, init, awaitAt) {
  13350. const isForIn = this.match(58);
  13351. this.next();
  13352. if (isForIn) {
  13353. if (awaitAt !== null) this.unexpected(awaitAt);
  13354. } else {
  13355. node.await = awaitAt !== null;
  13356. }
  13357. 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")) {
  13358. this.raise(Errors.ForInOfLoopInitializer, init, {
  13359. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13360. });
  13361. }
  13362. if (init.type === "AssignmentPattern") {
  13363. this.raise(Errors.InvalidLhs, init, {
  13364. ancestor: {
  13365. type: "ForStatement"
  13366. }
  13367. });
  13368. }
  13369. node.left = init;
  13370. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13371. this.expect(11);
  13372. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13373. this.scope.exit();
  13374. this.state.labels.pop();
  13375. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13376. }
  13377. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13378. const declarations = node.declarations = [];
  13379. node.kind = kind;
  13380. for (;;) {
  13381. const decl = this.startNode();
  13382. this.parseVarId(decl, kind);
  13383. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13384. if (decl.init === null && !allowMissingInitializer) {
  13385. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13386. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13387. kind: "destructuring"
  13388. });
  13389. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  13390. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13391. kind
  13392. });
  13393. }
  13394. }
  13395. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13396. if (!this.eat(12)) break;
  13397. }
  13398. return node;
  13399. }
  13400. parseVarId(decl, kind) {
  13401. const id = this.parseBindingAtom();
  13402. if (kind === "using" || kind === "await using") {
  13403. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  13404. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  13405. }
  13406. } else {
  13407. if (id.type === "VoidPattern") {
  13408. this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
  13409. }
  13410. }
  13411. this.checkLVal(id, {
  13412. type: "VariableDeclarator"
  13413. }, kind === "var" ? 5 : 8201);
  13414. decl.id = id;
  13415. }
  13416. parseAsyncFunctionExpression(node) {
  13417. return this.parseFunction(node, 8);
  13418. }
  13419. parseFunction(node, flags = 0) {
  13420. const hangingDeclaration = flags & 2;
  13421. const isDeclaration = !!(flags & 1);
  13422. const requireId = isDeclaration && !(flags & 4);
  13423. const isAsync = !!(flags & 8);
  13424. this.initFunction(node, isAsync);
  13425. if (this.match(55)) {
  13426. if (hangingDeclaration) {
  13427. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  13428. }
  13429. this.next();
  13430. node.generator = true;
  13431. }
  13432. if (isDeclaration) {
  13433. node.id = this.parseFunctionId(requireId);
  13434. }
  13435. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13436. this.state.maybeInArrowParameters = false;
  13437. this.scope.enter(514);
  13438. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13439. if (!isDeclaration) {
  13440. node.id = this.parseFunctionId();
  13441. }
  13442. this.parseFunctionParams(node, false);
  13443. this.withSmartMixTopicForbiddingContext(() => {
  13444. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13445. });
  13446. this.prodParam.exit();
  13447. this.scope.exit();
  13448. if (isDeclaration && !hangingDeclaration) {
  13449. this.registerFunctionStatementId(node);
  13450. }
  13451. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13452. return node;
  13453. }
  13454. parseFunctionId(requireId) {
  13455. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13456. }
  13457. parseFunctionParams(node, isConstructor) {
  13458. this.expect(10);
  13459. this.expressionScope.enter(newParameterDeclarationScope());
  13460. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13461. this.expressionScope.exit();
  13462. }
  13463. registerFunctionStatementId(node) {
  13464. if (!node.id) return;
  13465. 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);
  13466. }
  13467. parseClass(node, isStatement, optionalId) {
  13468. this.next();
  13469. const oldStrict = this.state.strict;
  13470. this.state.strict = true;
  13471. this.parseClassId(node, isStatement, optionalId);
  13472. this.parseClassSuper(node);
  13473. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13474. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13475. }
  13476. isClassProperty() {
  13477. return this.match(29) || this.match(13) || this.match(8);
  13478. }
  13479. isClassMethod() {
  13480. return this.match(10);
  13481. }
  13482. nameIsConstructor(key) {
  13483. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  13484. }
  13485. isNonstaticConstructor(method) {
  13486. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  13487. }
  13488. parseClassBody(hadSuperClass, oldStrict) {
  13489. this.classScope.enter();
  13490. const state = {
  13491. hadConstructor: false,
  13492. hadSuperClass
  13493. };
  13494. let decorators = [];
  13495. const classBody = this.startNode();
  13496. classBody.body = [];
  13497. this.expect(5);
  13498. this.withSmartMixTopicForbiddingContext(() => {
  13499. while (!this.match(8)) {
  13500. if (this.eat(13)) {
  13501. if (decorators.length > 0) {
  13502. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  13503. }
  13504. continue;
  13505. }
  13506. if (this.match(26)) {
  13507. decorators.push(this.parseDecorator());
  13508. continue;
  13509. }
  13510. const member = this.startNode();
  13511. if (decorators.length) {
  13512. member.decorators = decorators;
  13513. this.resetStartLocationFromNode(member, decorators[0]);
  13514. decorators = [];
  13515. }
  13516. this.parseClassMember(classBody, member, state);
  13517. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13518. this.raise(Errors.DecoratorConstructor, member);
  13519. }
  13520. }
  13521. });
  13522. this.state.strict = oldStrict;
  13523. this.next();
  13524. if (decorators.length) {
  13525. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13526. }
  13527. this.classScope.exit();
  13528. return this.finishNode(classBody, "ClassBody");
  13529. }
  13530. parseClassMemberFromModifier(classBody, member) {
  13531. const key = this.parseIdentifier(true);
  13532. if (this.isClassMethod()) {
  13533. const method = member;
  13534. method.kind = "method";
  13535. method.computed = false;
  13536. method.key = key;
  13537. method.static = false;
  13538. this.pushClassMethod(classBody, method, false, false, false, false);
  13539. return true;
  13540. } else if (this.isClassProperty()) {
  13541. const prop = member;
  13542. prop.computed = false;
  13543. prop.key = key;
  13544. prop.static = false;
  13545. classBody.body.push(this.parseClassProperty(prop));
  13546. return true;
  13547. }
  13548. this.resetPreviousNodeTrailingComments(key);
  13549. return false;
  13550. }
  13551. parseClassMember(classBody, member, state) {
  13552. const isStatic = this.isContextual(106);
  13553. if (isStatic) {
  13554. if (this.parseClassMemberFromModifier(classBody, member)) {
  13555. return;
  13556. }
  13557. if (this.eat(5)) {
  13558. this.parseClassStaticBlock(classBody, member);
  13559. return;
  13560. }
  13561. }
  13562. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13563. }
  13564. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13565. const publicMethod = member;
  13566. const privateMethod = member;
  13567. const publicProp = member;
  13568. const privateProp = member;
  13569. const accessorProp = member;
  13570. const method = publicMethod;
  13571. const publicMember = publicMethod;
  13572. member.static = isStatic;
  13573. this.parsePropertyNamePrefixOperator(member);
  13574. if (this.eat(55)) {
  13575. method.kind = "method";
  13576. const isPrivateName = this.match(139);
  13577. this.parseClassElementName(method);
  13578. this.parsePostMemberNameModifiers(method);
  13579. if (isPrivateName) {
  13580. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13581. return;
  13582. }
  13583. if (this.isNonstaticConstructor(publicMethod)) {
  13584. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13585. }
  13586. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13587. return;
  13588. }
  13589. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13590. const key = this.parseClassElementName(member);
  13591. const maybeContextualKw = isContextual ? key.name : null;
  13592. const isPrivate = this.isPrivateName(key);
  13593. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13594. this.parsePostMemberNameModifiers(publicMember);
  13595. if (this.isClassMethod()) {
  13596. method.kind = "method";
  13597. if (isPrivate) {
  13598. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13599. return;
  13600. }
  13601. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13602. let allowsDirectSuper = false;
  13603. if (isConstructor) {
  13604. publicMethod.kind = "constructor";
  13605. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13606. this.raise(Errors.DuplicateConstructor, key);
  13607. }
  13608. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13609. this.raise(Errors.OverrideOnConstructor, key);
  13610. }
  13611. state.hadConstructor = true;
  13612. allowsDirectSuper = state.hadSuperClass;
  13613. }
  13614. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13615. } else if (this.isClassProperty()) {
  13616. if (isPrivate) {
  13617. this.pushClassPrivateProperty(classBody, privateProp);
  13618. } else {
  13619. this.pushClassProperty(classBody, publicProp);
  13620. }
  13621. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13622. this.resetPreviousNodeTrailingComments(key);
  13623. const isGenerator = this.eat(55);
  13624. if (publicMember.optional) {
  13625. this.unexpected(maybeQuestionTokenStartLoc);
  13626. }
  13627. method.kind = "method";
  13628. const isPrivate = this.match(139);
  13629. this.parseClassElementName(method);
  13630. this.parsePostMemberNameModifiers(publicMember);
  13631. if (isPrivate) {
  13632. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13633. } else {
  13634. if (this.isNonstaticConstructor(publicMethod)) {
  13635. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13636. }
  13637. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13638. }
  13639. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13640. this.resetPreviousNodeTrailingComments(key);
  13641. method.kind = maybeContextualKw;
  13642. const isPrivate = this.match(139);
  13643. this.parseClassElementName(publicMethod);
  13644. if (isPrivate) {
  13645. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13646. } else {
  13647. if (this.isNonstaticConstructor(publicMethod)) {
  13648. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13649. }
  13650. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13651. }
  13652. this.checkGetterSetterParams(publicMethod);
  13653. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13654. this.expectPlugin("decoratorAutoAccessors");
  13655. this.resetPreviousNodeTrailingComments(key);
  13656. const isPrivate = this.match(139);
  13657. this.parseClassElementName(publicProp);
  13658. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13659. } else if (this.isLineTerminator()) {
  13660. if (isPrivate) {
  13661. this.pushClassPrivateProperty(classBody, privateProp);
  13662. } else {
  13663. this.pushClassProperty(classBody, publicProp);
  13664. }
  13665. } else {
  13666. this.unexpected();
  13667. }
  13668. }
  13669. parseClassElementName(member) {
  13670. const {
  13671. type,
  13672. value
  13673. } = this.state;
  13674. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  13675. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13676. }
  13677. if (type === 139) {
  13678. if (value === "constructor") {
  13679. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13680. }
  13681. const key = this.parsePrivateName();
  13682. member.key = key;
  13683. return key;
  13684. }
  13685. this.parsePropertyName(member);
  13686. return member.key;
  13687. }
  13688. parseClassStaticBlock(classBody, member) {
  13689. var _member$decorators;
  13690. this.scope.enter(576 | 128 | 16);
  13691. const oldLabels = this.state.labels;
  13692. this.state.labels = [];
  13693. this.prodParam.enter(0);
  13694. const body = member.body = [];
  13695. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13696. this.prodParam.exit();
  13697. this.scope.exit();
  13698. this.state.labels = oldLabels;
  13699. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13700. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13701. this.raise(Errors.DecoratorStaticBlock, member);
  13702. }
  13703. }
  13704. pushClassProperty(classBody, prop) {
  13705. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13706. this.raise(Errors.ConstructorClassField, prop.key);
  13707. }
  13708. classBody.body.push(this.parseClassProperty(prop));
  13709. }
  13710. pushClassPrivateProperty(classBody, prop) {
  13711. const node = this.parseClassPrivateProperty(prop);
  13712. classBody.body.push(node);
  13713. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13714. }
  13715. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13716. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13717. this.raise(Errors.ConstructorClassField, prop.key);
  13718. }
  13719. const node = this.parseClassAccessorProperty(prop);
  13720. classBody.body.push(node);
  13721. if (isPrivate) {
  13722. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13723. }
  13724. }
  13725. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13726. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13727. }
  13728. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13729. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13730. classBody.body.push(node);
  13731. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13732. this.declareClassPrivateMethodInScope(node, kind);
  13733. }
  13734. declareClassPrivateMethodInScope(node, kind) {
  13735. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13736. }
  13737. parsePostMemberNameModifiers(methodOrProp) {}
  13738. parseClassPrivateProperty(node) {
  13739. this.parseInitializer(node);
  13740. this.semicolon();
  13741. return this.finishNode(node, "ClassPrivateProperty");
  13742. }
  13743. parseClassProperty(node) {
  13744. this.parseInitializer(node);
  13745. this.semicolon();
  13746. return this.finishNode(node, "ClassProperty");
  13747. }
  13748. parseClassAccessorProperty(node) {
  13749. this.parseInitializer(node);
  13750. this.semicolon();
  13751. return this.finishNode(node, "ClassAccessorProperty");
  13752. }
  13753. parseInitializer(node) {
  13754. this.scope.enter(576 | 16);
  13755. this.expressionScope.enter(newExpressionScope());
  13756. this.prodParam.enter(0);
  13757. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13758. this.expressionScope.exit();
  13759. this.prodParam.exit();
  13760. this.scope.exit();
  13761. }
  13762. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13763. if (tokenIsIdentifier(this.state.type)) {
  13764. node.id = this.parseIdentifier();
  13765. if (isStatement) {
  13766. this.declareNameFromIdentifier(node.id, bindingType);
  13767. }
  13768. } else {
  13769. if (optionalId || !isStatement) {
  13770. node.id = null;
  13771. } else {
  13772. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13773. }
  13774. }
  13775. }
  13776. parseClassSuper(node) {
  13777. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13778. }
  13779. parseExport(node, decorators) {
  13780. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13781. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13782. const parseAfterDefault = !hasDefault || this.eat(12);
  13783. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13784. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13785. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13786. const isFromRequired = hasDefault || hasStar;
  13787. if (hasStar && !hasNamespace) {
  13788. if (hasDefault) this.unexpected();
  13789. if (decorators) {
  13790. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13791. }
  13792. this.parseExportFrom(node, true);
  13793. this.sawUnambiguousESM = true;
  13794. return this.finishNode(node, "ExportAllDeclaration");
  13795. }
  13796. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13797. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13798. this.unexpected(null, 5);
  13799. }
  13800. if (hasNamespace && parseAfterNamespace) {
  13801. this.unexpected(null, 98);
  13802. }
  13803. let hasDeclaration;
  13804. if (isFromRequired || hasSpecifiers) {
  13805. hasDeclaration = false;
  13806. if (decorators) {
  13807. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13808. }
  13809. this.parseExportFrom(node, isFromRequired);
  13810. } else {
  13811. hasDeclaration = this.maybeParseExportDeclaration(node);
  13812. }
  13813. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13814. var _node2$declaration;
  13815. const node2 = node;
  13816. this.checkExport(node2, true, false, !!node2.source);
  13817. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13818. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13819. } else if (decorators) {
  13820. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13821. }
  13822. this.sawUnambiguousESM = true;
  13823. return this.finishNode(node2, "ExportNamedDeclaration");
  13824. }
  13825. if (this.eat(65)) {
  13826. const node2 = node;
  13827. const decl = this.parseExportDefaultExpression();
  13828. node2.declaration = decl;
  13829. if (decl.type === "ClassDeclaration") {
  13830. this.maybeTakeDecorators(decorators, decl, node2);
  13831. } else if (decorators) {
  13832. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13833. }
  13834. this.checkExport(node2, true, true);
  13835. this.sawUnambiguousESM = true;
  13836. return this.finishNode(node2, "ExportDefaultDeclaration");
  13837. }
  13838. this.unexpected(null, 5);
  13839. }
  13840. eatExportStar(node) {
  13841. return this.eat(55);
  13842. }
  13843. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13844. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13845. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13846. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13847. const specifier = this.startNodeAtNode(id);
  13848. specifier.exported = id;
  13849. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13850. return true;
  13851. }
  13852. return false;
  13853. }
  13854. maybeParseExportNamespaceSpecifier(node) {
  13855. if (this.isContextual(93)) {
  13856. var _ref, _ref$specifiers;
  13857. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13858. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13859. this.next();
  13860. specifier.exported = this.parseModuleExportName();
  13861. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13862. return true;
  13863. }
  13864. return false;
  13865. }
  13866. maybeParseExportNamedSpecifiers(node) {
  13867. if (this.match(5)) {
  13868. const node2 = node;
  13869. if (!node2.specifiers) node2.specifiers = [];
  13870. const isTypeExport = node2.exportKind === "type";
  13871. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13872. node2.source = null;
  13873. if (this.hasPlugin("importAssertions")) {
  13874. node2.assertions = [];
  13875. } else {
  13876. node2.attributes = [];
  13877. }
  13878. node2.declaration = null;
  13879. return true;
  13880. }
  13881. return false;
  13882. }
  13883. maybeParseExportDeclaration(node) {
  13884. if (this.shouldParseExportDeclaration()) {
  13885. node.specifiers = [];
  13886. node.source = null;
  13887. if (this.hasPlugin("importAssertions")) {
  13888. node.assertions = [];
  13889. } else {
  13890. node.attributes = [];
  13891. }
  13892. node.declaration = this.parseExportDeclaration(node);
  13893. return true;
  13894. }
  13895. return false;
  13896. }
  13897. isAsyncFunction() {
  13898. if (!this.isContextual(95)) return false;
  13899. const next = this.nextTokenInLineStart();
  13900. return this.isUnparsedContextual(next, "function");
  13901. }
  13902. parseExportDefaultExpression() {
  13903. const expr = this.startNode();
  13904. if (this.match(68)) {
  13905. this.next();
  13906. return this.parseFunction(expr, 1 | 4);
  13907. } else if (this.isAsyncFunction()) {
  13908. this.next();
  13909. this.next();
  13910. return this.parseFunction(expr, 1 | 4 | 8);
  13911. }
  13912. if (this.match(80)) {
  13913. return this.parseClass(expr, true, true);
  13914. }
  13915. if (this.match(26)) {
  13916. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13917. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13918. }
  13919. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13920. }
  13921. if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
  13922. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13923. }
  13924. const res = this.parseMaybeAssignAllowIn();
  13925. this.semicolon();
  13926. return res;
  13927. }
  13928. parseExportDeclaration(node) {
  13929. if (this.match(80)) {
  13930. const node = this.parseClass(this.startNode(), true, false);
  13931. return node;
  13932. }
  13933. return this.parseStatementListItem();
  13934. }
  13935. isExportDefaultSpecifier() {
  13936. const {
  13937. type
  13938. } = this.state;
  13939. if (tokenIsIdentifier(type)) {
  13940. if (type === 95 && !this.state.containsEsc || type === 100) {
  13941. return false;
  13942. }
  13943. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13944. const next = this.nextTokenStart();
  13945. const nextChar = this.input.charCodeAt(next);
  13946. if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
  13947. this.expectOnePlugin(["flow", "typescript"]);
  13948. return false;
  13949. }
  13950. }
  13951. } else if (!this.match(65)) {
  13952. return false;
  13953. }
  13954. const next = this.nextTokenStart();
  13955. const hasFrom = this.isUnparsedContextual(next, "from");
  13956. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13957. return true;
  13958. }
  13959. if (this.match(65) && hasFrom) {
  13960. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13961. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13962. }
  13963. return false;
  13964. }
  13965. parseExportFrom(node, expect) {
  13966. if (this.eatContextual(98)) {
  13967. node.source = this.parseImportSource();
  13968. this.checkExport(node);
  13969. this.maybeParseImportAttributes(node);
  13970. this.checkJSONModuleImport(node);
  13971. } else if (expect) {
  13972. this.unexpected();
  13973. }
  13974. this.semicolon();
  13975. }
  13976. shouldParseExportDeclaration() {
  13977. const {
  13978. type
  13979. } = this.state;
  13980. if (type === 26) {
  13981. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13982. if (this.hasPlugin("decorators")) {
  13983. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13984. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13985. }
  13986. return true;
  13987. }
  13988. }
  13989. if (this.isUsing()) {
  13990. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13991. return true;
  13992. }
  13993. if (this.isAwaitUsing()) {
  13994. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13995. return true;
  13996. }
  13997. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13998. }
  13999. checkExport(node, checkNames, isDefault, isFrom) {
  14000. if (checkNames) {
  14001. var _node$specifiers;
  14002. if (isDefault) {
  14003. this.checkDuplicateExports(node, "default");
  14004. if (this.hasPlugin("exportDefaultFrom")) {
  14005. var _declaration$extra;
  14006. const declaration = node.declaration;
  14007. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  14008. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  14009. }
  14010. }
  14011. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  14012. for (const specifier of node.specifiers) {
  14013. const {
  14014. exported
  14015. } = specifier;
  14016. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  14017. this.checkDuplicateExports(specifier, exportName);
  14018. if (!isFrom && specifier.local) {
  14019. const {
  14020. local
  14021. } = specifier;
  14022. if (local.type !== "Identifier") {
  14023. this.raise(Errors.ExportBindingIsString, specifier, {
  14024. localName: local.value,
  14025. exportName
  14026. });
  14027. } else {
  14028. this.checkReservedWord(local.name, local.loc.start, true, false);
  14029. this.scope.checkLocalExport(local);
  14030. }
  14031. }
  14032. }
  14033. } else if (node.declaration) {
  14034. const decl = node.declaration;
  14035. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  14036. const {
  14037. id
  14038. } = decl;
  14039. if (!id) throw new Error("Assertion failure");
  14040. this.checkDuplicateExports(node, id.name);
  14041. } else if (decl.type === "VariableDeclaration") {
  14042. for (const declaration of decl.declarations) {
  14043. this.checkDeclaration(declaration.id);
  14044. }
  14045. }
  14046. }
  14047. }
  14048. }
  14049. checkDeclaration(node) {
  14050. if (node.type === "Identifier") {
  14051. this.checkDuplicateExports(node, node.name);
  14052. } else if (node.type === "ObjectPattern") {
  14053. for (const prop of node.properties) {
  14054. this.checkDeclaration(prop);
  14055. }
  14056. } else if (node.type === "ArrayPattern") {
  14057. for (const elem of node.elements) {
  14058. if (elem) {
  14059. this.checkDeclaration(elem);
  14060. }
  14061. }
  14062. } else if (node.type === "ObjectProperty") {
  14063. this.checkDeclaration(node.value);
  14064. } else if (node.type === "RestElement") {
  14065. this.checkDeclaration(node.argument);
  14066. } else if (node.type === "AssignmentPattern") {
  14067. this.checkDeclaration(node.left);
  14068. }
  14069. }
  14070. checkDuplicateExports(node, exportName) {
  14071. if (this.exportedIdentifiers.has(exportName)) {
  14072. if (exportName === "default") {
  14073. this.raise(Errors.DuplicateDefaultExport, node);
  14074. } else {
  14075. this.raise(Errors.DuplicateExport, node, {
  14076. exportName
  14077. });
  14078. }
  14079. }
  14080. this.exportedIdentifiers.add(exportName);
  14081. }
  14082. parseExportSpecifiers(isInTypeExport) {
  14083. const nodes = [];
  14084. let first = true;
  14085. this.expect(5);
  14086. while (!this.eat(8)) {
  14087. if (first) {
  14088. first = false;
  14089. } else {
  14090. this.expect(12);
  14091. if (this.eat(8)) break;
  14092. }
  14093. const isMaybeTypeOnly = this.isContextual(130);
  14094. const isString = this.match(134);
  14095. const node = this.startNode();
  14096. node.local = this.parseModuleExportName();
  14097. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  14098. }
  14099. return nodes;
  14100. }
  14101. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14102. if (this.eatContextual(93)) {
  14103. node.exported = this.parseModuleExportName();
  14104. } else if (isString) {
  14105. node.exported = this.cloneStringLiteral(node.local);
  14106. } else if (!node.exported) {
  14107. node.exported = this.cloneIdentifier(node.local);
  14108. }
  14109. return this.finishNode(node, "ExportSpecifier");
  14110. }
  14111. parseModuleExportName() {
  14112. if (this.match(134)) {
  14113. const result = this.parseStringLiteral(this.state.value);
  14114. const surrogate = loneSurrogate.exec(result.value);
  14115. if (surrogate) {
  14116. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  14117. surrogateCharCode: surrogate[0].charCodeAt(0)
  14118. });
  14119. }
  14120. return result;
  14121. }
  14122. return this.parseIdentifier(true);
  14123. }
  14124. isJSONModuleImport(node) {
  14125. if (node.assertions != null) {
  14126. return node.assertions.some(({
  14127. key,
  14128. value
  14129. }) => {
  14130. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14131. });
  14132. }
  14133. return false;
  14134. }
  14135. checkImportReflection(node) {
  14136. const {
  14137. specifiers
  14138. } = node;
  14139. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  14140. if (node.phase === "source") {
  14141. if (singleBindingType !== "ImportDefaultSpecifier") {
  14142. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  14143. }
  14144. } else if (node.phase === "defer") {
  14145. if (singleBindingType !== "ImportNamespaceSpecifier") {
  14146. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  14147. }
  14148. } else if (node.module) {
  14149. var _node$assertions;
  14150. if (singleBindingType !== "ImportDefaultSpecifier") {
  14151. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  14152. }
  14153. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14154. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  14155. }
  14156. }
  14157. }
  14158. checkJSONModuleImport(node) {
  14159. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14160. const {
  14161. specifiers
  14162. } = node;
  14163. if (specifiers != null) {
  14164. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14165. let imported;
  14166. if (specifier.type === "ExportSpecifier") {
  14167. imported = specifier.local;
  14168. } else if (specifier.type === "ImportSpecifier") {
  14169. imported = specifier.imported;
  14170. }
  14171. if (imported !== undefined) {
  14172. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14173. }
  14174. });
  14175. if (nonDefaultNamedSpecifier !== undefined) {
  14176. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  14177. }
  14178. }
  14179. }
  14180. }
  14181. isPotentialImportPhase(isExport) {
  14182. if (isExport) return false;
  14183. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  14184. }
  14185. applyImportPhase(node, isExport, phase, loc) {
  14186. if (isExport) {
  14187. return;
  14188. }
  14189. if (phase === "module") {
  14190. this.expectPlugin("importReflection", loc);
  14191. node.module = true;
  14192. } else if (this.hasPlugin("importReflection")) {
  14193. node.module = false;
  14194. }
  14195. if (phase === "source") {
  14196. this.expectPlugin("sourcePhaseImports", loc);
  14197. node.phase = "source";
  14198. } else if (phase === "defer") {
  14199. this.expectPlugin("deferredImportEvaluation", loc);
  14200. node.phase = "defer";
  14201. } else if (this.hasPlugin("sourcePhaseImports")) {
  14202. node.phase = null;
  14203. }
  14204. }
  14205. parseMaybeImportPhase(node, isExport) {
  14206. if (!this.isPotentialImportPhase(isExport)) {
  14207. this.applyImportPhase(node, isExport, null);
  14208. return null;
  14209. }
  14210. const phaseIdentifier = this.startNode();
  14211. const phaseIdentifierName = this.parseIdentifierName(true);
  14212. const {
  14213. type
  14214. } = this.state;
  14215. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14216. if (isImportPhase) {
  14217. this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
  14218. return null;
  14219. } else {
  14220. this.applyImportPhase(node, isExport, null);
  14221. return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
  14222. }
  14223. }
  14224. isPrecedingIdImportPhase(phase) {
  14225. const {
  14226. type
  14227. } = this.state;
  14228. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14229. }
  14230. parseImport(node) {
  14231. if (this.match(134)) {
  14232. return this.parseImportSourceAndAttributes(node);
  14233. }
  14234. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14235. }
  14236. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14237. node.specifiers = [];
  14238. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14239. const parseNext = !hasDefault || this.eat(12);
  14240. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14241. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14242. this.expectContextual(98);
  14243. return this.parseImportSourceAndAttributes(node);
  14244. }
  14245. parseImportSourceAndAttributes(node) {
  14246. var _node$specifiers2;
  14247. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14248. node.source = this.parseImportSource();
  14249. this.maybeParseImportAttributes(node);
  14250. this.checkImportReflection(node);
  14251. this.checkJSONModuleImport(node);
  14252. this.semicolon();
  14253. this.sawUnambiguousESM = true;
  14254. return this.finishNode(node, "ImportDeclaration");
  14255. }
  14256. parseImportSource() {
  14257. if (!this.match(134)) this.unexpected();
  14258. return this.parseExprAtom();
  14259. }
  14260. parseImportSpecifierLocal(node, specifier, type) {
  14261. specifier.local = this.parseIdentifier();
  14262. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14263. }
  14264. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14265. this.checkLVal(specifier.local, {
  14266. type
  14267. }, bindingType);
  14268. return this.finishNode(specifier, type);
  14269. }
  14270. parseImportAttributes() {
  14271. this.expect(5);
  14272. const attrs = [];
  14273. const attrNames = new Set();
  14274. do {
  14275. if (this.match(8)) {
  14276. break;
  14277. }
  14278. const node = this.startNode();
  14279. const keyName = this.state.value;
  14280. if (attrNames.has(keyName)) {
  14281. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  14282. key: keyName
  14283. });
  14284. }
  14285. attrNames.add(keyName);
  14286. if (this.match(134)) {
  14287. node.key = this.parseStringLiteral(keyName);
  14288. } else {
  14289. node.key = this.parseIdentifier(true);
  14290. }
  14291. this.expect(14);
  14292. if (!this.match(134)) {
  14293. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14294. }
  14295. node.value = this.parseStringLiteral(this.state.value);
  14296. attrs.push(this.finishNode(node, "ImportAttribute"));
  14297. } while (this.eat(12));
  14298. this.expect(8);
  14299. return attrs;
  14300. }
  14301. parseModuleAttributes() {
  14302. const attrs = [];
  14303. const attributes = new Set();
  14304. do {
  14305. const node = this.startNode();
  14306. node.key = this.parseIdentifier(true);
  14307. if (node.key.name !== "type") {
  14308. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  14309. }
  14310. if (attributes.has(node.key.name)) {
  14311. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  14312. key: node.key.name
  14313. });
  14314. }
  14315. attributes.add(node.key.name);
  14316. this.expect(14);
  14317. if (!this.match(134)) {
  14318. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14319. }
  14320. node.value = this.parseStringLiteral(this.state.value);
  14321. attrs.push(this.finishNode(node, "ImportAttribute"));
  14322. } while (this.eat(12));
  14323. return attrs;
  14324. }
  14325. maybeParseImportAttributes(node) {
  14326. let attributes;
  14327. {
  14328. var useWith = false;
  14329. }
  14330. if (this.match(76)) {
  14331. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14332. return;
  14333. }
  14334. this.next();
  14335. if (this.hasPlugin("moduleAttributes")) {
  14336. attributes = this.parseModuleAttributes();
  14337. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  14338. } else {
  14339. attributes = this.parseImportAttributes();
  14340. }
  14341. {
  14342. useWith = true;
  14343. }
  14344. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14345. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  14346. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  14347. }
  14348. if (!this.hasPlugin("importAssertions")) {
  14349. this.addExtra(node, "deprecatedAssertSyntax", true);
  14350. }
  14351. this.next();
  14352. attributes = this.parseImportAttributes();
  14353. } else {
  14354. attributes = [];
  14355. }
  14356. if (!useWith && this.hasPlugin("importAssertions")) {
  14357. node.assertions = attributes;
  14358. } else {
  14359. node.attributes = attributes;
  14360. }
  14361. }
  14362. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14363. if (maybeDefaultIdentifier) {
  14364. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14365. specifier.local = maybeDefaultIdentifier;
  14366. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14367. return true;
  14368. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14369. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14370. return true;
  14371. }
  14372. return false;
  14373. }
  14374. maybeParseStarImportSpecifier(node) {
  14375. if (this.match(55)) {
  14376. const specifier = this.startNode();
  14377. this.next();
  14378. this.expectContextual(93);
  14379. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14380. return true;
  14381. }
  14382. return false;
  14383. }
  14384. parseNamedImportSpecifiers(node) {
  14385. let first = true;
  14386. this.expect(5);
  14387. while (!this.eat(8)) {
  14388. if (first) {
  14389. first = false;
  14390. } else {
  14391. if (this.eat(14)) {
  14392. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  14393. }
  14394. this.expect(12);
  14395. if (this.eat(8)) break;
  14396. }
  14397. const specifier = this.startNode();
  14398. const importedIsString = this.match(134);
  14399. const isMaybeTypeOnly = this.isContextual(130);
  14400. specifier.imported = this.parseModuleExportName();
  14401. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14402. node.specifiers.push(importSpecifier);
  14403. }
  14404. }
  14405. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14406. if (this.eatContextual(93)) {
  14407. specifier.local = this.parseIdentifier();
  14408. } else {
  14409. const {
  14410. imported
  14411. } = specifier;
  14412. if (importedIsString) {
  14413. throw this.raise(Errors.ImportBindingIsString, specifier, {
  14414. importName: imported.value
  14415. });
  14416. }
  14417. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14418. if (!specifier.local) {
  14419. specifier.local = this.cloneIdentifier(imported);
  14420. }
  14421. }
  14422. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14423. }
  14424. isThisParam(param) {
  14425. return param.type === "Identifier" && param.name === "this";
  14426. }
  14427. }
  14428. class Parser extends StatementParser {
  14429. constructor(options, input, pluginsMap) {
  14430. options = getOptions(options);
  14431. super(options, input);
  14432. this.options = options;
  14433. this.initializeScopes();
  14434. this.plugins = pluginsMap;
  14435. this.filename = options.sourceFilename;
  14436. this.startIndex = options.startIndex;
  14437. let optionFlags = 0;
  14438. if (options.allowAwaitOutsideFunction) {
  14439. optionFlags |= 1;
  14440. }
  14441. if (options.allowReturnOutsideFunction) {
  14442. optionFlags |= 2;
  14443. }
  14444. if (options.allowImportExportEverywhere) {
  14445. optionFlags |= 8;
  14446. }
  14447. if (options.allowSuperOutsideMethod) {
  14448. optionFlags |= 16;
  14449. }
  14450. if (options.allowUndeclaredExports) {
  14451. optionFlags |= 64;
  14452. }
  14453. if (options.allowNewTargetOutsideFunction) {
  14454. optionFlags |= 4;
  14455. }
  14456. if (options.allowYieldOutsideFunction) {
  14457. optionFlags |= 32;
  14458. }
  14459. if (options.ranges) {
  14460. optionFlags |= 128;
  14461. }
  14462. if (options.tokens) {
  14463. optionFlags |= 256;
  14464. }
  14465. if (options.createImportExpressions) {
  14466. optionFlags |= 512;
  14467. }
  14468. if (options.createParenthesizedExpressions) {
  14469. optionFlags |= 1024;
  14470. }
  14471. if (options.errorRecovery) {
  14472. optionFlags |= 2048;
  14473. }
  14474. if (options.attachComment) {
  14475. optionFlags |= 4096;
  14476. }
  14477. if (options.annexB) {
  14478. optionFlags |= 8192;
  14479. }
  14480. this.optionFlags = optionFlags;
  14481. }
  14482. getScopeHandler() {
  14483. return ScopeHandler;
  14484. }
  14485. parse() {
  14486. this.enterInitialScopes();
  14487. const file = this.startNode();
  14488. const program = this.startNode();
  14489. this.nextToken();
  14490. file.errors = null;
  14491. this.parseTopLevel(file, program);
  14492. file.errors = this.state.errors;
  14493. file.comments.length = this.state.commentsLen;
  14494. return file;
  14495. }
  14496. }
  14497. function parse(input, options) {
  14498. var _options;
  14499. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14500. options = Object.assign({}, options);
  14501. try {
  14502. options.sourceType = "module";
  14503. const parser = getParser(options, input);
  14504. const ast = parser.parse();
  14505. if (parser.sawUnambiguousESM) {
  14506. return ast;
  14507. }
  14508. if (parser.ambiguousScriptDifferentAst) {
  14509. try {
  14510. options.sourceType = "script";
  14511. return getParser(options, input).parse();
  14512. } catch (_unused) {}
  14513. } else {
  14514. ast.program.sourceType = "script";
  14515. }
  14516. return ast;
  14517. } catch (moduleError) {
  14518. try {
  14519. options.sourceType = "script";
  14520. return getParser(options, input).parse();
  14521. } catch (_unused2) {}
  14522. throw moduleError;
  14523. }
  14524. } else {
  14525. return getParser(options, input).parse();
  14526. }
  14527. }
  14528. function parseExpression(input, options) {
  14529. const parser = getParser(options, input);
  14530. if (parser.options.strictMode) {
  14531. parser.state.strict = true;
  14532. }
  14533. return parser.getExpression();
  14534. }
  14535. function generateExportedTokenTypes(internalTokenTypes) {
  14536. const tokenTypes = {};
  14537. for (const typeName of Object.keys(internalTokenTypes)) {
  14538. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14539. }
  14540. return tokenTypes;
  14541. }
  14542. const tokTypes = generateExportedTokenTypes(tt);
  14543. function getParser(options, input) {
  14544. let cls = Parser;
  14545. const pluginsMap = new Map();
  14546. if (options != null && options.plugins) {
  14547. for (const plugin of options.plugins) {
  14548. let name, opts;
  14549. if (typeof plugin === "string") {
  14550. name = plugin;
  14551. } else {
  14552. [name, opts] = plugin;
  14553. }
  14554. if (!pluginsMap.has(name)) {
  14555. pluginsMap.set(name, opts || {});
  14556. }
  14557. }
  14558. validatePlugins(pluginsMap);
  14559. cls = getParserClass(pluginsMap);
  14560. }
  14561. return new cls(options, input, pluginsMap);
  14562. }
  14563. const parserClassCache = new Map();
  14564. function getParserClass(pluginsMap) {
  14565. const pluginList = [];
  14566. for (const name of mixinPluginNames) {
  14567. if (pluginsMap.has(name)) {
  14568. pluginList.push(name);
  14569. }
  14570. }
  14571. const key = pluginList.join("|");
  14572. let cls = parserClassCache.get(key);
  14573. if (!cls) {
  14574. cls = Parser;
  14575. for (const plugin of pluginList) {
  14576. cls = mixinPlugins[plugin](cls);
  14577. }
  14578. parserClassCache.set(key, cls);
  14579. }
  14580. return cls;
  14581. }
  14582. exports.parse = parse;
  14583. exports.parseExpression = parseExpression;
  14584. exports.tokTypes = tokTypes;
  14585. //# sourceMappingURL=index.js.map