智慧水务管理系统 - 精河县供水工程综合管理平台

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599
  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. const oldReasonCodes = {
  353. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  354. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  355. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  356. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  357. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  358. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  359. };
  360. if (oldReasonCodes[reasonCode]) {
  361. reasonCode = oldReasonCodes[reasonCode];
  362. }
  363. return function constructor(loc, details) {
  364. const error = new SyntaxError();
  365. error.code = code;
  366. error.reasonCode = reasonCode;
  367. error.loc = loc;
  368. error.pos = loc.index;
  369. error.syntaxPlugin = syntaxPlugin;
  370. if (hasMissingPlugin) {
  371. error.missingPlugin = details.missingPlugin;
  372. }
  373. defineHidden(error, "clone", function clone(overrides = {}) {
  374. var _overrides$loc;
  375. const {
  376. line,
  377. column,
  378. index
  379. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  380. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  381. });
  382. defineHidden(error, "details", details);
  383. Object.defineProperty(error, "message", {
  384. configurable: true,
  385. get() {
  386. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  387. this.message = message;
  388. return message;
  389. },
  390. set(value) {
  391. Object.defineProperty(this, "message", {
  392. value,
  393. writable: true
  394. });
  395. }
  396. });
  397. return error;
  398. };
  399. }
  400. function ParseErrorEnum(argument, syntaxPlugin) {
  401. if (Array.isArray(argument)) {
  402. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  403. }
  404. const ParseErrorConstructors = {};
  405. for (const reasonCode of Object.keys(argument)) {
  406. const template = argument[reasonCode];
  407. const _ref = typeof template === "string" ? {
  408. message: () => template
  409. } : typeof template === "function" ? {
  410. message: template
  411. } : template,
  412. {
  413. message
  414. } = _ref,
  415. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  416. const toMessage = typeof message === "string" ? () => message : message;
  417. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  418. code: "BABEL_PARSER_SYNTAX_ERROR",
  419. reasonCode,
  420. toMessage
  421. }, syntaxPlugin ? {
  422. syntaxPlugin
  423. } : {}, rest));
  424. }
  425. return ParseErrorConstructors;
  426. }
  427. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum(ParseExpressionErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  428. function createDefaultOptions() {
  429. return {
  430. sourceType: "script",
  431. sourceFilename: undefined,
  432. startIndex: 0,
  433. startColumn: 0,
  434. startLine: 1,
  435. allowAwaitOutsideFunction: false,
  436. allowReturnOutsideFunction: false,
  437. allowNewTargetOutsideFunction: false,
  438. allowImportExportEverywhere: false,
  439. allowSuperOutsideMethod: false,
  440. allowUndeclaredExports: false,
  441. allowYieldOutsideFunction: false,
  442. plugins: [],
  443. strictMode: undefined,
  444. ranges: false,
  445. tokens: false,
  446. createImportExpressions: false,
  447. createParenthesizedExpressions: false,
  448. errorRecovery: false,
  449. attachComment: true,
  450. annexB: true
  451. };
  452. }
  453. function getOptions(opts) {
  454. const options = createDefaultOptions();
  455. if (opts == null) {
  456. return options;
  457. }
  458. if (opts.annexB != null && opts.annexB !== false) {
  459. throw new Error("The `annexB` option can only be set to `false`.");
  460. }
  461. for (const key of Object.keys(options)) {
  462. if (opts[key] != null) options[key] = opts[key];
  463. }
  464. if (options.startLine === 1) {
  465. if (opts.startIndex == null && options.startColumn > 0) {
  466. options.startIndex = options.startColumn;
  467. } else if (opts.startColumn == null && options.startIndex > 0) {
  468. options.startColumn = options.startIndex;
  469. }
  470. } else if (opts.startColumn == null || opts.startIndex == null) {
  471. if (opts.startIndex != null) {
  472. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  473. }
  474. }
  475. if (options.sourceType === "commonjs") {
  476. if (opts.allowAwaitOutsideFunction != null) {
  477. throw new Error("The `allowAwaitOutsideFunction` option cannot be used with `sourceType: 'commonjs'`.");
  478. }
  479. if (opts.allowReturnOutsideFunction != null) {
  480. throw new Error("`sourceType: 'commonjs'` implies `allowReturnOutsideFunction: true`, please remove the `allowReturnOutsideFunction` option or use `sourceType: 'script'`.");
  481. }
  482. if (opts.allowNewTargetOutsideFunction != null) {
  483. throw new Error("`sourceType: 'commonjs'` implies `allowNewTargetOutsideFunction: true`, please remove the `allowNewTargetOutsideFunction` option or use `sourceType: 'script'`.");
  484. }
  485. }
  486. return options;
  487. }
  488. const {
  489. defineProperty
  490. } = Object;
  491. const toUnenumerable = (object, key) => {
  492. if (object) {
  493. defineProperty(object, key, {
  494. enumerable: false,
  495. value: object[key]
  496. });
  497. }
  498. };
  499. function toESTreeLocation(node) {
  500. toUnenumerable(node.loc.start, "index");
  501. toUnenumerable(node.loc.end, "index");
  502. return node;
  503. }
  504. var estree = superClass => class ESTreeParserMixin extends superClass {
  505. parse() {
  506. const file = toESTreeLocation(super.parse());
  507. if (this.optionFlags & 256) {
  508. file.tokens = file.tokens.map(toESTreeLocation);
  509. }
  510. return file;
  511. }
  512. parseRegExpLiteral({
  513. pattern,
  514. flags
  515. }) {
  516. let regex = null;
  517. try {
  518. regex = new RegExp(pattern, flags);
  519. } catch (_) {}
  520. const node = this.estreeParseLiteral(regex);
  521. node.regex = {
  522. pattern,
  523. flags
  524. };
  525. return node;
  526. }
  527. parseBigIntLiteral(value) {
  528. let bigInt;
  529. try {
  530. bigInt = BigInt(value);
  531. } catch (_unused) {
  532. bigInt = null;
  533. }
  534. const node = this.estreeParseLiteral(bigInt);
  535. node.bigint = String(node.value || value);
  536. return node;
  537. }
  538. parseDecimalLiteral(value) {
  539. const decimal = null;
  540. const node = this.estreeParseLiteral(decimal);
  541. node.decimal = String(node.value || value);
  542. return node;
  543. }
  544. estreeParseLiteral(value) {
  545. return this.parseLiteral(value, "Literal");
  546. }
  547. parseStringLiteral(value) {
  548. return this.estreeParseLiteral(value);
  549. }
  550. parseNumericLiteral(value) {
  551. return this.estreeParseLiteral(value);
  552. }
  553. parseNullLiteral() {
  554. return this.estreeParseLiteral(null);
  555. }
  556. parseBooleanLiteral(value) {
  557. return this.estreeParseLiteral(value);
  558. }
  559. estreeParseChainExpression(node, endLoc) {
  560. const chain = this.startNodeAtNode(node);
  561. chain.expression = node;
  562. return this.finishNodeAt(chain, "ChainExpression", endLoc);
  563. }
  564. directiveToStmt(directive) {
  565. const expression = directive.value;
  566. delete directive.value;
  567. this.castNodeTo(expression, "Literal");
  568. expression.raw = expression.extra.raw;
  569. expression.value = expression.extra.expressionValue;
  570. const stmt = this.castNodeTo(directive, "ExpressionStatement");
  571. stmt.expression = expression;
  572. stmt.directive = expression.extra.rawValue;
  573. delete expression.extra;
  574. return stmt;
  575. }
  576. fillOptionalPropertiesForTSESLint(node) {}
  577. cloneEstreeStringLiteral(node) {
  578. const {
  579. start,
  580. end,
  581. loc,
  582. range,
  583. raw,
  584. value
  585. } = node;
  586. const cloned = Object.create(node.constructor.prototype);
  587. cloned.type = "Literal";
  588. cloned.start = start;
  589. cloned.end = end;
  590. cloned.loc = loc;
  591. cloned.range = range;
  592. cloned.raw = raw;
  593. cloned.value = value;
  594. return cloned;
  595. }
  596. initFunction(node, isAsync) {
  597. super.initFunction(node, isAsync);
  598. node.expression = false;
  599. }
  600. checkDeclaration(node) {
  601. if (node != null && this.isObjectProperty(node)) {
  602. this.checkDeclaration(node.value);
  603. } else {
  604. super.checkDeclaration(node);
  605. }
  606. }
  607. getObjectOrClassMethodParams(method) {
  608. return method.value.params;
  609. }
  610. isValidDirective(stmt) {
  611. var _stmt$expression$extr;
  612. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  613. }
  614. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  615. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  616. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  617. node.body = directiveStatements.concat(node.body);
  618. delete node.directives;
  619. }
  620. parsePrivateName() {
  621. const node = super.parsePrivateName();
  622. if (!this.getPluginOption("estree", "classFeatures")) {
  623. return node;
  624. }
  625. return this.convertPrivateNameToPrivateIdentifier(node);
  626. }
  627. convertPrivateNameToPrivateIdentifier(node) {
  628. const name = super.getPrivateNameSV(node);
  629. delete node.id;
  630. node.name = name;
  631. return this.castNodeTo(node, "PrivateIdentifier");
  632. }
  633. isPrivateName(node) {
  634. if (!this.getPluginOption("estree", "classFeatures")) {
  635. return super.isPrivateName(node);
  636. }
  637. return node.type === "PrivateIdentifier";
  638. }
  639. getPrivateNameSV(node) {
  640. if (!this.getPluginOption("estree", "classFeatures")) {
  641. return super.getPrivateNameSV(node);
  642. }
  643. return node.name;
  644. }
  645. parseLiteral(value, type) {
  646. const node = super.parseLiteral(value, type);
  647. node.raw = node.extra.raw;
  648. delete node.extra;
  649. return node;
  650. }
  651. parseFunctionBody(node, allowExpression, isMethod = false) {
  652. super.parseFunctionBody(node, allowExpression, isMethod);
  653. node.expression = node.body.type !== "BlockStatement";
  654. }
  655. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  656. let funcNode = this.startNode();
  657. funcNode.kind = node.kind;
  658. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  659. delete funcNode.kind;
  660. const {
  661. typeParameters
  662. } = node;
  663. if (typeParameters) {
  664. delete node.typeParameters;
  665. funcNode.typeParameters = typeParameters;
  666. this.resetStartLocationFromNode(funcNode, typeParameters);
  667. }
  668. const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
  669. node.value = valueNode;
  670. if (type === "ClassPrivateMethod") {
  671. node.computed = false;
  672. }
  673. if (type === "ObjectMethod") {
  674. if (node.kind === "method") {
  675. node.kind = "init";
  676. }
  677. node.shorthand = false;
  678. return this.finishNode(node, "Property");
  679. } else {
  680. return this.finishNode(node, "MethodDefinition");
  681. }
  682. }
  683. nameIsConstructor(key) {
  684. if (key.type === "Literal") return key.value === "constructor";
  685. return super.nameIsConstructor(key);
  686. }
  687. parseClassProperty(...args) {
  688. const propertyNode = super.parseClassProperty(...args);
  689. if (!this.getPluginOption("estree", "classFeatures")) {
  690. return propertyNode;
  691. }
  692. this.castNodeTo(propertyNode, "PropertyDefinition");
  693. return propertyNode;
  694. }
  695. parseClassPrivateProperty(...args) {
  696. const propertyNode = super.parseClassPrivateProperty(...args);
  697. if (!this.getPluginOption("estree", "classFeatures")) {
  698. return propertyNode;
  699. }
  700. this.castNodeTo(propertyNode, "PropertyDefinition");
  701. propertyNode.computed = false;
  702. return propertyNode;
  703. }
  704. parseClassAccessorProperty(node) {
  705. const accessorPropertyNode = super.parseClassAccessorProperty(node);
  706. if (!this.getPluginOption("estree", "classFeatures")) {
  707. return accessorPropertyNode;
  708. }
  709. if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
  710. delete accessorPropertyNode.abstract;
  711. this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
  712. } else {
  713. this.castNodeTo(accessorPropertyNode, "AccessorProperty");
  714. }
  715. return accessorPropertyNode;
  716. }
  717. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  718. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  719. if (node) {
  720. node.kind = "init";
  721. this.castNodeTo(node, "Property");
  722. }
  723. return node;
  724. }
  725. finishObjectProperty(node) {
  726. node.kind = "init";
  727. return this.finishNode(node, "Property");
  728. }
  729. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  730. return type === "Property" ? "value" : super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  731. }
  732. isAssignable(node, isBinding) {
  733. if (node != null && this.isObjectProperty(node)) {
  734. return this.isAssignable(node.value, isBinding);
  735. }
  736. return super.isAssignable(node, isBinding);
  737. }
  738. toAssignable(node, isLHS = false) {
  739. if (node != null && this.isObjectProperty(node)) {
  740. const {
  741. key,
  742. value
  743. } = node;
  744. if (this.isPrivateName(key)) {
  745. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  746. }
  747. this.toAssignable(value, isLHS);
  748. } else {
  749. super.toAssignable(node, isLHS);
  750. }
  751. }
  752. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  753. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  754. this.raise(Errors.PatternHasAccessor, prop.key);
  755. } else if (prop.type === "Property" && prop.method) {
  756. this.raise(Errors.PatternHasMethod, prop.key);
  757. } else {
  758. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  759. }
  760. }
  761. finishCallExpression(unfinished, optional) {
  762. const node = super.finishCallExpression(unfinished, optional);
  763. if (node.callee.type === "Import") {
  764. var _ref, _ref2;
  765. this.castNodeTo(node, "ImportExpression");
  766. node.source = node.arguments[0];
  767. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  768. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  769. delete node.arguments;
  770. delete node.callee;
  771. } else if (node.type === "OptionalCallExpression") {
  772. this.castNodeTo(node, "CallExpression");
  773. } else {
  774. node.optional = false;
  775. }
  776. return node;
  777. }
  778. toReferencedArguments(node) {
  779. if (node.type === "ImportExpression") {
  780. return;
  781. }
  782. super.toReferencedArguments(node);
  783. }
  784. parseExport(unfinished, decorators) {
  785. const exportStartLoc = this.state.lastTokStartLoc;
  786. const node = super.parseExport(unfinished, decorators);
  787. switch (node.type) {
  788. case "ExportAllDeclaration":
  789. node.exported = null;
  790. break;
  791. case "ExportNamedDeclaration":
  792. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  793. this.castNodeTo(node, "ExportAllDeclaration");
  794. node.exported = node.specifiers[0].exported;
  795. delete node.specifiers;
  796. }
  797. case "ExportDefaultDeclaration":
  798. {
  799. var _declaration$decorato;
  800. const {
  801. declaration
  802. } = node;
  803. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  804. this.resetStartLocation(node, exportStartLoc);
  805. }
  806. }
  807. break;
  808. }
  809. return node;
  810. }
  811. stopParseSubscript(base, state) {
  812. const node = super.stopParseSubscript(base, state);
  813. if (state.optionalChainMember) {
  814. return this.estreeParseChainExpression(node, base.loc.end);
  815. }
  816. return node;
  817. }
  818. parseMember(base, startLoc, state, computed, optional) {
  819. const node = super.parseMember(base, startLoc, state, computed, optional);
  820. if (node.type === "OptionalMemberExpression") {
  821. this.castNodeTo(node, "MemberExpression");
  822. } else {
  823. node.optional = false;
  824. }
  825. return node;
  826. }
  827. isOptionalMemberExpression(node) {
  828. if (node.type === "ChainExpression") {
  829. return node.expression.type === "MemberExpression";
  830. }
  831. return super.isOptionalMemberExpression(node);
  832. }
  833. hasPropertyAsPrivateName(node) {
  834. if (node.type === "ChainExpression") {
  835. node = node.expression;
  836. }
  837. return super.hasPropertyAsPrivateName(node);
  838. }
  839. isObjectProperty(node) {
  840. return node.type === "Property" && node.kind === "init" && !node.method;
  841. }
  842. isObjectMethod(node) {
  843. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  844. }
  845. castNodeTo(node, type) {
  846. const result = super.castNodeTo(node, type);
  847. this.fillOptionalPropertiesForTSESLint(result);
  848. return result;
  849. }
  850. cloneIdentifier(node) {
  851. const cloned = super.cloneIdentifier(node);
  852. this.fillOptionalPropertiesForTSESLint(cloned);
  853. return cloned;
  854. }
  855. cloneStringLiteral(node) {
  856. if (node.type === "Literal") {
  857. return this.cloneEstreeStringLiteral(node);
  858. }
  859. return super.cloneStringLiteral(node);
  860. }
  861. finishNodeAt(node, type, endLoc) {
  862. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  863. }
  864. finishNode(node, type) {
  865. const result = super.finishNode(node, type);
  866. this.fillOptionalPropertiesForTSESLint(result);
  867. return result;
  868. }
  869. resetStartLocation(node, startLoc) {
  870. super.resetStartLocation(node, startLoc);
  871. toESTreeLocation(node);
  872. }
  873. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  874. super.resetEndLocation(node, endLoc);
  875. toESTreeLocation(node);
  876. }
  877. };
  878. class TokContext {
  879. constructor(token, preserveSpace) {
  880. this.token = void 0;
  881. this.preserveSpace = void 0;
  882. this.token = token;
  883. this.preserveSpace = !!preserveSpace;
  884. }
  885. }
  886. const types = {
  887. brace: new TokContext("{"),
  888. j_oTag: new TokContext("<tag"),
  889. j_cTag: new TokContext("</tag"),
  890. j_expr: new TokContext("<tag>...</tag>", true)
  891. };
  892. types.template = new TokContext("`", true);
  893. const beforeExpr = true;
  894. const startsExpr = true;
  895. const isLoop = true;
  896. const isAssign = true;
  897. const prefix = true;
  898. const postfix = true;
  899. class ExportedTokenType {
  900. constructor(label, conf = {}) {
  901. this.label = void 0;
  902. this.keyword = void 0;
  903. this.beforeExpr = void 0;
  904. this.startsExpr = void 0;
  905. this.rightAssociative = void 0;
  906. this.isLoop = void 0;
  907. this.isAssign = void 0;
  908. this.prefix = void 0;
  909. this.postfix = void 0;
  910. this.binop = void 0;
  911. this.label = label;
  912. this.keyword = conf.keyword;
  913. this.beforeExpr = !!conf.beforeExpr;
  914. this.startsExpr = !!conf.startsExpr;
  915. this.rightAssociative = !!conf.rightAssociative;
  916. this.isLoop = !!conf.isLoop;
  917. this.isAssign = !!conf.isAssign;
  918. this.prefix = !!conf.prefix;
  919. this.postfix = !!conf.postfix;
  920. this.binop = conf.binop != null ? conf.binop : null;
  921. this.updateContext = null;
  922. }
  923. }
  924. const keywords$1 = new Map();
  925. function createKeyword(name, options = {}) {
  926. options.keyword = name;
  927. const token = createToken(name, options);
  928. keywords$1.set(name, token);
  929. return token;
  930. }
  931. function createBinop(name, binop) {
  932. return createToken(name, {
  933. beforeExpr,
  934. binop
  935. });
  936. }
  937. let tokenTypeCounter = -1;
  938. const tokenTypes = [];
  939. const tokenLabels = [];
  940. const tokenBinops = [];
  941. const tokenBeforeExprs = [];
  942. const tokenStartsExprs = [];
  943. const tokenPrefixes = [];
  944. function createToken(name, options = {}) {
  945. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  946. ++tokenTypeCounter;
  947. tokenLabels.push(name);
  948. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  949. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  950. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  951. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  952. tokenTypes.push(new ExportedTokenType(name, options));
  953. return tokenTypeCounter;
  954. }
  955. function createKeywordLike(name, options = {}) {
  956. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  957. ++tokenTypeCounter;
  958. keywords$1.set(name, tokenTypeCounter);
  959. tokenLabels.push(name);
  960. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  961. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  962. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  963. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  964. tokenTypes.push(new ExportedTokenType("name", options));
  965. return tokenTypeCounter;
  966. }
  967. const tt = {
  968. bracketL: createToken("[", {
  969. beforeExpr,
  970. startsExpr
  971. }),
  972. bracketHashL: createToken("#[", {
  973. beforeExpr,
  974. startsExpr
  975. }),
  976. bracketBarL: createToken("[|", {
  977. beforeExpr,
  978. startsExpr
  979. }),
  980. bracketR: createToken("]"),
  981. bracketBarR: createToken("|]"),
  982. braceL: createToken("{", {
  983. beforeExpr,
  984. startsExpr
  985. }),
  986. braceBarL: createToken("{|", {
  987. beforeExpr,
  988. startsExpr
  989. }),
  990. braceHashL: createToken("#{", {
  991. beforeExpr,
  992. startsExpr
  993. }),
  994. braceR: createToken("}"),
  995. braceBarR: createToken("|}"),
  996. parenL: createToken("(", {
  997. beforeExpr,
  998. startsExpr
  999. }),
  1000. parenR: createToken(")"),
  1001. comma: createToken(",", {
  1002. beforeExpr
  1003. }),
  1004. semi: createToken(";", {
  1005. beforeExpr
  1006. }),
  1007. colon: createToken(":", {
  1008. beforeExpr
  1009. }),
  1010. doubleColon: createToken("::", {
  1011. beforeExpr
  1012. }),
  1013. dot: createToken("."),
  1014. question: createToken("?", {
  1015. beforeExpr
  1016. }),
  1017. questionDot: createToken("?."),
  1018. arrow: createToken("=>", {
  1019. beforeExpr
  1020. }),
  1021. template: createToken("template"),
  1022. ellipsis: createToken("...", {
  1023. beforeExpr
  1024. }),
  1025. backQuote: createToken("`", {
  1026. startsExpr
  1027. }),
  1028. dollarBraceL: createToken("${", {
  1029. beforeExpr,
  1030. startsExpr
  1031. }),
  1032. templateTail: createToken("...`", {
  1033. startsExpr
  1034. }),
  1035. templateNonTail: createToken("...${", {
  1036. beforeExpr,
  1037. startsExpr
  1038. }),
  1039. at: createToken("@"),
  1040. hash: createToken("#", {
  1041. startsExpr
  1042. }),
  1043. interpreterDirective: createToken("#!..."),
  1044. eq: createToken("=", {
  1045. beforeExpr,
  1046. isAssign
  1047. }),
  1048. assign: createToken("_=", {
  1049. beforeExpr,
  1050. isAssign
  1051. }),
  1052. slashAssign: createToken("_=", {
  1053. beforeExpr,
  1054. isAssign
  1055. }),
  1056. xorAssign: createToken("_=", {
  1057. beforeExpr,
  1058. isAssign
  1059. }),
  1060. moduloAssign: createToken("_=", {
  1061. beforeExpr,
  1062. isAssign
  1063. }),
  1064. incDec: createToken("++/--", {
  1065. prefix,
  1066. postfix,
  1067. startsExpr
  1068. }),
  1069. bang: createToken("!", {
  1070. beforeExpr,
  1071. prefix,
  1072. startsExpr
  1073. }),
  1074. tilde: createToken("~", {
  1075. beforeExpr,
  1076. prefix,
  1077. startsExpr
  1078. }),
  1079. doubleCaret: createToken("^^", {
  1080. startsExpr
  1081. }),
  1082. doubleAt: createToken("@@", {
  1083. startsExpr
  1084. }),
  1085. pipeline: createBinop("|>", 0),
  1086. nullishCoalescing: createBinop("??", 1),
  1087. logicalOR: createBinop("||", 1),
  1088. logicalAND: createBinop("&&", 2),
  1089. bitwiseOR: createBinop("|", 3),
  1090. bitwiseXOR: createBinop("^", 4),
  1091. bitwiseAND: createBinop("&", 5),
  1092. equality: createBinop("==/!=/===/!==", 6),
  1093. lt: createBinop("</>/<=/>=", 7),
  1094. gt: createBinop("</>/<=/>=", 7),
  1095. relational: createBinop("</>/<=/>=", 7),
  1096. bitShift: createBinop("<</>>/>>>", 8),
  1097. bitShiftL: createBinop("<</>>/>>>", 8),
  1098. bitShiftR: createBinop("<</>>/>>>", 8),
  1099. plusMin: createToken("+/-", {
  1100. beforeExpr,
  1101. binop: 9,
  1102. prefix,
  1103. startsExpr
  1104. }),
  1105. modulo: createToken("%", {
  1106. binop: 10,
  1107. startsExpr
  1108. }),
  1109. star: createToken("*", {
  1110. binop: 10
  1111. }),
  1112. slash: createBinop("/", 10),
  1113. exponent: createToken("**", {
  1114. beforeExpr,
  1115. binop: 11,
  1116. rightAssociative: true
  1117. }),
  1118. _in: createKeyword("in", {
  1119. beforeExpr,
  1120. binop: 7
  1121. }),
  1122. _instanceof: createKeyword("instanceof", {
  1123. beforeExpr,
  1124. binop: 7
  1125. }),
  1126. _break: createKeyword("break"),
  1127. _case: createKeyword("case", {
  1128. beforeExpr
  1129. }),
  1130. _catch: createKeyword("catch"),
  1131. _continue: createKeyword("continue"),
  1132. _debugger: createKeyword("debugger"),
  1133. _default: createKeyword("default", {
  1134. beforeExpr
  1135. }),
  1136. _else: createKeyword("else", {
  1137. beforeExpr
  1138. }),
  1139. _finally: createKeyword("finally"),
  1140. _function: createKeyword("function", {
  1141. startsExpr
  1142. }),
  1143. _if: createKeyword("if"),
  1144. _return: createKeyword("return", {
  1145. beforeExpr
  1146. }),
  1147. _switch: createKeyword("switch"),
  1148. _throw: createKeyword("throw", {
  1149. beforeExpr,
  1150. prefix,
  1151. startsExpr
  1152. }),
  1153. _try: createKeyword("try"),
  1154. _var: createKeyword("var"),
  1155. _const: createKeyword("const"),
  1156. _with: createKeyword("with"),
  1157. _new: createKeyword("new", {
  1158. beforeExpr,
  1159. startsExpr
  1160. }),
  1161. _this: createKeyword("this", {
  1162. startsExpr
  1163. }),
  1164. _super: createKeyword("super", {
  1165. startsExpr
  1166. }),
  1167. _class: createKeyword("class", {
  1168. startsExpr
  1169. }),
  1170. _extends: createKeyword("extends", {
  1171. beforeExpr
  1172. }),
  1173. _export: createKeyword("export"),
  1174. _import: createKeyword("import", {
  1175. startsExpr
  1176. }),
  1177. _null: createKeyword("null", {
  1178. startsExpr
  1179. }),
  1180. _true: createKeyword("true", {
  1181. startsExpr
  1182. }),
  1183. _false: createKeyword("false", {
  1184. startsExpr
  1185. }),
  1186. _typeof: createKeyword("typeof", {
  1187. beforeExpr,
  1188. prefix,
  1189. startsExpr
  1190. }),
  1191. _void: createKeyword("void", {
  1192. beforeExpr,
  1193. prefix,
  1194. startsExpr
  1195. }),
  1196. _delete: createKeyword("delete", {
  1197. beforeExpr,
  1198. prefix,
  1199. startsExpr
  1200. }),
  1201. _do: createKeyword("do", {
  1202. isLoop,
  1203. beforeExpr
  1204. }),
  1205. _for: createKeyword("for", {
  1206. isLoop
  1207. }),
  1208. _while: createKeyword("while", {
  1209. isLoop
  1210. }),
  1211. _as: createKeywordLike("as", {
  1212. startsExpr
  1213. }),
  1214. _assert: createKeywordLike("assert", {
  1215. startsExpr
  1216. }),
  1217. _async: createKeywordLike("async", {
  1218. startsExpr
  1219. }),
  1220. _await: createKeywordLike("await", {
  1221. startsExpr
  1222. }),
  1223. _defer: createKeywordLike("defer", {
  1224. startsExpr
  1225. }),
  1226. _from: createKeywordLike("from", {
  1227. startsExpr
  1228. }),
  1229. _get: createKeywordLike("get", {
  1230. startsExpr
  1231. }),
  1232. _let: createKeywordLike("let", {
  1233. startsExpr
  1234. }),
  1235. _meta: createKeywordLike("meta", {
  1236. startsExpr
  1237. }),
  1238. _of: createKeywordLike("of", {
  1239. startsExpr
  1240. }),
  1241. _sent: createKeywordLike("sent", {
  1242. startsExpr
  1243. }),
  1244. _set: createKeywordLike("set", {
  1245. startsExpr
  1246. }),
  1247. _source: createKeywordLike("source", {
  1248. startsExpr
  1249. }),
  1250. _static: createKeywordLike("static", {
  1251. startsExpr
  1252. }),
  1253. _using: createKeywordLike("using", {
  1254. startsExpr
  1255. }),
  1256. _yield: createKeywordLike("yield", {
  1257. startsExpr
  1258. }),
  1259. _asserts: createKeywordLike("asserts", {
  1260. startsExpr
  1261. }),
  1262. _checks: createKeywordLike("checks", {
  1263. startsExpr
  1264. }),
  1265. _exports: createKeywordLike("exports", {
  1266. startsExpr
  1267. }),
  1268. _global: createKeywordLike("global", {
  1269. startsExpr
  1270. }),
  1271. _implements: createKeywordLike("implements", {
  1272. startsExpr
  1273. }),
  1274. _intrinsic: createKeywordLike("intrinsic", {
  1275. startsExpr
  1276. }),
  1277. _infer: createKeywordLike("infer", {
  1278. startsExpr
  1279. }),
  1280. _is: createKeywordLike("is", {
  1281. startsExpr
  1282. }),
  1283. _mixins: createKeywordLike("mixins", {
  1284. startsExpr
  1285. }),
  1286. _proto: createKeywordLike("proto", {
  1287. startsExpr
  1288. }),
  1289. _require: createKeywordLike("require", {
  1290. startsExpr
  1291. }),
  1292. _satisfies: createKeywordLike("satisfies", {
  1293. startsExpr
  1294. }),
  1295. _keyof: createKeywordLike("keyof", {
  1296. startsExpr
  1297. }),
  1298. _readonly: createKeywordLike("readonly", {
  1299. startsExpr
  1300. }),
  1301. _unique: createKeywordLike("unique", {
  1302. startsExpr
  1303. }),
  1304. _abstract: createKeywordLike("abstract", {
  1305. startsExpr
  1306. }),
  1307. _declare: createKeywordLike("declare", {
  1308. startsExpr
  1309. }),
  1310. _enum: createKeywordLike("enum", {
  1311. startsExpr
  1312. }),
  1313. _module: createKeywordLike("module", {
  1314. startsExpr
  1315. }),
  1316. _namespace: createKeywordLike("namespace", {
  1317. startsExpr
  1318. }),
  1319. _interface: createKeywordLike("interface", {
  1320. startsExpr
  1321. }),
  1322. _type: createKeywordLike("type", {
  1323. startsExpr
  1324. }),
  1325. _opaque: createKeywordLike("opaque", {
  1326. startsExpr
  1327. }),
  1328. name: createToken("name", {
  1329. startsExpr
  1330. }),
  1331. placeholder: createToken("%%", {
  1332. startsExpr
  1333. }),
  1334. string: createToken("string", {
  1335. startsExpr
  1336. }),
  1337. num: createToken("num", {
  1338. startsExpr
  1339. }),
  1340. bigint: createToken("bigint", {
  1341. startsExpr
  1342. }),
  1343. decimal: createToken("decimal", {
  1344. startsExpr
  1345. }),
  1346. regexp: createToken("regexp", {
  1347. startsExpr
  1348. }),
  1349. privateName: createToken("#name", {
  1350. startsExpr
  1351. }),
  1352. eof: createToken("eof"),
  1353. jsxName: createToken("jsxName"),
  1354. jsxText: createToken("jsxText", {
  1355. beforeExpr
  1356. }),
  1357. jsxTagStart: createToken("jsxTagStart", {
  1358. startsExpr
  1359. }),
  1360. jsxTagEnd: createToken("jsxTagEnd")
  1361. };
  1362. function tokenIsIdentifier(token) {
  1363. return token >= 93 && token <= 133;
  1364. }
  1365. function tokenKeywordOrIdentifierIsKeyword(token) {
  1366. return token <= 92;
  1367. }
  1368. function tokenIsKeywordOrIdentifier(token) {
  1369. return token >= 58 && token <= 133;
  1370. }
  1371. function tokenIsLiteralPropertyName(token) {
  1372. return token >= 58 && token <= 137;
  1373. }
  1374. function tokenComesBeforeExpression(token) {
  1375. return tokenBeforeExprs[token];
  1376. }
  1377. function tokenCanStartExpression(token) {
  1378. return tokenStartsExprs[token];
  1379. }
  1380. function tokenIsAssignment(token) {
  1381. return token >= 29 && token <= 33;
  1382. }
  1383. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1384. return token >= 129 && token <= 131;
  1385. }
  1386. function tokenIsLoop(token) {
  1387. return token >= 90 && token <= 92;
  1388. }
  1389. function tokenIsKeyword(token) {
  1390. return token >= 58 && token <= 92;
  1391. }
  1392. function tokenIsOperator(token) {
  1393. return token >= 39 && token <= 59;
  1394. }
  1395. function tokenIsPostfix(token) {
  1396. return token === 34;
  1397. }
  1398. function tokenIsPrefix(token) {
  1399. return tokenPrefixes[token];
  1400. }
  1401. function tokenIsTSTypeOperator(token) {
  1402. return token >= 121 && token <= 123;
  1403. }
  1404. function tokenIsTSDeclarationStart(token) {
  1405. return token >= 124 && token <= 130;
  1406. }
  1407. function tokenLabelName(token) {
  1408. return tokenLabels[token];
  1409. }
  1410. function tokenOperatorPrecedence(token) {
  1411. return tokenBinops[token];
  1412. }
  1413. function tokenIsRightAssociative(token) {
  1414. return token === 57;
  1415. }
  1416. function tokenIsTemplate(token) {
  1417. return token >= 24 && token <= 25;
  1418. }
  1419. function getExportedToken(token) {
  1420. return tokenTypes[token];
  1421. }
  1422. tokenTypes[8].updateContext = context => {
  1423. context.pop();
  1424. };
  1425. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1426. context.push(types.brace);
  1427. };
  1428. tokenTypes[22].updateContext = context => {
  1429. if (context[context.length - 1] === types.template) {
  1430. context.pop();
  1431. } else {
  1432. context.push(types.template);
  1433. }
  1434. };
  1435. tokenTypes[143].updateContext = context => {
  1436. context.push(types.j_expr, types.j_oTag);
  1437. };
  1438. 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-\u088f\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\u0c5c\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdc-\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-\ua7dc\ua7f1-\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";
  1439. 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-\u1add\u1ae0-\u1aeb\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";
  1440. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1441. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1442. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1443. 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, 7, 25, 39, 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, 5, 57, 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, 24, 43, 261, 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, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 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, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 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, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489];
  1444. 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, 78, 5, 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, 199, 7, 137, 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, 55, 9, 266, 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, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1445. function isInAstralSet(code, set) {
  1446. let pos = 0x10000;
  1447. for (let i = 0, length = set.length; i < length; i += 2) {
  1448. pos += set[i];
  1449. if (pos > code) return false;
  1450. pos += set[i + 1];
  1451. if (pos >= code) return true;
  1452. }
  1453. return false;
  1454. }
  1455. function isIdentifierStart(code) {
  1456. if (code < 65) return code === 36;
  1457. if (code <= 90) return true;
  1458. if (code < 97) return code === 95;
  1459. if (code <= 122) return true;
  1460. if (code <= 0xffff) {
  1461. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1462. }
  1463. return isInAstralSet(code, astralIdentifierStartCodes);
  1464. }
  1465. function isIdentifierChar(code) {
  1466. if (code < 48) return code === 36;
  1467. if (code < 58) return true;
  1468. if (code < 65) return false;
  1469. if (code <= 90) return true;
  1470. if (code < 97) return code === 95;
  1471. if (code <= 122) return true;
  1472. if (code <= 0xffff) {
  1473. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1474. }
  1475. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1476. }
  1477. const reservedWords = {
  1478. 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"],
  1479. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1480. strictBind: ["eval", "arguments"]
  1481. };
  1482. const keywords = new Set(reservedWords.keyword);
  1483. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1484. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1485. function isReservedWord(word, inModule) {
  1486. return inModule && word === "await" || word === "enum";
  1487. }
  1488. function isStrictReservedWord(word, inModule) {
  1489. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1490. }
  1491. function isStrictBindOnlyReservedWord(word) {
  1492. return reservedWordsStrictBindSet.has(word);
  1493. }
  1494. function isStrictBindReservedWord(word, inModule) {
  1495. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1496. }
  1497. function isKeyword(word) {
  1498. return keywords.has(word);
  1499. }
  1500. function isIteratorStart(current, next, next2) {
  1501. return current === 64 && next === 64 && isIdentifierStart(next2);
  1502. }
  1503. 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"]);
  1504. function canBeReservedWord(word) {
  1505. return reservedWordLikeSet.has(word);
  1506. }
  1507. class Scope {
  1508. constructor(flags) {
  1509. this.flags = 0;
  1510. this.names = new Map();
  1511. this.firstLexicalName = "";
  1512. this.flags = flags;
  1513. }
  1514. }
  1515. class ScopeHandler {
  1516. constructor(parser, inModule) {
  1517. this.parser = void 0;
  1518. this.scopeStack = [];
  1519. this.inModule = void 0;
  1520. this.undefinedExports = new Map();
  1521. this.parser = parser;
  1522. this.inModule = inModule;
  1523. }
  1524. get inTopLevel() {
  1525. return (this.currentScope().flags & 1) > 0;
  1526. }
  1527. get inFunction() {
  1528. return (this.currentVarScopeFlags() & 2) > 0;
  1529. }
  1530. get allowSuper() {
  1531. return (this.currentThisScopeFlags() & 16) > 0;
  1532. }
  1533. get allowDirectSuper() {
  1534. return (this.currentThisScopeFlags() & 32) > 0;
  1535. }
  1536. get allowNewTarget() {
  1537. return (this.currentThisScopeFlags() & 512) > 0;
  1538. }
  1539. get inClass() {
  1540. return (this.currentThisScopeFlags() & 64) > 0;
  1541. }
  1542. get inClassAndNotInNonArrowFunction() {
  1543. const flags = this.currentThisScopeFlags();
  1544. return (flags & 64) > 0 && (flags & 2) === 0;
  1545. }
  1546. get inStaticBlock() {
  1547. for (let i = this.scopeStack.length - 1;; i--) {
  1548. const {
  1549. flags
  1550. } = this.scopeStack[i];
  1551. if (flags & 128) {
  1552. return true;
  1553. }
  1554. if (flags & (1667 | 64)) {
  1555. return false;
  1556. }
  1557. }
  1558. }
  1559. get inNonArrowFunction() {
  1560. return (this.currentThisScopeFlags() & 2) > 0;
  1561. }
  1562. get inBareCaseStatement() {
  1563. return (this.currentScope().flags & 256) > 0;
  1564. }
  1565. get treatFunctionsAsVar() {
  1566. return this.treatFunctionsAsVarInScope(this.currentScope());
  1567. }
  1568. createScope(flags) {
  1569. return new Scope(flags);
  1570. }
  1571. enter(flags) {
  1572. this.scopeStack.push(this.createScope(flags));
  1573. }
  1574. exit() {
  1575. const scope = this.scopeStack.pop();
  1576. return scope.flags;
  1577. }
  1578. treatFunctionsAsVarInScope(scope) {
  1579. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1580. }
  1581. declareName(name, bindingType, loc) {
  1582. let scope = this.currentScope();
  1583. if (bindingType & 8 || bindingType & 16) {
  1584. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1585. let type = scope.names.get(name) || 0;
  1586. if (bindingType & 16) {
  1587. type = type | 4;
  1588. } else {
  1589. if (!scope.firstLexicalName) {
  1590. scope.firstLexicalName = name;
  1591. }
  1592. type = type | 2;
  1593. }
  1594. scope.names.set(name, type);
  1595. if (bindingType & 8) {
  1596. this.maybeExportDefined(scope, name);
  1597. }
  1598. } else if (bindingType & 4) {
  1599. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1600. scope = this.scopeStack[i];
  1601. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1602. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1603. this.maybeExportDefined(scope, name);
  1604. if (scope.flags & 1667) break;
  1605. }
  1606. }
  1607. if (this.parser.inModule && scope.flags & 1) {
  1608. this.undefinedExports.delete(name);
  1609. }
  1610. }
  1611. maybeExportDefined(scope, name) {
  1612. if (this.parser.inModule && scope.flags & 1) {
  1613. this.undefinedExports.delete(name);
  1614. }
  1615. }
  1616. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1617. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1618. this.parser.raise(Errors.VarRedeclaration, loc, {
  1619. identifierName: name
  1620. });
  1621. }
  1622. }
  1623. isRedeclaredInScope(scope, name, bindingType) {
  1624. if (!(bindingType & 1)) return false;
  1625. if (bindingType & 8) {
  1626. return scope.names.has(name);
  1627. }
  1628. const type = scope.names.get(name) || 0;
  1629. if (bindingType & 16) {
  1630. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1631. }
  1632. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1633. }
  1634. checkLocalExport(id) {
  1635. const {
  1636. name
  1637. } = id;
  1638. const topLevelScope = this.scopeStack[0];
  1639. if (!topLevelScope.names.has(name)) {
  1640. this.undefinedExports.set(name, id.loc.start);
  1641. }
  1642. }
  1643. currentScope() {
  1644. return this.scopeStack[this.scopeStack.length - 1];
  1645. }
  1646. currentVarScopeFlags() {
  1647. for (let i = this.scopeStack.length - 1;; i--) {
  1648. const {
  1649. flags
  1650. } = this.scopeStack[i];
  1651. if (flags & 1667) {
  1652. return flags;
  1653. }
  1654. }
  1655. }
  1656. currentThisScopeFlags() {
  1657. for (let i = this.scopeStack.length - 1;; i--) {
  1658. const {
  1659. flags
  1660. } = this.scopeStack[i];
  1661. if (flags & (1667 | 64) && !(flags & 4)) {
  1662. return flags;
  1663. }
  1664. }
  1665. }
  1666. }
  1667. class FlowScope extends Scope {
  1668. constructor(...args) {
  1669. super(...args);
  1670. this.declareFunctions = new Set();
  1671. }
  1672. }
  1673. class FlowScopeHandler extends ScopeHandler {
  1674. createScope(flags) {
  1675. return new FlowScope(flags);
  1676. }
  1677. declareName(name, bindingType, loc) {
  1678. const scope = this.currentScope();
  1679. if (bindingType & 2048) {
  1680. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1681. this.maybeExportDefined(scope, name);
  1682. scope.declareFunctions.add(name);
  1683. return;
  1684. }
  1685. super.declareName(name, bindingType, loc);
  1686. }
  1687. isRedeclaredInScope(scope, name, bindingType) {
  1688. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1689. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1690. const type = scope.names.get(name);
  1691. return (type & 4) > 0 || (type & 2) > 0;
  1692. }
  1693. return false;
  1694. }
  1695. checkLocalExport(id) {
  1696. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1697. super.checkLocalExport(id);
  1698. }
  1699. }
  1700. }
  1701. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  1702. const FlowErrors = ParseErrorEnum`flow`({
  1703. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  1704. 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.",
  1705. AssignReservedType: ({
  1706. reservedType
  1707. }) => `Cannot overwrite reserved type ${reservedType}.`,
  1708. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  1709. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  1710. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  1711. EnumBooleanMemberNotInitialized: ({
  1712. memberName,
  1713. enumName
  1714. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  1715. EnumDuplicateMemberName: ({
  1716. memberName,
  1717. enumName
  1718. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  1719. EnumInconsistentMemberValues: ({
  1720. enumName
  1721. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  1722. EnumInvalidExplicitType: ({
  1723. invalidEnumType,
  1724. enumName
  1725. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1726. EnumInvalidExplicitTypeUnknownSupplied: ({
  1727. enumName
  1728. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1729. EnumInvalidMemberInitializerPrimaryType: ({
  1730. enumName,
  1731. memberName,
  1732. explicitType
  1733. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  1734. EnumInvalidMemberInitializerSymbolType: ({
  1735. enumName,
  1736. memberName
  1737. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  1738. EnumInvalidMemberInitializerUnknownType: ({
  1739. enumName,
  1740. memberName
  1741. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  1742. EnumInvalidMemberName: ({
  1743. enumName,
  1744. memberName,
  1745. suggestion
  1746. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  1747. EnumNumberMemberNotInitialized: ({
  1748. enumName,
  1749. memberName
  1750. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  1751. EnumStringMemberInconsistentlyInitialized: ({
  1752. enumName
  1753. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  1754. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  1755. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  1756. 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.",
  1757. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  1758. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  1759. InexactVariance: "Explicit inexact syntax cannot have variance.",
  1760. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  1761. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  1762. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  1763. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  1764. PatternIsOptional: Object.assign({
  1765. message: "A binding pattern parameter cannot be optional in an implementation signature."
  1766. }, {
  1767. reasonCode: "OptionalBindingPattern"
  1768. }),
  1769. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  1770. SpreadVariance: "Spread properties cannot have variance.",
  1771. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  1772. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  1773. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  1774. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  1775. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  1776. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  1777. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  1778. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  1779. UnexpectedReservedType: ({
  1780. reservedType
  1781. }) => `Unexpected reserved type ${reservedType}.`,
  1782. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  1783. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  1784. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  1785. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  1786. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  1787. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  1788. UnsupportedDeclareExportKind: ({
  1789. unsupportedExportKind,
  1790. suggestion
  1791. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  1792. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  1793. UnterminatedFlowComment: "Unterminated flow-comment."
  1794. });
  1795. function isEsModuleType(bodyElement) {
  1796. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  1797. }
  1798. function hasTypeImportKind(node) {
  1799. return node.importKind === "type" || node.importKind === "typeof";
  1800. }
  1801. const exportSuggestions = {
  1802. const: "declare export var",
  1803. let: "declare export var",
  1804. type: "export type",
  1805. interface: "export interface"
  1806. };
  1807. function partition(list, test) {
  1808. const list1 = [];
  1809. const list2 = [];
  1810. for (let i = 0; i < list.length; i++) {
  1811. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  1812. }
  1813. return [list1, list2];
  1814. }
  1815. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  1816. var flow = superClass => class FlowParserMixin extends superClass {
  1817. constructor(...args) {
  1818. super(...args);
  1819. this.flowPragma = undefined;
  1820. }
  1821. getScopeHandler() {
  1822. return FlowScopeHandler;
  1823. }
  1824. shouldParseTypes() {
  1825. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  1826. }
  1827. finishToken(type, val) {
  1828. if (type !== 134 && type !== 13 && type !== 28) {
  1829. if (this.flowPragma === undefined) {
  1830. this.flowPragma = null;
  1831. }
  1832. }
  1833. super.finishToken(type, val);
  1834. }
  1835. addComment(comment) {
  1836. if (this.flowPragma === undefined) {
  1837. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  1838. if (!matches) ;else if (matches[1] === "flow") {
  1839. this.flowPragma = "flow";
  1840. } else if (matches[1] === "noflow") {
  1841. this.flowPragma = "noflow";
  1842. } else {
  1843. throw new Error("Unexpected flow pragma");
  1844. }
  1845. }
  1846. super.addComment(comment);
  1847. }
  1848. flowParseTypeInitialiser(tok) {
  1849. const oldInType = this.state.inType;
  1850. this.state.inType = true;
  1851. this.expect(tok || 14);
  1852. const type = this.flowParseType();
  1853. this.state.inType = oldInType;
  1854. return type;
  1855. }
  1856. flowParsePredicate() {
  1857. const node = this.startNode();
  1858. const moduloLoc = this.state.startLoc;
  1859. this.next();
  1860. this.expectContextual(110);
  1861. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  1862. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  1863. }
  1864. if (this.eat(10)) {
  1865. node.value = super.parseExpression();
  1866. this.expect(11);
  1867. return this.finishNode(node, "DeclaredPredicate");
  1868. } else {
  1869. return this.finishNode(node, "InferredPredicate");
  1870. }
  1871. }
  1872. flowParseTypeAndPredicateInitialiser() {
  1873. const oldInType = this.state.inType;
  1874. this.state.inType = true;
  1875. this.expect(14);
  1876. let type = null;
  1877. let predicate = null;
  1878. if (this.match(54)) {
  1879. this.state.inType = oldInType;
  1880. predicate = this.flowParsePredicate();
  1881. } else {
  1882. type = this.flowParseType();
  1883. this.state.inType = oldInType;
  1884. if (this.match(54)) {
  1885. predicate = this.flowParsePredicate();
  1886. }
  1887. }
  1888. return [type, predicate];
  1889. }
  1890. flowParseDeclareClass(node) {
  1891. this.next();
  1892. this.flowParseInterfaceish(node, true);
  1893. return this.finishNode(node, "DeclareClass");
  1894. }
  1895. flowParseDeclareFunction(node) {
  1896. this.next();
  1897. const id = node.id = this.parseIdentifier();
  1898. const typeNode = this.startNode();
  1899. const typeContainer = this.startNode();
  1900. if (this.match(47)) {
  1901. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  1902. } else {
  1903. typeNode.typeParameters = null;
  1904. }
  1905. this.expect(10);
  1906. const tmp = this.flowParseFunctionTypeParams();
  1907. typeNode.params = tmp.params;
  1908. typeNode.rest = tmp.rest;
  1909. typeNode.this = tmp._this;
  1910. this.expect(11);
  1911. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  1912. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  1913. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  1914. this.resetEndLocation(id);
  1915. this.semicolon();
  1916. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  1917. return this.finishNode(node, "DeclareFunction");
  1918. }
  1919. flowParseDeclare(node, insideModule) {
  1920. if (this.match(80)) {
  1921. return this.flowParseDeclareClass(node);
  1922. } else if (this.match(68)) {
  1923. return this.flowParseDeclareFunction(node);
  1924. } else if (this.match(74)) {
  1925. return this.flowParseDeclareVariable(node);
  1926. } else if (this.eatContextual(127)) {
  1927. if (this.match(16)) {
  1928. return this.flowParseDeclareModuleExports(node);
  1929. } else {
  1930. if (insideModule) {
  1931. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  1932. }
  1933. return this.flowParseDeclareModule(node);
  1934. }
  1935. } else if (this.isContextual(130)) {
  1936. return this.flowParseDeclareTypeAlias(node);
  1937. } else if (this.isContextual(131)) {
  1938. return this.flowParseDeclareOpaqueType(node);
  1939. } else if (this.isContextual(129)) {
  1940. return this.flowParseDeclareInterface(node);
  1941. } else if (this.match(82)) {
  1942. return this.flowParseDeclareExportDeclaration(node, insideModule);
  1943. }
  1944. throw this.unexpected();
  1945. }
  1946. flowParseDeclareVariable(node) {
  1947. this.next();
  1948. node.id = this.flowParseTypeAnnotatableIdentifier();
  1949. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  1950. this.semicolon();
  1951. return this.finishNode(node, "DeclareVariable");
  1952. }
  1953. flowParseDeclareModule(node) {
  1954. this.scope.enter(0);
  1955. if (this.match(134)) {
  1956. node.id = super.parseExprAtom();
  1957. } else {
  1958. node.id = this.parseIdentifier();
  1959. }
  1960. const bodyNode = node.body = this.startNode();
  1961. const body = bodyNode.body = [];
  1962. this.expect(5);
  1963. while (!this.match(8)) {
  1964. const bodyNode = this.startNode();
  1965. if (this.match(83)) {
  1966. this.next();
  1967. if (!this.isContextual(130) && !this.match(87)) {
  1968. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  1969. }
  1970. body.push(super.parseImport(bodyNode));
  1971. } else {
  1972. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  1973. body.push(this.flowParseDeclare(bodyNode, true));
  1974. }
  1975. }
  1976. this.scope.exit();
  1977. this.expect(8);
  1978. this.finishNode(bodyNode, "BlockStatement");
  1979. let kind = null;
  1980. let hasModuleExport = false;
  1981. body.forEach(bodyElement => {
  1982. if (isEsModuleType(bodyElement)) {
  1983. if (kind === "CommonJS") {
  1984. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  1985. }
  1986. kind = "ES";
  1987. } else if (bodyElement.type === "DeclareModuleExports") {
  1988. if (hasModuleExport) {
  1989. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  1990. }
  1991. if (kind === "ES") {
  1992. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  1993. }
  1994. kind = "CommonJS";
  1995. hasModuleExport = true;
  1996. }
  1997. });
  1998. node.kind = kind || "CommonJS";
  1999. return this.finishNode(node, "DeclareModule");
  2000. }
  2001. flowParseDeclareExportDeclaration(node, insideModule) {
  2002. this.expect(82);
  2003. if (this.eat(65)) {
  2004. if (this.match(68) || this.match(80)) {
  2005. node.declaration = this.flowParseDeclare(this.startNode());
  2006. } else {
  2007. node.declaration = this.flowParseType();
  2008. this.semicolon();
  2009. }
  2010. node.default = true;
  2011. return this.finishNode(node, "DeclareExportDeclaration");
  2012. } else {
  2013. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  2014. const label = this.state.value;
  2015. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  2016. unsupportedExportKind: label,
  2017. suggestion: exportSuggestions[label]
  2018. });
  2019. }
  2020. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  2021. node.declaration = this.flowParseDeclare(this.startNode());
  2022. node.default = false;
  2023. return this.finishNode(node, "DeclareExportDeclaration");
  2024. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  2025. node = this.parseExport(node, null);
  2026. if (node.type === "ExportNamedDeclaration") {
  2027. node.default = false;
  2028. delete node.exportKind;
  2029. return this.castNodeTo(node, "DeclareExportDeclaration");
  2030. } else {
  2031. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  2032. }
  2033. }
  2034. }
  2035. throw this.unexpected();
  2036. }
  2037. flowParseDeclareModuleExports(node) {
  2038. this.next();
  2039. this.expectContextual(111);
  2040. node.typeAnnotation = this.flowParseTypeAnnotation();
  2041. this.semicolon();
  2042. return this.finishNode(node, "DeclareModuleExports");
  2043. }
  2044. flowParseDeclareTypeAlias(node) {
  2045. this.next();
  2046. const finished = this.flowParseTypeAlias(node);
  2047. this.castNodeTo(finished, "DeclareTypeAlias");
  2048. return finished;
  2049. }
  2050. flowParseDeclareOpaqueType(node) {
  2051. this.next();
  2052. const finished = this.flowParseOpaqueType(node, true);
  2053. this.castNodeTo(finished, "DeclareOpaqueType");
  2054. return finished;
  2055. }
  2056. flowParseDeclareInterface(node) {
  2057. this.next();
  2058. this.flowParseInterfaceish(node, false);
  2059. return this.finishNode(node, "DeclareInterface");
  2060. }
  2061. flowParseInterfaceish(node, isClass) {
  2062. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  2063. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  2064. if (this.match(47)) {
  2065. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2066. } else {
  2067. node.typeParameters = null;
  2068. }
  2069. node.extends = [];
  2070. if (this.eat(81)) {
  2071. do {
  2072. node.extends.push(this.flowParseInterfaceExtends());
  2073. } while (!isClass && this.eat(12));
  2074. }
  2075. if (isClass) {
  2076. node.implements = [];
  2077. node.mixins = [];
  2078. if (this.eatContextual(117)) {
  2079. do {
  2080. node.mixins.push(this.flowParseInterfaceExtends());
  2081. } while (this.eat(12));
  2082. }
  2083. if (this.eatContextual(113)) {
  2084. do {
  2085. node.implements.push(this.flowParseInterfaceExtends());
  2086. } while (this.eat(12));
  2087. }
  2088. }
  2089. node.body = this.flowParseObjectType({
  2090. allowStatic: isClass,
  2091. allowExact: false,
  2092. allowSpread: false,
  2093. allowProto: isClass,
  2094. allowInexact: false
  2095. });
  2096. }
  2097. flowParseInterfaceExtends() {
  2098. const node = this.startNode();
  2099. node.id = this.flowParseQualifiedTypeIdentifier();
  2100. if (this.match(47)) {
  2101. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2102. } else {
  2103. node.typeParameters = null;
  2104. }
  2105. return this.finishNode(node, "InterfaceExtends");
  2106. }
  2107. flowParseInterface(node) {
  2108. this.flowParseInterfaceish(node, false);
  2109. return this.finishNode(node, "InterfaceDeclaration");
  2110. }
  2111. checkNotUnderscore(word) {
  2112. if (word === "_") {
  2113. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  2114. }
  2115. }
  2116. checkReservedType(word, startLoc, declaration) {
  2117. if (!reservedTypes.has(word)) return;
  2118. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  2119. reservedType: word
  2120. });
  2121. }
  2122. flowParseRestrictedIdentifierName(liberal, declaration) {
  2123. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  2124. return this.parseIdentifierName(liberal);
  2125. }
  2126. flowParseRestrictedIdentifier(liberal, declaration) {
  2127. const node = this.startNode();
  2128. const name = this.flowParseRestrictedIdentifierName(liberal, declaration);
  2129. return this.createIdentifier(node, name);
  2130. }
  2131. flowParseTypeAlias(node) {
  2132. node.id = this.flowParseRestrictedIdentifier(false, true);
  2133. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2134. if (this.match(47)) {
  2135. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2136. } else {
  2137. node.typeParameters = null;
  2138. }
  2139. node.right = this.flowParseTypeInitialiser(29);
  2140. this.semicolon();
  2141. return this.finishNode(node, "TypeAlias");
  2142. }
  2143. flowParseOpaqueType(node, declare) {
  2144. this.expectContextual(130);
  2145. node.id = this.flowParseRestrictedIdentifier(true, true);
  2146. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2147. if (this.match(47)) {
  2148. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2149. } else {
  2150. node.typeParameters = null;
  2151. }
  2152. node.supertype = null;
  2153. if (this.match(14)) {
  2154. node.supertype = this.flowParseTypeInitialiser(14);
  2155. }
  2156. node.impltype = null;
  2157. if (!declare) {
  2158. node.impltype = this.flowParseTypeInitialiser(29);
  2159. }
  2160. this.semicolon();
  2161. return this.finishNode(node, "OpaqueType");
  2162. }
  2163. flowParseTypeParameterBound() {
  2164. if (this.match(14) || this.isContextual(81)) {
  2165. const node = this.startNode();
  2166. this.next();
  2167. node.typeAnnotation = this.flowParseType();
  2168. return this.finishNode(node, "TypeAnnotation");
  2169. }
  2170. }
  2171. flowParseTypeParameter(requireDefault = false) {
  2172. const nodeStartLoc = this.state.startLoc;
  2173. const node = this.startNode();
  2174. const variance = this.flowParseVariance();
  2175. node.name = this.flowParseRestrictedIdentifierName();
  2176. node.variance = variance;
  2177. node.bound = this.flowParseTypeParameterBound();
  2178. if (this.match(29)) {
  2179. this.eat(29);
  2180. node.default = this.flowParseType();
  2181. } else {
  2182. if (requireDefault) {
  2183. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  2184. }
  2185. }
  2186. return this.finishNode(node, "TypeParameter");
  2187. }
  2188. flowParseTypeParameterDeclaration() {
  2189. const oldInType = this.state.inType;
  2190. const node = this.startNode();
  2191. node.params = [];
  2192. this.state.inType = true;
  2193. if (this.match(47) || this.match(143)) {
  2194. this.next();
  2195. } else {
  2196. this.unexpected();
  2197. }
  2198. let defaultRequired = false;
  2199. do {
  2200. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  2201. node.params.push(typeParameter);
  2202. if (typeParameter.default) {
  2203. defaultRequired = true;
  2204. }
  2205. if (!this.match(48)) {
  2206. this.expect(12);
  2207. }
  2208. } while (!this.match(48));
  2209. this.expect(48);
  2210. this.state.inType = oldInType;
  2211. return this.finishNode(node, "TypeParameterDeclaration");
  2212. }
  2213. flowInTopLevelContext(cb) {
  2214. if (this.curContext() !== types.brace) {
  2215. const oldContext = this.state.context;
  2216. this.state.context = [oldContext[0]];
  2217. try {
  2218. return cb();
  2219. } finally {
  2220. this.state.context = oldContext;
  2221. }
  2222. } else {
  2223. return cb();
  2224. }
  2225. }
  2226. flowParseTypeParameterInstantiationInExpression() {
  2227. if (this.reScan_lt() !== 47) return;
  2228. return this.flowParseTypeParameterInstantiation();
  2229. }
  2230. flowParseTypeParameterInstantiation() {
  2231. const node = this.startNode();
  2232. const oldInType = this.state.inType;
  2233. this.state.inType = true;
  2234. node.params = [];
  2235. this.flowInTopLevelContext(() => {
  2236. this.expect(47);
  2237. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2238. this.state.noAnonFunctionType = false;
  2239. while (!this.match(48)) {
  2240. node.params.push(this.flowParseType());
  2241. if (!this.match(48)) {
  2242. this.expect(12);
  2243. }
  2244. }
  2245. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2246. });
  2247. this.state.inType = oldInType;
  2248. if (!this.state.inType && this.curContext() === types.brace) {
  2249. this.reScan_lt_gt();
  2250. }
  2251. this.expect(48);
  2252. return this.finishNode(node, "TypeParameterInstantiation");
  2253. }
  2254. flowParseTypeParameterInstantiationCallOrNew() {
  2255. if (this.reScan_lt() !== 47) return null;
  2256. const node = this.startNode();
  2257. const oldInType = this.state.inType;
  2258. node.params = [];
  2259. this.state.inType = true;
  2260. this.expect(47);
  2261. while (!this.match(48)) {
  2262. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  2263. if (!this.match(48)) {
  2264. this.expect(12);
  2265. }
  2266. }
  2267. this.expect(48);
  2268. this.state.inType = oldInType;
  2269. return this.finishNode(node, "TypeParameterInstantiation");
  2270. }
  2271. flowParseInterfaceType() {
  2272. const node = this.startNode();
  2273. this.expectContextual(129);
  2274. node.extends = [];
  2275. if (this.eat(81)) {
  2276. do {
  2277. node.extends.push(this.flowParseInterfaceExtends());
  2278. } while (this.eat(12));
  2279. }
  2280. node.body = this.flowParseObjectType({
  2281. allowStatic: false,
  2282. allowExact: false,
  2283. allowSpread: false,
  2284. allowProto: false,
  2285. allowInexact: false
  2286. });
  2287. return this.finishNode(node, "InterfaceTypeAnnotation");
  2288. }
  2289. flowParseObjectPropertyKey() {
  2290. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  2291. }
  2292. flowParseObjectTypeIndexer(node, isStatic, variance) {
  2293. node.static = isStatic;
  2294. if (this.lookahead().type === 14) {
  2295. node.id = this.flowParseObjectPropertyKey();
  2296. node.key = this.flowParseTypeInitialiser();
  2297. } else {
  2298. node.id = null;
  2299. node.key = this.flowParseType();
  2300. }
  2301. this.expect(3);
  2302. node.value = this.flowParseTypeInitialiser();
  2303. node.variance = variance;
  2304. return this.finishNode(node, "ObjectTypeIndexer");
  2305. }
  2306. flowParseObjectTypeInternalSlot(node, isStatic) {
  2307. node.static = isStatic;
  2308. node.id = this.flowParseObjectPropertyKey();
  2309. this.expect(3);
  2310. this.expect(3);
  2311. if (this.match(47) || this.match(10)) {
  2312. node.method = true;
  2313. node.optional = false;
  2314. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2315. } else {
  2316. node.method = false;
  2317. if (this.eat(17)) {
  2318. node.optional = true;
  2319. }
  2320. node.value = this.flowParseTypeInitialiser();
  2321. }
  2322. return this.finishNode(node, "ObjectTypeInternalSlot");
  2323. }
  2324. flowParseObjectTypeMethodish(node) {
  2325. node.params = [];
  2326. node.rest = null;
  2327. node.typeParameters = null;
  2328. node.this = null;
  2329. if (this.match(47)) {
  2330. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2331. }
  2332. this.expect(10);
  2333. if (this.match(78)) {
  2334. node.this = this.flowParseFunctionTypeParam(true);
  2335. node.this.name = null;
  2336. if (!this.match(11)) {
  2337. this.expect(12);
  2338. }
  2339. }
  2340. while (!this.match(11) && !this.match(21)) {
  2341. node.params.push(this.flowParseFunctionTypeParam(false));
  2342. if (!this.match(11)) {
  2343. this.expect(12);
  2344. }
  2345. }
  2346. if (this.eat(21)) {
  2347. node.rest = this.flowParseFunctionTypeParam(false);
  2348. }
  2349. this.expect(11);
  2350. node.returnType = this.flowParseTypeInitialiser();
  2351. return this.finishNode(node, "FunctionTypeAnnotation");
  2352. }
  2353. flowParseObjectTypeCallProperty(node, isStatic) {
  2354. const valueNode = this.startNode();
  2355. node.static = isStatic;
  2356. node.value = this.flowParseObjectTypeMethodish(valueNode);
  2357. return this.finishNode(node, "ObjectTypeCallProperty");
  2358. }
  2359. flowParseObjectType({
  2360. allowStatic,
  2361. allowExact,
  2362. allowSpread,
  2363. allowProto,
  2364. allowInexact
  2365. }) {
  2366. const oldInType = this.state.inType;
  2367. this.state.inType = true;
  2368. const nodeStart = this.startNode();
  2369. nodeStart.callProperties = [];
  2370. nodeStart.properties = [];
  2371. nodeStart.indexers = [];
  2372. nodeStart.internalSlots = [];
  2373. let endDelim;
  2374. let exact;
  2375. let inexact = false;
  2376. if (allowExact && this.match(6)) {
  2377. this.expect(6);
  2378. endDelim = 9;
  2379. exact = true;
  2380. } else {
  2381. this.expect(5);
  2382. endDelim = 8;
  2383. exact = false;
  2384. }
  2385. nodeStart.exact = exact;
  2386. while (!this.match(endDelim)) {
  2387. let isStatic = false;
  2388. let protoStartLoc = null;
  2389. let inexactStartLoc = null;
  2390. const node = this.startNode();
  2391. if (allowProto && this.isContextual(118)) {
  2392. const lookahead = this.lookahead();
  2393. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2394. this.next();
  2395. protoStartLoc = this.state.startLoc;
  2396. allowStatic = false;
  2397. }
  2398. }
  2399. if (allowStatic && this.isContextual(106)) {
  2400. const lookahead = this.lookahead();
  2401. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2402. this.next();
  2403. isStatic = true;
  2404. }
  2405. }
  2406. const variance = this.flowParseVariance();
  2407. if (this.eat(0)) {
  2408. if (protoStartLoc != null) {
  2409. this.unexpected(protoStartLoc);
  2410. }
  2411. if (this.eat(0)) {
  2412. if (variance) {
  2413. this.unexpected(variance.loc.start);
  2414. }
  2415. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  2416. } else {
  2417. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  2418. }
  2419. } else if (this.match(10) || this.match(47)) {
  2420. if (protoStartLoc != null) {
  2421. this.unexpected(protoStartLoc);
  2422. }
  2423. if (variance) {
  2424. this.unexpected(variance.loc.start);
  2425. }
  2426. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  2427. } else {
  2428. let kind = "init";
  2429. if (this.isContextual(99) || this.isContextual(104)) {
  2430. const lookahead = this.lookahead();
  2431. if (tokenIsLiteralPropertyName(lookahead.type)) {
  2432. kind = this.state.value;
  2433. this.next();
  2434. }
  2435. }
  2436. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  2437. if (propOrInexact === null) {
  2438. inexact = true;
  2439. inexactStartLoc = this.state.lastTokStartLoc;
  2440. } else {
  2441. nodeStart.properties.push(propOrInexact);
  2442. }
  2443. }
  2444. this.flowObjectTypeSemicolon();
  2445. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  2446. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  2447. }
  2448. }
  2449. this.expect(endDelim);
  2450. if (allowSpread) {
  2451. nodeStart.inexact = inexact;
  2452. }
  2453. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  2454. this.state.inType = oldInType;
  2455. return out;
  2456. }
  2457. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  2458. if (this.eat(21)) {
  2459. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  2460. if (isInexactToken) {
  2461. if (!allowSpread) {
  2462. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  2463. } else if (!allowInexact) {
  2464. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  2465. }
  2466. if (variance) {
  2467. this.raise(FlowErrors.InexactVariance, variance);
  2468. }
  2469. return null;
  2470. }
  2471. if (!allowSpread) {
  2472. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  2473. }
  2474. if (protoStartLoc != null) {
  2475. this.unexpected(protoStartLoc);
  2476. }
  2477. if (variance) {
  2478. this.raise(FlowErrors.SpreadVariance, variance);
  2479. }
  2480. node.argument = this.flowParseType();
  2481. return this.finishNode(node, "ObjectTypeSpreadProperty");
  2482. } else {
  2483. node.key = this.flowParseObjectPropertyKey();
  2484. node.static = isStatic;
  2485. node.proto = protoStartLoc != null;
  2486. node.kind = kind;
  2487. let optional = false;
  2488. if (this.match(47) || this.match(10)) {
  2489. node.method = true;
  2490. if (protoStartLoc != null) {
  2491. this.unexpected(protoStartLoc);
  2492. }
  2493. if (variance) {
  2494. this.unexpected(variance.loc.start);
  2495. }
  2496. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2497. if (kind === "get" || kind === "set") {
  2498. this.flowCheckGetterSetterParams(node);
  2499. }
  2500. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  2501. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  2502. }
  2503. } else {
  2504. if (kind !== "init") this.unexpected();
  2505. node.method = false;
  2506. if (this.eat(17)) {
  2507. optional = true;
  2508. }
  2509. node.value = this.flowParseTypeInitialiser();
  2510. node.variance = variance;
  2511. }
  2512. node.optional = optional;
  2513. return this.finishNode(node, "ObjectTypeProperty");
  2514. }
  2515. }
  2516. flowCheckGetterSetterParams(property) {
  2517. const paramCount = property.kind === "get" ? 0 : 1;
  2518. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  2519. if (property.value.this) {
  2520. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  2521. }
  2522. if (length !== paramCount) {
  2523. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  2524. }
  2525. if (property.kind === "set" && property.value.rest) {
  2526. this.raise(Errors.BadSetterRestParameter, property);
  2527. }
  2528. }
  2529. flowObjectTypeSemicolon() {
  2530. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  2531. this.unexpected();
  2532. }
  2533. }
  2534. flowParseQualifiedTypeIdentifier(startLoc, id) {
  2535. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  2536. let node = id || this.flowParseRestrictedIdentifier(true);
  2537. while (this.eat(16)) {
  2538. const node2 = this.startNodeAt(startLoc);
  2539. node2.qualification = node;
  2540. node2.id = this.flowParseRestrictedIdentifier(true);
  2541. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  2542. }
  2543. return node;
  2544. }
  2545. flowParseGenericType(startLoc, id) {
  2546. const node = this.startNodeAt(startLoc);
  2547. node.typeParameters = null;
  2548. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  2549. if (this.match(47)) {
  2550. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2551. }
  2552. return this.finishNode(node, "GenericTypeAnnotation");
  2553. }
  2554. flowParseTypeofType() {
  2555. const node = this.startNode();
  2556. this.expect(87);
  2557. node.argument = this.flowParsePrimaryType();
  2558. return this.finishNode(node, "TypeofTypeAnnotation");
  2559. }
  2560. flowParseTupleType() {
  2561. const node = this.startNode();
  2562. node.types = [];
  2563. this.expect(0);
  2564. while (this.state.pos < this.length && !this.match(3)) {
  2565. node.types.push(this.flowParseType());
  2566. if (this.match(3)) break;
  2567. this.expect(12);
  2568. }
  2569. this.expect(3);
  2570. return this.finishNode(node, "TupleTypeAnnotation");
  2571. }
  2572. flowParseFunctionTypeParam(first) {
  2573. let name = null;
  2574. let optional = false;
  2575. let typeAnnotation = null;
  2576. const node = this.startNode();
  2577. const lh = this.lookahead();
  2578. const isThis = this.state.type === 78;
  2579. if (lh.type === 14 || lh.type === 17) {
  2580. if (isThis && !first) {
  2581. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  2582. }
  2583. name = this.parseIdentifier(isThis);
  2584. if (this.eat(17)) {
  2585. optional = true;
  2586. if (isThis) {
  2587. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  2588. }
  2589. }
  2590. typeAnnotation = this.flowParseTypeInitialiser();
  2591. } else {
  2592. typeAnnotation = this.flowParseType();
  2593. }
  2594. node.name = name;
  2595. node.optional = optional;
  2596. node.typeAnnotation = typeAnnotation;
  2597. return this.finishNode(node, "FunctionTypeParam");
  2598. }
  2599. reinterpretTypeAsFunctionTypeParam(type) {
  2600. const node = this.startNodeAt(type.loc.start);
  2601. node.name = null;
  2602. node.optional = false;
  2603. node.typeAnnotation = type;
  2604. return this.finishNode(node, "FunctionTypeParam");
  2605. }
  2606. flowParseFunctionTypeParams(params = []) {
  2607. let rest = null;
  2608. let _this = null;
  2609. if (this.match(78)) {
  2610. _this = this.flowParseFunctionTypeParam(true);
  2611. _this.name = null;
  2612. if (!this.match(11)) {
  2613. this.expect(12);
  2614. }
  2615. }
  2616. while (!this.match(11) && !this.match(21)) {
  2617. params.push(this.flowParseFunctionTypeParam(false));
  2618. if (!this.match(11)) {
  2619. this.expect(12);
  2620. }
  2621. }
  2622. if (this.eat(21)) {
  2623. rest = this.flowParseFunctionTypeParam(false);
  2624. }
  2625. return {
  2626. params,
  2627. rest,
  2628. _this
  2629. };
  2630. }
  2631. flowIdentToTypeAnnotation(startLoc, node, id) {
  2632. switch (id.name) {
  2633. case "any":
  2634. return this.finishNode(node, "AnyTypeAnnotation");
  2635. case "bool":
  2636. case "boolean":
  2637. return this.finishNode(node, "BooleanTypeAnnotation");
  2638. case "mixed":
  2639. return this.finishNode(node, "MixedTypeAnnotation");
  2640. case "empty":
  2641. return this.finishNode(node, "EmptyTypeAnnotation");
  2642. case "number":
  2643. return this.finishNode(node, "NumberTypeAnnotation");
  2644. case "string":
  2645. return this.finishNode(node, "StringTypeAnnotation");
  2646. case "symbol":
  2647. return this.finishNode(node, "SymbolTypeAnnotation");
  2648. default:
  2649. this.checkNotUnderscore(id.name);
  2650. return this.flowParseGenericType(startLoc, id);
  2651. }
  2652. }
  2653. flowParsePrimaryType() {
  2654. const startLoc = this.state.startLoc;
  2655. const node = this.startNode();
  2656. let tmp;
  2657. let type;
  2658. let isGroupedType = false;
  2659. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2660. switch (this.state.type) {
  2661. case 5:
  2662. return this.flowParseObjectType({
  2663. allowStatic: false,
  2664. allowExact: false,
  2665. allowSpread: true,
  2666. allowProto: false,
  2667. allowInexact: true
  2668. });
  2669. case 6:
  2670. return this.flowParseObjectType({
  2671. allowStatic: false,
  2672. allowExact: true,
  2673. allowSpread: true,
  2674. allowProto: false,
  2675. allowInexact: false
  2676. });
  2677. case 0:
  2678. this.state.noAnonFunctionType = false;
  2679. type = this.flowParseTupleType();
  2680. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2681. return type;
  2682. case 47:
  2683. {
  2684. const node = this.startNode();
  2685. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2686. this.expect(10);
  2687. tmp = this.flowParseFunctionTypeParams();
  2688. node.params = tmp.params;
  2689. node.rest = tmp.rest;
  2690. node.this = tmp._this;
  2691. this.expect(11);
  2692. this.expect(19);
  2693. node.returnType = this.flowParseType();
  2694. return this.finishNode(node, "FunctionTypeAnnotation");
  2695. }
  2696. case 10:
  2697. {
  2698. const node = this.startNode();
  2699. this.next();
  2700. if (!this.match(11) && !this.match(21)) {
  2701. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  2702. const token = this.lookahead().type;
  2703. isGroupedType = token !== 17 && token !== 14;
  2704. } else {
  2705. isGroupedType = true;
  2706. }
  2707. }
  2708. if (isGroupedType) {
  2709. this.state.noAnonFunctionType = false;
  2710. type = this.flowParseType();
  2711. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2712. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  2713. this.expect(11);
  2714. return type;
  2715. } else {
  2716. this.eat(12);
  2717. }
  2718. }
  2719. if (type) {
  2720. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  2721. } else {
  2722. tmp = this.flowParseFunctionTypeParams();
  2723. }
  2724. node.params = tmp.params;
  2725. node.rest = tmp.rest;
  2726. node.this = tmp._this;
  2727. this.expect(11);
  2728. this.expect(19);
  2729. node.returnType = this.flowParseType();
  2730. node.typeParameters = null;
  2731. return this.finishNode(node, "FunctionTypeAnnotation");
  2732. }
  2733. case 134:
  2734. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  2735. case 85:
  2736. case 86:
  2737. node.value = this.match(85);
  2738. this.next();
  2739. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  2740. case 53:
  2741. if (this.state.value === "-") {
  2742. this.next();
  2743. if (this.match(135)) {
  2744. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  2745. }
  2746. if (this.match(136)) {
  2747. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  2748. }
  2749. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  2750. }
  2751. throw this.unexpected();
  2752. case 135:
  2753. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  2754. case 136:
  2755. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  2756. case 88:
  2757. this.next();
  2758. return this.finishNode(node, "VoidTypeAnnotation");
  2759. case 84:
  2760. this.next();
  2761. return this.finishNode(node, "NullLiteralTypeAnnotation");
  2762. case 78:
  2763. this.next();
  2764. return this.finishNode(node, "ThisTypeAnnotation");
  2765. case 55:
  2766. this.next();
  2767. return this.finishNode(node, "ExistsTypeAnnotation");
  2768. case 87:
  2769. return this.flowParseTypeofType();
  2770. default:
  2771. if (tokenIsKeyword(this.state.type)) {
  2772. const label = tokenLabelName(this.state.type);
  2773. this.next();
  2774. return super.createIdentifier(node, label);
  2775. } else if (tokenIsIdentifier(this.state.type)) {
  2776. if (this.isContextual(129)) {
  2777. return this.flowParseInterfaceType();
  2778. }
  2779. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  2780. }
  2781. }
  2782. throw this.unexpected();
  2783. }
  2784. flowParsePostfixType() {
  2785. const startLoc = this.state.startLoc;
  2786. let type = this.flowParsePrimaryType();
  2787. let seenOptionalIndexedAccess = false;
  2788. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  2789. const node = this.startNodeAt(startLoc);
  2790. const optional = this.eat(18);
  2791. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  2792. this.expect(0);
  2793. if (!optional && this.match(3)) {
  2794. node.elementType = type;
  2795. this.next();
  2796. type = this.finishNode(node, "ArrayTypeAnnotation");
  2797. } else {
  2798. node.objectType = type;
  2799. node.indexType = this.flowParseType();
  2800. this.expect(3);
  2801. if (seenOptionalIndexedAccess) {
  2802. node.optional = optional;
  2803. type = this.finishNode(node, "OptionalIndexedAccessType");
  2804. } else {
  2805. type = this.finishNode(node, "IndexedAccessType");
  2806. }
  2807. }
  2808. }
  2809. return type;
  2810. }
  2811. flowParsePrefixType() {
  2812. const node = this.startNode();
  2813. if (this.eat(17)) {
  2814. node.typeAnnotation = this.flowParsePrefixType();
  2815. return this.finishNode(node, "NullableTypeAnnotation");
  2816. } else {
  2817. return this.flowParsePostfixType();
  2818. }
  2819. }
  2820. flowParseAnonFunctionWithoutParens() {
  2821. const param = this.flowParsePrefixType();
  2822. if (!this.state.noAnonFunctionType && this.eat(19)) {
  2823. const node = this.startNodeAt(param.loc.start);
  2824. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  2825. node.rest = null;
  2826. node.this = null;
  2827. node.returnType = this.flowParseType();
  2828. node.typeParameters = null;
  2829. return this.finishNode(node, "FunctionTypeAnnotation");
  2830. }
  2831. return param;
  2832. }
  2833. flowParseIntersectionType() {
  2834. const node = this.startNode();
  2835. this.eat(45);
  2836. const type = this.flowParseAnonFunctionWithoutParens();
  2837. node.types = [type];
  2838. while (this.eat(45)) {
  2839. node.types.push(this.flowParseAnonFunctionWithoutParens());
  2840. }
  2841. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  2842. }
  2843. flowParseUnionType() {
  2844. const node = this.startNode();
  2845. this.eat(43);
  2846. const type = this.flowParseIntersectionType();
  2847. node.types = [type];
  2848. while (this.eat(43)) {
  2849. node.types.push(this.flowParseIntersectionType());
  2850. }
  2851. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  2852. }
  2853. flowParseType() {
  2854. const oldInType = this.state.inType;
  2855. this.state.inType = true;
  2856. const type = this.flowParseUnionType();
  2857. this.state.inType = oldInType;
  2858. return type;
  2859. }
  2860. flowParseTypeOrImplicitInstantiation() {
  2861. if (this.state.type === 132 && this.state.value === "_") {
  2862. const startLoc = this.state.startLoc;
  2863. const node = this.parseIdentifier();
  2864. return this.flowParseGenericType(startLoc, node);
  2865. } else {
  2866. return this.flowParseType();
  2867. }
  2868. }
  2869. flowParseTypeAnnotation() {
  2870. const node = this.startNode();
  2871. node.typeAnnotation = this.flowParseTypeInitialiser();
  2872. return this.finishNode(node, "TypeAnnotation");
  2873. }
  2874. flowParseTypeAnnotatableIdentifier() {
  2875. const node = this.startNode();
  2876. const name = this.parseIdentifierName();
  2877. if (this.match(14)) {
  2878. node.typeAnnotation = this.flowParseTypeAnnotation();
  2879. }
  2880. return this.createIdentifier(node, name);
  2881. }
  2882. typeCastToParameter(node) {
  2883. node.expression.typeAnnotation = node.typeAnnotation;
  2884. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  2885. return node.expression;
  2886. }
  2887. flowParseVariance() {
  2888. let variance = null;
  2889. if (this.match(53)) {
  2890. variance = this.startNode();
  2891. if (this.state.value === "+") {
  2892. variance.kind = "plus";
  2893. } else {
  2894. variance.kind = "minus";
  2895. }
  2896. this.next();
  2897. return this.finishNode(variance, "Variance");
  2898. }
  2899. return variance;
  2900. }
  2901. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  2902. if (allowExpressionBody) {
  2903. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  2904. return;
  2905. }
  2906. super.parseFunctionBody(node, false, isMethod);
  2907. }
  2908. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  2909. if (this.match(14)) {
  2910. const typeNode = this.startNode();
  2911. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  2912. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  2913. }
  2914. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  2915. }
  2916. parseStatementLike(flags) {
  2917. if (this.state.strict && this.isContextual(129)) {
  2918. const lookahead = this.lookahead();
  2919. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  2920. const node = this.startNode();
  2921. this.next();
  2922. return this.flowParseInterface(node);
  2923. }
  2924. } else if (this.isContextual(126)) {
  2925. const node = this.startNode();
  2926. this.next();
  2927. return this.flowParseEnumDeclaration(node);
  2928. }
  2929. const stmt = super.parseStatementLike(flags);
  2930. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  2931. this.flowPragma = null;
  2932. }
  2933. return stmt;
  2934. }
  2935. parseExpressionStatement(node, expr, decorators) {
  2936. if (expr.type === "Identifier") {
  2937. if (expr.name === "declare") {
  2938. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  2939. return this.flowParseDeclare(node);
  2940. }
  2941. } else if (tokenIsIdentifier(this.state.type)) {
  2942. if (expr.name === "interface") {
  2943. return this.flowParseInterface(node);
  2944. } else if (expr.name === "type") {
  2945. return this.flowParseTypeAlias(node);
  2946. } else if (expr.name === "opaque") {
  2947. return this.flowParseOpaqueType(node, false);
  2948. }
  2949. }
  2950. }
  2951. return super.parseExpressionStatement(node, expr, decorators);
  2952. }
  2953. shouldParseExportDeclaration() {
  2954. const {
  2955. type
  2956. } = this.state;
  2957. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2958. return !this.state.containsEsc;
  2959. }
  2960. return super.shouldParseExportDeclaration();
  2961. }
  2962. isExportDefaultSpecifier() {
  2963. const {
  2964. type
  2965. } = this.state;
  2966. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2967. return this.state.containsEsc;
  2968. }
  2969. return super.isExportDefaultSpecifier();
  2970. }
  2971. parseExportDefaultExpression() {
  2972. if (this.isContextual(126)) {
  2973. const node = this.startNode();
  2974. this.next();
  2975. return this.flowParseEnumDeclaration(node);
  2976. }
  2977. return super.parseExportDefaultExpression();
  2978. }
  2979. parseConditional(expr, startLoc, refExpressionErrors) {
  2980. if (!this.match(17)) return expr;
  2981. if (this.state.maybeInArrowParameters) {
  2982. const nextCh = this.lookaheadCharCode();
  2983. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  2984. this.setOptionalParametersError(refExpressionErrors);
  2985. return expr;
  2986. }
  2987. }
  2988. this.expect(17);
  2989. const state = this.state.clone();
  2990. const originalNoArrowAt = this.state.noArrowAt;
  2991. const node = this.startNodeAt(startLoc);
  2992. let {
  2993. consequent,
  2994. failed
  2995. } = this.tryParseConditionalConsequent();
  2996. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  2997. if (failed || invalid.length > 0) {
  2998. const noArrowAt = [...originalNoArrowAt];
  2999. if (invalid.length > 0) {
  3000. this.state = state;
  3001. this.state.noArrowAt = noArrowAt;
  3002. for (let i = 0; i < invalid.length; i++) {
  3003. noArrowAt.push(invalid[i].start);
  3004. }
  3005. ({
  3006. consequent,
  3007. failed
  3008. } = this.tryParseConditionalConsequent());
  3009. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  3010. }
  3011. if (failed && valid.length > 1) {
  3012. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  3013. }
  3014. if (failed && valid.length === 1) {
  3015. this.state = state;
  3016. noArrowAt.push(valid[0].start);
  3017. this.state.noArrowAt = noArrowAt;
  3018. ({
  3019. consequent,
  3020. failed
  3021. } = this.tryParseConditionalConsequent());
  3022. }
  3023. }
  3024. this.getArrowLikeExpressions(consequent, true);
  3025. this.state.noArrowAt = originalNoArrowAt;
  3026. this.expect(14);
  3027. node.test = expr;
  3028. node.consequent = consequent;
  3029. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  3030. return this.finishNode(node, "ConditionalExpression");
  3031. }
  3032. tryParseConditionalConsequent() {
  3033. this.state.noArrowParamsConversionAt.push(this.state.start);
  3034. const consequent = this.parseMaybeAssignAllowIn();
  3035. const failed = !this.match(14);
  3036. this.state.noArrowParamsConversionAt.pop();
  3037. return {
  3038. consequent,
  3039. failed
  3040. };
  3041. }
  3042. getArrowLikeExpressions(node, disallowInvalid) {
  3043. const stack = [node];
  3044. const arrows = [];
  3045. while (stack.length !== 0) {
  3046. const node = stack.pop();
  3047. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  3048. if (node.typeParameters || !node.returnType) {
  3049. this.finishArrowValidation(node);
  3050. } else {
  3051. arrows.push(node);
  3052. }
  3053. stack.push(node.body);
  3054. } else if (node.type === "ConditionalExpression") {
  3055. stack.push(node.consequent);
  3056. stack.push(node.alternate);
  3057. }
  3058. }
  3059. if (disallowInvalid) {
  3060. arrows.forEach(node => this.finishArrowValidation(node));
  3061. return [arrows, []];
  3062. }
  3063. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  3064. }
  3065. finishArrowValidation(node) {
  3066. var _node$extra;
  3067. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  3068. this.scope.enter(514 | 4);
  3069. super.checkParams(node, false, true);
  3070. this.scope.exit();
  3071. }
  3072. forwardNoArrowParamsConversionAt(node, parse) {
  3073. let result;
  3074. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3075. this.state.noArrowParamsConversionAt.push(this.state.start);
  3076. result = parse();
  3077. this.state.noArrowParamsConversionAt.pop();
  3078. } else {
  3079. result = parse();
  3080. }
  3081. return result;
  3082. }
  3083. parseParenItem(node, startLoc) {
  3084. const newNode = super.parseParenItem(node, startLoc);
  3085. if (this.eat(17)) {
  3086. newNode.optional = true;
  3087. this.resetEndLocation(node);
  3088. }
  3089. if (this.match(14)) {
  3090. const typeCastNode = this.startNodeAt(startLoc);
  3091. typeCastNode.expression = newNode;
  3092. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  3093. return this.finishNode(typeCastNode, "TypeCastExpression");
  3094. }
  3095. return newNode;
  3096. }
  3097. assertModuleNodeAllowed(node) {
  3098. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  3099. return;
  3100. }
  3101. super.assertModuleNodeAllowed(node);
  3102. }
  3103. parseExportDeclaration(node) {
  3104. if (this.isContextual(130)) {
  3105. node.exportKind = "type";
  3106. const declarationNode = this.startNode();
  3107. this.next();
  3108. if (this.match(5)) {
  3109. node.specifiers = this.parseExportSpecifiers(true);
  3110. super.parseExportFrom(node);
  3111. return null;
  3112. } else {
  3113. return this.flowParseTypeAlias(declarationNode);
  3114. }
  3115. } else if (this.isContextual(131)) {
  3116. node.exportKind = "type";
  3117. const declarationNode = this.startNode();
  3118. this.next();
  3119. return this.flowParseOpaqueType(declarationNode, false);
  3120. } else if (this.isContextual(129)) {
  3121. node.exportKind = "type";
  3122. const declarationNode = this.startNode();
  3123. this.next();
  3124. return this.flowParseInterface(declarationNode);
  3125. } else if (this.isContextual(126)) {
  3126. node.exportKind = "value";
  3127. const declarationNode = this.startNode();
  3128. this.next();
  3129. return this.flowParseEnumDeclaration(declarationNode);
  3130. } else {
  3131. return super.parseExportDeclaration(node);
  3132. }
  3133. }
  3134. eatExportStar(node) {
  3135. if (super.eatExportStar(node)) return true;
  3136. if (this.isContextual(130) && this.lookahead().type === 55) {
  3137. node.exportKind = "type";
  3138. this.next();
  3139. this.next();
  3140. return true;
  3141. }
  3142. return false;
  3143. }
  3144. maybeParseExportNamespaceSpecifier(node) {
  3145. const {
  3146. startLoc
  3147. } = this.state;
  3148. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  3149. if (hasNamespace && node.exportKind === "type") {
  3150. this.unexpected(startLoc);
  3151. }
  3152. return hasNamespace;
  3153. }
  3154. parseClassId(node, isStatement, optionalId) {
  3155. super.parseClassId(node, isStatement, optionalId);
  3156. if (this.match(47)) {
  3157. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3158. }
  3159. }
  3160. parseClassMember(classBody, member, state) {
  3161. const {
  3162. startLoc
  3163. } = this.state;
  3164. if (this.isContextual(125)) {
  3165. if (super.parseClassMemberFromModifier(classBody, member)) {
  3166. return;
  3167. }
  3168. member.declare = true;
  3169. }
  3170. super.parseClassMember(classBody, member, state);
  3171. if (member.declare) {
  3172. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  3173. this.raise(FlowErrors.DeclareClassElement, startLoc);
  3174. } else if (member.value) {
  3175. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  3176. }
  3177. }
  3178. }
  3179. isIterator(word) {
  3180. return word === "iterator" || word === "asyncIterator";
  3181. }
  3182. readIterator() {
  3183. const word = super.readWord1();
  3184. const fullWord = "@@" + word;
  3185. if (!this.isIterator(word) || !this.state.inType) {
  3186. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  3187. identifierName: fullWord
  3188. });
  3189. }
  3190. this.finishToken(132, fullWord);
  3191. }
  3192. getTokenFromCode(code) {
  3193. const next = this.input.charCodeAt(this.state.pos + 1);
  3194. if (code === 123 && next === 124) {
  3195. this.finishOp(6, 2);
  3196. } else if (this.state.inType && (code === 62 || code === 60)) {
  3197. this.finishOp(code === 62 ? 48 : 47, 1);
  3198. } else if (this.state.inType && code === 63) {
  3199. if (next === 46) {
  3200. this.finishOp(18, 2);
  3201. } else {
  3202. this.finishOp(17, 1);
  3203. }
  3204. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  3205. this.state.pos += 2;
  3206. this.readIterator();
  3207. } else {
  3208. super.getTokenFromCode(code);
  3209. }
  3210. }
  3211. isAssignable(node, isBinding) {
  3212. if (node.type === "TypeCastExpression") {
  3213. return this.isAssignable(node.expression, isBinding);
  3214. } else {
  3215. return super.isAssignable(node, isBinding);
  3216. }
  3217. }
  3218. toAssignable(node, isLHS = false) {
  3219. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  3220. node.left = this.typeCastToParameter(node.left);
  3221. }
  3222. super.toAssignable(node, isLHS);
  3223. }
  3224. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  3225. for (let i = 0; i < exprList.length; i++) {
  3226. const expr = exprList[i];
  3227. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  3228. exprList[i] = this.typeCastToParameter(expr);
  3229. }
  3230. }
  3231. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  3232. }
  3233. toReferencedList(exprList, isParenthesizedExpr) {
  3234. for (let i = 0; i < exprList.length; i++) {
  3235. var _expr$extra;
  3236. const expr = exprList[i];
  3237. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  3238. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  3239. }
  3240. }
  3241. return exprList;
  3242. }
  3243. parseArrayLike(close, isTuple, refExpressionErrors) {
  3244. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  3245. if (refExpressionErrors != null && !this.state.maybeInArrowParameters) {
  3246. this.toReferencedList(node.elements);
  3247. }
  3248. return node;
  3249. }
  3250. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  3251. return type === "TypeCastExpression" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  3252. }
  3253. parseClassProperty(node) {
  3254. if (this.match(14)) {
  3255. node.typeAnnotation = this.flowParseTypeAnnotation();
  3256. }
  3257. return super.parseClassProperty(node);
  3258. }
  3259. parseClassPrivateProperty(node) {
  3260. if (this.match(14)) {
  3261. node.typeAnnotation = this.flowParseTypeAnnotation();
  3262. }
  3263. return super.parseClassPrivateProperty(node);
  3264. }
  3265. isClassMethod() {
  3266. return this.match(47) || super.isClassMethod();
  3267. }
  3268. isClassProperty() {
  3269. return this.match(14) || super.isClassProperty();
  3270. }
  3271. isNonstaticConstructor(method) {
  3272. return !this.match(14) && super.isNonstaticConstructor(method);
  3273. }
  3274. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  3275. if (method.variance) {
  3276. this.unexpected(method.variance.loc.start);
  3277. }
  3278. delete method.variance;
  3279. if (this.match(47)) {
  3280. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3281. }
  3282. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  3283. if (method.params && isConstructor) {
  3284. const params = method.params;
  3285. if (params.length > 0 && this.isThisParam(params[0])) {
  3286. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3287. }
  3288. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  3289. const params = method.value.params;
  3290. if (params.length > 0 && this.isThisParam(params[0])) {
  3291. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3292. }
  3293. }
  3294. }
  3295. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  3296. if (method.variance) {
  3297. this.unexpected(method.variance.loc.start);
  3298. }
  3299. delete method.variance;
  3300. if (this.match(47)) {
  3301. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3302. }
  3303. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  3304. }
  3305. parseClassSuper(node) {
  3306. super.parseClassSuper(node);
  3307. if (node.superClass && (this.match(47) || this.match(51))) {
  3308. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  3309. }
  3310. if (this.isContextual(113)) {
  3311. this.next();
  3312. const implemented = node.implements = [];
  3313. do {
  3314. const node = this.startNode();
  3315. node.id = this.flowParseRestrictedIdentifier(true);
  3316. if (this.match(47)) {
  3317. node.typeParameters = this.flowParseTypeParameterInstantiation();
  3318. } else {
  3319. node.typeParameters = null;
  3320. }
  3321. implemented.push(this.finishNode(node, "ClassImplements"));
  3322. } while (this.eat(12));
  3323. }
  3324. }
  3325. checkGetterSetterParams(method) {
  3326. super.checkGetterSetterParams(method);
  3327. const params = this.getObjectOrClassMethodParams(method);
  3328. if (params.length > 0) {
  3329. const param = params[0];
  3330. if (this.isThisParam(param) && method.kind === "get") {
  3331. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  3332. } else if (this.isThisParam(param)) {
  3333. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  3334. }
  3335. }
  3336. }
  3337. parsePropertyNamePrefixOperator(node) {
  3338. node.variance = this.flowParseVariance();
  3339. }
  3340. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  3341. if (prop.variance) {
  3342. this.unexpected(prop.variance.loc.start);
  3343. }
  3344. delete prop.variance;
  3345. let typeParameters;
  3346. if (this.match(47) && !isAccessor) {
  3347. typeParameters = this.flowParseTypeParameterDeclaration();
  3348. if (!this.match(10)) this.unexpected();
  3349. }
  3350. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  3351. if (typeParameters) {
  3352. (result.value || result).typeParameters = typeParameters;
  3353. }
  3354. return result;
  3355. }
  3356. parseFunctionParamType(param) {
  3357. if (this.eat(17)) {
  3358. if (param.type !== "Identifier") {
  3359. this.raise(FlowErrors.PatternIsOptional, param);
  3360. }
  3361. if (this.isThisParam(param)) {
  3362. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  3363. }
  3364. param.optional = true;
  3365. }
  3366. if (this.match(14)) {
  3367. param.typeAnnotation = this.flowParseTypeAnnotation();
  3368. } else if (this.isThisParam(param)) {
  3369. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  3370. }
  3371. if (this.match(29) && this.isThisParam(param)) {
  3372. this.raise(FlowErrors.ThisParamNoDefault, param);
  3373. }
  3374. this.resetEndLocation(param);
  3375. return param;
  3376. }
  3377. parseMaybeDefault(startLoc, left) {
  3378. const node = super.parseMaybeDefault(startLoc, left);
  3379. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  3380. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  3381. }
  3382. return node;
  3383. }
  3384. checkImportReflection(node) {
  3385. super.checkImportReflection(node);
  3386. if (node.module && node.importKind !== "value") {
  3387. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  3388. }
  3389. }
  3390. parseImportSpecifierLocal(node, specifier, type) {
  3391. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  3392. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  3393. }
  3394. isPotentialImportPhase(isExport) {
  3395. if (super.isPotentialImportPhase(isExport)) return true;
  3396. if (this.isContextual(130)) {
  3397. if (!isExport) return true;
  3398. const ch = this.lookaheadCharCode();
  3399. return ch === 123 || ch === 42;
  3400. }
  3401. return !isExport && this.isContextual(87);
  3402. }
  3403. applyImportPhase(node, isExport, phase, loc) {
  3404. super.applyImportPhase(node, isExport, phase, loc);
  3405. if (isExport) {
  3406. if (!phase && this.match(65)) {
  3407. return;
  3408. }
  3409. node.exportKind = phase === "type" ? phase : "value";
  3410. } else {
  3411. if (phase === "type" && this.match(55)) this.unexpected();
  3412. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  3413. }
  3414. }
  3415. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  3416. const firstIdent = specifier.imported;
  3417. let specifierTypeKind = null;
  3418. if (firstIdent.type === "Identifier") {
  3419. if (firstIdent.name === "type") {
  3420. specifierTypeKind = "type";
  3421. } else if (firstIdent.name === "typeof") {
  3422. specifierTypeKind = "typeof";
  3423. }
  3424. }
  3425. let isBinding = false;
  3426. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  3427. const as_ident = this.parseIdentifier(true);
  3428. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  3429. specifier.imported = as_ident;
  3430. specifier.importKind = specifierTypeKind;
  3431. specifier.local = this.cloneIdentifier(as_ident);
  3432. } else {
  3433. specifier.imported = firstIdent;
  3434. specifier.importKind = null;
  3435. specifier.local = this.parseIdentifier();
  3436. }
  3437. } else {
  3438. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  3439. specifier.imported = this.parseIdentifier(true);
  3440. specifier.importKind = specifierTypeKind;
  3441. } else {
  3442. if (importedIsString) {
  3443. throw this.raise(Errors.ImportBindingIsString, specifier, {
  3444. importName: firstIdent.value
  3445. });
  3446. }
  3447. specifier.imported = firstIdent;
  3448. specifier.importKind = null;
  3449. }
  3450. if (this.eatContextual(93)) {
  3451. specifier.local = this.parseIdentifier();
  3452. } else {
  3453. isBinding = true;
  3454. specifier.local = this.cloneIdentifier(specifier.imported);
  3455. }
  3456. }
  3457. const specifierIsTypeImport = hasTypeImportKind(specifier);
  3458. if (isInTypeOnlyImport && specifierIsTypeImport) {
  3459. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  3460. }
  3461. if (isInTypeOnlyImport || specifierIsTypeImport) {
  3462. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  3463. }
  3464. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  3465. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  3466. }
  3467. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  3468. }
  3469. parseBindingAtom() {
  3470. switch (this.state.type) {
  3471. case 78:
  3472. return this.parseIdentifier(true);
  3473. default:
  3474. return super.parseBindingAtom();
  3475. }
  3476. }
  3477. parseFunctionParams(node, isConstructor) {
  3478. const kind = node.kind;
  3479. if (kind !== "get" && kind !== "set" && this.match(47)) {
  3480. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3481. }
  3482. super.parseFunctionParams(node, isConstructor);
  3483. }
  3484. parseVarId(decl, kind) {
  3485. super.parseVarId(decl, kind);
  3486. if (this.match(14)) {
  3487. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  3488. this.resetEndLocation(decl.id);
  3489. }
  3490. }
  3491. parseAsyncArrowFromCallExpression(node, call) {
  3492. if (this.match(14)) {
  3493. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3494. this.state.noAnonFunctionType = true;
  3495. node.returnType = this.flowParseTypeAnnotation();
  3496. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3497. }
  3498. return super.parseAsyncArrowFromCallExpression(node, call);
  3499. }
  3500. shouldParseAsyncArrow() {
  3501. return this.match(14) || super.shouldParseAsyncArrow();
  3502. }
  3503. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  3504. var _jsx;
  3505. let state = null;
  3506. let jsx;
  3507. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  3508. state = this.state.clone();
  3509. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  3510. if (!jsx.error) return jsx.node;
  3511. const {
  3512. context
  3513. } = this.state;
  3514. const currentContext = context[context.length - 1];
  3515. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  3516. context.pop();
  3517. }
  3518. }
  3519. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  3520. var _jsx2, _jsx3;
  3521. state = state || this.state.clone();
  3522. let typeParameters;
  3523. const arrow = this.tryParse(abort => {
  3524. var _arrowExpression$extr;
  3525. typeParameters = this.flowParseTypeParameterDeclaration();
  3526. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  3527. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3528. this.resetStartLocationFromNode(result, typeParameters);
  3529. return result;
  3530. });
  3531. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  3532. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  3533. if (expr.type !== "ArrowFunctionExpression") abort();
  3534. expr.typeParameters = typeParameters;
  3535. this.resetStartLocationFromNode(expr, typeParameters);
  3536. return arrowExpression;
  3537. }, state);
  3538. let arrowExpression = null;
  3539. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  3540. if (!arrow.error && !arrow.aborted) {
  3541. if (arrow.node.async) {
  3542. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  3543. }
  3544. return arrow.node;
  3545. }
  3546. arrowExpression = arrow.node;
  3547. }
  3548. if ((_jsx2 = jsx) != null && _jsx2.node) {
  3549. this.state = jsx.failState;
  3550. return jsx.node;
  3551. }
  3552. if (arrowExpression) {
  3553. this.state = arrow.failState;
  3554. return arrowExpression;
  3555. }
  3556. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  3557. if (arrow.thrown) throw arrow.error;
  3558. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  3559. }
  3560. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3561. }
  3562. parseArrow(node) {
  3563. if (this.match(14)) {
  3564. const result = this.tryParse(() => {
  3565. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3566. this.state.noAnonFunctionType = true;
  3567. const typeNode = this.startNode();
  3568. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  3569. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3570. if (this.canInsertSemicolon()) this.unexpected();
  3571. if (!this.match(19)) this.unexpected();
  3572. return typeNode;
  3573. });
  3574. if (result.thrown) return null;
  3575. if (result.error) this.state = result.failState;
  3576. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  3577. }
  3578. return super.parseArrow(node);
  3579. }
  3580. shouldParseArrow(params) {
  3581. return this.match(14) || super.shouldParseArrow(params);
  3582. }
  3583. setArrowFunctionParameters(node, params) {
  3584. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3585. node.params = params;
  3586. } else {
  3587. super.setArrowFunctionParameters(node, params);
  3588. }
  3589. }
  3590. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  3591. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3592. return;
  3593. }
  3594. for (let i = 0; i < node.params.length; i++) {
  3595. if (this.isThisParam(node.params[i]) && i > 0) {
  3596. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  3597. }
  3598. }
  3599. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  3600. }
  3601. parseParenAndDistinguishExpression(canBeArrow) {
  3602. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  3603. }
  3604. parseSubscripts(base, startLoc, noCalls) {
  3605. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  3606. this.next();
  3607. const node = this.startNodeAt(startLoc);
  3608. node.callee = base;
  3609. node.arguments = super.parseCallExpressionArguments();
  3610. base = this.finishNode(node, "CallExpression");
  3611. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  3612. const state = this.state.clone();
  3613. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  3614. if (!arrow.error && !arrow.aborted) return arrow.node;
  3615. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  3616. if (result.node && !result.error) return result.node;
  3617. if (arrow.node) {
  3618. this.state = arrow.failState;
  3619. return arrow.node;
  3620. }
  3621. if (result.node) {
  3622. this.state = result.failState;
  3623. return result.node;
  3624. }
  3625. throw arrow.error || result.error;
  3626. }
  3627. return super.parseSubscripts(base, startLoc, noCalls);
  3628. }
  3629. parseSubscript(base, startLoc, noCalls, subscriptState) {
  3630. if (this.match(18) && this.isLookaheadToken_lt()) {
  3631. subscriptState.optionalChainMember = true;
  3632. if (noCalls) {
  3633. subscriptState.stop = true;
  3634. return base;
  3635. }
  3636. this.next();
  3637. const node = this.startNodeAt(startLoc);
  3638. node.callee = base;
  3639. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  3640. this.expect(10);
  3641. node.arguments = this.parseCallExpressionArguments();
  3642. node.optional = true;
  3643. return this.finishCallExpression(node, true);
  3644. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  3645. const node = this.startNodeAt(startLoc);
  3646. node.callee = base;
  3647. const result = this.tryParse(() => {
  3648. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  3649. this.expect(10);
  3650. node.arguments = super.parseCallExpressionArguments();
  3651. if (subscriptState.optionalChainMember) {
  3652. node.optional = false;
  3653. }
  3654. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  3655. });
  3656. if (result.node) {
  3657. if (result.error) this.state = result.failState;
  3658. return result.node;
  3659. }
  3660. }
  3661. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  3662. }
  3663. parseNewCallee(node) {
  3664. super.parseNewCallee(node);
  3665. let targs = null;
  3666. if (this.shouldParseTypes() && this.match(47)) {
  3667. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  3668. }
  3669. node.typeArguments = targs;
  3670. }
  3671. parseAsyncArrowWithTypeParameters(startLoc) {
  3672. const node = this.startNodeAt(startLoc);
  3673. this.parseFunctionParams(node, false);
  3674. if (!this.parseArrow(node)) return;
  3675. return super.parseArrowExpression(node, undefined, true);
  3676. }
  3677. readToken_mult_modulo(code) {
  3678. const next = this.input.charCodeAt(this.state.pos + 1);
  3679. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  3680. this.state.hasFlowComment = false;
  3681. this.state.pos += 2;
  3682. this.nextToken();
  3683. return;
  3684. }
  3685. super.readToken_mult_modulo(code);
  3686. }
  3687. readToken_pipe_amp(code) {
  3688. const next = this.input.charCodeAt(this.state.pos + 1);
  3689. if (code === 124 && next === 125) {
  3690. this.finishOp(9, 2);
  3691. return;
  3692. }
  3693. super.readToken_pipe_amp(code);
  3694. }
  3695. parseTopLevel(file, program) {
  3696. const fileNode = super.parseTopLevel(file, program);
  3697. if (this.state.hasFlowComment) {
  3698. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  3699. }
  3700. return fileNode;
  3701. }
  3702. skipBlockComment() {
  3703. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  3704. if (this.state.hasFlowComment) {
  3705. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  3706. }
  3707. this.hasFlowCommentCompletion();
  3708. const commentSkip = this.skipFlowComment();
  3709. if (commentSkip) {
  3710. this.state.pos += commentSkip;
  3711. this.state.hasFlowComment = true;
  3712. }
  3713. return;
  3714. }
  3715. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  3716. }
  3717. skipFlowComment() {
  3718. const {
  3719. pos
  3720. } = this.state;
  3721. let shiftToFirstNonWhiteSpace = 2;
  3722. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  3723. shiftToFirstNonWhiteSpace++;
  3724. }
  3725. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  3726. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  3727. if (ch2 === 58 && ch3 === 58) {
  3728. return shiftToFirstNonWhiteSpace + 2;
  3729. }
  3730. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  3731. return shiftToFirstNonWhiteSpace + 12;
  3732. }
  3733. if (ch2 === 58 && ch3 !== 58) {
  3734. return shiftToFirstNonWhiteSpace;
  3735. }
  3736. return false;
  3737. }
  3738. hasFlowCommentCompletion() {
  3739. const end = this.input.indexOf("*/", this.state.pos);
  3740. if (end === -1) {
  3741. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  3742. }
  3743. }
  3744. flowEnumErrorBooleanMemberNotInitialized(loc, {
  3745. enumName,
  3746. memberName
  3747. }) {
  3748. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  3749. memberName,
  3750. enumName
  3751. });
  3752. }
  3753. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  3754. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  3755. }
  3756. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  3757. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  3758. }
  3759. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  3760. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  3761. }
  3762. flowEnumMemberInit() {
  3763. const startLoc = this.state.startLoc;
  3764. const endOfInit = () => this.match(12) || this.match(8);
  3765. switch (this.state.type) {
  3766. case 135:
  3767. {
  3768. const literal = this.parseNumericLiteral(this.state.value);
  3769. if (endOfInit()) {
  3770. return {
  3771. type: "number",
  3772. loc: literal.loc.start,
  3773. value: literal
  3774. };
  3775. }
  3776. return {
  3777. type: "invalid",
  3778. loc: startLoc
  3779. };
  3780. }
  3781. case 134:
  3782. {
  3783. const literal = this.parseStringLiteral(this.state.value);
  3784. if (endOfInit()) {
  3785. return {
  3786. type: "string",
  3787. loc: literal.loc.start,
  3788. value: literal
  3789. };
  3790. }
  3791. return {
  3792. type: "invalid",
  3793. loc: startLoc
  3794. };
  3795. }
  3796. case 85:
  3797. case 86:
  3798. {
  3799. const literal = this.parseBooleanLiteral(this.match(85));
  3800. if (endOfInit()) {
  3801. return {
  3802. type: "boolean",
  3803. loc: literal.loc.start,
  3804. value: literal
  3805. };
  3806. }
  3807. return {
  3808. type: "invalid",
  3809. loc: startLoc
  3810. };
  3811. }
  3812. default:
  3813. return {
  3814. type: "invalid",
  3815. loc: startLoc
  3816. };
  3817. }
  3818. }
  3819. flowEnumMemberRaw() {
  3820. const loc = this.state.startLoc;
  3821. const id = this.parseIdentifier(true);
  3822. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  3823. type: "none",
  3824. loc
  3825. };
  3826. return {
  3827. id,
  3828. init
  3829. };
  3830. }
  3831. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  3832. const {
  3833. explicitType
  3834. } = context;
  3835. if (explicitType === null) {
  3836. return;
  3837. }
  3838. if (explicitType !== expectedType) {
  3839. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  3840. }
  3841. }
  3842. flowEnumMembers({
  3843. enumName,
  3844. explicitType
  3845. }) {
  3846. const seenNames = new Set();
  3847. const members = {
  3848. booleanMembers: [],
  3849. numberMembers: [],
  3850. stringMembers: [],
  3851. defaultedMembers: []
  3852. };
  3853. let hasUnknownMembers = false;
  3854. while (!this.match(8)) {
  3855. if (this.eat(21)) {
  3856. hasUnknownMembers = true;
  3857. break;
  3858. }
  3859. const memberNode = this.startNode();
  3860. const {
  3861. id,
  3862. init
  3863. } = this.flowEnumMemberRaw();
  3864. const memberName = id.name;
  3865. if (memberName === "") {
  3866. continue;
  3867. }
  3868. if (/^[a-z]/.test(memberName)) {
  3869. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  3870. memberName,
  3871. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  3872. enumName
  3873. });
  3874. }
  3875. if (seenNames.has(memberName)) {
  3876. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  3877. memberName,
  3878. enumName
  3879. });
  3880. }
  3881. seenNames.add(memberName);
  3882. const context = {
  3883. enumName,
  3884. explicitType,
  3885. memberName
  3886. };
  3887. memberNode.id = id;
  3888. switch (init.type) {
  3889. case "boolean":
  3890. {
  3891. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  3892. memberNode.init = init.value;
  3893. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  3894. break;
  3895. }
  3896. case "number":
  3897. {
  3898. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  3899. memberNode.init = init.value;
  3900. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  3901. break;
  3902. }
  3903. case "string":
  3904. {
  3905. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  3906. memberNode.init = init.value;
  3907. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  3908. break;
  3909. }
  3910. case "invalid":
  3911. {
  3912. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  3913. }
  3914. case "none":
  3915. {
  3916. switch (explicitType) {
  3917. case "boolean":
  3918. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  3919. break;
  3920. case "number":
  3921. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  3922. break;
  3923. default:
  3924. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  3925. }
  3926. }
  3927. }
  3928. if (!this.match(8)) {
  3929. this.expect(12);
  3930. }
  3931. }
  3932. return {
  3933. members,
  3934. hasUnknownMembers
  3935. };
  3936. }
  3937. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  3938. enumName
  3939. }) {
  3940. if (initializedMembers.length === 0) {
  3941. return defaultedMembers;
  3942. } else if (defaultedMembers.length === 0) {
  3943. return initializedMembers;
  3944. } else if (defaultedMembers.length > initializedMembers.length) {
  3945. for (const member of initializedMembers) {
  3946. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3947. enumName
  3948. });
  3949. }
  3950. return defaultedMembers;
  3951. } else {
  3952. for (const member of defaultedMembers) {
  3953. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3954. enumName
  3955. });
  3956. }
  3957. return initializedMembers;
  3958. }
  3959. }
  3960. flowEnumParseExplicitType({
  3961. enumName
  3962. }) {
  3963. if (!this.eatContextual(102)) return null;
  3964. if (!tokenIsIdentifier(this.state.type)) {
  3965. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  3966. enumName
  3967. });
  3968. }
  3969. const {
  3970. value
  3971. } = this.state;
  3972. this.next();
  3973. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  3974. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  3975. enumName,
  3976. invalidEnumType: value
  3977. });
  3978. }
  3979. return value;
  3980. }
  3981. flowEnumBody(node, id) {
  3982. const enumName = id.name;
  3983. const nameLoc = id.loc.start;
  3984. const explicitType = this.flowEnumParseExplicitType({
  3985. enumName
  3986. });
  3987. this.expect(5);
  3988. const {
  3989. members,
  3990. hasUnknownMembers
  3991. } = this.flowEnumMembers({
  3992. enumName,
  3993. explicitType
  3994. });
  3995. node.hasUnknownMembers = hasUnknownMembers;
  3996. switch (explicitType) {
  3997. case "boolean":
  3998. node.explicitType = true;
  3999. node.members = members.booleanMembers;
  4000. this.expect(8);
  4001. return this.finishNode(node, "EnumBooleanBody");
  4002. case "number":
  4003. node.explicitType = true;
  4004. node.members = members.numberMembers;
  4005. this.expect(8);
  4006. return this.finishNode(node, "EnumNumberBody");
  4007. case "string":
  4008. node.explicitType = true;
  4009. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4010. enumName
  4011. });
  4012. this.expect(8);
  4013. return this.finishNode(node, "EnumStringBody");
  4014. case "symbol":
  4015. node.members = members.defaultedMembers;
  4016. this.expect(8);
  4017. return this.finishNode(node, "EnumSymbolBody");
  4018. default:
  4019. {
  4020. const empty = () => {
  4021. node.members = [];
  4022. this.expect(8);
  4023. return this.finishNode(node, "EnumStringBody");
  4024. };
  4025. node.explicitType = false;
  4026. const boolsLen = members.booleanMembers.length;
  4027. const numsLen = members.numberMembers.length;
  4028. const strsLen = members.stringMembers.length;
  4029. const defaultedLen = members.defaultedMembers.length;
  4030. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  4031. return empty();
  4032. } else if (!boolsLen && !numsLen) {
  4033. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4034. enumName
  4035. });
  4036. this.expect(8);
  4037. return this.finishNode(node, "EnumStringBody");
  4038. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  4039. for (const member of members.defaultedMembers) {
  4040. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  4041. enumName,
  4042. memberName: member.id.name
  4043. });
  4044. }
  4045. node.members = members.booleanMembers;
  4046. this.expect(8);
  4047. return this.finishNode(node, "EnumBooleanBody");
  4048. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  4049. for (const member of members.defaultedMembers) {
  4050. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  4051. enumName,
  4052. memberName: member.id.name
  4053. });
  4054. }
  4055. node.members = members.numberMembers;
  4056. this.expect(8);
  4057. return this.finishNode(node, "EnumNumberBody");
  4058. } else {
  4059. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  4060. enumName
  4061. });
  4062. return empty();
  4063. }
  4064. }
  4065. }
  4066. }
  4067. flowParseEnumDeclaration(node) {
  4068. const id = this.parseIdentifier();
  4069. node.id = id;
  4070. node.body = this.flowEnumBody(this.startNode(), id);
  4071. return this.finishNode(node, "EnumDeclaration");
  4072. }
  4073. jsxParseOpeningElementAfterName(node) {
  4074. if (this.shouldParseTypes()) {
  4075. if (this.match(47) || this.match(51)) {
  4076. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  4077. }
  4078. }
  4079. return super.jsxParseOpeningElementAfterName(node);
  4080. }
  4081. isLookaheadToken_lt() {
  4082. const next = this.nextTokenStart();
  4083. if (this.input.charCodeAt(next) === 60) {
  4084. const afterNext = this.input.charCodeAt(next + 1);
  4085. return afterNext !== 60 && afterNext !== 61;
  4086. }
  4087. return false;
  4088. }
  4089. reScan_lt_gt() {
  4090. const {
  4091. type
  4092. } = this.state;
  4093. if (type === 47) {
  4094. this.state.pos -= 1;
  4095. this.readToken_lt();
  4096. } else if (type === 48) {
  4097. this.state.pos -= 1;
  4098. this.readToken_gt();
  4099. }
  4100. }
  4101. reScan_lt() {
  4102. const {
  4103. type
  4104. } = this.state;
  4105. if (type === 51) {
  4106. this.state.pos -= 2;
  4107. this.finishOp(47, 1);
  4108. return 47;
  4109. }
  4110. return type;
  4111. }
  4112. maybeUnwrapTypeCastExpression(node) {
  4113. return node.type === "TypeCastExpression" ? node.expression : node;
  4114. }
  4115. };
  4116. const entities = {
  4117. __proto__: null,
  4118. quot: "\u0022",
  4119. amp: "&",
  4120. apos: "\u0027",
  4121. lt: "<",
  4122. gt: ">",
  4123. nbsp: "\u00A0",
  4124. iexcl: "\u00A1",
  4125. cent: "\u00A2",
  4126. pound: "\u00A3",
  4127. curren: "\u00A4",
  4128. yen: "\u00A5",
  4129. brvbar: "\u00A6",
  4130. sect: "\u00A7",
  4131. uml: "\u00A8",
  4132. copy: "\u00A9",
  4133. ordf: "\u00AA",
  4134. laquo: "\u00AB",
  4135. not: "\u00AC",
  4136. shy: "\u00AD",
  4137. reg: "\u00AE",
  4138. macr: "\u00AF",
  4139. deg: "\u00B0",
  4140. plusmn: "\u00B1",
  4141. sup2: "\u00B2",
  4142. sup3: "\u00B3",
  4143. acute: "\u00B4",
  4144. micro: "\u00B5",
  4145. para: "\u00B6",
  4146. middot: "\u00B7",
  4147. cedil: "\u00B8",
  4148. sup1: "\u00B9",
  4149. ordm: "\u00BA",
  4150. raquo: "\u00BB",
  4151. frac14: "\u00BC",
  4152. frac12: "\u00BD",
  4153. frac34: "\u00BE",
  4154. iquest: "\u00BF",
  4155. Agrave: "\u00C0",
  4156. Aacute: "\u00C1",
  4157. Acirc: "\u00C2",
  4158. Atilde: "\u00C3",
  4159. Auml: "\u00C4",
  4160. Aring: "\u00C5",
  4161. AElig: "\u00C6",
  4162. Ccedil: "\u00C7",
  4163. Egrave: "\u00C8",
  4164. Eacute: "\u00C9",
  4165. Ecirc: "\u00CA",
  4166. Euml: "\u00CB",
  4167. Igrave: "\u00CC",
  4168. Iacute: "\u00CD",
  4169. Icirc: "\u00CE",
  4170. Iuml: "\u00CF",
  4171. ETH: "\u00D0",
  4172. Ntilde: "\u00D1",
  4173. Ograve: "\u00D2",
  4174. Oacute: "\u00D3",
  4175. Ocirc: "\u00D4",
  4176. Otilde: "\u00D5",
  4177. Ouml: "\u00D6",
  4178. times: "\u00D7",
  4179. Oslash: "\u00D8",
  4180. Ugrave: "\u00D9",
  4181. Uacute: "\u00DA",
  4182. Ucirc: "\u00DB",
  4183. Uuml: "\u00DC",
  4184. Yacute: "\u00DD",
  4185. THORN: "\u00DE",
  4186. szlig: "\u00DF",
  4187. agrave: "\u00E0",
  4188. aacute: "\u00E1",
  4189. acirc: "\u00E2",
  4190. atilde: "\u00E3",
  4191. auml: "\u00E4",
  4192. aring: "\u00E5",
  4193. aelig: "\u00E6",
  4194. ccedil: "\u00E7",
  4195. egrave: "\u00E8",
  4196. eacute: "\u00E9",
  4197. ecirc: "\u00EA",
  4198. euml: "\u00EB",
  4199. igrave: "\u00EC",
  4200. iacute: "\u00ED",
  4201. icirc: "\u00EE",
  4202. iuml: "\u00EF",
  4203. eth: "\u00F0",
  4204. ntilde: "\u00F1",
  4205. ograve: "\u00F2",
  4206. oacute: "\u00F3",
  4207. ocirc: "\u00F4",
  4208. otilde: "\u00F5",
  4209. ouml: "\u00F6",
  4210. divide: "\u00F7",
  4211. oslash: "\u00F8",
  4212. ugrave: "\u00F9",
  4213. uacute: "\u00FA",
  4214. ucirc: "\u00FB",
  4215. uuml: "\u00FC",
  4216. yacute: "\u00FD",
  4217. thorn: "\u00FE",
  4218. yuml: "\u00FF",
  4219. OElig: "\u0152",
  4220. oelig: "\u0153",
  4221. Scaron: "\u0160",
  4222. scaron: "\u0161",
  4223. Yuml: "\u0178",
  4224. fnof: "\u0192",
  4225. circ: "\u02C6",
  4226. tilde: "\u02DC",
  4227. Alpha: "\u0391",
  4228. Beta: "\u0392",
  4229. Gamma: "\u0393",
  4230. Delta: "\u0394",
  4231. Epsilon: "\u0395",
  4232. Zeta: "\u0396",
  4233. Eta: "\u0397",
  4234. Theta: "\u0398",
  4235. Iota: "\u0399",
  4236. Kappa: "\u039A",
  4237. Lambda: "\u039B",
  4238. Mu: "\u039C",
  4239. Nu: "\u039D",
  4240. Xi: "\u039E",
  4241. Omicron: "\u039F",
  4242. Pi: "\u03A0",
  4243. Rho: "\u03A1",
  4244. Sigma: "\u03A3",
  4245. Tau: "\u03A4",
  4246. Upsilon: "\u03A5",
  4247. Phi: "\u03A6",
  4248. Chi: "\u03A7",
  4249. Psi: "\u03A8",
  4250. Omega: "\u03A9",
  4251. alpha: "\u03B1",
  4252. beta: "\u03B2",
  4253. gamma: "\u03B3",
  4254. delta: "\u03B4",
  4255. epsilon: "\u03B5",
  4256. zeta: "\u03B6",
  4257. eta: "\u03B7",
  4258. theta: "\u03B8",
  4259. iota: "\u03B9",
  4260. kappa: "\u03BA",
  4261. lambda: "\u03BB",
  4262. mu: "\u03BC",
  4263. nu: "\u03BD",
  4264. xi: "\u03BE",
  4265. omicron: "\u03BF",
  4266. pi: "\u03C0",
  4267. rho: "\u03C1",
  4268. sigmaf: "\u03C2",
  4269. sigma: "\u03C3",
  4270. tau: "\u03C4",
  4271. upsilon: "\u03C5",
  4272. phi: "\u03C6",
  4273. chi: "\u03C7",
  4274. psi: "\u03C8",
  4275. omega: "\u03C9",
  4276. thetasym: "\u03D1",
  4277. upsih: "\u03D2",
  4278. piv: "\u03D6",
  4279. ensp: "\u2002",
  4280. emsp: "\u2003",
  4281. thinsp: "\u2009",
  4282. zwnj: "\u200C",
  4283. zwj: "\u200D",
  4284. lrm: "\u200E",
  4285. rlm: "\u200F",
  4286. ndash: "\u2013",
  4287. mdash: "\u2014",
  4288. lsquo: "\u2018",
  4289. rsquo: "\u2019",
  4290. sbquo: "\u201A",
  4291. ldquo: "\u201C",
  4292. rdquo: "\u201D",
  4293. bdquo: "\u201E",
  4294. dagger: "\u2020",
  4295. Dagger: "\u2021",
  4296. bull: "\u2022",
  4297. hellip: "\u2026",
  4298. permil: "\u2030",
  4299. prime: "\u2032",
  4300. Prime: "\u2033",
  4301. lsaquo: "\u2039",
  4302. rsaquo: "\u203A",
  4303. oline: "\u203E",
  4304. frasl: "\u2044",
  4305. euro: "\u20AC",
  4306. image: "\u2111",
  4307. weierp: "\u2118",
  4308. real: "\u211C",
  4309. trade: "\u2122",
  4310. alefsym: "\u2135",
  4311. larr: "\u2190",
  4312. uarr: "\u2191",
  4313. rarr: "\u2192",
  4314. darr: "\u2193",
  4315. harr: "\u2194",
  4316. crarr: "\u21B5",
  4317. lArr: "\u21D0",
  4318. uArr: "\u21D1",
  4319. rArr: "\u21D2",
  4320. dArr: "\u21D3",
  4321. hArr: "\u21D4",
  4322. forall: "\u2200",
  4323. part: "\u2202",
  4324. exist: "\u2203",
  4325. empty: "\u2205",
  4326. nabla: "\u2207",
  4327. isin: "\u2208",
  4328. notin: "\u2209",
  4329. ni: "\u220B",
  4330. prod: "\u220F",
  4331. sum: "\u2211",
  4332. minus: "\u2212",
  4333. lowast: "\u2217",
  4334. radic: "\u221A",
  4335. prop: "\u221D",
  4336. infin: "\u221E",
  4337. ang: "\u2220",
  4338. and: "\u2227",
  4339. or: "\u2228",
  4340. cap: "\u2229",
  4341. cup: "\u222A",
  4342. int: "\u222B",
  4343. there4: "\u2234",
  4344. sim: "\u223C",
  4345. cong: "\u2245",
  4346. asymp: "\u2248",
  4347. ne: "\u2260",
  4348. equiv: "\u2261",
  4349. le: "\u2264",
  4350. ge: "\u2265",
  4351. sub: "\u2282",
  4352. sup: "\u2283",
  4353. nsub: "\u2284",
  4354. sube: "\u2286",
  4355. supe: "\u2287",
  4356. oplus: "\u2295",
  4357. otimes: "\u2297",
  4358. perp: "\u22A5",
  4359. sdot: "\u22C5",
  4360. lceil: "\u2308",
  4361. rceil: "\u2309",
  4362. lfloor: "\u230A",
  4363. rfloor: "\u230B",
  4364. lang: "\u2329",
  4365. rang: "\u232A",
  4366. loz: "\u25CA",
  4367. spades: "\u2660",
  4368. clubs: "\u2663",
  4369. hearts: "\u2665",
  4370. diams: "\u2666"
  4371. };
  4372. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  4373. const lineBreakG = new RegExp(lineBreak.source, "g");
  4374. function isNewLine(code) {
  4375. switch (code) {
  4376. case 10:
  4377. case 13:
  4378. case 8232:
  4379. case 8233:
  4380. return true;
  4381. default:
  4382. return false;
  4383. }
  4384. }
  4385. function hasNewLine(input, start, end) {
  4386. for (let i = start; i < end; i++) {
  4387. if (isNewLine(input.charCodeAt(i))) {
  4388. return true;
  4389. }
  4390. }
  4391. return false;
  4392. }
  4393. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  4394. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  4395. function isWhitespace(code) {
  4396. switch (code) {
  4397. case 0x0009:
  4398. case 0x000b:
  4399. case 0x000c:
  4400. case 32:
  4401. case 160:
  4402. case 5760:
  4403. case 0x2000:
  4404. case 0x2001:
  4405. case 0x2002:
  4406. case 0x2003:
  4407. case 0x2004:
  4408. case 0x2005:
  4409. case 0x2006:
  4410. case 0x2007:
  4411. case 0x2008:
  4412. case 0x2009:
  4413. case 0x200a:
  4414. case 0x202f:
  4415. case 0x205f:
  4416. case 0x3000:
  4417. case 0xfeff:
  4418. return true;
  4419. default:
  4420. return false;
  4421. }
  4422. }
  4423. const JsxErrors = ParseErrorEnum`jsx`({
  4424. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  4425. MissingClosingTagElement: ({
  4426. openingTagName
  4427. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  4428. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  4429. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  4430. UnexpectedToken: ({
  4431. unexpected,
  4432. HTMLEntity
  4433. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  4434. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  4435. UnterminatedJsxContent: "Unterminated JSX contents.",
  4436. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  4437. });
  4438. function isFragment(object) {
  4439. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  4440. }
  4441. function getQualifiedJSXName(object) {
  4442. if (object.type === "JSXIdentifier") {
  4443. return object.name;
  4444. }
  4445. if (object.type === "JSXNamespacedName") {
  4446. return object.namespace.name + ":" + object.name.name;
  4447. }
  4448. if (object.type === "JSXMemberExpression") {
  4449. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  4450. }
  4451. throw new Error("Node had unexpected type: " + object.type);
  4452. }
  4453. var jsx = superClass => class JSXParserMixin extends superClass {
  4454. jsxReadToken() {
  4455. let out = "";
  4456. let chunkStart = this.state.pos;
  4457. for (;;) {
  4458. if (this.state.pos >= this.length) {
  4459. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  4460. }
  4461. const ch = this.input.charCodeAt(this.state.pos);
  4462. switch (ch) {
  4463. case 60:
  4464. case 123:
  4465. if (this.state.pos === this.state.start) {
  4466. if (ch === 60 && this.state.canStartJSXElement) {
  4467. ++this.state.pos;
  4468. this.finishToken(143);
  4469. } else {
  4470. super.getTokenFromCode(ch);
  4471. }
  4472. return;
  4473. }
  4474. out += this.input.slice(chunkStart, this.state.pos);
  4475. this.finishToken(142, out);
  4476. return;
  4477. case 38:
  4478. out += this.input.slice(chunkStart, this.state.pos);
  4479. out += this.jsxReadEntity();
  4480. chunkStart = this.state.pos;
  4481. break;
  4482. case 62:
  4483. case 125:
  4484. default:
  4485. if (isNewLine(ch)) {
  4486. out += this.input.slice(chunkStart, this.state.pos);
  4487. out += this.jsxReadNewLine(true);
  4488. chunkStart = this.state.pos;
  4489. } else {
  4490. ++this.state.pos;
  4491. }
  4492. }
  4493. }
  4494. }
  4495. jsxReadNewLine(normalizeCRLF) {
  4496. const ch = this.input.charCodeAt(this.state.pos);
  4497. let out;
  4498. ++this.state.pos;
  4499. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  4500. ++this.state.pos;
  4501. out = normalizeCRLF ? "\n" : "\r\n";
  4502. } else {
  4503. out = String.fromCharCode(ch);
  4504. }
  4505. ++this.state.curLine;
  4506. this.state.lineStart = this.state.pos;
  4507. return out;
  4508. }
  4509. jsxReadString(quote) {
  4510. let out = "";
  4511. let chunkStart = ++this.state.pos;
  4512. for (;;) {
  4513. if (this.state.pos >= this.length) {
  4514. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  4515. }
  4516. const ch = this.input.charCodeAt(this.state.pos);
  4517. if (ch === quote) break;
  4518. if (ch === 38) {
  4519. out += this.input.slice(chunkStart, this.state.pos);
  4520. out += this.jsxReadEntity();
  4521. chunkStart = this.state.pos;
  4522. } else if (isNewLine(ch)) {
  4523. out += this.input.slice(chunkStart, this.state.pos);
  4524. out += this.jsxReadNewLine(false);
  4525. chunkStart = this.state.pos;
  4526. } else {
  4527. ++this.state.pos;
  4528. }
  4529. }
  4530. out += this.input.slice(chunkStart, this.state.pos++);
  4531. this.finishToken(134, out);
  4532. }
  4533. jsxReadEntity() {
  4534. const startPos = ++this.state.pos;
  4535. if (this.codePointAtPos(this.state.pos) === 35) {
  4536. ++this.state.pos;
  4537. let radix = 10;
  4538. if (this.codePointAtPos(this.state.pos) === 120) {
  4539. radix = 16;
  4540. ++this.state.pos;
  4541. }
  4542. const codePoint = this.readInt(radix, undefined, false, "bail");
  4543. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  4544. ++this.state.pos;
  4545. return String.fromCodePoint(codePoint);
  4546. }
  4547. } else {
  4548. let count = 0;
  4549. let semi = false;
  4550. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  4551. ++this.state.pos;
  4552. }
  4553. if (semi) {
  4554. const desc = this.input.slice(startPos, this.state.pos);
  4555. const entity = entities[desc];
  4556. ++this.state.pos;
  4557. if (entity) {
  4558. return entity;
  4559. }
  4560. }
  4561. }
  4562. this.state.pos = startPos;
  4563. return "&";
  4564. }
  4565. jsxReadWord() {
  4566. let ch;
  4567. const start = this.state.pos;
  4568. do {
  4569. ch = this.input.charCodeAt(++this.state.pos);
  4570. } while (isIdentifierChar(ch) || ch === 45);
  4571. this.finishToken(141, this.input.slice(start, this.state.pos));
  4572. }
  4573. jsxParseIdentifier() {
  4574. const node = this.startNode();
  4575. if (this.match(141)) {
  4576. node.name = this.state.value;
  4577. } else if (tokenIsKeyword(this.state.type)) {
  4578. node.name = tokenLabelName(this.state.type);
  4579. } else {
  4580. this.unexpected();
  4581. }
  4582. this.next();
  4583. return this.finishNode(node, "JSXIdentifier");
  4584. }
  4585. jsxParseNamespacedName() {
  4586. const startLoc = this.state.startLoc;
  4587. const name = this.jsxParseIdentifier();
  4588. if (!this.eat(14)) return name;
  4589. const node = this.startNodeAt(startLoc);
  4590. node.namespace = name;
  4591. node.name = this.jsxParseIdentifier();
  4592. return this.finishNode(node, "JSXNamespacedName");
  4593. }
  4594. jsxParseElementName() {
  4595. const startLoc = this.state.startLoc;
  4596. let node = this.jsxParseNamespacedName();
  4597. if (node.type === "JSXNamespacedName") {
  4598. return node;
  4599. }
  4600. while (this.eat(16)) {
  4601. const newNode = this.startNodeAt(startLoc);
  4602. newNode.object = node;
  4603. newNode.property = this.jsxParseIdentifier();
  4604. node = this.finishNode(newNode, "JSXMemberExpression");
  4605. }
  4606. return node;
  4607. }
  4608. jsxParseAttributeValue() {
  4609. let node;
  4610. switch (this.state.type) {
  4611. case 5:
  4612. node = this.startNode();
  4613. this.setContext(types.brace);
  4614. this.next();
  4615. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  4616. if (node.expression.type === "JSXEmptyExpression") {
  4617. this.raise(JsxErrors.AttributeIsEmpty, node);
  4618. }
  4619. return node;
  4620. case 143:
  4621. case 134:
  4622. return this.parseExprAtom();
  4623. default:
  4624. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  4625. }
  4626. }
  4627. jsxParseEmptyExpression() {
  4628. const node = this.startNodeAt(this.state.lastTokEndLoc);
  4629. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  4630. }
  4631. jsxParseSpreadChild(node) {
  4632. this.next();
  4633. node.expression = this.parseExpression();
  4634. this.setContext(types.j_expr);
  4635. this.state.canStartJSXElement = true;
  4636. this.expect(8);
  4637. return this.finishNode(node, "JSXSpreadChild");
  4638. }
  4639. jsxParseExpressionContainer(node, previousContext) {
  4640. if (this.match(8)) {
  4641. node.expression = this.jsxParseEmptyExpression();
  4642. } else {
  4643. const expression = this.parseExpression();
  4644. node.expression = expression;
  4645. }
  4646. this.setContext(previousContext);
  4647. this.state.canStartJSXElement = true;
  4648. this.expect(8);
  4649. return this.finishNode(node, "JSXExpressionContainer");
  4650. }
  4651. jsxParseAttribute() {
  4652. const node = this.startNode();
  4653. if (this.match(5)) {
  4654. this.setContext(types.brace);
  4655. this.next();
  4656. this.expect(21);
  4657. node.argument = this.parseMaybeAssignAllowIn();
  4658. this.setContext(types.j_oTag);
  4659. this.state.canStartJSXElement = true;
  4660. this.expect(8);
  4661. return this.finishNode(node, "JSXSpreadAttribute");
  4662. }
  4663. node.name = this.jsxParseNamespacedName();
  4664. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  4665. return this.finishNode(node, "JSXAttribute");
  4666. }
  4667. jsxParseOpeningElementAt(startLoc) {
  4668. const node = this.startNodeAt(startLoc);
  4669. if (this.eat(144)) {
  4670. return this.finishNode(node, "JSXOpeningFragment");
  4671. }
  4672. node.name = this.jsxParseElementName();
  4673. return this.jsxParseOpeningElementAfterName(node);
  4674. }
  4675. jsxParseOpeningElementAfterName(node) {
  4676. const attributes = [];
  4677. while (!this.match(56) && !this.match(144)) {
  4678. attributes.push(this.jsxParseAttribute());
  4679. }
  4680. node.attributes = attributes;
  4681. node.selfClosing = this.eat(56);
  4682. this.expect(144);
  4683. return this.finishNode(node, "JSXOpeningElement");
  4684. }
  4685. jsxParseClosingElementAt(startLoc) {
  4686. const node = this.startNodeAt(startLoc);
  4687. if (this.eat(144)) {
  4688. return this.finishNode(node, "JSXClosingFragment");
  4689. }
  4690. node.name = this.jsxParseElementName();
  4691. this.expect(144);
  4692. return this.finishNode(node, "JSXClosingElement");
  4693. }
  4694. jsxParseElementAt(startLoc) {
  4695. const node = this.startNodeAt(startLoc);
  4696. const children = [];
  4697. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  4698. let closingElement = null;
  4699. if (!openingElement.selfClosing) {
  4700. contents: for (;;) {
  4701. switch (this.state.type) {
  4702. case 143:
  4703. startLoc = this.state.startLoc;
  4704. this.next();
  4705. if (this.eat(56)) {
  4706. closingElement = this.jsxParseClosingElementAt(startLoc);
  4707. break contents;
  4708. }
  4709. children.push(this.jsxParseElementAt(startLoc));
  4710. break;
  4711. case 142:
  4712. children.push(this.parseLiteral(this.state.value, "JSXText"));
  4713. break;
  4714. case 5:
  4715. {
  4716. const node = this.startNode();
  4717. this.setContext(types.brace);
  4718. this.next();
  4719. if (this.match(21)) {
  4720. children.push(this.jsxParseSpreadChild(node));
  4721. } else {
  4722. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  4723. }
  4724. break;
  4725. }
  4726. default:
  4727. this.unexpected();
  4728. }
  4729. }
  4730. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  4731. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  4732. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  4733. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4734. openingTagName: getQualifiedJSXName(openingElement.name)
  4735. });
  4736. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  4737. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  4738. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4739. openingTagName: getQualifiedJSXName(openingElement.name)
  4740. });
  4741. }
  4742. }
  4743. }
  4744. if (isFragment(openingElement)) {
  4745. node.openingFragment = openingElement;
  4746. node.closingFragment = closingElement;
  4747. } else {
  4748. node.openingElement = openingElement;
  4749. node.closingElement = closingElement;
  4750. }
  4751. node.children = children;
  4752. if (this.match(47)) {
  4753. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  4754. }
  4755. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  4756. }
  4757. jsxParseElement() {
  4758. const startLoc = this.state.startLoc;
  4759. this.next();
  4760. return this.jsxParseElementAt(startLoc);
  4761. }
  4762. setContext(newContext) {
  4763. const {
  4764. context
  4765. } = this.state;
  4766. context[context.length - 1] = newContext;
  4767. }
  4768. parseExprAtom(refExpressionErrors) {
  4769. if (this.match(143)) {
  4770. return this.jsxParseElement();
  4771. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  4772. this.replaceToken(143);
  4773. return this.jsxParseElement();
  4774. } else {
  4775. return super.parseExprAtom(refExpressionErrors);
  4776. }
  4777. }
  4778. skipSpace() {
  4779. const curContext = this.curContext();
  4780. if (!curContext.preserveSpace) super.skipSpace();
  4781. }
  4782. getTokenFromCode(code) {
  4783. const context = this.curContext();
  4784. if (context === types.j_expr) {
  4785. this.jsxReadToken();
  4786. return;
  4787. }
  4788. if (context === types.j_oTag || context === types.j_cTag) {
  4789. if (isIdentifierStart(code)) {
  4790. this.jsxReadWord();
  4791. return;
  4792. }
  4793. if (code === 62) {
  4794. ++this.state.pos;
  4795. this.finishToken(144);
  4796. return;
  4797. }
  4798. if ((code === 34 || code === 39) && context === types.j_oTag) {
  4799. this.jsxReadString(code);
  4800. return;
  4801. }
  4802. }
  4803. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  4804. ++this.state.pos;
  4805. this.finishToken(143);
  4806. return;
  4807. }
  4808. super.getTokenFromCode(code);
  4809. }
  4810. updateContext(prevType) {
  4811. const {
  4812. context,
  4813. type
  4814. } = this.state;
  4815. if (type === 56 && prevType === 143) {
  4816. context.splice(-2, 2, types.j_cTag);
  4817. this.state.canStartJSXElement = false;
  4818. } else if (type === 143) {
  4819. context.push(types.j_oTag);
  4820. } else if (type === 144) {
  4821. const out = context[context.length - 1];
  4822. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  4823. context.pop();
  4824. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  4825. } else {
  4826. this.setContext(types.j_expr);
  4827. this.state.canStartJSXElement = true;
  4828. }
  4829. } else {
  4830. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  4831. }
  4832. }
  4833. };
  4834. class TypeScriptScope extends Scope {
  4835. constructor(...args) {
  4836. super(...args);
  4837. this.tsNames = new Map();
  4838. }
  4839. }
  4840. class TypeScriptScopeHandler extends ScopeHandler {
  4841. constructor(...args) {
  4842. super(...args);
  4843. this.importsStack = [];
  4844. }
  4845. createScope(flags) {
  4846. this.importsStack.push(new Set());
  4847. return new TypeScriptScope(flags);
  4848. }
  4849. enter(flags) {
  4850. if (flags === 1024) {
  4851. this.importsStack.push(new Set());
  4852. }
  4853. super.enter(flags);
  4854. }
  4855. exit() {
  4856. const flags = super.exit();
  4857. if (flags === 1024) {
  4858. this.importsStack.pop();
  4859. }
  4860. return flags;
  4861. }
  4862. hasImport(name, allowShadow) {
  4863. const len = this.importsStack.length;
  4864. if (this.importsStack[len - 1].has(name)) {
  4865. return true;
  4866. }
  4867. if (!allowShadow && len > 1) {
  4868. for (let i = 0; i < len - 1; i++) {
  4869. if (this.importsStack[i].has(name)) return true;
  4870. }
  4871. }
  4872. return false;
  4873. }
  4874. declareName(name, bindingType, loc) {
  4875. if (bindingType & 4096) {
  4876. if (this.hasImport(name, true)) {
  4877. this.parser.raise(Errors.VarRedeclaration, loc, {
  4878. identifierName: name
  4879. });
  4880. }
  4881. this.importsStack[this.importsStack.length - 1].add(name);
  4882. return;
  4883. }
  4884. const scope = this.currentScope();
  4885. let type = scope.tsNames.get(name) || 0;
  4886. if (bindingType & 1024) {
  4887. this.maybeExportDefined(scope, name);
  4888. scope.tsNames.set(name, type | 16);
  4889. return;
  4890. }
  4891. super.declareName(name, bindingType, loc);
  4892. if (bindingType & 2) {
  4893. if (!(bindingType & 1)) {
  4894. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4895. this.maybeExportDefined(scope, name);
  4896. }
  4897. type = type | 1;
  4898. }
  4899. if (bindingType & 256) {
  4900. type = type | 2;
  4901. }
  4902. if (bindingType & 512) {
  4903. type = type | 4;
  4904. }
  4905. if (bindingType & 128) {
  4906. type = type | 8;
  4907. }
  4908. if (type) scope.tsNames.set(name, type);
  4909. }
  4910. isRedeclaredInScope(scope, name, bindingType) {
  4911. const type = scope.tsNames.get(name);
  4912. if ((type & 2) > 0) {
  4913. if (bindingType & 256) {
  4914. const isConst = !!(bindingType & 512);
  4915. const wasConst = (type & 4) > 0;
  4916. return isConst !== wasConst;
  4917. }
  4918. return true;
  4919. }
  4920. if (bindingType & 128 && (type & 8) > 0) {
  4921. if (scope.names.get(name) & 2) {
  4922. return !!(bindingType & 1);
  4923. } else {
  4924. return false;
  4925. }
  4926. }
  4927. if (bindingType & 2 && (type & 1) > 0) {
  4928. return true;
  4929. }
  4930. return super.isRedeclaredInScope(scope, name, bindingType);
  4931. }
  4932. checkLocalExport(id) {
  4933. const {
  4934. name
  4935. } = id;
  4936. if (this.hasImport(name)) return;
  4937. const len = this.scopeStack.length;
  4938. for (let i = len - 1; i >= 0; i--) {
  4939. const scope = this.scopeStack[i];
  4940. const type = scope.tsNames.get(name);
  4941. if ((type & 1) > 0 || (type & 16) > 0) {
  4942. return;
  4943. }
  4944. }
  4945. super.checkLocalExport(id);
  4946. }
  4947. }
  4948. class ProductionParameterHandler {
  4949. constructor() {
  4950. this.stacks = [];
  4951. }
  4952. enter(flags) {
  4953. this.stacks.push(flags);
  4954. }
  4955. exit() {
  4956. this.stacks.pop();
  4957. }
  4958. currentFlags() {
  4959. return this.stacks[this.stacks.length - 1];
  4960. }
  4961. get hasAwait() {
  4962. return (this.currentFlags() & 2) > 0;
  4963. }
  4964. get hasYield() {
  4965. return (this.currentFlags() & 1) > 0;
  4966. }
  4967. get hasReturn() {
  4968. return (this.currentFlags() & 4) > 0;
  4969. }
  4970. get hasIn() {
  4971. return (this.currentFlags() & 8) > 0;
  4972. }
  4973. }
  4974. function functionFlags(isAsync, isGenerator) {
  4975. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  4976. }
  4977. class BaseParser {
  4978. constructor() {
  4979. this.sawUnambiguousESM = false;
  4980. this.ambiguousScriptDifferentAst = false;
  4981. }
  4982. sourceToOffsetPos(sourcePos) {
  4983. return sourcePos + this.startIndex;
  4984. }
  4985. offsetToSourcePos(offsetPos) {
  4986. return offsetPos - this.startIndex;
  4987. }
  4988. hasPlugin(pluginConfig) {
  4989. if (typeof pluginConfig === "string") {
  4990. return this.plugins.has(pluginConfig);
  4991. } else {
  4992. const [pluginName, pluginOptions] = pluginConfig;
  4993. if (!this.hasPlugin(pluginName)) {
  4994. return false;
  4995. }
  4996. const actualOptions = this.plugins.get(pluginName);
  4997. for (const key of Object.keys(pluginOptions)) {
  4998. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  4999. return false;
  5000. }
  5001. }
  5002. return true;
  5003. }
  5004. }
  5005. getPluginOption(plugin, name) {
  5006. var _this$plugins$get;
  5007. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  5008. }
  5009. }
  5010. function setTrailingComments(node, comments) {
  5011. if (node.trailingComments === undefined) {
  5012. node.trailingComments = comments;
  5013. } else {
  5014. node.trailingComments.unshift(...comments);
  5015. }
  5016. }
  5017. function setLeadingComments(node, comments) {
  5018. if (node.leadingComments === undefined) {
  5019. node.leadingComments = comments;
  5020. } else {
  5021. node.leadingComments.unshift(...comments);
  5022. }
  5023. }
  5024. function setInnerComments(node, comments) {
  5025. if (node.innerComments === undefined) {
  5026. node.innerComments = comments;
  5027. } else {
  5028. node.innerComments.unshift(...comments);
  5029. }
  5030. }
  5031. function adjustInnerComments(node, elements, commentWS) {
  5032. let lastElement = null;
  5033. let i = elements.length;
  5034. while (lastElement === null && i > 0) {
  5035. lastElement = elements[--i];
  5036. }
  5037. if (lastElement === null || lastElement.start > commentWS.start) {
  5038. setInnerComments(node, commentWS.comments);
  5039. } else {
  5040. setTrailingComments(lastElement, commentWS.comments);
  5041. }
  5042. }
  5043. class CommentsParser extends BaseParser {
  5044. addComment(comment) {
  5045. if (this.filename) comment.loc.filename = this.filename;
  5046. const {
  5047. commentsLen
  5048. } = this.state;
  5049. if (this.comments.length !== commentsLen) {
  5050. this.comments.length = commentsLen;
  5051. }
  5052. this.comments.push(comment);
  5053. this.state.commentsLen++;
  5054. }
  5055. processComment(node) {
  5056. const {
  5057. commentStack
  5058. } = this.state;
  5059. const commentStackLength = commentStack.length;
  5060. if (commentStackLength === 0) return;
  5061. let i = commentStackLength - 1;
  5062. const lastCommentWS = commentStack[i];
  5063. if (lastCommentWS.start === node.end) {
  5064. lastCommentWS.leadingNode = node;
  5065. i--;
  5066. }
  5067. const {
  5068. start: nodeStart
  5069. } = node;
  5070. for (; i >= 0; i--) {
  5071. const commentWS = commentStack[i];
  5072. const commentEnd = commentWS.end;
  5073. if (commentEnd > nodeStart) {
  5074. commentWS.containingNode = node;
  5075. this.finalizeComment(commentWS);
  5076. commentStack.splice(i, 1);
  5077. } else {
  5078. if (commentEnd === nodeStart) {
  5079. commentWS.trailingNode = node;
  5080. }
  5081. break;
  5082. }
  5083. }
  5084. }
  5085. finalizeComment(commentWS) {
  5086. var _node$options;
  5087. const {
  5088. comments
  5089. } = commentWS;
  5090. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  5091. if (commentWS.leadingNode !== null) {
  5092. setTrailingComments(commentWS.leadingNode, comments);
  5093. }
  5094. if (commentWS.trailingNode !== null) {
  5095. setLeadingComments(commentWS.trailingNode, comments);
  5096. }
  5097. } else {
  5098. const node = commentWS.containingNode;
  5099. const commentStart = commentWS.start;
  5100. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  5101. switch (node.type) {
  5102. case "ObjectExpression":
  5103. case "ObjectPattern":
  5104. adjustInnerComments(node, node.properties, commentWS);
  5105. break;
  5106. case "CallExpression":
  5107. case "NewExpression":
  5108. case "OptionalCallExpression":
  5109. adjustInnerComments(node, node.arguments, commentWS);
  5110. break;
  5111. case "ImportExpression":
  5112. adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
  5113. break;
  5114. case "FunctionDeclaration":
  5115. case "FunctionExpression":
  5116. case "ArrowFunctionExpression":
  5117. case "ObjectMethod":
  5118. case "ClassMethod":
  5119. case "ClassPrivateMethod":
  5120. case "TSTypeParameterDeclaration":
  5121. adjustInnerComments(node, node.params, commentWS);
  5122. break;
  5123. case "ArrayExpression":
  5124. case "ArrayPattern":
  5125. adjustInnerComments(node, node.elements, commentWS);
  5126. break;
  5127. case "ExportNamedDeclaration":
  5128. case "ImportDeclaration":
  5129. adjustInnerComments(node, node.specifiers, commentWS);
  5130. break;
  5131. case "TSEnumDeclaration":
  5132. adjustInnerComments(node, node.members, commentWS);
  5133. break;
  5134. case "TSEnumBody":
  5135. adjustInnerComments(node, node.members, commentWS);
  5136. break;
  5137. case "TSInterfaceBody":
  5138. adjustInnerComments(node, node.body, commentWS);
  5139. break;
  5140. default:
  5141. {
  5142. if (node.type === "RecordExpression") {
  5143. adjustInnerComments(node, node.properties, commentWS);
  5144. break;
  5145. }
  5146. if (node.type === "TupleExpression") {
  5147. adjustInnerComments(node, node.elements, commentWS);
  5148. break;
  5149. }
  5150. setInnerComments(node, comments);
  5151. }
  5152. }
  5153. } else {
  5154. setInnerComments(node, comments);
  5155. }
  5156. }
  5157. }
  5158. finalizeRemainingComments() {
  5159. const {
  5160. commentStack
  5161. } = this.state;
  5162. for (let i = commentStack.length - 1; i >= 0; i--) {
  5163. this.finalizeComment(commentStack[i]);
  5164. }
  5165. this.state.commentStack = [];
  5166. }
  5167. resetPreviousNodeTrailingComments(node) {
  5168. const {
  5169. commentStack
  5170. } = this.state;
  5171. const {
  5172. length
  5173. } = commentStack;
  5174. if (length === 0) return;
  5175. const commentWS = commentStack[length - 1];
  5176. if (commentWS.leadingNode === node) {
  5177. commentWS.leadingNode = null;
  5178. }
  5179. }
  5180. takeSurroundingComments(node, start, end) {
  5181. const {
  5182. commentStack
  5183. } = this.state;
  5184. const commentStackLength = commentStack.length;
  5185. if (commentStackLength === 0) return;
  5186. let i = commentStackLength - 1;
  5187. for (; i >= 0; i--) {
  5188. const commentWS = commentStack[i];
  5189. const commentEnd = commentWS.end;
  5190. const commentStart = commentWS.start;
  5191. if (commentStart === end) {
  5192. commentWS.leadingNode = node;
  5193. } else if (commentEnd === start) {
  5194. commentWS.trailingNode = node;
  5195. } else if (commentEnd < start) {
  5196. break;
  5197. }
  5198. }
  5199. }
  5200. }
  5201. class State {
  5202. constructor() {
  5203. this.flags = 1024;
  5204. this.startIndex = void 0;
  5205. this.curLine = void 0;
  5206. this.lineStart = void 0;
  5207. this.startLoc = void 0;
  5208. this.endLoc = void 0;
  5209. this.errors = [];
  5210. this.potentialArrowAt = -1;
  5211. this.noArrowAt = [];
  5212. this.noArrowParamsConversionAt = [];
  5213. this.topicContext = {
  5214. maxNumOfResolvableTopics: 0,
  5215. maxTopicIndex: null
  5216. };
  5217. this.labels = [];
  5218. this.commentsLen = 0;
  5219. this.commentStack = [];
  5220. this.pos = 0;
  5221. this.type = 140;
  5222. this.value = null;
  5223. this.start = 0;
  5224. this.end = 0;
  5225. this.lastTokEndLoc = null;
  5226. this.lastTokStartLoc = null;
  5227. this.context = [types.brace];
  5228. this.firstInvalidTemplateEscapePos = null;
  5229. this.strictErrors = new Map();
  5230. this.tokensLength = 0;
  5231. }
  5232. get strict() {
  5233. return (this.flags & 1) > 0;
  5234. }
  5235. set strict(v) {
  5236. if (v) this.flags |= 1;else this.flags &= -2;
  5237. }
  5238. init({
  5239. strictMode,
  5240. sourceType,
  5241. startIndex,
  5242. startLine,
  5243. startColumn
  5244. }) {
  5245. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  5246. this.startIndex = startIndex;
  5247. this.curLine = startLine;
  5248. this.lineStart = -startColumn;
  5249. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  5250. }
  5251. get maybeInArrowParameters() {
  5252. return (this.flags & 2) > 0;
  5253. }
  5254. set maybeInArrowParameters(v) {
  5255. if (v) this.flags |= 2;else this.flags &= -3;
  5256. }
  5257. get inType() {
  5258. return (this.flags & 4) > 0;
  5259. }
  5260. set inType(v) {
  5261. if (v) this.flags |= 4;else this.flags &= -5;
  5262. }
  5263. get noAnonFunctionType() {
  5264. return (this.flags & 8) > 0;
  5265. }
  5266. set noAnonFunctionType(v) {
  5267. if (v) this.flags |= 8;else this.flags &= -9;
  5268. }
  5269. get hasFlowComment() {
  5270. return (this.flags & 16) > 0;
  5271. }
  5272. set hasFlowComment(v) {
  5273. if (v) this.flags |= 16;else this.flags &= -17;
  5274. }
  5275. get isAmbientContext() {
  5276. return (this.flags & 32) > 0;
  5277. }
  5278. set isAmbientContext(v) {
  5279. if (v) this.flags |= 32;else this.flags &= -33;
  5280. }
  5281. get inAbstractClass() {
  5282. return (this.flags & 64) > 0;
  5283. }
  5284. set inAbstractClass(v) {
  5285. if (v) this.flags |= 64;else this.flags &= -65;
  5286. }
  5287. get inDisallowConditionalTypesContext() {
  5288. return (this.flags & 128) > 0;
  5289. }
  5290. set inDisallowConditionalTypesContext(v) {
  5291. if (v) this.flags |= 128;else this.flags &= -129;
  5292. }
  5293. get soloAwait() {
  5294. return (this.flags & 256) > 0;
  5295. }
  5296. set soloAwait(v) {
  5297. if (v) this.flags |= 256;else this.flags &= -257;
  5298. }
  5299. get inFSharpPipelineDirectBody() {
  5300. return (this.flags & 512) > 0;
  5301. }
  5302. set inFSharpPipelineDirectBody(v) {
  5303. if (v) this.flags |= 512;else this.flags &= -513;
  5304. }
  5305. get canStartJSXElement() {
  5306. return (this.flags & 1024) > 0;
  5307. }
  5308. set canStartJSXElement(v) {
  5309. if (v) this.flags |= 1024;else this.flags &= -1025;
  5310. }
  5311. get containsEsc() {
  5312. return (this.flags & 2048) > 0;
  5313. }
  5314. set containsEsc(v) {
  5315. if (v) this.flags |= 2048;else this.flags &= -2049;
  5316. }
  5317. get hasTopLevelAwait() {
  5318. return (this.flags & 4096) > 0;
  5319. }
  5320. set hasTopLevelAwait(v) {
  5321. if (v) this.flags |= 4096;else this.flags &= -4097;
  5322. }
  5323. curPosition() {
  5324. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  5325. }
  5326. clone() {
  5327. const state = new State();
  5328. state.flags = this.flags;
  5329. state.startIndex = this.startIndex;
  5330. state.curLine = this.curLine;
  5331. state.lineStart = this.lineStart;
  5332. state.startLoc = this.startLoc;
  5333. state.endLoc = this.endLoc;
  5334. state.errors = this.errors.slice();
  5335. state.potentialArrowAt = this.potentialArrowAt;
  5336. state.noArrowAt = this.noArrowAt.slice();
  5337. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  5338. state.topicContext = this.topicContext;
  5339. state.labels = this.labels.slice();
  5340. state.commentsLen = this.commentsLen;
  5341. state.commentStack = this.commentStack.slice();
  5342. state.pos = this.pos;
  5343. state.type = this.type;
  5344. state.value = this.value;
  5345. state.start = this.start;
  5346. state.end = this.end;
  5347. state.lastTokEndLoc = this.lastTokEndLoc;
  5348. state.lastTokStartLoc = this.lastTokStartLoc;
  5349. state.context = this.context.slice();
  5350. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  5351. state.strictErrors = this.strictErrors;
  5352. state.tokensLength = this.tokensLength;
  5353. return state;
  5354. }
  5355. }
  5356. var _isDigit = function isDigit(code) {
  5357. return code >= 48 && code <= 57;
  5358. };
  5359. const forbiddenNumericSeparatorSiblings = {
  5360. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  5361. hex: new Set([46, 88, 95, 120])
  5362. };
  5363. const isAllowedNumericSeparatorSibling = {
  5364. bin: ch => ch === 48 || ch === 49,
  5365. oct: ch => ch >= 48 && ch <= 55,
  5366. dec: ch => ch >= 48 && ch <= 57,
  5367. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  5368. };
  5369. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  5370. const initialPos = pos;
  5371. const initialLineStart = lineStart;
  5372. const initialCurLine = curLine;
  5373. let out = "";
  5374. let firstInvalidLoc = null;
  5375. let chunkStart = pos;
  5376. const {
  5377. length
  5378. } = input;
  5379. for (;;) {
  5380. if (pos >= length) {
  5381. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5382. out += input.slice(chunkStart, pos);
  5383. break;
  5384. }
  5385. const ch = input.charCodeAt(pos);
  5386. if (isStringEnd(type, ch, input, pos)) {
  5387. out += input.slice(chunkStart, pos);
  5388. break;
  5389. }
  5390. if (ch === 92) {
  5391. out += input.slice(chunkStart, pos);
  5392. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  5393. if (res.ch === null && !firstInvalidLoc) {
  5394. firstInvalidLoc = {
  5395. pos,
  5396. lineStart,
  5397. curLine
  5398. };
  5399. } else {
  5400. out += res.ch;
  5401. }
  5402. ({
  5403. pos,
  5404. lineStart,
  5405. curLine
  5406. } = res);
  5407. chunkStart = pos;
  5408. } else if (ch === 8232 || ch === 8233) {
  5409. ++pos;
  5410. ++curLine;
  5411. lineStart = pos;
  5412. } else if (ch === 10 || ch === 13) {
  5413. if (type === "template") {
  5414. out += input.slice(chunkStart, pos) + "\n";
  5415. ++pos;
  5416. if (ch === 13 && input.charCodeAt(pos) === 10) {
  5417. ++pos;
  5418. }
  5419. ++curLine;
  5420. chunkStart = lineStart = pos;
  5421. } else {
  5422. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5423. }
  5424. } else {
  5425. ++pos;
  5426. }
  5427. }
  5428. return {
  5429. pos,
  5430. str: out,
  5431. firstInvalidLoc,
  5432. lineStart,
  5433. curLine,
  5434. containsInvalid: !!firstInvalidLoc
  5435. };
  5436. }
  5437. function isStringEnd(type, ch, input, pos) {
  5438. if (type === "template") {
  5439. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  5440. }
  5441. return ch === (type === "double" ? 34 : 39);
  5442. }
  5443. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  5444. const throwOnInvalid = !inTemplate;
  5445. pos++;
  5446. const res = ch => ({
  5447. pos,
  5448. ch,
  5449. lineStart,
  5450. curLine
  5451. });
  5452. const ch = input.charCodeAt(pos++);
  5453. switch (ch) {
  5454. case 110:
  5455. return res("\n");
  5456. case 114:
  5457. return res("\r");
  5458. case 120:
  5459. {
  5460. let code;
  5461. ({
  5462. code,
  5463. pos
  5464. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  5465. return res(code === null ? null : String.fromCharCode(code));
  5466. }
  5467. case 117:
  5468. {
  5469. let code;
  5470. ({
  5471. code,
  5472. pos
  5473. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  5474. return res(code === null ? null : String.fromCodePoint(code));
  5475. }
  5476. case 116:
  5477. return res("\t");
  5478. case 98:
  5479. return res("\b");
  5480. case 118:
  5481. return res("\u000b");
  5482. case 102:
  5483. return res("\f");
  5484. case 13:
  5485. if (input.charCodeAt(pos) === 10) {
  5486. ++pos;
  5487. }
  5488. case 10:
  5489. lineStart = pos;
  5490. ++curLine;
  5491. case 8232:
  5492. case 8233:
  5493. return res("");
  5494. case 56:
  5495. case 57:
  5496. if (inTemplate) {
  5497. return res(null);
  5498. } else {
  5499. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  5500. }
  5501. default:
  5502. if (ch >= 48 && ch <= 55) {
  5503. const startPos = pos - 1;
  5504. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  5505. let octalStr = match[0];
  5506. let octal = parseInt(octalStr, 8);
  5507. if (octal > 255) {
  5508. octalStr = octalStr.slice(0, -1);
  5509. octal = parseInt(octalStr, 8);
  5510. }
  5511. pos += octalStr.length - 1;
  5512. const next = input.charCodeAt(pos);
  5513. if (octalStr !== "0" || next === 56 || next === 57) {
  5514. if (inTemplate) {
  5515. return res(null);
  5516. } else {
  5517. errors.strictNumericEscape(startPos, lineStart, curLine);
  5518. }
  5519. }
  5520. return res(String.fromCharCode(octal));
  5521. }
  5522. return res(String.fromCharCode(ch));
  5523. }
  5524. }
  5525. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  5526. const initialPos = pos;
  5527. let n;
  5528. ({
  5529. n,
  5530. pos
  5531. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  5532. if (n === null) {
  5533. if (throwOnInvalid) {
  5534. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  5535. } else {
  5536. pos = initialPos - 1;
  5537. }
  5538. }
  5539. return {
  5540. code: n,
  5541. pos
  5542. };
  5543. }
  5544. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  5545. const start = pos;
  5546. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  5547. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  5548. let invalid = false;
  5549. let total = 0;
  5550. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  5551. const code = input.charCodeAt(pos);
  5552. let val;
  5553. if (code === 95 && allowNumSeparator !== "bail") {
  5554. const prev = input.charCodeAt(pos - 1);
  5555. const next = input.charCodeAt(pos + 1);
  5556. if (!allowNumSeparator) {
  5557. if (bailOnError) return {
  5558. n: null,
  5559. pos
  5560. };
  5561. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  5562. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  5563. if (bailOnError) return {
  5564. n: null,
  5565. pos
  5566. };
  5567. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  5568. }
  5569. ++pos;
  5570. continue;
  5571. }
  5572. if (code >= 97) {
  5573. val = code - 97 + 10;
  5574. } else if (code >= 65) {
  5575. val = code - 65 + 10;
  5576. } else if (_isDigit(code)) {
  5577. val = code - 48;
  5578. } else {
  5579. val = Infinity;
  5580. }
  5581. if (val >= radix) {
  5582. if (val <= 9 && bailOnError) {
  5583. return {
  5584. n: null,
  5585. pos
  5586. };
  5587. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  5588. val = 0;
  5589. } else if (forceLen) {
  5590. val = 0;
  5591. invalid = true;
  5592. } else {
  5593. break;
  5594. }
  5595. }
  5596. ++pos;
  5597. total = total * radix + val;
  5598. }
  5599. if (pos === start || len != null && pos - start !== len || invalid) {
  5600. return {
  5601. n: null,
  5602. pos
  5603. };
  5604. }
  5605. return {
  5606. n: total,
  5607. pos
  5608. };
  5609. }
  5610. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  5611. const ch = input.charCodeAt(pos);
  5612. let code;
  5613. if (ch === 123) {
  5614. ++pos;
  5615. ({
  5616. code,
  5617. pos
  5618. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  5619. ++pos;
  5620. if (code !== null && code > 0x10ffff) {
  5621. if (throwOnInvalid) {
  5622. errors.invalidCodePoint(pos, lineStart, curLine);
  5623. } else {
  5624. return {
  5625. code: null,
  5626. pos
  5627. };
  5628. }
  5629. }
  5630. } else {
  5631. ({
  5632. code,
  5633. pos
  5634. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  5635. }
  5636. return {
  5637. code,
  5638. pos
  5639. };
  5640. }
  5641. function buildPosition(pos, lineStart, curLine) {
  5642. return new Position(curLine, pos - lineStart, pos);
  5643. }
  5644. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  5645. class Token {
  5646. constructor(state) {
  5647. const startIndex = state.startIndex || 0;
  5648. this.type = state.type;
  5649. this.value = state.value;
  5650. this.start = startIndex + state.start;
  5651. this.end = startIndex + state.end;
  5652. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  5653. }
  5654. }
  5655. class Tokenizer extends CommentsParser {
  5656. constructor(options, input) {
  5657. super();
  5658. this.isLookahead = void 0;
  5659. this.tokens = [];
  5660. this.errorHandlers_readInt = {
  5661. invalidDigit: (pos, lineStart, curLine, radix) => {
  5662. if (!(this.optionFlags & 2048)) return false;
  5663. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  5664. radix
  5665. });
  5666. return true;
  5667. },
  5668. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  5669. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  5670. };
  5671. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  5672. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  5673. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  5674. });
  5675. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  5676. strictNumericEscape: (pos, lineStart, curLine) => {
  5677. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  5678. },
  5679. unterminated: (pos, lineStart, curLine) => {
  5680. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  5681. }
  5682. });
  5683. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  5684. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  5685. unterminated: (pos, lineStart, curLine) => {
  5686. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  5687. }
  5688. });
  5689. this.state = new State();
  5690. this.state.init(options);
  5691. this.input = input;
  5692. this.length = input.length;
  5693. this.comments = [];
  5694. this.isLookahead = false;
  5695. }
  5696. pushToken(token) {
  5697. this.tokens.length = this.state.tokensLength;
  5698. this.tokens.push(token);
  5699. ++this.state.tokensLength;
  5700. }
  5701. next() {
  5702. this.checkKeywordEscapes();
  5703. if (this.optionFlags & 256) {
  5704. this.pushToken(new Token(this.state));
  5705. }
  5706. this.state.lastTokEndLoc = this.state.endLoc;
  5707. this.state.lastTokStartLoc = this.state.startLoc;
  5708. this.nextToken();
  5709. }
  5710. eat(type) {
  5711. if (this.match(type)) {
  5712. this.next();
  5713. return true;
  5714. } else {
  5715. return false;
  5716. }
  5717. }
  5718. match(type) {
  5719. return this.state.type === type;
  5720. }
  5721. createLookaheadState(state) {
  5722. return {
  5723. pos: state.pos,
  5724. value: null,
  5725. type: state.type,
  5726. start: state.start,
  5727. end: state.end,
  5728. context: [this.curContext()],
  5729. inType: state.inType,
  5730. startLoc: state.startLoc,
  5731. lastTokEndLoc: state.lastTokEndLoc,
  5732. curLine: state.curLine,
  5733. lineStart: state.lineStart,
  5734. curPosition: state.curPosition
  5735. };
  5736. }
  5737. lookahead() {
  5738. const old = this.state;
  5739. this.state = this.createLookaheadState(old);
  5740. this.isLookahead = true;
  5741. this.nextToken();
  5742. this.isLookahead = false;
  5743. const curr = this.state;
  5744. this.state = old;
  5745. return curr;
  5746. }
  5747. nextTokenStart() {
  5748. return this.nextTokenStartSince(this.state.pos);
  5749. }
  5750. nextTokenStartSince(pos) {
  5751. skipWhiteSpace.lastIndex = pos;
  5752. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  5753. }
  5754. lookaheadCharCode() {
  5755. return this.lookaheadCharCodeSince(this.state.pos);
  5756. }
  5757. lookaheadCharCodeSince(pos) {
  5758. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  5759. }
  5760. nextTokenInLineStart() {
  5761. return this.nextTokenInLineStartSince(this.state.pos);
  5762. }
  5763. nextTokenInLineStartSince(pos) {
  5764. skipWhiteSpaceInLine.lastIndex = pos;
  5765. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  5766. }
  5767. lookaheadInLineCharCode() {
  5768. return this.input.charCodeAt(this.nextTokenInLineStart());
  5769. }
  5770. codePointAtPos(pos) {
  5771. let cp = this.input.charCodeAt(pos);
  5772. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  5773. const trail = this.input.charCodeAt(pos);
  5774. if ((trail & 0xfc00) === 0xdc00) {
  5775. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  5776. }
  5777. }
  5778. return cp;
  5779. }
  5780. setStrict(strict) {
  5781. this.state.strict = strict;
  5782. if (strict) {
  5783. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  5784. this.state.strictErrors.clear();
  5785. }
  5786. }
  5787. curContext() {
  5788. return this.state.context[this.state.context.length - 1];
  5789. }
  5790. nextToken() {
  5791. this.skipSpace();
  5792. this.state.start = this.state.pos;
  5793. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  5794. if (this.state.pos >= this.length) {
  5795. this.finishToken(140);
  5796. return;
  5797. }
  5798. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  5799. }
  5800. skipBlockComment(commentEnd) {
  5801. let startLoc;
  5802. if (!this.isLookahead) startLoc = this.state.curPosition();
  5803. const start = this.state.pos;
  5804. const end = this.input.indexOf(commentEnd, start + 2);
  5805. if (end === -1) {
  5806. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5807. }
  5808. this.state.pos = end + commentEnd.length;
  5809. lineBreakG.lastIndex = start + 2;
  5810. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  5811. ++this.state.curLine;
  5812. this.state.lineStart = lineBreakG.lastIndex;
  5813. }
  5814. if (this.isLookahead) return;
  5815. const comment = {
  5816. type: "CommentBlock",
  5817. value: this.input.slice(start + 2, end),
  5818. start: this.sourceToOffsetPos(start),
  5819. end: this.sourceToOffsetPos(end + commentEnd.length),
  5820. loc: new SourceLocation(startLoc, this.state.curPosition())
  5821. };
  5822. if (this.optionFlags & 256) this.pushToken(comment);
  5823. return comment;
  5824. }
  5825. skipLineComment(startSkip) {
  5826. const start = this.state.pos;
  5827. let startLoc;
  5828. if (!this.isLookahead) startLoc = this.state.curPosition();
  5829. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  5830. if (this.state.pos < this.length) {
  5831. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  5832. ch = this.input.charCodeAt(this.state.pos);
  5833. }
  5834. }
  5835. if (this.isLookahead) return;
  5836. const end = this.state.pos;
  5837. const value = this.input.slice(start + startSkip, end);
  5838. const comment = {
  5839. type: "CommentLine",
  5840. value,
  5841. start: this.sourceToOffsetPos(start),
  5842. end: this.sourceToOffsetPos(end),
  5843. loc: new SourceLocation(startLoc, this.state.curPosition())
  5844. };
  5845. if (this.optionFlags & 256) this.pushToken(comment);
  5846. return comment;
  5847. }
  5848. skipSpace() {
  5849. const spaceStart = this.state.pos;
  5850. const comments = this.optionFlags & 4096 ? [] : null;
  5851. loop: while (this.state.pos < this.length) {
  5852. const ch = this.input.charCodeAt(this.state.pos);
  5853. switch (ch) {
  5854. case 32:
  5855. case 160:
  5856. case 9:
  5857. ++this.state.pos;
  5858. break;
  5859. case 13:
  5860. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  5861. ++this.state.pos;
  5862. }
  5863. case 10:
  5864. case 8232:
  5865. case 8233:
  5866. ++this.state.pos;
  5867. ++this.state.curLine;
  5868. this.state.lineStart = this.state.pos;
  5869. break;
  5870. case 47:
  5871. switch (this.input.charCodeAt(this.state.pos + 1)) {
  5872. case 42:
  5873. {
  5874. const comment = this.skipBlockComment("*/");
  5875. if (comment !== undefined) {
  5876. this.addComment(comment);
  5877. comments == null || comments.push(comment);
  5878. }
  5879. break;
  5880. }
  5881. case 47:
  5882. {
  5883. const comment = this.skipLineComment(2);
  5884. if (comment !== undefined) {
  5885. this.addComment(comment);
  5886. comments == null || comments.push(comment);
  5887. }
  5888. break;
  5889. }
  5890. default:
  5891. break loop;
  5892. }
  5893. break;
  5894. default:
  5895. if (isWhitespace(ch)) {
  5896. ++this.state.pos;
  5897. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  5898. const pos = this.state.pos;
  5899. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  5900. const comment = this.skipLineComment(3);
  5901. if (comment !== undefined) {
  5902. this.addComment(comment);
  5903. comments == null || comments.push(comment);
  5904. }
  5905. } else {
  5906. break loop;
  5907. }
  5908. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  5909. const pos = this.state.pos;
  5910. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  5911. const comment = this.skipLineComment(4);
  5912. if (comment !== undefined) {
  5913. this.addComment(comment);
  5914. comments == null || comments.push(comment);
  5915. }
  5916. } else {
  5917. break loop;
  5918. }
  5919. } else {
  5920. break loop;
  5921. }
  5922. }
  5923. }
  5924. if ((comments == null ? void 0 : comments.length) > 0) {
  5925. const end = this.state.pos;
  5926. const commentWhitespace = {
  5927. start: this.sourceToOffsetPos(spaceStart),
  5928. end: this.sourceToOffsetPos(end),
  5929. comments: comments,
  5930. leadingNode: null,
  5931. trailingNode: null,
  5932. containingNode: null
  5933. };
  5934. this.state.commentStack.push(commentWhitespace);
  5935. }
  5936. }
  5937. finishToken(type, val) {
  5938. this.state.end = this.state.pos;
  5939. this.state.endLoc = this.state.curPosition();
  5940. const prevType = this.state.type;
  5941. this.state.type = type;
  5942. this.state.value = val;
  5943. if (!this.isLookahead) {
  5944. this.updateContext(prevType);
  5945. }
  5946. }
  5947. replaceToken(type) {
  5948. this.state.type = type;
  5949. this.updateContext();
  5950. }
  5951. readToken_numberSign() {
  5952. if (this.state.pos === 0 && this.readToken_interpreter()) {
  5953. return;
  5954. }
  5955. const nextPos = this.state.pos + 1;
  5956. const next = this.codePointAtPos(nextPos);
  5957. if (next >= 48 && next <= 57) {
  5958. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  5959. }
  5960. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  5961. this.expectPlugin("recordAndTuple");
  5962. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  5963. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  5964. }
  5965. this.state.pos += 2;
  5966. if (next === 123) {
  5967. this.finishToken(7);
  5968. } else {
  5969. this.finishToken(1);
  5970. }
  5971. } else if (isIdentifierStart(next)) {
  5972. ++this.state.pos;
  5973. this.finishToken(139, this.readWord1(next));
  5974. } else if (next === 92) {
  5975. ++this.state.pos;
  5976. this.finishToken(139, this.readWord1());
  5977. } else {
  5978. this.finishOp(27, 1);
  5979. }
  5980. }
  5981. readToken_dot() {
  5982. const next = this.input.charCodeAt(this.state.pos + 1);
  5983. if (next >= 48 && next <= 57) {
  5984. this.readNumber(true);
  5985. return;
  5986. }
  5987. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  5988. this.state.pos += 3;
  5989. this.finishToken(21);
  5990. } else {
  5991. ++this.state.pos;
  5992. this.finishToken(16);
  5993. }
  5994. }
  5995. readToken_slash() {
  5996. const next = this.input.charCodeAt(this.state.pos + 1);
  5997. if (next === 61) {
  5998. this.finishOp(31, 2);
  5999. } else {
  6000. this.finishOp(56, 1);
  6001. }
  6002. }
  6003. readToken_interpreter() {
  6004. if (this.state.pos !== 0 || this.length < 2) return false;
  6005. let ch = this.input.charCodeAt(this.state.pos + 1);
  6006. if (ch !== 33) return false;
  6007. const start = this.state.pos;
  6008. this.state.pos += 1;
  6009. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  6010. ch = this.input.charCodeAt(this.state.pos);
  6011. }
  6012. const value = this.input.slice(start + 2, this.state.pos);
  6013. this.finishToken(28, value);
  6014. return true;
  6015. }
  6016. readToken_mult_modulo(code) {
  6017. let type = code === 42 ? 55 : 54;
  6018. let width = 1;
  6019. let next = this.input.charCodeAt(this.state.pos + 1);
  6020. if (code === 42 && next === 42) {
  6021. width++;
  6022. next = this.input.charCodeAt(this.state.pos + 2);
  6023. type = 57;
  6024. }
  6025. if (next === 61 && !this.state.inType) {
  6026. width++;
  6027. type = code === 37 ? 33 : 30;
  6028. }
  6029. this.finishOp(type, width);
  6030. }
  6031. readToken_pipe_amp(code) {
  6032. const next = this.input.charCodeAt(this.state.pos + 1);
  6033. if (next === code) {
  6034. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  6035. this.finishOp(30, 3);
  6036. } else {
  6037. this.finishOp(code === 124 ? 41 : 42, 2);
  6038. }
  6039. return;
  6040. }
  6041. if (code === 124) {
  6042. if (next === 62) {
  6043. this.finishOp(39, 2);
  6044. return;
  6045. }
  6046. if (this.hasPlugin("recordAndTuple") && next === 125) {
  6047. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6048. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6049. }
  6050. this.state.pos += 2;
  6051. this.finishToken(9);
  6052. return;
  6053. }
  6054. if (this.hasPlugin("recordAndTuple") && next === 93) {
  6055. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6056. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6057. }
  6058. this.state.pos += 2;
  6059. this.finishToken(4);
  6060. return;
  6061. }
  6062. }
  6063. if (next === 61) {
  6064. this.finishOp(30, 2);
  6065. return;
  6066. }
  6067. this.finishOp(code === 124 ? 43 : 45, 1);
  6068. }
  6069. readToken_caret() {
  6070. const next = this.input.charCodeAt(this.state.pos + 1);
  6071. if (next === 61 && !this.state.inType) {
  6072. this.finishOp(32, 2);
  6073. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  6074. proposal: "hack",
  6075. topicToken: "^^"
  6076. }])) {
  6077. this.finishOp(37, 2);
  6078. const lookaheadCh = this.input.codePointAt(this.state.pos);
  6079. if (lookaheadCh === 94) {
  6080. this.unexpected();
  6081. }
  6082. } else {
  6083. this.finishOp(44, 1);
  6084. }
  6085. }
  6086. readToken_atSign() {
  6087. const next = this.input.charCodeAt(this.state.pos + 1);
  6088. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  6089. proposal: "hack",
  6090. topicToken: "@@"
  6091. }])) {
  6092. this.finishOp(38, 2);
  6093. } else {
  6094. this.finishOp(26, 1);
  6095. }
  6096. }
  6097. readToken_plus_min(code) {
  6098. const next = this.input.charCodeAt(this.state.pos + 1);
  6099. if (next === code) {
  6100. this.finishOp(34, 2);
  6101. return;
  6102. }
  6103. if (next === 61) {
  6104. this.finishOp(30, 2);
  6105. } else {
  6106. this.finishOp(53, 1);
  6107. }
  6108. }
  6109. readToken_lt() {
  6110. const {
  6111. pos
  6112. } = this.state;
  6113. const next = this.input.charCodeAt(pos + 1);
  6114. if (next === 60) {
  6115. if (this.input.charCodeAt(pos + 2) === 61) {
  6116. this.finishOp(30, 3);
  6117. return;
  6118. }
  6119. this.finishOp(51, 2);
  6120. return;
  6121. }
  6122. if (next === 61) {
  6123. this.finishOp(49, 2);
  6124. return;
  6125. }
  6126. this.finishOp(47, 1);
  6127. }
  6128. readToken_gt() {
  6129. const {
  6130. pos
  6131. } = this.state;
  6132. const next = this.input.charCodeAt(pos + 1);
  6133. if (next === 62) {
  6134. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  6135. if (this.input.charCodeAt(pos + size) === 61) {
  6136. this.finishOp(30, size + 1);
  6137. return;
  6138. }
  6139. this.finishOp(52, size);
  6140. return;
  6141. }
  6142. if (next === 61) {
  6143. this.finishOp(49, 2);
  6144. return;
  6145. }
  6146. this.finishOp(48, 1);
  6147. }
  6148. readToken_eq_excl(code) {
  6149. const next = this.input.charCodeAt(this.state.pos + 1);
  6150. if (next === 61) {
  6151. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  6152. return;
  6153. }
  6154. if (code === 61 && next === 62) {
  6155. this.state.pos += 2;
  6156. this.finishToken(19);
  6157. return;
  6158. }
  6159. this.finishOp(code === 61 ? 29 : 35, 1);
  6160. }
  6161. readToken_question() {
  6162. const next = this.input.charCodeAt(this.state.pos + 1);
  6163. const next2 = this.input.charCodeAt(this.state.pos + 2);
  6164. if (next === 63) {
  6165. if (next2 === 61) {
  6166. this.finishOp(30, 3);
  6167. } else {
  6168. this.finishOp(40, 2);
  6169. }
  6170. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  6171. this.state.pos += 2;
  6172. this.finishToken(18);
  6173. } else {
  6174. ++this.state.pos;
  6175. this.finishToken(17);
  6176. }
  6177. }
  6178. getTokenFromCode(code) {
  6179. switch (code) {
  6180. case 46:
  6181. this.readToken_dot();
  6182. return;
  6183. case 40:
  6184. ++this.state.pos;
  6185. this.finishToken(10);
  6186. return;
  6187. case 41:
  6188. ++this.state.pos;
  6189. this.finishToken(11);
  6190. return;
  6191. case 59:
  6192. ++this.state.pos;
  6193. this.finishToken(13);
  6194. return;
  6195. case 44:
  6196. ++this.state.pos;
  6197. this.finishToken(12);
  6198. return;
  6199. case 91:
  6200. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6201. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6202. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6203. }
  6204. this.state.pos += 2;
  6205. this.finishToken(2);
  6206. } else {
  6207. ++this.state.pos;
  6208. this.finishToken(0);
  6209. }
  6210. return;
  6211. case 93:
  6212. ++this.state.pos;
  6213. this.finishToken(3);
  6214. return;
  6215. case 123:
  6216. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6217. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6218. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6219. }
  6220. this.state.pos += 2;
  6221. this.finishToken(6);
  6222. } else {
  6223. ++this.state.pos;
  6224. this.finishToken(5);
  6225. }
  6226. return;
  6227. case 125:
  6228. ++this.state.pos;
  6229. this.finishToken(8);
  6230. return;
  6231. case 58:
  6232. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  6233. this.finishOp(15, 2);
  6234. } else {
  6235. ++this.state.pos;
  6236. this.finishToken(14);
  6237. }
  6238. return;
  6239. case 63:
  6240. this.readToken_question();
  6241. return;
  6242. case 96:
  6243. this.readTemplateToken();
  6244. return;
  6245. case 48:
  6246. {
  6247. const next = this.input.charCodeAt(this.state.pos + 1);
  6248. if (next === 120 || next === 88) {
  6249. this.readRadixNumber(16);
  6250. return;
  6251. }
  6252. if (next === 111 || next === 79) {
  6253. this.readRadixNumber(8);
  6254. return;
  6255. }
  6256. if (next === 98 || next === 66) {
  6257. this.readRadixNumber(2);
  6258. return;
  6259. }
  6260. }
  6261. case 49:
  6262. case 50:
  6263. case 51:
  6264. case 52:
  6265. case 53:
  6266. case 54:
  6267. case 55:
  6268. case 56:
  6269. case 57:
  6270. this.readNumber(false);
  6271. return;
  6272. case 34:
  6273. case 39:
  6274. this.readString(code);
  6275. return;
  6276. case 47:
  6277. this.readToken_slash();
  6278. return;
  6279. case 37:
  6280. case 42:
  6281. this.readToken_mult_modulo(code);
  6282. return;
  6283. case 124:
  6284. case 38:
  6285. this.readToken_pipe_amp(code);
  6286. return;
  6287. case 94:
  6288. this.readToken_caret();
  6289. return;
  6290. case 43:
  6291. case 45:
  6292. this.readToken_plus_min(code);
  6293. return;
  6294. case 60:
  6295. this.readToken_lt();
  6296. return;
  6297. case 62:
  6298. this.readToken_gt();
  6299. return;
  6300. case 61:
  6301. case 33:
  6302. this.readToken_eq_excl(code);
  6303. return;
  6304. case 126:
  6305. this.finishOp(36, 1);
  6306. return;
  6307. case 64:
  6308. this.readToken_atSign();
  6309. return;
  6310. case 35:
  6311. this.readToken_numberSign();
  6312. return;
  6313. case 92:
  6314. this.readWord();
  6315. return;
  6316. default:
  6317. if (isIdentifierStart(code)) {
  6318. this.readWord(code);
  6319. return;
  6320. }
  6321. }
  6322. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  6323. unexpected: String.fromCodePoint(code)
  6324. });
  6325. }
  6326. finishOp(type, size) {
  6327. const str = this.input.slice(this.state.pos, this.state.pos + size);
  6328. this.state.pos += size;
  6329. this.finishToken(type, str);
  6330. }
  6331. readRegexp() {
  6332. const startLoc = this.state.startLoc;
  6333. const start = this.state.start + 1;
  6334. let escaped, inClass;
  6335. let {
  6336. pos
  6337. } = this.state;
  6338. for (;; ++pos) {
  6339. if (pos >= this.length) {
  6340. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6341. }
  6342. const ch = this.input.charCodeAt(pos);
  6343. if (isNewLine(ch)) {
  6344. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6345. }
  6346. if (escaped) {
  6347. escaped = false;
  6348. } else {
  6349. if (ch === 91) {
  6350. inClass = true;
  6351. } else if (ch === 93 && inClass) {
  6352. inClass = false;
  6353. } else if (ch === 47 && !inClass) {
  6354. break;
  6355. }
  6356. escaped = ch === 92;
  6357. }
  6358. }
  6359. const content = this.input.slice(start, pos);
  6360. ++pos;
  6361. let mods = "";
  6362. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  6363. while (pos < this.length) {
  6364. const cp = this.codePointAtPos(pos);
  6365. const char = String.fromCharCode(cp);
  6366. if (VALID_REGEX_FLAGS.has(cp)) {
  6367. if (cp === 118) {
  6368. if (mods.includes("u")) {
  6369. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6370. }
  6371. } else if (cp === 117) {
  6372. if (mods.includes("v")) {
  6373. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6374. }
  6375. }
  6376. if (mods.includes(char)) {
  6377. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  6378. }
  6379. } else if (isIdentifierChar(cp) || cp === 92) {
  6380. this.raise(Errors.MalformedRegExpFlags, nextPos());
  6381. } else {
  6382. break;
  6383. }
  6384. ++pos;
  6385. mods += char;
  6386. }
  6387. this.state.pos = pos;
  6388. this.finishToken(138, {
  6389. pattern: content,
  6390. flags: mods
  6391. });
  6392. }
  6393. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  6394. const {
  6395. n,
  6396. pos
  6397. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  6398. this.state.pos = pos;
  6399. return n;
  6400. }
  6401. readRadixNumber(radix) {
  6402. const start = this.state.pos;
  6403. const startLoc = this.state.curPosition();
  6404. let isBigInt = false;
  6405. this.state.pos += 2;
  6406. const val = this.readInt(radix);
  6407. if (val == null) {
  6408. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  6409. radix
  6410. });
  6411. }
  6412. const next = this.input.charCodeAt(this.state.pos);
  6413. if (next === 110) {
  6414. ++this.state.pos;
  6415. isBigInt = true;
  6416. } else if (next === 109) {
  6417. throw this.raise(Errors.InvalidDecimal, startLoc);
  6418. }
  6419. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6420. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6421. }
  6422. if (isBigInt) {
  6423. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  6424. this.finishToken(136, str);
  6425. return;
  6426. }
  6427. this.finishToken(135, val);
  6428. }
  6429. readNumber(startsWithDot) {
  6430. const start = this.state.pos;
  6431. const startLoc = this.state.curPosition();
  6432. let isFloat = false;
  6433. let isBigInt = false;
  6434. let hasExponent = false;
  6435. let isOctal = false;
  6436. if (!startsWithDot && this.readInt(10) === null) {
  6437. this.raise(Errors.InvalidNumber, this.state.curPosition());
  6438. }
  6439. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  6440. if (hasLeadingZero) {
  6441. const integer = this.input.slice(start, this.state.pos);
  6442. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  6443. if (!this.state.strict) {
  6444. const underscorePos = integer.indexOf("_");
  6445. if (underscorePos > 0) {
  6446. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  6447. }
  6448. }
  6449. isOctal = hasLeadingZero && !/[89]/.test(integer);
  6450. }
  6451. let next = this.input.charCodeAt(this.state.pos);
  6452. if (next === 46 && !isOctal) {
  6453. ++this.state.pos;
  6454. this.readInt(10);
  6455. isFloat = true;
  6456. next = this.input.charCodeAt(this.state.pos);
  6457. }
  6458. if ((next === 69 || next === 101) && !isOctal) {
  6459. next = this.input.charCodeAt(++this.state.pos);
  6460. if (next === 43 || next === 45) {
  6461. ++this.state.pos;
  6462. }
  6463. if (this.readInt(10) === null) {
  6464. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  6465. }
  6466. isFloat = true;
  6467. hasExponent = true;
  6468. next = this.input.charCodeAt(this.state.pos);
  6469. }
  6470. if (next === 110) {
  6471. if (isFloat || hasLeadingZero) {
  6472. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  6473. }
  6474. ++this.state.pos;
  6475. isBigInt = true;
  6476. }
  6477. if (next === 109) {
  6478. this.expectPlugin("decimal", this.state.curPosition());
  6479. if (hasExponent || hasLeadingZero) {
  6480. this.raise(Errors.InvalidDecimal, startLoc);
  6481. }
  6482. ++this.state.pos;
  6483. var isDecimal = true;
  6484. }
  6485. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6486. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6487. }
  6488. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  6489. if (isBigInt) {
  6490. this.finishToken(136, str);
  6491. return;
  6492. }
  6493. if (isDecimal) {
  6494. this.finishToken(137, str);
  6495. return;
  6496. }
  6497. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  6498. this.finishToken(135, val);
  6499. }
  6500. readCodePoint(throwOnInvalid) {
  6501. const {
  6502. code,
  6503. pos
  6504. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  6505. this.state.pos = pos;
  6506. return code;
  6507. }
  6508. readString(quote) {
  6509. const {
  6510. str,
  6511. pos,
  6512. curLine,
  6513. lineStart
  6514. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  6515. this.state.pos = pos + 1;
  6516. this.state.lineStart = lineStart;
  6517. this.state.curLine = curLine;
  6518. this.finishToken(134, str);
  6519. }
  6520. readTemplateContinuation() {
  6521. if (!this.match(8)) {
  6522. this.unexpected(null, 8);
  6523. }
  6524. this.state.pos--;
  6525. this.readTemplateToken();
  6526. }
  6527. readTemplateToken() {
  6528. const opening = this.input[this.state.pos];
  6529. const {
  6530. str,
  6531. firstInvalidLoc,
  6532. pos,
  6533. curLine,
  6534. lineStart
  6535. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  6536. this.state.pos = pos + 1;
  6537. this.state.lineStart = lineStart;
  6538. this.state.curLine = curLine;
  6539. if (firstInvalidLoc) {
  6540. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  6541. }
  6542. if (this.input.codePointAt(pos) === 96) {
  6543. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  6544. } else {
  6545. this.state.pos++;
  6546. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  6547. }
  6548. }
  6549. recordStrictModeErrors(toParseError, at) {
  6550. const index = at.index;
  6551. if (this.state.strict && !this.state.strictErrors.has(index)) {
  6552. this.raise(toParseError, at);
  6553. } else {
  6554. this.state.strictErrors.set(index, [toParseError, at]);
  6555. }
  6556. }
  6557. readWord1(firstCode) {
  6558. this.state.containsEsc = false;
  6559. let word = "";
  6560. const start = this.state.pos;
  6561. let chunkStart = this.state.pos;
  6562. if (firstCode !== undefined) {
  6563. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  6564. }
  6565. while (this.state.pos < this.length) {
  6566. const ch = this.codePointAtPos(this.state.pos);
  6567. if (isIdentifierChar(ch)) {
  6568. this.state.pos += ch <= 0xffff ? 1 : 2;
  6569. } else if (ch === 92) {
  6570. this.state.containsEsc = true;
  6571. word += this.input.slice(chunkStart, this.state.pos);
  6572. const escStart = this.state.curPosition();
  6573. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  6574. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  6575. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  6576. chunkStart = this.state.pos - 1;
  6577. continue;
  6578. }
  6579. ++this.state.pos;
  6580. const esc = this.readCodePoint(true);
  6581. if (esc !== null) {
  6582. if (!identifierCheck(esc)) {
  6583. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  6584. }
  6585. word += String.fromCodePoint(esc);
  6586. }
  6587. chunkStart = this.state.pos;
  6588. } else {
  6589. break;
  6590. }
  6591. }
  6592. return word + this.input.slice(chunkStart, this.state.pos);
  6593. }
  6594. readWord(firstCode) {
  6595. const word = this.readWord1(firstCode);
  6596. const type = keywords$1.get(word);
  6597. if (type !== undefined) {
  6598. this.finishToken(type, tokenLabelName(type));
  6599. } else {
  6600. this.finishToken(132, word);
  6601. }
  6602. }
  6603. checkKeywordEscapes() {
  6604. const {
  6605. type
  6606. } = this.state;
  6607. if (tokenIsKeyword(type) && this.state.containsEsc) {
  6608. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  6609. reservedWord: tokenLabelName(type)
  6610. });
  6611. }
  6612. }
  6613. raise(toParseError, at, details = {}) {
  6614. const loc = at instanceof Position ? at : at.loc.start;
  6615. const error = toParseError(loc, details);
  6616. if (!(this.optionFlags & 2048)) throw error;
  6617. if (!this.isLookahead) this.state.errors.push(error);
  6618. return error;
  6619. }
  6620. raiseOverwrite(toParseError, at, details = {}) {
  6621. const loc = at instanceof Position ? at : at.loc.start;
  6622. const pos = loc.index;
  6623. const errors = this.state.errors;
  6624. for (let i = errors.length - 1; i >= 0; i--) {
  6625. const error = errors[i];
  6626. if (error.loc.index === pos) {
  6627. return errors[i] = toParseError(loc, details);
  6628. }
  6629. if (error.loc.index < pos) break;
  6630. }
  6631. return this.raise(toParseError, at, details);
  6632. }
  6633. updateContext(prevType) {}
  6634. unexpected(loc, type) {
  6635. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  6636. expected: type ? tokenLabelName(type) : null
  6637. });
  6638. }
  6639. expectPlugin(pluginName, loc) {
  6640. if (this.hasPlugin(pluginName)) {
  6641. return true;
  6642. }
  6643. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  6644. missingPlugin: [pluginName]
  6645. });
  6646. }
  6647. expectOnePlugin(pluginNames) {
  6648. if (!pluginNames.some(name => this.hasPlugin(name))) {
  6649. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  6650. missingPlugin: pluginNames
  6651. });
  6652. }
  6653. }
  6654. errorBuilder(error) {
  6655. return (pos, lineStart, curLine) => {
  6656. this.raise(error, buildPosition(pos, lineStart, curLine));
  6657. };
  6658. }
  6659. }
  6660. class ClassScope {
  6661. constructor() {
  6662. this.privateNames = new Set();
  6663. this.loneAccessors = new Map();
  6664. this.undefinedPrivateNames = new Map();
  6665. }
  6666. }
  6667. class ClassScopeHandler {
  6668. constructor(parser) {
  6669. this.parser = void 0;
  6670. this.stack = [];
  6671. this.undefinedPrivateNames = new Map();
  6672. this.parser = parser;
  6673. }
  6674. current() {
  6675. return this.stack[this.stack.length - 1];
  6676. }
  6677. enter() {
  6678. this.stack.push(new ClassScope());
  6679. }
  6680. exit() {
  6681. const oldClassScope = this.stack.pop();
  6682. const current = this.current();
  6683. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  6684. if (current) {
  6685. if (!current.undefinedPrivateNames.has(name)) {
  6686. current.undefinedPrivateNames.set(name, loc);
  6687. }
  6688. } else {
  6689. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6690. identifierName: name
  6691. });
  6692. }
  6693. }
  6694. }
  6695. declarePrivateName(name, elementType, loc) {
  6696. const {
  6697. privateNames,
  6698. loneAccessors,
  6699. undefinedPrivateNames
  6700. } = this.current();
  6701. let redefined = privateNames.has(name);
  6702. if (elementType & 3) {
  6703. const accessor = redefined && loneAccessors.get(name);
  6704. if (accessor) {
  6705. const oldStatic = accessor & 4;
  6706. const newStatic = elementType & 4;
  6707. const oldKind = accessor & 3;
  6708. const newKind = elementType & 3;
  6709. redefined = oldKind === newKind || oldStatic !== newStatic;
  6710. if (!redefined) loneAccessors.delete(name);
  6711. } else if (!redefined) {
  6712. loneAccessors.set(name, elementType);
  6713. }
  6714. }
  6715. if (redefined) {
  6716. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  6717. identifierName: name
  6718. });
  6719. }
  6720. privateNames.add(name);
  6721. undefinedPrivateNames.delete(name);
  6722. }
  6723. usePrivateName(name, loc) {
  6724. let classScope;
  6725. for (classScope of this.stack) {
  6726. if (classScope.privateNames.has(name)) return;
  6727. }
  6728. if (classScope) {
  6729. classScope.undefinedPrivateNames.set(name, loc);
  6730. } else {
  6731. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6732. identifierName: name
  6733. });
  6734. }
  6735. }
  6736. }
  6737. class ExpressionScope {
  6738. constructor(type = 0) {
  6739. this.type = type;
  6740. }
  6741. canBeArrowParameterDeclaration() {
  6742. return this.type === 2 || this.type === 1;
  6743. }
  6744. isCertainlyParameterDeclaration() {
  6745. return this.type === 3;
  6746. }
  6747. }
  6748. class ArrowHeadParsingScope extends ExpressionScope {
  6749. constructor(type) {
  6750. super(type);
  6751. this.declarationErrors = new Map();
  6752. }
  6753. recordDeclarationError(ParsingErrorClass, at) {
  6754. const index = at.index;
  6755. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  6756. }
  6757. clearDeclarationError(index) {
  6758. this.declarationErrors.delete(index);
  6759. }
  6760. iterateErrors(iterator) {
  6761. this.declarationErrors.forEach(iterator);
  6762. }
  6763. }
  6764. class ExpressionScopeHandler {
  6765. constructor(parser) {
  6766. this.parser = void 0;
  6767. this.stack = [new ExpressionScope()];
  6768. this.parser = parser;
  6769. }
  6770. enter(scope) {
  6771. this.stack.push(scope);
  6772. }
  6773. exit() {
  6774. this.stack.pop();
  6775. }
  6776. recordParameterInitializerError(toParseError, node) {
  6777. const origin = node.loc.start;
  6778. const {
  6779. stack
  6780. } = this;
  6781. let i = stack.length - 1;
  6782. let scope = stack[i];
  6783. while (!scope.isCertainlyParameterDeclaration()) {
  6784. if (scope.canBeArrowParameterDeclaration()) {
  6785. scope.recordDeclarationError(toParseError, origin);
  6786. } else {
  6787. return;
  6788. }
  6789. scope = stack[--i];
  6790. }
  6791. this.parser.raise(toParseError, origin);
  6792. }
  6793. recordArrowParameterBindingError(error, node) {
  6794. const {
  6795. stack
  6796. } = this;
  6797. const scope = stack[stack.length - 1];
  6798. const origin = node.loc.start;
  6799. if (scope.isCertainlyParameterDeclaration()) {
  6800. this.parser.raise(error, origin);
  6801. } else if (scope.canBeArrowParameterDeclaration()) {
  6802. scope.recordDeclarationError(error, origin);
  6803. } else {
  6804. return;
  6805. }
  6806. }
  6807. recordAsyncArrowParametersError(at) {
  6808. const {
  6809. stack
  6810. } = this;
  6811. let i = stack.length - 1;
  6812. let scope = stack[i];
  6813. while (scope.canBeArrowParameterDeclaration()) {
  6814. if (scope.type === 2) {
  6815. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  6816. }
  6817. scope = stack[--i];
  6818. }
  6819. }
  6820. validateAsPattern() {
  6821. const {
  6822. stack
  6823. } = this;
  6824. const currentScope = stack[stack.length - 1];
  6825. if (!currentScope.canBeArrowParameterDeclaration()) return;
  6826. currentScope.iterateErrors(([toParseError, loc]) => {
  6827. this.parser.raise(toParseError, loc);
  6828. let i = stack.length - 2;
  6829. let scope = stack[i];
  6830. while (scope.canBeArrowParameterDeclaration()) {
  6831. scope.clearDeclarationError(loc.index);
  6832. scope = stack[--i];
  6833. }
  6834. });
  6835. }
  6836. }
  6837. function newParameterDeclarationScope() {
  6838. return new ExpressionScope(3);
  6839. }
  6840. function newArrowHeadScope() {
  6841. return new ArrowHeadParsingScope(1);
  6842. }
  6843. function newAsyncArrowScope() {
  6844. return new ArrowHeadParsingScope(2);
  6845. }
  6846. function newExpressionScope() {
  6847. return new ExpressionScope();
  6848. }
  6849. class UtilParser extends Tokenizer {
  6850. addExtra(node, key, value, enumerable = true) {
  6851. if (!node) return;
  6852. let {
  6853. extra
  6854. } = node;
  6855. if (extra == null) {
  6856. extra = {};
  6857. node.extra = extra;
  6858. }
  6859. if (enumerable) {
  6860. extra[key] = value;
  6861. } else {
  6862. Object.defineProperty(extra, key, {
  6863. enumerable,
  6864. value
  6865. });
  6866. }
  6867. }
  6868. isContextual(token) {
  6869. return this.state.type === token && !this.state.containsEsc;
  6870. }
  6871. isUnparsedContextual(nameStart, name) {
  6872. if (this.input.startsWith(name, nameStart)) {
  6873. const nextCh = this.input.charCodeAt(nameStart + name.length);
  6874. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  6875. }
  6876. return false;
  6877. }
  6878. isLookaheadContextual(name) {
  6879. const next = this.nextTokenStart();
  6880. return this.isUnparsedContextual(next, name);
  6881. }
  6882. eatContextual(token) {
  6883. if (this.isContextual(token)) {
  6884. this.next();
  6885. return true;
  6886. }
  6887. return false;
  6888. }
  6889. expectContextual(token, toParseError) {
  6890. if (!this.eatContextual(token)) {
  6891. if (toParseError != null) {
  6892. throw this.raise(toParseError, this.state.startLoc);
  6893. }
  6894. this.unexpected(null, token);
  6895. }
  6896. }
  6897. canInsertSemicolon() {
  6898. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  6899. }
  6900. hasPrecedingLineBreak() {
  6901. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  6902. }
  6903. hasFollowingLineBreak() {
  6904. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  6905. }
  6906. isLineTerminator() {
  6907. return this.eat(13) || this.canInsertSemicolon();
  6908. }
  6909. semicolon(allowAsi = true) {
  6910. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  6911. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  6912. }
  6913. expect(type, loc) {
  6914. if (!this.eat(type)) {
  6915. this.unexpected(loc, type);
  6916. }
  6917. }
  6918. tryParse(fn, oldState = this.state.clone()) {
  6919. const abortSignal = {
  6920. node: null
  6921. };
  6922. try {
  6923. const node = fn((node = null) => {
  6924. abortSignal.node = node;
  6925. throw abortSignal;
  6926. });
  6927. if (this.state.errors.length > oldState.errors.length) {
  6928. const failState = this.state;
  6929. this.state = oldState;
  6930. this.state.tokensLength = failState.tokensLength;
  6931. return {
  6932. node,
  6933. error: failState.errors[oldState.errors.length],
  6934. thrown: false,
  6935. aborted: false,
  6936. failState
  6937. };
  6938. }
  6939. return {
  6940. node: node,
  6941. error: null,
  6942. thrown: false,
  6943. aborted: false,
  6944. failState: null
  6945. };
  6946. } catch (error) {
  6947. const failState = this.state;
  6948. this.state = oldState;
  6949. if (error instanceof SyntaxError) {
  6950. return {
  6951. node: null,
  6952. error,
  6953. thrown: true,
  6954. aborted: false,
  6955. failState
  6956. };
  6957. }
  6958. if (error === abortSignal) {
  6959. return {
  6960. node: abortSignal.node,
  6961. error: null,
  6962. thrown: false,
  6963. aborted: true,
  6964. failState
  6965. };
  6966. }
  6967. throw error;
  6968. }
  6969. }
  6970. checkExpressionErrors(refExpressionErrors, andThrow) {
  6971. if (!refExpressionErrors) return false;
  6972. const {
  6973. shorthandAssignLoc,
  6974. doubleProtoLoc,
  6975. privateKeyLoc,
  6976. optionalParametersLoc,
  6977. voidPatternLoc
  6978. } = refExpressionErrors;
  6979. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
  6980. if (!andThrow) {
  6981. return hasErrors;
  6982. }
  6983. if (shorthandAssignLoc != null) {
  6984. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  6985. }
  6986. if (doubleProtoLoc != null) {
  6987. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  6988. }
  6989. if (privateKeyLoc != null) {
  6990. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  6991. }
  6992. if (optionalParametersLoc != null) {
  6993. this.unexpected(optionalParametersLoc);
  6994. }
  6995. if (voidPatternLoc != null) {
  6996. this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
  6997. }
  6998. }
  6999. isLiteralPropertyName() {
  7000. return tokenIsLiteralPropertyName(this.state.type);
  7001. }
  7002. isPrivateName(node) {
  7003. return node.type === "PrivateName";
  7004. }
  7005. getPrivateNameSV(node) {
  7006. return node.id.name;
  7007. }
  7008. hasPropertyAsPrivateName(node) {
  7009. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  7010. }
  7011. isObjectProperty(node) {
  7012. return node.type === "ObjectProperty";
  7013. }
  7014. isObjectMethod(node) {
  7015. return node.type === "ObjectMethod";
  7016. }
  7017. initializeScopes(inModule = this.options.sourceType === "module") {
  7018. const oldLabels = this.state.labels;
  7019. this.state.labels = [];
  7020. const oldExportedIdentifiers = this.exportedIdentifiers;
  7021. this.exportedIdentifiers = new Set();
  7022. const oldInModule = this.inModule;
  7023. this.inModule = inModule;
  7024. const oldScope = this.scope;
  7025. const ScopeHandler = this.getScopeHandler();
  7026. this.scope = new ScopeHandler(this, inModule);
  7027. const oldProdParam = this.prodParam;
  7028. this.prodParam = new ProductionParameterHandler();
  7029. const oldClassScope = this.classScope;
  7030. this.classScope = new ClassScopeHandler(this);
  7031. const oldExpressionScope = this.expressionScope;
  7032. this.expressionScope = new ExpressionScopeHandler(this);
  7033. return () => {
  7034. this.state.labels = oldLabels;
  7035. this.exportedIdentifiers = oldExportedIdentifiers;
  7036. this.inModule = oldInModule;
  7037. this.scope = oldScope;
  7038. this.prodParam = oldProdParam;
  7039. this.classScope = oldClassScope;
  7040. this.expressionScope = oldExpressionScope;
  7041. };
  7042. }
  7043. enterInitialScopes() {
  7044. let paramFlags = 0;
  7045. if (this.inModule || this.optionFlags & 1) {
  7046. paramFlags |= 2;
  7047. }
  7048. if (this.optionFlags & 32) {
  7049. paramFlags |= 1;
  7050. }
  7051. const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
  7052. if (isCommonJS || this.optionFlags & 2) {
  7053. paramFlags |= 4;
  7054. }
  7055. this.prodParam.enter(paramFlags);
  7056. let scopeFlags = isCommonJS ? 514 : 1;
  7057. if (this.optionFlags & 4) {
  7058. scopeFlags |= 512;
  7059. }
  7060. this.scope.enter(scopeFlags);
  7061. }
  7062. checkDestructuringPrivate(refExpressionErrors) {
  7063. const {
  7064. privateKeyLoc
  7065. } = refExpressionErrors;
  7066. if (privateKeyLoc !== null) {
  7067. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  7068. }
  7069. }
  7070. }
  7071. class ExpressionErrors {
  7072. constructor() {
  7073. this.shorthandAssignLoc = null;
  7074. this.doubleProtoLoc = null;
  7075. this.privateKeyLoc = null;
  7076. this.optionalParametersLoc = null;
  7077. this.voidPatternLoc = null;
  7078. }
  7079. }
  7080. class Node {
  7081. constructor(parser, pos, loc) {
  7082. this.type = "";
  7083. this.start = pos;
  7084. this.end = 0;
  7085. this.loc = new SourceLocation(loc);
  7086. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  7087. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  7088. }
  7089. }
  7090. const NodePrototype = Node.prototype;
  7091. NodePrototype.__clone = function () {
  7092. const newNode = new Node(undefined, this.start, this.loc.start);
  7093. const keys = Object.keys(this);
  7094. for (let i = 0, length = keys.length; i < length; i++) {
  7095. const key = keys[i];
  7096. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  7097. newNode[key] = this[key];
  7098. }
  7099. }
  7100. return newNode;
  7101. };
  7102. class NodeUtils extends UtilParser {
  7103. startNode() {
  7104. const loc = this.state.startLoc;
  7105. return new Node(this, loc.index, loc);
  7106. }
  7107. startNodeAt(loc) {
  7108. return new Node(this, loc.index, loc);
  7109. }
  7110. startNodeAtNode(type) {
  7111. return this.startNodeAt(type.loc.start);
  7112. }
  7113. finishNode(node, type) {
  7114. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  7115. }
  7116. finishNodeAt(node, type, endLoc) {
  7117. node.type = type;
  7118. node.end = endLoc.index;
  7119. node.loc.end = endLoc;
  7120. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7121. if (this.optionFlags & 4096) {
  7122. this.processComment(node);
  7123. }
  7124. return node;
  7125. }
  7126. resetStartLocation(node, startLoc) {
  7127. node.start = startLoc.index;
  7128. node.loc.start = startLoc;
  7129. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  7130. }
  7131. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  7132. node.end = endLoc.index;
  7133. node.loc.end = endLoc;
  7134. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7135. }
  7136. resetStartLocationFromNode(node, locationNode) {
  7137. this.resetStartLocation(node, locationNode.loc.start);
  7138. }
  7139. castNodeTo(node, type) {
  7140. node.type = type;
  7141. return node;
  7142. }
  7143. cloneIdentifier(node) {
  7144. const {
  7145. type,
  7146. start,
  7147. end,
  7148. loc,
  7149. range,
  7150. name
  7151. } = node;
  7152. const cloned = Object.create(NodePrototype);
  7153. cloned.type = type;
  7154. cloned.start = start;
  7155. cloned.end = end;
  7156. cloned.loc = loc;
  7157. cloned.range = range;
  7158. cloned.name = name;
  7159. if (node.extra) cloned.extra = node.extra;
  7160. return cloned;
  7161. }
  7162. cloneStringLiteral(node) {
  7163. const {
  7164. type,
  7165. start,
  7166. end,
  7167. loc,
  7168. range,
  7169. extra
  7170. } = node;
  7171. const cloned = Object.create(NodePrototype);
  7172. cloned.type = type;
  7173. cloned.start = start;
  7174. cloned.end = end;
  7175. cloned.loc = loc;
  7176. cloned.range = range;
  7177. cloned.extra = extra;
  7178. cloned.value = node.value;
  7179. return cloned;
  7180. }
  7181. }
  7182. const unwrapParenthesizedExpression = node => {
  7183. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7184. };
  7185. class LValParser extends NodeUtils {
  7186. toAssignable(node, isLHS = false) {
  7187. var _node$extra, _node$extra3;
  7188. let parenthesized = undefined;
  7189. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7190. parenthesized = unwrapParenthesizedExpression(node);
  7191. if (isLHS) {
  7192. if (parenthesized.type === "Identifier") {
  7193. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7194. } else if (parenthesized.type !== "CallExpression" && parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7195. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7196. }
  7197. } else {
  7198. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7199. }
  7200. }
  7201. switch (node.type) {
  7202. case "Identifier":
  7203. case "ObjectPattern":
  7204. case "ArrayPattern":
  7205. case "AssignmentPattern":
  7206. case "RestElement":
  7207. case "VoidPattern":
  7208. break;
  7209. case "ObjectExpression":
  7210. this.castNodeTo(node, "ObjectPattern");
  7211. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7212. var _node$extra2;
  7213. const prop = node.properties[i];
  7214. const isLast = i === last;
  7215. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7216. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7217. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7218. }
  7219. }
  7220. break;
  7221. case "ObjectProperty":
  7222. {
  7223. const {
  7224. key,
  7225. value
  7226. } = node;
  7227. if (this.isPrivateName(key)) {
  7228. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7229. }
  7230. this.toAssignable(value, isLHS);
  7231. break;
  7232. }
  7233. case "SpreadElement":
  7234. {
  7235. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7236. }
  7237. case "ArrayExpression":
  7238. this.castNodeTo(node, "ArrayPattern");
  7239. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7240. break;
  7241. case "AssignmentExpression":
  7242. if (node.operator !== "=") {
  7243. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7244. }
  7245. this.castNodeTo(node, "AssignmentPattern");
  7246. delete node.operator;
  7247. if (node.left.type === "VoidPattern") {
  7248. this.raise(Errors.VoidPatternInitializer, node.left);
  7249. }
  7250. this.toAssignable(node.left, isLHS);
  7251. break;
  7252. case "ParenthesizedExpression":
  7253. this.toAssignable(parenthesized, isLHS);
  7254. break;
  7255. }
  7256. }
  7257. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7258. if (prop.type === "ObjectMethod") {
  7259. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7260. } else if (prop.type === "SpreadElement") {
  7261. this.castNodeTo(prop, "RestElement");
  7262. const arg = prop.argument;
  7263. this.checkToRestConversion(arg, false);
  7264. this.toAssignable(arg, isLHS);
  7265. if (!isLast) {
  7266. this.raise(Errors.RestTrailingComma, prop);
  7267. }
  7268. } else {
  7269. this.toAssignable(prop, isLHS);
  7270. }
  7271. }
  7272. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7273. const end = exprList.length - 1;
  7274. for (let i = 0; i <= end; i++) {
  7275. const elt = exprList[i];
  7276. if (!elt) continue;
  7277. this.toAssignableListItem(exprList, i, isLHS);
  7278. if (elt.type === "RestElement") {
  7279. if (i < end) {
  7280. this.raise(Errors.RestTrailingComma, elt);
  7281. } else if (trailingCommaLoc) {
  7282. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7283. }
  7284. }
  7285. }
  7286. }
  7287. toAssignableListItem(exprList, index, isLHS) {
  7288. const node = exprList[index];
  7289. if (node.type === "SpreadElement") {
  7290. this.castNodeTo(node, "RestElement");
  7291. const arg = node.argument;
  7292. this.checkToRestConversion(arg, true);
  7293. this.toAssignable(arg, isLHS);
  7294. } else {
  7295. this.toAssignable(node, isLHS);
  7296. }
  7297. }
  7298. isAssignable(node, isBinding) {
  7299. switch (node.type) {
  7300. case "Identifier":
  7301. case "ObjectPattern":
  7302. case "ArrayPattern":
  7303. case "AssignmentPattern":
  7304. case "RestElement":
  7305. case "VoidPattern":
  7306. return true;
  7307. case "ObjectExpression":
  7308. {
  7309. const last = node.properties.length - 1;
  7310. return node.properties.every((prop, i) => {
  7311. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7312. });
  7313. }
  7314. case "ObjectProperty":
  7315. return this.isAssignable(node.value);
  7316. case "SpreadElement":
  7317. return this.isAssignable(node.argument);
  7318. case "ArrayExpression":
  7319. return node.elements.every(element => element === null || this.isAssignable(element));
  7320. case "AssignmentExpression":
  7321. return node.operator === "=";
  7322. case "ParenthesizedExpression":
  7323. return this.isAssignable(node.expression);
  7324. case "MemberExpression":
  7325. case "OptionalMemberExpression":
  7326. return !isBinding;
  7327. default:
  7328. return false;
  7329. }
  7330. }
  7331. toReferencedList(exprList, isParenthesizedExpr) {
  7332. return exprList;
  7333. }
  7334. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7335. this.toReferencedList(exprList, isParenthesizedExpr);
  7336. for (const expr of exprList) {
  7337. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7338. this.toReferencedListDeep(expr.elements);
  7339. }
  7340. }
  7341. }
  7342. parseSpread(refExpressionErrors) {
  7343. const node = this.startNode();
  7344. this.next();
  7345. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7346. return this.finishNode(node, "SpreadElement");
  7347. }
  7348. parseRestBinding() {
  7349. const node = this.startNode();
  7350. this.next();
  7351. const argument = this.parseBindingAtom();
  7352. if (argument.type === "VoidPattern") {
  7353. this.raise(Errors.UnexpectedVoidPattern, argument);
  7354. }
  7355. node.argument = argument;
  7356. return this.finishNode(node, "RestElement");
  7357. }
  7358. parseBindingAtom() {
  7359. switch (this.state.type) {
  7360. case 0:
  7361. {
  7362. const node = this.startNode();
  7363. this.next();
  7364. node.elements = this.parseBindingList(3, 93, 1);
  7365. return this.finishNode(node, "ArrayPattern");
  7366. }
  7367. case 5:
  7368. return this.parseObjectLike(8, true);
  7369. case 88:
  7370. return this.parseVoidPattern(null);
  7371. }
  7372. return this.parseIdentifier();
  7373. }
  7374. parseBindingList(close, closeCharCode, flags) {
  7375. const allowEmpty = flags & 1;
  7376. const elts = [];
  7377. let first = true;
  7378. while (!this.eat(close)) {
  7379. if (first) {
  7380. first = false;
  7381. } else {
  7382. this.expect(12);
  7383. }
  7384. if (allowEmpty && this.match(12)) {
  7385. elts.push(null);
  7386. } else if (this.eat(close)) {
  7387. break;
  7388. } else if (this.match(21)) {
  7389. let rest = this.parseRestBinding();
  7390. if (this.hasPlugin("flow") || flags & 2) {
  7391. rest = this.parseFunctionParamType(rest);
  7392. }
  7393. elts.push(rest);
  7394. if (!this.checkCommaAfterRest(closeCharCode)) {
  7395. this.expect(close);
  7396. break;
  7397. }
  7398. } else {
  7399. const decorators = [];
  7400. if (flags & 2) {
  7401. if (this.match(26) && this.hasPlugin("decorators")) {
  7402. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7403. }
  7404. while (this.match(26)) {
  7405. decorators.push(this.parseDecorator());
  7406. }
  7407. }
  7408. elts.push(this.parseBindingElement(flags, decorators));
  7409. }
  7410. }
  7411. return elts;
  7412. }
  7413. parseBindingRestProperty(prop) {
  7414. this.next();
  7415. if (this.hasPlugin("discardBinding") && this.match(88)) {
  7416. prop.argument = this.parseVoidPattern(null);
  7417. this.raise(Errors.UnexpectedVoidPattern, prop.argument);
  7418. } else {
  7419. prop.argument = this.parseIdentifier();
  7420. }
  7421. this.checkCommaAfterRest(125);
  7422. return this.finishNode(prop, "RestElement");
  7423. }
  7424. parseBindingProperty() {
  7425. const {
  7426. type,
  7427. startLoc
  7428. } = this.state;
  7429. if (type === 21) {
  7430. return this.parseBindingRestProperty(this.startNode());
  7431. }
  7432. const prop = this.startNode();
  7433. if (type === 139) {
  7434. this.expectPlugin("destructuringPrivate", startLoc);
  7435. this.classScope.usePrivateName(this.state.value, startLoc);
  7436. prop.key = this.parsePrivateName();
  7437. } else {
  7438. this.parsePropertyName(prop);
  7439. }
  7440. prop.method = false;
  7441. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7442. }
  7443. parseBindingElement(flags, decorators) {
  7444. const left = this.parseMaybeDefault();
  7445. if (this.hasPlugin("flow") || flags & 2) {
  7446. this.parseFunctionParamType(left);
  7447. }
  7448. if (decorators.length) {
  7449. left.decorators = decorators;
  7450. this.resetStartLocationFromNode(left, decorators[0]);
  7451. }
  7452. const elt = this.parseMaybeDefault(left.loc.start, left);
  7453. return elt;
  7454. }
  7455. parseFunctionParamType(param) {
  7456. return param;
  7457. }
  7458. parseMaybeDefault(startLoc, left) {
  7459. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  7460. left = left != null ? left : this.parseBindingAtom();
  7461. if (!this.eat(29)) return left;
  7462. const node = this.startNodeAt(startLoc);
  7463. if (left.type === "VoidPattern") {
  7464. this.raise(Errors.VoidPatternInitializer, left);
  7465. }
  7466. node.left = left;
  7467. node.right = this.parseMaybeAssignAllowIn();
  7468. return this.finishNode(node, "AssignmentPattern");
  7469. }
  7470. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  7471. switch (type) {
  7472. case "AssignmentPattern":
  7473. return "left";
  7474. case "RestElement":
  7475. return "argument";
  7476. case "ObjectProperty":
  7477. return "value";
  7478. case "ParenthesizedExpression":
  7479. return "expression";
  7480. case "ArrayPattern":
  7481. return "elements";
  7482. case "ObjectPattern":
  7483. return "properties";
  7484. case "VoidPattern":
  7485. return true;
  7486. case "CallExpression":
  7487. if (!disallowCallExpression && !this.state.strict && this.optionFlags & 8192) {
  7488. return true;
  7489. }
  7490. }
  7491. return false;
  7492. }
  7493. isOptionalMemberExpression(expression) {
  7494. return expression.type === "OptionalMemberExpression";
  7495. }
  7496. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false, disallowCallExpression = false) {
  7497. var _expression$extra;
  7498. const type = expression.type;
  7499. if (this.isObjectMethod(expression)) return;
  7500. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7501. if (isOptionalMemberExpression || type === "MemberExpression") {
  7502. if (isOptionalMemberExpression) {
  7503. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7504. if (ancestor.type !== "AssignmentExpression") {
  7505. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7506. ancestor
  7507. });
  7508. }
  7509. }
  7510. if (binding !== 64) {
  7511. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7512. }
  7513. return;
  7514. }
  7515. if (type === "Identifier") {
  7516. this.checkIdentifier(expression, binding, strictModeChanged);
  7517. const {
  7518. name
  7519. } = expression;
  7520. if (checkClashes) {
  7521. if (checkClashes.has(name)) {
  7522. this.raise(Errors.ParamDupe, expression);
  7523. } else {
  7524. checkClashes.add(name);
  7525. }
  7526. }
  7527. return;
  7528. } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
  7529. this.raise(Errors.VoidPatternCatchClauseParam, expression);
  7530. }
  7531. const unwrappedExpression = unwrapParenthesizedExpression(expression);
  7532. disallowCallExpression || (disallowCallExpression = unwrappedExpression.type === "CallExpression" && (unwrappedExpression.callee.type === "Import" || unwrappedExpression.callee.type === "Super"));
  7533. const validity = this.isValidLVal(type, disallowCallExpression, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7534. if (validity === true) return;
  7535. if (validity === false) {
  7536. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7537. this.raise(ParseErrorClass, expression, {
  7538. ancestor
  7539. });
  7540. return;
  7541. }
  7542. let key, isParenthesizedExpression;
  7543. if (typeof validity === "string") {
  7544. key = validity;
  7545. isParenthesizedExpression = type === "ParenthesizedExpression";
  7546. } else {
  7547. [key, isParenthesizedExpression] = validity;
  7548. }
  7549. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7550. type
  7551. } : ancestor;
  7552. const val = expression[key];
  7553. if (Array.isArray(val)) {
  7554. for (const child of val) {
  7555. if (child) {
  7556. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, true);
  7557. }
  7558. }
  7559. } else if (val) {
  7560. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, disallowCallExpression);
  7561. }
  7562. }
  7563. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7564. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7565. if (bindingType === 64) {
  7566. this.raise(Errors.StrictEvalArguments, at, {
  7567. referenceName: at.name
  7568. });
  7569. } else {
  7570. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  7571. bindingName: at.name
  7572. });
  7573. }
  7574. }
  7575. if (bindingType & 8192 && at.name === "let") {
  7576. this.raise(Errors.LetInLexicalBinding, at);
  7577. }
  7578. if (!(bindingType & 64)) {
  7579. this.declareNameFromIdentifier(at, bindingType);
  7580. }
  7581. }
  7582. declareNameFromIdentifier(identifier, binding) {
  7583. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7584. }
  7585. checkToRestConversion(node, allowPattern) {
  7586. switch (node.type) {
  7587. case "ParenthesizedExpression":
  7588. this.checkToRestConversion(node.expression, allowPattern);
  7589. break;
  7590. case "Identifier":
  7591. case "MemberExpression":
  7592. break;
  7593. case "ArrayExpression":
  7594. case "ObjectExpression":
  7595. if (allowPattern) break;
  7596. default:
  7597. this.raise(Errors.InvalidRestAssignmentPattern, node);
  7598. }
  7599. }
  7600. checkCommaAfterRest(close) {
  7601. if (!this.match(12)) {
  7602. return false;
  7603. }
  7604. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  7605. return true;
  7606. }
  7607. }
  7608. const keywordAndTSRelationalOperator = /in(?:stanceof)?|as|satisfies/y;
  7609. function nonNull(x) {
  7610. if (x == null) {
  7611. throw new Error(`Unexpected ${x} value.`);
  7612. }
  7613. return x;
  7614. }
  7615. function assert(x) {
  7616. if (!x) {
  7617. throw new Error("Assert fail");
  7618. }
  7619. }
  7620. const TSErrors = ParseErrorEnum`typescript`({
  7621. AbstractMethodHasImplementation: ({
  7622. methodName
  7623. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7624. AbstractPropertyHasInitializer: ({
  7625. propertyName
  7626. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7627. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7628. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7629. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7630. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7631. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7632. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7633. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7634. DeclareAccessor: ({
  7635. kind
  7636. }) => `'declare' is not allowed in ${kind}ters.`,
  7637. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7638. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7639. DuplicateAccessibilityModifier: ({
  7640. modifier
  7641. }) => `Accessibility modifier already seen: '${modifier}'.`,
  7642. DuplicateModifier: ({
  7643. modifier
  7644. }) => `Duplicate modifier: '${modifier}'.`,
  7645. EmptyHeritageClauseType: ({
  7646. token
  7647. }) => `'${token}' list cannot be empty.`,
  7648. EmptyTypeArguments: "Type argument list cannot be empty.",
  7649. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7650. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7651. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7652. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7653. IncompatibleModifiers: ({
  7654. modifiers
  7655. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7656. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7657. IndexSignatureHasAccessibility: ({
  7658. modifier
  7659. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7660. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7661. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7662. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7663. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7664. InvalidHeritageClauseType: ({
  7665. token
  7666. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  7667. InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
  7668. InvalidModifierOnTypeMember: ({
  7669. modifier
  7670. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7671. InvalidModifierOnTypeParameter: ({
  7672. modifier
  7673. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7674. InvalidModifierOnTypeParameterPositions: ({
  7675. modifier
  7676. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7677. InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
  7678. InvalidModifiersOrder: ({
  7679. orderedModifiers
  7680. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7681. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7682. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7683. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7684. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7685. NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7686. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7687. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7688. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7689. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7690. PrivateElementHasAccessibility: ({
  7691. modifier
  7692. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7693. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7694. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7695. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7696. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7697. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7698. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7699. SingleTypeParameterWithoutTrailingComma: ({
  7700. typeParameterName
  7701. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7702. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7703. 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?`).",
  7704. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7705. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7706. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7707. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7708. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7709. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7710. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7711. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7712. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7713. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7714. UnsupportedSignatureParameterKind: ({
  7715. type
  7716. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
  7717. UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
  7718. });
  7719. function keywordTypeFromName(value) {
  7720. switch (value) {
  7721. case "any":
  7722. return "TSAnyKeyword";
  7723. case "boolean":
  7724. return "TSBooleanKeyword";
  7725. case "bigint":
  7726. return "TSBigIntKeyword";
  7727. case "never":
  7728. return "TSNeverKeyword";
  7729. case "number":
  7730. return "TSNumberKeyword";
  7731. case "object":
  7732. return "TSObjectKeyword";
  7733. case "string":
  7734. return "TSStringKeyword";
  7735. case "symbol":
  7736. return "TSSymbolKeyword";
  7737. case "undefined":
  7738. return "TSUndefinedKeyword";
  7739. case "unknown":
  7740. return "TSUnknownKeyword";
  7741. default:
  7742. return undefined;
  7743. }
  7744. }
  7745. function tsIsAccessModifier(modifier) {
  7746. return modifier === "private" || modifier === "public" || modifier === "protected";
  7747. }
  7748. function tsIsVarianceAnnotations(modifier) {
  7749. return modifier === "in" || modifier === "out";
  7750. }
  7751. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7752. constructor(...args) {
  7753. super(...args);
  7754. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7755. allowedModifiers: ["in", "out"],
  7756. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7757. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7758. });
  7759. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7760. allowedModifiers: ["const"],
  7761. disallowedModifiers: ["in", "out"],
  7762. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7763. });
  7764. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7765. allowedModifiers: ["in", "out", "const"],
  7766. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7767. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7768. });
  7769. }
  7770. getScopeHandler() {
  7771. return TypeScriptScopeHandler;
  7772. }
  7773. tsIsIdentifier() {
  7774. return tokenIsIdentifier(this.state.type);
  7775. }
  7776. tsTokenCanFollowModifier() {
  7777. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  7778. }
  7779. tsNextTokenOnSameLineAndCanFollowModifier() {
  7780. this.next();
  7781. if (this.hasPrecedingLineBreak()) {
  7782. return false;
  7783. }
  7784. return this.tsTokenCanFollowModifier();
  7785. }
  7786. tsNextTokenCanFollowModifier() {
  7787. if (this.match(106)) {
  7788. this.next();
  7789. return this.tsTokenCanFollowModifier();
  7790. }
  7791. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  7792. }
  7793. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
  7794. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7795. return undefined;
  7796. }
  7797. const modifier = this.state.value;
  7798. if (allowedModifiers.includes(modifier)) {
  7799. if (hasSeenStaticModifier && this.match(106)) {
  7800. return undefined;
  7801. }
  7802. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7803. return undefined;
  7804. }
  7805. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7806. return modifier;
  7807. }
  7808. }
  7809. return undefined;
  7810. }
  7811. tsParseModifiers({
  7812. allowedModifiers,
  7813. disallowedModifiers,
  7814. stopOnStartOfClassStaticBlock,
  7815. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7816. }, modified) {
  7817. const enforceOrder = (loc, modifier, before, after) => {
  7818. if (modifier === before && modified[after]) {
  7819. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7820. orderedModifiers: [before, after]
  7821. });
  7822. }
  7823. };
  7824. const incompatible = (loc, modifier, mod1, mod2) => {
  7825. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7826. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7827. modifiers: [mod1, mod2]
  7828. });
  7829. }
  7830. };
  7831. for (;;) {
  7832. const {
  7833. startLoc
  7834. } = this.state;
  7835. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
  7836. if (!modifier) break;
  7837. if (tsIsAccessModifier(modifier)) {
  7838. if (modified.accessibility) {
  7839. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7840. modifier
  7841. });
  7842. } else {
  7843. enforceOrder(startLoc, modifier, modifier, "override");
  7844. enforceOrder(startLoc, modifier, modifier, "static");
  7845. enforceOrder(startLoc, modifier, modifier, "readonly");
  7846. modified.accessibility = modifier;
  7847. }
  7848. } else if (tsIsVarianceAnnotations(modifier)) {
  7849. if (modified[modifier]) {
  7850. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7851. modifier
  7852. });
  7853. }
  7854. modified[modifier] = true;
  7855. enforceOrder(startLoc, modifier, "in", "out");
  7856. } else {
  7857. if (hasOwnProperty.call(modified, modifier)) {
  7858. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7859. modifier
  7860. });
  7861. } else {
  7862. enforceOrder(startLoc, modifier, "static", "readonly");
  7863. enforceOrder(startLoc, modifier, "static", "override");
  7864. enforceOrder(startLoc, modifier, "override", "readonly");
  7865. enforceOrder(startLoc, modifier, "abstract", "override");
  7866. incompatible(startLoc, modifier, "declare", "override");
  7867. incompatible(startLoc, modifier, "static", "abstract");
  7868. }
  7869. modified[modifier] = true;
  7870. }
  7871. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7872. this.raise(errorTemplate, startLoc, {
  7873. modifier
  7874. });
  7875. }
  7876. }
  7877. }
  7878. tsIsListTerminator(kind) {
  7879. switch (kind) {
  7880. case "EnumMembers":
  7881. case "TypeMembers":
  7882. return this.match(8);
  7883. case "HeritageClauseElement":
  7884. return this.match(5);
  7885. case "TupleElementTypes":
  7886. return this.match(3);
  7887. case "TypeParametersOrArguments":
  7888. return this.match(48);
  7889. }
  7890. }
  7891. tsParseList(kind, parseElement) {
  7892. const result = [];
  7893. while (!this.tsIsListTerminator(kind)) {
  7894. result.push(parseElement());
  7895. }
  7896. return result;
  7897. }
  7898. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7899. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7900. }
  7901. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7902. const result = [];
  7903. let trailingCommaPos = -1;
  7904. for (;;) {
  7905. if (this.tsIsListTerminator(kind)) {
  7906. break;
  7907. }
  7908. trailingCommaPos = -1;
  7909. const element = parseElement();
  7910. if (element == null) {
  7911. return undefined;
  7912. }
  7913. result.push(element);
  7914. if (this.eat(12)) {
  7915. trailingCommaPos = this.state.lastTokStartLoc.index;
  7916. continue;
  7917. }
  7918. if (this.tsIsListTerminator(kind)) {
  7919. break;
  7920. }
  7921. if (expectSuccess) {
  7922. this.expect(12);
  7923. }
  7924. return undefined;
  7925. }
  7926. if (refTrailingCommaPos) {
  7927. refTrailingCommaPos.value = trailingCommaPos;
  7928. }
  7929. return result;
  7930. }
  7931. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7932. if (!skipFirstToken) {
  7933. if (bracket) {
  7934. this.expect(0);
  7935. } else {
  7936. this.expect(47);
  7937. }
  7938. }
  7939. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7940. if (bracket) {
  7941. this.expect(3);
  7942. } else {
  7943. this.expect(48);
  7944. }
  7945. return result;
  7946. }
  7947. tsParseImportType() {
  7948. const node = this.startNode();
  7949. this.expect(83);
  7950. this.expect(10);
  7951. if (!this.match(134)) {
  7952. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7953. node.argument = super.parseExprAtom();
  7954. } else {
  7955. node.argument = this.parseStringLiteral(this.state.value);
  7956. }
  7957. if (this.eat(12)) {
  7958. node.options = this.tsParseImportTypeOptions();
  7959. } else {
  7960. node.options = null;
  7961. }
  7962. this.expect(11);
  7963. if (this.eat(16)) {
  7964. node.qualifier = this.tsParseEntityName(1 | 2);
  7965. }
  7966. if (this.match(47)) {
  7967. node.typeParameters = this.tsParseTypeArguments();
  7968. }
  7969. return this.finishNode(node, "TSImportType");
  7970. }
  7971. tsParseImportTypeOptions() {
  7972. const node = this.startNode();
  7973. this.expect(5);
  7974. const withProperty = this.startNode();
  7975. if (this.isContextual(76)) {
  7976. withProperty.method = false;
  7977. withProperty.key = this.parseIdentifier(true);
  7978. withProperty.computed = false;
  7979. withProperty.shorthand = false;
  7980. } else {
  7981. this.unexpected(null, 76);
  7982. }
  7983. this.expect(14);
  7984. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  7985. node.properties = [this.finishObjectProperty(withProperty)];
  7986. this.eat(12);
  7987. this.expect(8);
  7988. return this.finishNode(node, "ObjectExpression");
  7989. }
  7990. tsParseImportTypeWithPropertyValue() {
  7991. const node = this.startNode();
  7992. const properties = [];
  7993. this.expect(5);
  7994. while (!this.match(8)) {
  7995. const type = this.state.type;
  7996. if (tokenIsIdentifier(type) || type === 134) {
  7997. properties.push(super.parsePropertyDefinition(null));
  7998. } else {
  7999. this.unexpected();
  8000. }
  8001. this.eat(12);
  8002. }
  8003. node.properties = properties;
  8004. this.next();
  8005. return this.finishNode(node, "ObjectExpression");
  8006. }
  8007. tsParseEntityName(flags) {
  8008. let entity;
  8009. if (flags & 1 && this.match(78)) {
  8010. if (flags & 2) {
  8011. entity = this.parseIdentifier(true);
  8012. } else {
  8013. const node = this.startNode();
  8014. this.next();
  8015. entity = this.finishNode(node, "ThisExpression");
  8016. }
  8017. } else {
  8018. entity = this.parseIdentifier(!!(flags & 1));
  8019. }
  8020. while (this.eat(16)) {
  8021. const node = this.startNodeAtNode(entity);
  8022. node.left = entity;
  8023. node.right = this.parseIdentifier(!!(flags & 1));
  8024. entity = this.finishNode(node, "TSQualifiedName");
  8025. }
  8026. return entity;
  8027. }
  8028. tsParseTypeReference() {
  8029. const node = this.startNode();
  8030. node.typeName = this.tsParseEntityName(1);
  8031. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8032. node.typeParameters = this.tsParseTypeArguments();
  8033. }
  8034. return this.finishNode(node, "TSTypeReference");
  8035. }
  8036. tsParseThisTypePredicate(lhs) {
  8037. this.next();
  8038. const node = this.startNodeAtNode(lhs);
  8039. node.parameterName = lhs;
  8040. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  8041. node.asserts = false;
  8042. return this.finishNode(node, "TSTypePredicate");
  8043. }
  8044. tsParseThisTypeNode() {
  8045. const node = this.startNode();
  8046. this.next();
  8047. return this.finishNode(node, "TSThisType");
  8048. }
  8049. tsParseTypeQuery() {
  8050. const node = this.startNode();
  8051. this.expect(87);
  8052. if (this.match(83)) {
  8053. node.exprName = this.tsParseImportType();
  8054. } else {
  8055. node.exprName = this.tsParseEntityName(1 | 2);
  8056. }
  8057. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8058. node.typeParameters = this.tsParseTypeArguments();
  8059. }
  8060. return this.finishNode(node, "TSTypeQuery");
  8061. }
  8062. tsParseTypeParameter(parseModifiers) {
  8063. const node = this.startNode();
  8064. parseModifiers(node);
  8065. node.name = this.tsParseTypeParameterName();
  8066. node.constraint = this.tsEatThenParseType(81);
  8067. node.default = this.tsEatThenParseType(29);
  8068. return this.finishNode(node, "TSTypeParameter");
  8069. }
  8070. tsTryParseTypeParameters(parseModifiers) {
  8071. if (this.match(47)) {
  8072. return this.tsParseTypeParameters(parseModifiers);
  8073. }
  8074. }
  8075. tsParseTypeParameters(parseModifiers) {
  8076. const node = this.startNode();
  8077. if (this.match(47) || this.match(143)) {
  8078. this.next();
  8079. } else {
  8080. this.unexpected();
  8081. }
  8082. const refTrailingCommaPos = {
  8083. value: -1
  8084. };
  8085. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  8086. if (node.params.length === 0) {
  8087. this.raise(TSErrors.EmptyTypeParameters, node);
  8088. }
  8089. if (refTrailingCommaPos.value !== -1) {
  8090. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  8091. }
  8092. return this.finishNode(node, "TSTypeParameterDeclaration");
  8093. }
  8094. tsFillSignature(returnToken, signature) {
  8095. const returnTokenRequired = returnToken === 19;
  8096. const paramsKey = "parameters";
  8097. const returnTypeKey = "typeAnnotation";
  8098. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  8099. this.expect(10);
  8100. signature[paramsKey] = this.tsParseBindingListForSignature();
  8101. if (returnTokenRequired) {
  8102. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8103. } else if (this.match(returnToken)) {
  8104. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8105. }
  8106. }
  8107. tsParseBindingListForSignature() {
  8108. const list = super.parseBindingList(11, 41, 2);
  8109. for (const pattern of list) {
  8110. const {
  8111. type
  8112. } = pattern;
  8113. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  8114. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  8115. type
  8116. });
  8117. }
  8118. }
  8119. return list;
  8120. }
  8121. tsParseTypeMemberSemicolon() {
  8122. if (!this.eat(12) && !this.isLineTerminator()) {
  8123. this.expect(13);
  8124. }
  8125. }
  8126. tsParseSignatureMember(kind, node) {
  8127. this.tsFillSignature(14, node);
  8128. this.tsParseTypeMemberSemicolon();
  8129. return this.finishNode(node, kind);
  8130. }
  8131. tsIsUnambiguouslyIndexSignature() {
  8132. this.next();
  8133. if (tokenIsIdentifier(this.state.type)) {
  8134. this.next();
  8135. return this.match(14);
  8136. }
  8137. return false;
  8138. }
  8139. tsTryParseIndexSignature(node) {
  8140. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8141. return;
  8142. }
  8143. this.expect(0);
  8144. const id = this.parseIdentifier();
  8145. id.typeAnnotation = this.tsParseTypeAnnotation();
  8146. this.resetEndLocation(id);
  8147. this.expect(3);
  8148. node.parameters = [id];
  8149. const type = this.tsTryParseTypeAnnotation();
  8150. if (type) node.typeAnnotation = type;
  8151. this.tsParseTypeMemberSemicolon();
  8152. return this.finishNode(node, "TSIndexSignature");
  8153. }
  8154. tsParsePropertyOrMethodSignature(node, readonly) {
  8155. if (this.eat(17)) node.optional = true;
  8156. if (this.match(10) || this.match(47)) {
  8157. if (readonly) {
  8158. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  8159. }
  8160. const method = node;
  8161. if (method.kind && this.match(47)) {
  8162. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  8163. }
  8164. this.tsFillSignature(14, method);
  8165. this.tsParseTypeMemberSemicolon();
  8166. const paramsKey = "parameters";
  8167. const returnTypeKey = "typeAnnotation";
  8168. if (method.kind === "get") {
  8169. if (method[paramsKey].length > 0) {
  8170. this.raise(Errors.BadGetterArity, this.state.curPosition());
  8171. if (this.isThisParam(method[paramsKey][0])) {
  8172. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8173. }
  8174. }
  8175. } else if (method.kind === "set") {
  8176. if (method[paramsKey].length !== 1) {
  8177. this.raise(Errors.BadSetterArity, this.state.curPosition());
  8178. } else {
  8179. const firstParameter = method[paramsKey][0];
  8180. if (this.isThisParam(firstParameter)) {
  8181. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8182. }
  8183. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8184. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  8185. }
  8186. if (firstParameter.type === "RestElement") {
  8187. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  8188. }
  8189. }
  8190. if (method[returnTypeKey]) {
  8191. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  8192. }
  8193. } else {
  8194. method.kind = "method";
  8195. }
  8196. return this.finishNode(method, "TSMethodSignature");
  8197. } else {
  8198. const property = node;
  8199. if (readonly) property.readonly = true;
  8200. const type = this.tsTryParseTypeAnnotation();
  8201. if (type) property.typeAnnotation = type;
  8202. this.tsParseTypeMemberSemicolon();
  8203. return this.finishNode(property, "TSPropertySignature");
  8204. }
  8205. }
  8206. tsParseTypeMember() {
  8207. const node = this.startNode();
  8208. if (this.match(10) || this.match(47)) {
  8209. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8210. }
  8211. if (this.match(77)) {
  8212. const id = this.startNode();
  8213. this.next();
  8214. if (this.match(10) || this.match(47)) {
  8215. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8216. } else {
  8217. node.key = this.createIdentifier(id, "new");
  8218. return this.tsParsePropertyOrMethodSignature(node, false);
  8219. }
  8220. }
  8221. this.tsParseModifiers({
  8222. allowedModifiers: ["readonly"],
  8223. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8224. }, node);
  8225. const idx = this.tsTryParseIndexSignature(node);
  8226. if (idx) {
  8227. return idx;
  8228. }
  8229. super.parsePropertyName(node);
  8230. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8231. node.kind = node.key.name;
  8232. super.parsePropertyName(node);
  8233. if (!this.match(10) && !this.match(47)) {
  8234. this.unexpected(null, 10);
  8235. }
  8236. }
  8237. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8238. }
  8239. tsParseTypeLiteral() {
  8240. const node = this.startNode();
  8241. node.members = this.tsParseObjectTypeMembers();
  8242. return this.finishNode(node, "TSTypeLiteral");
  8243. }
  8244. tsParseObjectTypeMembers() {
  8245. this.expect(5);
  8246. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8247. this.expect(8);
  8248. return members;
  8249. }
  8250. tsIsStartOfMappedType() {
  8251. this.next();
  8252. if (this.eat(53)) {
  8253. return this.isContextual(122);
  8254. }
  8255. if (this.isContextual(122)) {
  8256. this.next();
  8257. }
  8258. if (!this.match(0)) {
  8259. return false;
  8260. }
  8261. this.next();
  8262. if (!this.tsIsIdentifier()) {
  8263. return false;
  8264. }
  8265. this.next();
  8266. return this.match(58);
  8267. }
  8268. tsParseMappedType() {
  8269. const node = this.startNode();
  8270. this.expect(5);
  8271. if (this.match(53)) {
  8272. node.readonly = this.state.value;
  8273. this.next();
  8274. this.expectContextual(122);
  8275. } else if (this.eatContextual(122)) {
  8276. node.readonly = true;
  8277. }
  8278. this.expect(0);
  8279. const typeParameter = this.startNode();
  8280. typeParameter.name = this.tsParseTypeParameterName();
  8281. typeParameter.constraint = this.tsExpectThenParseType(58);
  8282. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8283. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8284. this.expect(3);
  8285. if (this.match(53)) {
  8286. node.optional = this.state.value;
  8287. this.next();
  8288. this.expect(17);
  8289. } else if (this.eat(17)) {
  8290. node.optional = true;
  8291. }
  8292. node.typeAnnotation = this.tsTryParseType();
  8293. this.semicolon();
  8294. this.expect(8);
  8295. return this.finishNode(node, "TSMappedType");
  8296. }
  8297. tsParseTupleType() {
  8298. const node = this.startNode();
  8299. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8300. let seenOptionalElement = false;
  8301. node.elementTypes.forEach(elementNode => {
  8302. const {
  8303. type
  8304. } = elementNode;
  8305. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8306. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8307. }
  8308. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8309. });
  8310. return this.finishNode(node, "TSTupleType");
  8311. }
  8312. tsParseTupleElementType() {
  8313. const restStartLoc = this.state.startLoc;
  8314. const rest = this.eat(21);
  8315. const {
  8316. startLoc
  8317. } = this.state;
  8318. let labeled;
  8319. let label;
  8320. let optional;
  8321. let type;
  8322. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8323. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8324. if (chAfterWord === 58) {
  8325. labeled = true;
  8326. optional = false;
  8327. label = this.parseIdentifier(true);
  8328. this.expect(14);
  8329. type = this.tsParseType();
  8330. } else if (chAfterWord === 63) {
  8331. optional = true;
  8332. const wordName = this.state.value;
  8333. const typeOrLabel = this.tsParseNonArrayType();
  8334. if (this.lookaheadCharCode() === 58) {
  8335. labeled = true;
  8336. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8337. this.expect(17);
  8338. this.expect(14);
  8339. type = this.tsParseType();
  8340. } else {
  8341. labeled = false;
  8342. type = typeOrLabel;
  8343. this.expect(17);
  8344. }
  8345. } else {
  8346. type = this.tsParseType();
  8347. optional = this.eat(17);
  8348. labeled = this.eat(14);
  8349. }
  8350. if (labeled) {
  8351. let labeledNode;
  8352. if (label) {
  8353. labeledNode = this.startNodeAt(startLoc);
  8354. labeledNode.optional = optional;
  8355. labeledNode.label = label;
  8356. labeledNode.elementType = type;
  8357. if (this.eat(17)) {
  8358. labeledNode.optional = true;
  8359. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8360. }
  8361. } else {
  8362. labeledNode = this.startNodeAt(startLoc);
  8363. labeledNode.optional = optional;
  8364. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8365. labeledNode.label = type;
  8366. labeledNode.elementType = this.tsParseType();
  8367. }
  8368. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8369. } else if (optional) {
  8370. const optionalTypeNode = this.startNodeAt(startLoc);
  8371. optionalTypeNode.typeAnnotation = type;
  8372. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8373. }
  8374. if (rest) {
  8375. const restNode = this.startNodeAt(restStartLoc);
  8376. restNode.typeAnnotation = type;
  8377. type = this.finishNode(restNode, "TSRestType");
  8378. }
  8379. return type;
  8380. }
  8381. tsParseParenthesizedType() {
  8382. const node = this.startNode();
  8383. this.expect(10);
  8384. node.typeAnnotation = this.tsParseType();
  8385. this.expect(11);
  8386. return this.finishNode(node, "TSParenthesizedType");
  8387. }
  8388. tsParseFunctionOrConstructorType(type, abstract) {
  8389. const node = this.startNode();
  8390. if (type === "TSConstructorType") {
  8391. node.abstract = !!abstract;
  8392. if (abstract) this.next();
  8393. this.next();
  8394. }
  8395. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8396. return this.finishNode(node, type);
  8397. }
  8398. tsParseLiteralTypeNode() {
  8399. const node = this.startNode();
  8400. switch (this.state.type) {
  8401. case 135:
  8402. case 136:
  8403. case 134:
  8404. case 85:
  8405. case 86:
  8406. node.literal = super.parseExprAtom();
  8407. break;
  8408. default:
  8409. this.unexpected();
  8410. }
  8411. return this.finishNode(node, "TSLiteralType");
  8412. }
  8413. tsParseTemplateLiteralType() {
  8414. const node = this.startNode();
  8415. node.literal = super.parseTemplate(false);
  8416. return this.finishNode(node, "TSLiteralType");
  8417. }
  8418. parseTemplateSubstitution() {
  8419. if (this.state.inType) return this.tsParseType();
  8420. return super.parseTemplateSubstitution();
  8421. }
  8422. tsParseThisTypeOrThisTypePredicate() {
  8423. const thisKeyword = this.tsParseThisTypeNode();
  8424. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8425. return this.tsParseThisTypePredicate(thisKeyword);
  8426. } else {
  8427. return thisKeyword;
  8428. }
  8429. }
  8430. tsParseNonArrayType() {
  8431. switch (this.state.type) {
  8432. case 134:
  8433. case 135:
  8434. case 136:
  8435. case 85:
  8436. case 86:
  8437. return this.tsParseLiteralTypeNode();
  8438. case 53:
  8439. if (this.state.value === "-") {
  8440. const node = this.startNode();
  8441. const nextToken = this.lookahead();
  8442. if (nextToken.type !== 135 && nextToken.type !== 136) {
  8443. this.unexpected();
  8444. }
  8445. node.literal = this.parseMaybeUnary();
  8446. return this.finishNode(node, "TSLiteralType");
  8447. }
  8448. break;
  8449. case 78:
  8450. return this.tsParseThisTypeOrThisTypePredicate();
  8451. case 87:
  8452. return this.tsParseTypeQuery();
  8453. case 83:
  8454. return this.tsParseImportType();
  8455. case 5:
  8456. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8457. case 0:
  8458. return this.tsParseTupleType();
  8459. case 10:
  8460. return this.tsParseParenthesizedType();
  8461. case 25:
  8462. case 24:
  8463. return this.tsParseTemplateLiteralType();
  8464. default:
  8465. {
  8466. const {
  8467. type
  8468. } = this.state;
  8469. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8470. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8471. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8472. const node = this.startNode();
  8473. this.next();
  8474. return this.finishNode(node, nodeType);
  8475. }
  8476. return this.tsParseTypeReference();
  8477. }
  8478. }
  8479. }
  8480. throw this.unexpected();
  8481. }
  8482. tsParseArrayTypeOrHigher() {
  8483. const {
  8484. startLoc
  8485. } = this.state;
  8486. let type = this.tsParseNonArrayType();
  8487. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8488. if (this.match(3)) {
  8489. const node = this.startNodeAt(startLoc);
  8490. node.elementType = type;
  8491. this.expect(3);
  8492. type = this.finishNode(node, "TSArrayType");
  8493. } else {
  8494. const node = this.startNodeAt(startLoc);
  8495. node.objectType = type;
  8496. node.indexType = this.tsParseType();
  8497. this.expect(3);
  8498. type = this.finishNode(node, "TSIndexedAccessType");
  8499. }
  8500. }
  8501. return type;
  8502. }
  8503. tsParseTypeOperator() {
  8504. const node = this.startNode();
  8505. const operator = this.state.value;
  8506. this.next();
  8507. node.operator = operator;
  8508. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8509. if (operator === "readonly") {
  8510. this.tsCheckTypeAnnotationForReadOnly(node);
  8511. }
  8512. return this.finishNode(node, "TSTypeOperator");
  8513. }
  8514. tsCheckTypeAnnotationForReadOnly(node) {
  8515. switch (node.typeAnnotation.type) {
  8516. case "TSTupleType":
  8517. case "TSArrayType":
  8518. return;
  8519. default:
  8520. this.raise(TSErrors.UnexpectedReadonly, node);
  8521. }
  8522. }
  8523. tsParseInferType() {
  8524. const node = this.startNode();
  8525. this.expectContextual(115);
  8526. const typeParameter = this.startNode();
  8527. typeParameter.name = this.tsParseTypeParameterName();
  8528. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8529. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8530. return this.finishNode(node, "TSInferType");
  8531. }
  8532. tsParseConstraintForInferType() {
  8533. if (this.eat(81)) {
  8534. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8535. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8536. return constraint;
  8537. }
  8538. }
  8539. }
  8540. tsParseTypeOperatorOrHigher() {
  8541. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8542. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8543. }
  8544. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8545. const node = this.startNode();
  8546. const hasLeadingOperator = this.eat(operator);
  8547. const types = [];
  8548. do {
  8549. types.push(parseConstituentType());
  8550. } while (this.eat(operator));
  8551. if (types.length === 1 && !hasLeadingOperator) {
  8552. return types[0];
  8553. }
  8554. node.types = types;
  8555. return this.finishNode(node, kind);
  8556. }
  8557. tsParseIntersectionTypeOrHigher() {
  8558. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8559. }
  8560. tsParseUnionTypeOrHigher() {
  8561. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8562. }
  8563. tsIsStartOfFunctionType() {
  8564. if (this.match(47)) {
  8565. return true;
  8566. }
  8567. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8568. }
  8569. tsSkipParameterStart() {
  8570. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8571. this.next();
  8572. return true;
  8573. }
  8574. if (this.match(5)) {
  8575. const {
  8576. errors
  8577. } = this.state;
  8578. const previousErrorCount = errors.length;
  8579. try {
  8580. this.parseObjectLike(8, true);
  8581. return errors.length === previousErrorCount;
  8582. } catch (_unused) {
  8583. return false;
  8584. }
  8585. }
  8586. if (this.match(0)) {
  8587. this.next();
  8588. const {
  8589. errors
  8590. } = this.state;
  8591. const previousErrorCount = errors.length;
  8592. try {
  8593. super.parseBindingList(3, 93, 1);
  8594. return errors.length === previousErrorCount;
  8595. } catch (_unused2) {
  8596. return false;
  8597. }
  8598. }
  8599. return false;
  8600. }
  8601. tsIsUnambiguouslyStartOfFunctionType() {
  8602. this.next();
  8603. if (this.match(11) || this.match(21)) {
  8604. return true;
  8605. }
  8606. if (this.tsSkipParameterStart()) {
  8607. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8608. return true;
  8609. }
  8610. if (this.match(11)) {
  8611. this.next();
  8612. if (this.match(19)) {
  8613. return true;
  8614. }
  8615. }
  8616. }
  8617. return false;
  8618. }
  8619. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8620. return this.tsInType(() => {
  8621. const t = this.startNode();
  8622. this.expect(returnToken);
  8623. const node = this.startNode();
  8624. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8625. if (asserts && this.match(78)) {
  8626. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8627. if (thisTypePredicate.type === "TSThisType") {
  8628. node.parameterName = thisTypePredicate;
  8629. node.asserts = true;
  8630. node.typeAnnotation = null;
  8631. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8632. } else {
  8633. this.resetStartLocationFromNode(thisTypePredicate, node);
  8634. thisTypePredicate.asserts = true;
  8635. }
  8636. t.typeAnnotation = thisTypePredicate;
  8637. return this.finishNode(t, "TSTypeAnnotation");
  8638. }
  8639. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8640. if (!typePredicateVariable) {
  8641. if (!asserts) {
  8642. return this.tsParseTypeAnnotation(false, t);
  8643. }
  8644. node.parameterName = this.parseIdentifier();
  8645. node.asserts = asserts;
  8646. node.typeAnnotation = null;
  8647. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8648. return this.finishNode(t, "TSTypeAnnotation");
  8649. }
  8650. const type = this.tsParseTypeAnnotation(false);
  8651. node.parameterName = typePredicateVariable;
  8652. node.typeAnnotation = type;
  8653. node.asserts = asserts;
  8654. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8655. return this.finishNode(t, "TSTypeAnnotation");
  8656. });
  8657. }
  8658. tsTryParseTypeOrTypePredicateAnnotation() {
  8659. if (this.match(14)) {
  8660. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8661. }
  8662. }
  8663. tsTryParseTypeAnnotation() {
  8664. if (this.match(14)) {
  8665. return this.tsParseTypeAnnotation();
  8666. }
  8667. }
  8668. tsTryParseType() {
  8669. return this.tsEatThenParseType(14);
  8670. }
  8671. tsParseTypePredicatePrefix() {
  8672. const id = this.parseIdentifier();
  8673. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8674. this.next();
  8675. return id;
  8676. }
  8677. }
  8678. tsParseTypePredicateAsserts() {
  8679. if (this.state.type !== 109) {
  8680. return false;
  8681. }
  8682. const containsEsc = this.state.containsEsc;
  8683. this.next();
  8684. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8685. return false;
  8686. }
  8687. if (containsEsc) {
  8688. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8689. reservedWord: "asserts"
  8690. });
  8691. }
  8692. return true;
  8693. }
  8694. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8695. this.tsInType(() => {
  8696. if (eatColon) this.expect(14);
  8697. t.typeAnnotation = this.tsParseType();
  8698. });
  8699. return this.finishNode(t, "TSTypeAnnotation");
  8700. }
  8701. tsParseType() {
  8702. assert(this.state.inType);
  8703. const type = this.tsParseNonConditionalType();
  8704. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8705. return type;
  8706. }
  8707. const node = this.startNodeAtNode(type);
  8708. node.checkType = type;
  8709. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8710. this.expect(17);
  8711. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8712. this.expect(14);
  8713. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8714. return this.finishNode(node, "TSConditionalType");
  8715. }
  8716. isAbstractConstructorSignature() {
  8717. return this.isContextual(124) && this.isLookaheadContextual("new");
  8718. }
  8719. tsParseNonConditionalType() {
  8720. if (this.tsIsStartOfFunctionType()) {
  8721. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8722. }
  8723. if (this.match(77)) {
  8724. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8725. } else if (this.isAbstractConstructorSignature()) {
  8726. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8727. }
  8728. return this.tsParseUnionTypeOrHigher();
  8729. }
  8730. tsParseTypeAssertion() {
  8731. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8732. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8733. }
  8734. const node = this.startNode();
  8735. node.typeAnnotation = this.tsInType(() => {
  8736. this.next();
  8737. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8738. });
  8739. this.expect(48);
  8740. node.expression = this.parseMaybeUnary();
  8741. return this.finishNode(node, "TSTypeAssertion");
  8742. }
  8743. tsParseHeritageClause(token) {
  8744. const originalStartLoc = this.state.startLoc;
  8745. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8746. const node = this.startNode();
  8747. node.expression = this.tsParseEntityName(1 | 2);
  8748. if (this.match(47)) {
  8749. node.typeParameters = this.tsParseTypeArguments();
  8750. }
  8751. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8752. });
  8753. if (!delimitedList.length) {
  8754. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8755. token
  8756. });
  8757. }
  8758. return delimitedList;
  8759. }
  8760. tsParseInterfaceDeclaration(node, properties = {}) {
  8761. if (this.hasFollowingLineBreak()) return null;
  8762. this.expectContextual(129);
  8763. if (properties.declare) node.declare = true;
  8764. if (tokenIsIdentifier(this.state.type)) {
  8765. node.id = this.parseIdentifier();
  8766. this.checkIdentifier(node.id, 130);
  8767. } else {
  8768. node.id = null;
  8769. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8770. }
  8771. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8772. if (this.eat(81)) {
  8773. node.extends = this.tsParseHeritageClause("extends");
  8774. }
  8775. const body = this.startNode();
  8776. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8777. node.body = this.finishNode(body, "TSInterfaceBody");
  8778. return this.finishNode(node, "TSInterfaceDeclaration");
  8779. }
  8780. tsParseTypeAliasDeclaration(node) {
  8781. node.id = this.parseIdentifier();
  8782. this.checkIdentifier(node.id, 2);
  8783. node.typeAnnotation = this.tsInType(() => {
  8784. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8785. this.expect(29);
  8786. if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
  8787. const node = this.startNode();
  8788. this.next();
  8789. return this.finishNode(node, "TSIntrinsicKeyword");
  8790. }
  8791. return this.tsParseType();
  8792. });
  8793. this.semicolon();
  8794. return this.finishNode(node, "TSTypeAliasDeclaration");
  8795. }
  8796. tsInTopLevelContext(cb) {
  8797. if (this.curContext() !== types.brace) {
  8798. const oldContext = this.state.context;
  8799. this.state.context = [oldContext[0]];
  8800. try {
  8801. return cb();
  8802. } finally {
  8803. this.state.context = oldContext;
  8804. }
  8805. } else {
  8806. return cb();
  8807. }
  8808. }
  8809. tsInType(cb) {
  8810. const oldInType = this.state.inType;
  8811. this.state.inType = true;
  8812. try {
  8813. return cb();
  8814. } finally {
  8815. this.state.inType = oldInType;
  8816. }
  8817. }
  8818. tsInDisallowConditionalTypesContext(cb) {
  8819. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8820. this.state.inDisallowConditionalTypesContext = true;
  8821. try {
  8822. return cb();
  8823. } finally {
  8824. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8825. }
  8826. }
  8827. tsInAllowConditionalTypesContext(cb) {
  8828. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8829. this.state.inDisallowConditionalTypesContext = false;
  8830. try {
  8831. return cb();
  8832. } finally {
  8833. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8834. }
  8835. }
  8836. tsEatThenParseType(token) {
  8837. if (this.match(token)) {
  8838. return this.tsNextThenParseType();
  8839. }
  8840. }
  8841. tsExpectThenParseType(token) {
  8842. return this.tsInType(() => {
  8843. this.expect(token);
  8844. return this.tsParseType();
  8845. });
  8846. }
  8847. tsNextThenParseType() {
  8848. return this.tsInType(() => {
  8849. this.next();
  8850. return this.tsParseType();
  8851. });
  8852. }
  8853. tsParseEnumMember() {
  8854. const node = this.startNode();
  8855. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8856. if (this.eat(29)) {
  8857. node.initializer = super.parseMaybeAssignAllowIn();
  8858. }
  8859. return this.finishNode(node, "TSEnumMember");
  8860. }
  8861. tsParseEnumDeclaration(node, properties = {}) {
  8862. if (properties.const) node.const = true;
  8863. if (properties.declare) node.declare = true;
  8864. this.expectContextual(126);
  8865. node.id = this.parseIdentifier();
  8866. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8867. this.expect(5);
  8868. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8869. this.expect(8);
  8870. return this.finishNode(node, "TSEnumDeclaration");
  8871. }
  8872. tsParseEnumBody() {
  8873. const node = this.startNode();
  8874. this.expect(5);
  8875. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8876. this.expect(8);
  8877. return this.finishNode(node, "TSEnumBody");
  8878. }
  8879. tsParseModuleBlock() {
  8880. const node = this.startNode();
  8881. this.scope.enter(0);
  8882. this.expect(5);
  8883. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8884. this.scope.exit();
  8885. return this.finishNode(node, "TSModuleBlock");
  8886. }
  8887. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8888. node.id = this.parseIdentifier();
  8889. if (!nested) {
  8890. this.checkIdentifier(node.id, 1024);
  8891. }
  8892. if (this.eat(16)) {
  8893. const inner = this.startNode();
  8894. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8895. node.body = inner;
  8896. } else {
  8897. this.scope.enter(1024);
  8898. this.prodParam.enter(0);
  8899. node.body = this.tsParseModuleBlock();
  8900. this.prodParam.exit();
  8901. this.scope.exit();
  8902. }
  8903. return this.finishNode(node, "TSModuleDeclaration");
  8904. }
  8905. tsParseAmbientExternalModuleDeclaration(node) {
  8906. if (this.isContextual(112)) {
  8907. node.kind = "global";
  8908. node.global = true;
  8909. node.id = this.parseIdentifier();
  8910. } else if (this.match(134)) {
  8911. node.kind = "module";
  8912. node.id = super.parseStringLiteral(this.state.value);
  8913. } else {
  8914. this.unexpected();
  8915. }
  8916. if (this.match(5)) {
  8917. this.scope.enter(1024);
  8918. this.prodParam.enter(0);
  8919. node.body = this.tsParseModuleBlock();
  8920. this.prodParam.exit();
  8921. this.scope.exit();
  8922. } else {
  8923. this.semicolon();
  8924. }
  8925. return this.finishNode(node, "TSModuleDeclaration");
  8926. }
  8927. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8928. node.isExport = isExport || false;
  8929. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8930. this.checkIdentifier(node.id, 4096);
  8931. this.expect(29);
  8932. const moduleReference = this.tsParseModuleReference();
  8933. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8934. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8935. }
  8936. node.moduleReference = moduleReference;
  8937. this.semicolon();
  8938. return this.finishNode(node, "TSImportEqualsDeclaration");
  8939. }
  8940. tsIsExternalModuleReference() {
  8941. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8942. }
  8943. tsParseModuleReference() {
  8944. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  8945. }
  8946. tsParseExternalModuleReference() {
  8947. const node = this.startNode();
  8948. this.expectContextual(119);
  8949. this.expect(10);
  8950. if (!this.match(134)) {
  8951. this.unexpected();
  8952. }
  8953. node.expression = super.parseExprAtom();
  8954. this.expect(11);
  8955. this.sawUnambiguousESM = true;
  8956. return this.finishNode(node, "TSExternalModuleReference");
  8957. }
  8958. tsLookAhead(f) {
  8959. const state = this.state.clone();
  8960. const res = f();
  8961. this.state = state;
  8962. return res;
  8963. }
  8964. tsTryParseAndCatch(f) {
  8965. const result = this.tryParse(abort => f() || abort());
  8966. if (result.aborted || !result.node) return;
  8967. if (result.error) this.state = result.failState;
  8968. return result.node;
  8969. }
  8970. tsTryParse(f) {
  8971. const state = this.state.clone();
  8972. const result = f();
  8973. if (result !== undefined && result !== false) {
  8974. return result;
  8975. }
  8976. this.state = state;
  8977. }
  8978. tsTryParseDeclare(node) {
  8979. if (this.isLineTerminator()) {
  8980. return;
  8981. }
  8982. const startType = this.state.type;
  8983. return this.tsInAmbientContext(() => {
  8984. switch (startType) {
  8985. case 68:
  8986. node.declare = true;
  8987. return super.parseFunctionStatement(node, false, false);
  8988. case 80:
  8989. node.declare = true;
  8990. return this.parseClass(node, true, false);
  8991. case 126:
  8992. return this.tsParseEnumDeclaration(node, {
  8993. declare: true
  8994. });
  8995. case 112:
  8996. return this.tsParseAmbientExternalModuleDeclaration(node);
  8997. case 100:
  8998. if (this.state.containsEsc) {
  8999. return;
  9000. }
  9001. case 75:
  9002. case 74:
  9003. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  9004. node.declare = true;
  9005. return this.parseVarStatement(node, this.state.value, true);
  9006. }
  9007. this.expect(75);
  9008. return this.tsParseEnumDeclaration(node, {
  9009. const: true,
  9010. declare: true
  9011. });
  9012. case 107:
  9013. if (this.isUsing()) {
  9014. this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
  9015. node.declare = true;
  9016. return this.parseVarStatement(node, "using", true);
  9017. }
  9018. break;
  9019. case 96:
  9020. if (this.isAwaitUsing()) {
  9021. this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
  9022. node.declare = true;
  9023. this.next();
  9024. return this.parseVarStatement(node, "await using", true);
  9025. }
  9026. break;
  9027. case 129:
  9028. {
  9029. const result = this.tsParseInterfaceDeclaration(node, {
  9030. declare: true
  9031. });
  9032. if (result) return result;
  9033. }
  9034. default:
  9035. if (tokenIsIdentifier(startType)) {
  9036. return this.tsParseDeclaration(node, this.state.type, true, null);
  9037. }
  9038. }
  9039. });
  9040. }
  9041. tsTryParseExportDeclaration() {
  9042. return this.tsParseDeclaration(this.startNode(), this.state.type, true, null);
  9043. }
  9044. tsParseDeclaration(node, type, next, decorators) {
  9045. switch (type) {
  9046. case 124:
  9047. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  9048. return this.tsParseAbstractDeclaration(node, decorators);
  9049. }
  9050. break;
  9051. case 127:
  9052. if (this.tsCheckLineTerminator(next)) {
  9053. if (this.match(134)) {
  9054. return this.tsParseAmbientExternalModuleDeclaration(node);
  9055. } else if (tokenIsIdentifier(this.state.type)) {
  9056. node.kind = "module";
  9057. return this.tsParseModuleOrNamespaceDeclaration(node);
  9058. }
  9059. }
  9060. break;
  9061. case 128:
  9062. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9063. node.kind = "namespace";
  9064. return this.tsParseModuleOrNamespaceDeclaration(node);
  9065. }
  9066. break;
  9067. case 130:
  9068. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9069. return this.tsParseTypeAliasDeclaration(node);
  9070. }
  9071. break;
  9072. }
  9073. }
  9074. tsCheckLineTerminator(next) {
  9075. if (next) {
  9076. if (this.hasFollowingLineBreak()) return false;
  9077. this.next();
  9078. return true;
  9079. }
  9080. return !this.isLineTerminator();
  9081. }
  9082. tsTryParseGenericAsyncArrowFunction(startLoc) {
  9083. if (!this.match(47)) return;
  9084. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9085. this.state.maybeInArrowParameters = true;
  9086. const res = this.tsTryParseAndCatch(() => {
  9087. const node = this.startNodeAt(startLoc);
  9088. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9089. super.parseFunctionParams(node);
  9090. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9091. this.expect(19);
  9092. return node;
  9093. });
  9094. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9095. if (!res) return;
  9096. return super.parseArrowExpression(res, null, true);
  9097. }
  9098. tsParseTypeArgumentsInExpression() {
  9099. if (this.reScan_lt() !== 47) return;
  9100. return this.tsParseTypeArguments();
  9101. }
  9102. tsParseTypeArguments() {
  9103. const node = this.startNode();
  9104. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  9105. this.expect(47);
  9106. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9107. }));
  9108. if (node.params.length === 0) {
  9109. this.raise(TSErrors.EmptyTypeArguments, node);
  9110. } else if (!this.state.inType && this.curContext() === types.brace) {
  9111. this.reScan_lt_gt();
  9112. }
  9113. this.expect(48);
  9114. return this.finishNode(node, "TSTypeParameterInstantiation");
  9115. }
  9116. tsIsDeclarationStart() {
  9117. return tokenIsTSDeclarationStart(this.state.type);
  9118. }
  9119. isExportDefaultSpecifier() {
  9120. if (this.tsIsDeclarationStart()) return false;
  9121. return super.isExportDefaultSpecifier();
  9122. }
  9123. parseBindingElement(flags, decorators) {
  9124. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  9125. const modified = {};
  9126. this.tsParseModifiers({
  9127. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9128. }, modified);
  9129. const accessibility = modified.accessibility;
  9130. const override = modified.override;
  9131. const readonly = modified.readonly;
  9132. if (!(flags & 4) && (accessibility || readonly || override)) {
  9133. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  9134. }
  9135. const left = this.parseMaybeDefault();
  9136. if (flags & 2) {
  9137. this.parseFunctionParamType(left);
  9138. }
  9139. const elt = this.parseMaybeDefault(left.loc.start, left);
  9140. if (accessibility || readonly || override) {
  9141. const pp = this.startNodeAt(startLoc);
  9142. if (decorators.length) {
  9143. pp.decorators = decorators;
  9144. }
  9145. if (accessibility) pp.accessibility = accessibility;
  9146. if (readonly) pp.readonly = readonly;
  9147. if (override) pp.override = override;
  9148. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9149. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  9150. }
  9151. pp.parameter = elt;
  9152. return this.finishNode(pp, "TSParameterProperty");
  9153. }
  9154. if (decorators.length) {
  9155. left.decorators = decorators;
  9156. }
  9157. return elt;
  9158. }
  9159. isSimpleParameter(node) {
  9160. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9161. }
  9162. tsDisallowOptionalPattern(node) {
  9163. for (const param of node.params) {
  9164. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9165. this.raise(TSErrors.PatternIsOptional, param);
  9166. }
  9167. }
  9168. }
  9169. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9170. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9171. this.tsDisallowOptionalPattern(node);
  9172. }
  9173. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9174. if (this.match(14)) {
  9175. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9176. }
  9177. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9178. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9179. return this.finishNode(node, bodilessType);
  9180. }
  9181. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9182. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  9183. if (node.declare) {
  9184. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9185. }
  9186. }
  9187. this.tsDisallowOptionalPattern(node);
  9188. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9189. }
  9190. registerFunctionStatementId(node) {
  9191. if (!node.body && node.id) {
  9192. this.checkIdentifier(node.id, 1024);
  9193. } else {
  9194. super.registerFunctionStatementId(node);
  9195. }
  9196. }
  9197. tsCheckForInvalidTypeCasts(items) {
  9198. items.forEach(node => {
  9199. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9200. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  9201. }
  9202. });
  9203. }
  9204. toReferencedList(exprList, isInParens) {
  9205. this.tsCheckForInvalidTypeCasts(exprList);
  9206. return exprList;
  9207. }
  9208. parseArrayLike(close, isTuple, refExpressionErrors) {
  9209. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  9210. if (node.type === "ArrayExpression") {
  9211. this.tsCheckForInvalidTypeCasts(node.elements);
  9212. }
  9213. return node;
  9214. }
  9215. parseSubscript(base, startLoc, noCalls, state) {
  9216. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9217. this.state.canStartJSXElement = false;
  9218. this.next();
  9219. const nonNullExpression = this.startNodeAt(startLoc);
  9220. nonNullExpression.expression = base;
  9221. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9222. }
  9223. let isOptionalCall = false;
  9224. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9225. if (noCalls) {
  9226. state.stop = true;
  9227. return base;
  9228. }
  9229. state.optionalChainMember = isOptionalCall = true;
  9230. this.next();
  9231. }
  9232. if (this.match(47) || this.match(51)) {
  9233. let missingParenErrorLoc;
  9234. const result = this.tsTryParseAndCatch(() => {
  9235. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9236. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9237. if (asyncArrowFn) {
  9238. state.stop = true;
  9239. return asyncArrowFn;
  9240. }
  9241. }
  9242. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9243. if (!typeArguments) return;
  9244. if (isOptionalCall && !this.match(10)) {
  9245. missingParenErrorLoc = this.state.curPosition();
  9246. return;
  9247. }
  9248. if (tokenIsTemplate(this.state.type)) {
  9249. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9250. result.typeParameters = typeArguments;
  9251. return result;
  9252. }
  9253. if (!noCalls && this.eat(10)) {
  9254. const node = this.startNodeAt(startLoc);
  9255. node.callee = base;
  9256. node.arguments = this.parseCallExpressionArguments();
  9257. this.tsCheckForInvalidTypeCasts(node.arguments);
  9258. node.typeParameters = typeArguments;
  9259. if (state.optionalChainMember) {
  9260. node.optional = isOptionalCall;
  9261. }
  9262. return this.finishCallExpression(node, state.optionalChainMember);
  9263. }
  9264. const tokenType = this.state.type;
  9265. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenType !== 93 && tokenType !== 120 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9266. return;
  9267. }
  9268. const node = this.startNodeAt(startLoc);
  9269. node.expression = base;
  9270. node.typeParameters = typeArguments;
  9271. return this.finishNode(node, "TSInstantiationExpression");
  9272. });
  9273. if (missingParenErrorLoc) {
  9274. this.unexpected(missingParenErrorLoc, 10);
  9275. }
  9276. if (result) {
  9277. if (result.type === "TSInstantiationExpression") {
  9278. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  9279. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  9280. }
  9281. if (!this.match(16) && !this.match(18)) {
  9282. result.expression = super.stopParseSubscript(base, state);
  9283. }
  9284. }
  9285. return result;
  9286. }
  9287. }
  9288. return super.parseSubscript(base, startLoc, noCalls, state);
  9289. }
  9290. parseNewCallee(node) {
  9291. var _callee$extra;
  9292. super.parseNewCallee(node);
  9293. const {
  9294. callee
  9295. } = node;
  9296. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9297. node.typeParameters = callee.typeParameters;
  9298. node.callee = callee.expression;
  9299. }
  9300. }
  9301. parseExprOp(left, leftStartLoc, minPrec) {
  9302. let isSatisfies;
  9303. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9304. const node = this.startNodeAt(leftStartLoc);
  9305. node.expression = left;
  9306. node.typeAnnotation = this.tsInType(() => {
  9307. this.next();
  9308. if (this.match(75)) {
  9309. if (isSatisfies) {
  9310. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9311. keyword: "const"
  9312. });
  9313. }
  9314. return this.tsParseTypeReference();
  9315. }
  9316. return this.tsParseType();
  9317. });
  9318. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9319. this.reScan_lt_gt();
  9320. return this.parseExprOp(node, leftStartLoc, minPrec);
  9321. }
  9322. return super.parseExprOp(left, leftStartLoc, minPrec);
  9323. }
  9324. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9325. if (!this.state.isAmbientContext) {
  9326. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9327. }
  9328. }
  9329. checkImportReflection(node) {
  9330. super.checkImportReflection(node);
  9331. if (node.module && node.importKind !== "value") {
  9332. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9333. }
  9334. }
  9335. checkDuplicateExports() {}
  9336. isPotentialImportPhase(isExport) {
  9337. if (super.isPotentialImportPhase(isExport)) return true;
  9338. if (this.isContextual(130)) {
  9339. const ch = this.lookaheadCharCode();
  9340. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9341. }
  9342. return !isExport && this.isContextual(87);
  9343. }
  9344. applyImportPhase(node, isExport, phase, loc) {
  9345. super.applyImportPhase(node, isExport, phase, loc);
  9346. if (isExport) {
  9347. node.exportKind = phase === "type" ? "type" : "value";
  9348. } else {
  9349. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9350. }
  9351. }
  9352. parseImport(node) {
  9353. if (this.match(134)) {
  9354. node.importKind = "value";
  9355. return super.parseImport(node);
  9356. }
  9357. let importNode;
  9358. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9359. node.importKind = "value";
  9360. return this.tsParseImportEqualsDeclaration(node);
  9361. } else if (this.isContextual(130)) {
  9362. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9363. if (this.lookaheadCharCode() === 61) {
  9364. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9365. } else {
  9366. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9367. }
  9368. } else {
  9369. importNode = super.parseImport(node);
  9370. }
  9371. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9372. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9373. }
  9374. return importNode;
  9375. }
  9376. parseExport(node, decorators) {
  9377. if (this.match(83)) {
  9378. const nodeImportEquals = node;
  9379. this.next();
  9380. let maybeDefaultIdentifier = null;
  9381. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9382. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9383. } else {
  9384. nodeImportEquals.importKind = "value";
  9385. }
  9386. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9387. return declaration;
  9388. } else if (this.eat(29)) {
  9389. const assign = node;
  9390. assign.expression = super.parseExpression();
  9391. this.semicolon();
  9392. this.sawUnambiguousESM = true;
  9393. return this.finishNode(assign, "TSExportAssignment");
  9394. } else if (this.eatContextual(93)) {
  9395. const decl = node;
  9396. this.expectContextual(128);
  9397. decl.id = this.parseIdentifier();
  9398. this.semicolon();
  9399. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9400. } else {
  9401. return super.parseExport(node, decorators);
  9402. }
  9403. }
  9404. isAbstractClass() {
  9405. return this.isContextual(124) && this.isLookaheadContextual("class");
  9406. }
  9407. parseExportDefaultExpression() {
  9408. if (this.isAbstractClass()) {
  9409. const cls = this.startNode();
  9410. this.next();
  9411. cls.abstract = true;
  9412. return this.parseClass(cls, true, true);
  9413. }
  9414. if (this.match(129)) {
  9415. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9416. if (result) return result;
  9417. }
  9418. return super.parseExportDefaultExpression();
  9419. }
  9420. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9421. const {
  9422. isAmbientContext
  9423. } = this.state;
  9424. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9425. if (!isAmbientContext) return declaration;
  9426. if (!node.declare && (kind === "using" || kind === "await using")) {
  9427. this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
  9428. return declaration;
  9429. }
  9430. for (const {
  9431. id,
  9432. init
  9433. } of declaration.declarations) {
  9434. if (!init) continue;
  9435. if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
  9436. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9437. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9438. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9439. }
  9440. }
  9441. return declaration;
  9442. }
  9443. parseStatementContent(flags, decorators) {
  9444. if (!this.state.containsEsc) {
  9445. switch (this.state.type) {
  9446. case 75:
  9447. {
  9448. if (this.isLookaheadContextual("enum")) {
  9449. const node = this.startNode();
  9450. this.expect(75);
  9451. return this.tsParseEnumDeclaration(node, {
  9452. const: true
  9453. });
  9454. }
  9455. break;
  9456. }
  9457. case 124:
  9458. case 125:
  9459. {
  9460. if (this.nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine()) {
  9461. const token = this.state.type;
  9462. const node = this.startNode();
  9463. this.next();
  9464. const declaration = token === 125 ? this.tsTryParseDeclare(node) : this.tsParseAbstractDeclaration(node, decorators);
  9465. if (declaration) {
  9466. if (token === 125) {
  9467. declaration.declare = true;
  9468. }
  9469. return declaration;
  9470. } else {
  9471. node.expression = this.createIdentifier(this.startNodeAt(node.loc.start), token === 125 ? "declare" : "abstract");
  9472. this.semicolon(false);
  9473. return this.finishNode(node, "ExpressionStatement");
  9474. }
  9475. }
  9476. break;
  9477. }
  9478. case 126:
  9479. return this.tsParseEnumDeclaration(this.startNode());
  9480. case 112:
  9481. {
  9482. const nextCh = this.lookaheadCharCode();
  9483. if (nextCh === 123) {
  9484. const node = this.startNode();
  9485. return this.tsParseAmbientExternalModuleDeclaration(node);
  9486. }
  9487. break;
  9488. }
  9489. case 129:
  9490. {
  9491. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9492. if (result) return result;
  9493. break;
  9494. }
  9495. case 127:
  9496. {
  9497. if (this.nextTokenIsIdentifierOrStringLiteralOnSameLine()) {
  9498. const node = this.startNode();
  9499. this.next();
  9500. return this.tsParseDeclaration(node, 127, false, decorators);
  9501. }
  9502. break;
  9503. }
  9504. case 128:
  9505. {
  9506. if (this.nextTokenIsIdentifierOnSameLine()) {
  9507. const node = this.startNode();
  9508. this.next();
  9509. return this.tsParseDeclaration(node, 128, false, decorators);
  9510. }
  9511. break;
  9512. }
  9513. case 130:
  9514. {
  9515. if (this.nextTokenIsIdentifierOnSameLine()) {
  9516. const node = this.startNode();
  9517. this.next();
  9518. return this.tsParseTypeAliasDeclaration(node);
  9519. }
  9520. break;
  9521. }
  9522. }
  9523. }
  9524. return super.parseStatementContent(flags, decorators);
  9525. }
  9526. parseAccessModifier() {
  9527. return this.tsParseModifier(["public", "protected", "private"]);
  9528. }
  9529. tsHasSomeModifiers(member, modifiers) {
  9530. return modifiers.some(modifier => {
  9531. if (tsIsAccessModifier(modifier)) {
  9532. return member.accessibility === modifier;
  9533. }
  9534. return !!member[modifier];
  9535. });
  9536. }
  9537. tsIsStartOfStaticBlocks() {
  9538. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9539. }
  9540. parseClassMember(classBody, member, state) {
  9541. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9542. this.tsParseModifiers({
  9543. allowedModifiers: modifiers,
  9544. disallowedModifiers: ["in", "out"],
  9545. stopOnStartOfClassStaticBlock: true,
  9546. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9547. }, member);
  9548. const callParseClassMemberWithIsStatic = () => {
  9549. if (this.tsIsStartOfStaticBlocks()) {
  9550. this.next();
  9551. this.next();
  9552. if (this.tsHasSomeModifiers(member, modifiers)) {
  9553. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9554. }
  9555. super.parseClassStaticBlock(classBody, member);
  9556. } else {
  9557. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9558. }
  9559. };
  9560. if (member.declare) {
  9561. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9562. } else {
  9563. callParseClassMemberWithIsStatic();
  9564. }
  9565. }
  9566. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9567. const idx = this.tsTryParseIndexSignature(member);
  9568. if (idx) {
  9569. classBody.body.push(idx);
  9570. if (member.abstract) {
  9571. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9572. }
  9573. if (member.accessibility) {
  9574. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9575. modifier: member.accessibility
  9576. });
  9577. }
  9578. if (member.declare) {
  9579. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9580. }
  9581. if (member.override) {
  9582. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9583. }
  9584. return;
  9585. }
  9586. if (!this.state.inAbstractClass && member.abstract) {
  9587. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9588. }
  9589. if (member.override) {
  9590. if (!state.hadSuperClass) {
  9591. this.raise(TSErrors.OverrideNotInSubClass, member);
  9592. }
  9593. }
  9594. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9595. }
  9596. parsePostMemberNameModifiers(methodOrProp) {
  9597. const optional = this.eat(17);
  9598. if (optional) methodOrProp.optional = true;
  9599. if (methodOrProp.readonly && this.match(10)) {
  9600. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9601. }
  9602. if (methodOrProp.declare && this.match(10)) {
  9603. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9604. }
  9605. }
  9606. shouldParseExportDeclaration() {
  9607. if (this.tsIsDeclarationStart()) return true;
  9608. return super.shouldParseExportDeclaration();
  9609. }
  9610. parseConditional(expr, startLoc, refExpressionErrors) {
  9611. if (!this.match(17)) return expr;
  9612. if (this.state.maybeInArrowParameters) {
  9613. const nextCh = this.lookaheadCharCode();
  9614. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  9615. this.setOptionalParametersError(refExpressionErrors);
  9616. return expr;
  9617. }
  9618. }
  9619. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9620. }
  9621. parseParenItem(node, startLoc) {
  9622. const newNode = super.parseParenItem(node, startLoc);
  9623. if (this.eat(17)) {
  9624. newNode.optional = true;
  9625. this.resetEndLocation(node);
  9626. }
  9627. if (this.match(14)) {
  9628. const typeCastNode = this.startNodeAt(startLoc);
  9629. typeCastNode.expression = node;
  9630. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9631. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9632. }
  9633. return node;
  9634. }
  9635. parseExportDeclaration(node) {
  9636. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9637. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9638. }
  9639. const startLoc = this.state.startLoc;
  9640. const isDeclare = this.eatContextual(125);
  9641. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9642. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9643. }
  9644. const isIdentifier = tokenIsIdentifier(this.state.type);
  9645. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9646. if (!declaration) return null;
  9647. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9648. node.exportKind = "type";
  9649. }
  9650. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  9651. this.resetStartLocation(declaration, startLoc);
  9652. declaration.declare = true;
  9653. }
  9654. return declaration;
  9655. }
  9656. parseClassId(node, isStatement, optionalId, bindingType) {
  9657. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9658. return;
  9659. }
  9660. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9661. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9662. if (typeParameters) node.typeParameters = typeParameters;
  9663. }
  9664. parseClassPropertyAnnotation(node) {
  9665. if (!node.optional) {
  9666. if (this.eat(35)) {
  9667. node.definite = true;
  9668. } else if (this.eat(17)) {
  9669. node.optional = true;
  9670. }
  9671. }
  9672. const type = this.tsTryParseTypeAnnotation();
  9673. if (type) node.typeAnnotation = type;
  9674. }
  9675. parseClassProperty(node) {
  9676. this.parseClassPropertyAnnotation(node);
  9677. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9678. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9679. }
  9680. if (node.abstract && this.match(29)) {
  9681. const {
  9682. key
  9683. } = node;
  9684. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9685. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9686. });
  9687. }
  9688. return super.parseClassProperty(node);
  9689. }
  9690. parseClassPrivateProperty(node) {
  9691. if (node.abstract) {
  9692. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9693. }
  9694. if (node.accessibility) {
  9695. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9696. modifier: node.accessibility
  9697. });
  9698. }
  9699. this.parseClassPropertyAnnotation(node);
  9700. return super.parseClassPrivateProperty(node);
  9701. }
  9702. parseClassAccessorProperty(node) {
  9703. this.parseClassPropertyAnnotation(node);
  9704. if (node.optional) {
  9705. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9706. }
  9707. return super.parseClassAccessorProperty(node);
  9708. }
  9709. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9710. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9711. if (typeParameters && isConstructor) {
  9712. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9713. }
  9714. const {
  9715. declare = false,
  9716. kind
  9717. } = method;
  9718. if (declare && (kind === "get" || kind === "set")) {
  9719. this.raise(TSErrors.DeclareAccessor, method, {
  9720. kind
  9721. });
  9722. }
  9723. if (typeParameters) method.typeParameters = typeParameters;
  9724. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9725. }
  9726. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9727. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9728. if (typeParameters) method.typeParameters = typeParameters;
  9729. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9730. }
  9731. declareClassPrivateMethodInScope(node, kind) {
  9732. if (node.type === "TSDeclareMethod") return;
  9733. if (node.type === "MethodDefinition" && node.value.body == null) {
  9734. return;
  9735. }
  9736. super.declareClassPrivateMethodInScope(node, kind);
  9737. }
  9738. parseClassSuper(node) {
  9739. super.parseClassSuper(node);
  9740. if (node.superClass) {
  9741. if (node.superClass.type === "TSInstantiationExpression") {
  9742. const tsInstantiationExpression = node.superClass;
  9743. const superClass = tsInstantiationExpression.expression;
  9744. this.takeSurroundingComments(superClass, superClass.start, superClass.end);
  9745. const superTypeArguments = tsInstantiationExpression.typeParameters;
  9746. this.takeSurroundingComments(superTypeArguments, superTypeArguments.start, superTypeArguments.end);
  9747. node.superClass = superClass;
  9748. node.superTypeParameters = superTypeArguments;
  9749. } else if (this.match(47) || this.match(51)) {
  9750. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9751. }
  9752. }
  9753. if (this.eatContextual(113)) {
  9754. node.implements = this.tsParseHeritageClause("implements");
  9755. }
  9756. }
  9757. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9758. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9759. if (typeParameters) prop.typeParameters = typeParameters;
  9760. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9761. }
  9762. parseFunctionParams(node, isConstructor) {
  9763. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9764. if (typeParameters) node.typeParameters = typeParameters;
  9765. super.parseFunctionParams(node, isConstructor);
  9766. }
  9767. parseVarId(decl, kind) {
  9768. super.parseVarId(decl, kind);
  9769. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9770. decl.definite = true;
  9771. }
  9772. const type = this.tsTryParseTypeAnnotation();
  9773. if (type) {
  9774. decl.id.typeAnnotation = type;
  9775. this.resetEndLocation(decl.id);
  9776. }
  9777. }
  9778. parseAsyncArrowFromCallExpression(node, call) {
  9779. if (this.match(14)) {
  9780. node.returnType = this.tsParseTypeAnnotation();
  9781. }
  9782. return super.parseAsyncArrowFromCallExpression(node, call);
  9783. }
  9784. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9785. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9786. let state;
  9787. let jsx;
  9788. let typeCast;
  9789. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  9790. state = this.state.clone();
  9791. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9792. if (!jsx.error) return jsx.node;
  9793. const {
  9794. context
  9795. } = this.state;
  9796. const currentContext = context[context.length - 1];
  9797. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9798. context.pop();
  9799. }
  9800. }
  9801. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9802. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9803. }
  9804. if (!state || state === this.state) state = this.state.clone();
  9805. let typeParameters;
  9806. const arrow = this.tryParse(abort => {
  9807. var _expr$extra, _typeParameters;
  9808. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9809. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9810. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9811. abort();
  9812. }
  9813. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9814. this.resetStartLocationFromNode(expr, typeParameters);
  9815. }
  9816. expr.typeParameters = typeParameters;
  9817. return expr;
  9818. }, state);
  9819. if (!arrow.error && !arrow.aborted) {
  9820. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9821. return arrow.node;
  9822. }
  9823. if (!jsx) {
  9824. assert(!this.hasPlugin("jsx"));
  9825. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9826. if (!typeCast.error) return typeCast.node;
  9827. }
  9828. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9829. this.state = jsx.failState;
  9830. return jsx.node;
  9831. }
  9832. if (arrow.node) {
  9833. this.state = arrow.failState;
  9834. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9835. return arrow.node;
  9836. }
  9837. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9838. this.state = typeCast.failState;
  9839. return typeCast.node;
  9840. }
  9841. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9842. }
  9843. reportReservedArrowTypeParam(node) {
  9844. var _node$extra2;
  9845. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9846. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9847. }
  9848. }
  9849. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9850. if (!this.hasPlugin("jsx") && this.match(47)) {
  9851. return this.tsParseTypeAssertion();
  9852. }
  9853. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9854. }
  9855. parseArrow(node) {
  9856. if (this.match(14)) {
  9857. const result = this.tryParse(abort => {
  9858. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9859. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9860. return returnType;
  9861. });
  9862. if (result.aborted) return;
  9863. if (!result.thrown) {
  9864. if (result.error) this.state = result.failState;
  9865. node.returnType = result.node;
  9866. }
  9867. }
  9868. return super.parseArrow(node);
  9869. }
  9870. parseFunctionParamType(param) {
  9871. if (this.eat(17)) {
  9872. param.optional = true;
  9873. }
  9874. const type = this.tsTryParseTypeAnnotation();
  9875. if (type) param.typeAnnotation = type;
  9876. this.resetEndLocation(param);
  9877. return param;
  9878. }
  9879. isAssignable(node, isBinding) {
  9880. switch (node.type) {
  9881. case "TSTypeCastExpression":
  9882. return this.isAssignable(node.expression, isBinding);
  9883. case "TSParameterProperty":
  9884. return true;
  9885. default:
  9886. return super.isAssignable(node, isBinding);
  9887. }
  9888. }
  9889. toAssignable(node, isLHS = false) {
  9890. switch (node.type) {
  9891. case "ParenthesizedExpression":
  9892. this.toAssignableParenthesizedExpression(node, isLHS);
  9893. break;
  9894. case "TSAsExpression":
  9895. case "TSSatisfiesExpression":
  9896. case "TSNonNullExpression":
  9897. case "TSTypeAssertion":
  9898. if (isLHS) {
  9899. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9900. } else {
  9901. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9902. }
  9903. this.toAssignable(node.expression, isLHS);
  9904. break;
  9905. case "AssignmentExpression":
  9906. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9907. node.left = this.typeCastToParameter(node.left);
  9908. }
  9909. default:
  9910. super.toAssignable(node, isLHS);
  9911. }
  9912. }
  9913. toAssignableParenthesizedExpression(node, isLHS) {
  9914. switch (node.expression.type) {
  9915. case "TSAsExpression":
  9916. case "TSSatisfiesExpression":
  9917. case "TSNonNullExpression":
  9918. case "TSTypeAssertion":
  9919. case "ParenthesizedExpression":
  9920. this.toAssignable(node.expression, isLHS);
  9921. break;
  9922. default:
  9923. super.toAssignable(node, isLHS);
  9924. }
  9925. }
  9926. checkToRestConversion(node, allowPattern) {
  9927. switch (node.type) {
  9928. case "TSAsExpression":
  9929. case "TSSatisfiesExpression":
  9930. case "TSTypeAssertion":
  9931. case "TSNonNullExpression":
  9932. this.checkToRestConversion(node.expression, false);
  9933. break;
  9934. default:
  9935. super.checkToRestConversion(node, allowPattern);
  9936. }
  9937. }
  9938. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  9939. switch (type) {
  9940. case "TSTypeCastExpression":
  9941. return true;
  9942. case "TSParameterProperty":
  9943. return "parameter";
  9944. case "TSNonNullExpression":
  9945. return "expression";
  9946. case "TSAsExpression":
  9947. case "TSSatisfiesExpression":
  9948. case "TSTypeAssertion":
  9949. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  9950. default:
  9951. return super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  9952. }
  9953. }
  9954. parseBindingAtom() {
  9955. if (this.state.type === 78) {
  9956. return this.parseIdentifier(true);
  9957. }
  9958. return super.parseBindingAtom();
  9959. }
  9960. parseMaybeDecoratorArguments(expr, startLoc) {
  9961. if (this.match(47) || this.match(51)) {
  9962. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9963. if (this.match(10)) {
  9964. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  9965. call.typeParameters = typeArguments;
  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. node.typeParameters = typeArguments;
  10057. }
  10058. }
  10059. return super.jsxParseOpeningElementAfterName(node);
  10060. }
  10061. getGetterSetterExpectedParamCount(method) {
  10062. const baseCount = super.getGetterSetterExpectedParamCount(method);
  10063. const params = this.getObjectOrClassMethodParams(method);
  10064. const firstParam = params[0];
  10065. const hasContextParam = firstParam && this.isThisParam(firstParam);
  10066. return hasContextParam ? baseCount + 1 : baseCount;
  10067. }
  10068. parseCatchClauseParam() {
  10069. const param = super.parseCatchClauseParam();
  10070. const type = this.tsTryParseTypeAnnotation();
  10071. if (type) {
  10072. param.typeAnnotation = type;
  10073. this.resetEndLocation(param);
  10074. }
  10075. return param;
  10076. }
  10077. tsInAmbientContext(cb) {
  10078. const {
  10079. isAmbientContext: oldIsAmbientContext,
  10080. strict: oldStrict
  10081. } = this.state;
  10082. this.state.isAmbientContext = true;
  10083. this.state.strict = false;
  10084. try {
  10085. return cb();
  10086. } finally {
  10087. this.state.isAmbientContext = oldIsAmbientContext;
  10088. this.state.strict = oldStrict;
  10089. }
  10090. }
  10091. parseClass(node, isStatement, optionalId) {
  10092. const oldInAbstractClass = this.state.inAbstractClass;
  10093. this.state.inAbstractClass = !!node.abstract;
  10094. try {
  10095. return super.parseClass(node, isStatement, optionalId);
  10096. } finally {
  10097. this.state.inAbstractClass = oldInAbstractClass;
  10098. }
  10099. }
  10100. tsParseAbstractDeclaration(node, decorators) {
  10101. if (this.match(80)) {
  10102. node.abstract = true;
  10103. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  10104. } else if (this.isContextual(129)) {
  10105. if (!this.hasFollowingLineBreak()) {
  10106. node.abstract = true;
  10107. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
  10108. return this.tsParseInterfaceDeclaration(node);
  10109. } else {
  10110. return null;
  10111. }
  10112. }
  10113. throw this.unexpected(null, 80);
  10114. }
  10115. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  10116. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  10117. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  10118. const hasEstreePlugin = this.hasPlugin("estree");
  10119. const methodFn = hasEstreePlugin ? method.value : method;
  10120. if (methodFn.body) {
  10121. const {
  10122. key
  10123. } = method;
  10124. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  10125. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  10126. });
  10127. }
  10128. }
  10129. return method;
  10130. }
  10131. tsParseTypeParameterName() {
  10132. const typeName = this.parseIdentifier();
  10133. return typeName.name;
  10134. }
  10135. shouldParseAsAmbientContext() {
  10136. return !!this.getPluginOption("typescript", "dts");
  10137. }
  10138. parse() {
  10139. if (this.shouldParseAsAmbientContext()) {
  10140. this.state.isAmbientContext = true;
  10141. }
  10142. return super.parse();
  10143. }
  10144. getExpression() {
  10145. if (this.shouldParseAsAmbientContext()) {
  10146. this.state.isAmbientContext = true;
  10147. }
  10148. return super.getExpression();
  10149. }
  10150. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10151. if (!isString && isMaybeTypeOnly) {
  10152. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10153. return this.finishNode(node, "ExportSpecifier");
  10154. }
  10155. node.exportKind = "value";
  10156. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10157. }
  10158. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10159. if (!importedIsString && isMaybeTypeOnly) {
  10160. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10161. return this.finishNode(specifier, "ImportSpecifier");
  10162. }
  10163. specifier.importKind = "value";
  10164. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  10165. }
  10166. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10167. const leftOfAsKey = isImport ? "imported" : "local";
  10168. const rightOfAsKey = isImport ? "local" : "exported";
  10169. let leftOfAs = node[leftOfAsKey];
  10170. let rightOfAs;
  10171. let hasTypeSpecifier = false;
  10172. let canParseAsKeyword = true;
  10173. const loc = leftOfAs.loc.start;
  10174. if (this.isContextual(93)) {
  10175. const firstAs = this.parseIdentifier();
  10176. if (this.isContextual(93)) {
  10177. const secondAs = this.parseIdentifier();
  10178. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10179. hasTypeSpecifier = true;
  10180. leftOfAs = firstAs;
  10181. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10182. canParseAsKeyword = false;
  10183. } else {
  10184. rightOfAs = secondAs;
  10185. canParseAsKeyword = false;
  10186. }
  10187. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10188. canParseAsKeyword = false;
  10189. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10190. } else {
  10191. hasTypeSpecifier = true;
  10192. leftOfAs = firstAs;
  10193. }
  10194. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10195. hasTypeSpecifier = true;
  10196. if (isImport) {
  10197. leftOfAs = this.parseIdentifier(true);
  10198. if (!this.isContextual(93)) {
  10199. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10200. }
  10201. } else {
  10202. leftOfAs = this.parseModuleExportName();
  10203. }
  10204. }
  10205. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10206. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  10207. }
  10208. node[leftOfAsKey] = leftOfAs;
  10209. node[rightOfAsKey] = rightOfAs;
  10210. const kindKey = isImport ? "importKind" : "exportKind";
  10211. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10212. if (canParseAsKeyword && this.eatContextual(93)) {
  10213. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10214. }
  10215. if (!node[rightOfAsKey]) {
  10216. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  10217. }
  10218. if (isImport) {
  10219. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10220. }
  10221. }
  10222. fillOptionalPropertiesForTSESLint(node) {
  10223. 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$optional5, _node$readonly4, _node$declare7, _node$global, _node$const2, _node$in, _node$out;
  10224. switch (node.type) {
  10225. case "ExpressionStatement":
  10226. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  10227. return;
  10228. case "RestElement":
  10229. node.value = undefined;
  10230. case "Identifier":
  10231. case "ArrayPattern":
  10232. case "AssignmentPattern":
  10233. case "ObjectPattern":
  10234. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  10235. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  10236. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  10237. return;
  10238. case "TSParameterProperty":
  10239. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  10240. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  10241. (_node$override = node.override) != null ? _node$override : node.override = false;
  10242. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  10243. (_node$static = node.static) != null ? _node$static : node.static = false;
  10244. return;
  10245. case "TSEmptyBodyFunctionExpression":
  10246. node.body = null;
  10247. case "TSDeclareFunction":
  10248. case "FunctionDeclaration":
  10249. case "FunctionExpression":
  10250. case "ClassMethod":
  10251. case "ClassPrivateMethod":
  10252. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  10253. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  10254. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  10255. return;
  10256. case "Property":
  10257. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  10258. return;
  10259. case "TSMethodSignature":
  10260. case "TSPropertySignature":
  10261. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  10262. case "TSIndexSignature":
  10263. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  10264. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  10265. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  10266. return;
  10267. case "TSAbstractPropertyDefinition":
  10268. case "PropertyDefinition":
  10269. case "TSAbstractAccessorProperty":
  10270. case "AccessorProperty":
  10271. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  10272. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  10273. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  10274. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  10275. case "TSAbstractMethodDefinition":
  10276. case "MethodDefinition":
  10277. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  10278. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  10279. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  10280. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  10281. return;
  10282. case "ClassExpression":
  10283. (_node$id = node.id) != null ? _node$id : node.id = null;
  10284. case "ClassDeclaration":
  10285. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  10286. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  10287. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  10288. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  10289. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  10290. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  10291. return;
  10292. case "TSTypeAliasDeclaration":
  10293. case "VariableDeclaration":
  10294. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  10295. return;
  10296. case "VariableDeclarator":
  10297. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  10298. return;
  10299. case "TSEnumDeclaration":
  10300. (_node$const = node.const) != null ? _node$const : node.const = false;
  10301. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  10302. return;
  10303. case "TSEnumMember":
  10304. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  10305. return;
  10306. case "TSImportType":
  10307. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  10308. (_node$options = node.options) != null ? _node$options : node.options = null;
  10309. return;
  10310. case "TSInterfaceDeclaration":
  10311. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  10312. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  10313. return;
  10314. case "TSMappedType":
  10315. (_node$optional5 = node.optional) != null ? _node$optional5 : node.optional = false;
  10316. (_node$readonly4 = node.readonly) != null ? _node$readonly4 : node.readonly = undefined;
  10317. return;
  10318. case "TSModuleDeclaration":
  10319. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  10320. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  10321. return;
  10322. case "TSTypeParameter":
  10323. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  10324. (_node$in = node.in) != null ? _node$in : node.in = false;
  10325. (_node$out = node.out) != null ? _node$out : node.out = false;
  10326. return;
  10327. }
  10328. }
  10329. chStartsBindingIdentifierAndNotRelationalOperator(ch, pos) {
  10330. if (isIdentifierStart(ch)) {
  10331. keywordAndTSRelationalOperator.lastIndex = pos;
  10332. if (keywordAndTSRelationalOperator.test(this.input)) {
  10333. const endCh = this.codePointAtPos(keywordAndTSRelationalOperator.lastIndex);
  10334. if (!isIdentifierChar(endCh) && endCh !== 92) {
  10335. return false;
  10336. }
  10337. }
  10338. return true;
  10339. } else if (ch === 92) {
  10340. return true;
  10341. } else {
  10342. return false;
  10343. }
  10344. }
  10345. nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine() {
  10346. const next = this.nextTokenInLineStart();
  10347. const nextCh = this.codePointAtPos(next);
  10348. return this.chStartsBindingIdentifierAndNotRelationalOperator(nextCh, next);
  10349. }
  10350. nextTokenIsIdentifierOrStringLiteralOnSameLine() {
  10351. const next = this.nextTokenInLineStart();
  10352. const nextCh = this.codePointAtPos(next);
  10353. return this.chStartsBindingIdentifier(nextCh, next) || nextCh === 34 || nextCh === 39;
  10354. }
  10355. };
  10356. function isPossiblyLiteralEnum(expression) {
  10357. if (expression.type !== "MemberExpression") return false;
  10358. const {
  10359. computed,
  10360. property
  10361. } = expression;
  10362. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10363. return false;
  10364. }
  10365. return isUncomputedMemberExpressionChain(expression.object);
  10366. }
  10367. function isValidAmbientConstInitializer(expression, estree) {
  10368. var _expression$extra;
  10369. const {
  10370. type
  10371. } = expression;
  10372. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10373. return false;
  10374. }
  10375. if (estree) {
  10376. if (type === "Literal") {
  10377. const {
  10378. value
  10379. } = expression;
  10380. if (typeof value === "string" || typeof value === "boolean") {
  10381. return true;
  10382. }
  10383. }
  10384. } else {
  10385. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10386. return true;
  10387. }
  10388. }
  10389. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10390. return true;
  10391. }
  10392. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10393. return true;
  10394. }
  10395. if (isPossiblyLiteralEnum(expression)) {
  10396. return true;
  10397. }
  10398. return false;
  10399. }
  10400. function isNumber(expression, estree) {
  10401. if (estree) {
  10402. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10403. }
  10404. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10405. }
  10406. function isNegativeNumber(expression, estree) {
  10407. if (expression.type === "UnaryExpression") {
  10408. const {
  10409. operator,
  10410. argument
  10411. } = expression;
  10412. if (operator === "-" && isNumber(argument, estree)) {
  10413. return true;
  10414. }
  10415. }
  10416. return false;
  10417. }
  10418. function isUncomputedMemberExpressionChain(expression) {
  10419. if (expression.type === "Identifier") return true;
  10420. if (expression.type !== "MemberExpression" || expression.computed) {
  10421. return false;
  10422. }
  10423. return isUncomputedMemberExpressionChain(expression.object);
  10424. }
  10425. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10426. ClassNameIsRequired: "A class name is required.",
  10427. UnexpectedSpace: "Unexpected space in placeholder."
  10428. });
  10429. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10430. parsePlaceholder(expectedNode) {
  10431. if (this.match(133)) {
  10432. const node = this.startNode();
  10433. this.next();
  10434. this.assertNoSpace();
  10435. node.name = super.parseIdentifier(true);
  10436. this.assertNoSpace();
  10437. this.expect(133);
  10438. return this.finishPlaceholder(node, expectedNode);
  10439. }
  10440. }
  10441. finishPlaceholder(node, expectedNode) {
  10442. let placeholder = node;
  10443. if (!placeholder.expectedNode || !placeholder.type) {
  10444. placeholder = this.finishNode(placeholder, "Placeholder");
  10445. }
  10446. placeholder.expectedNode = expectedNode;
  10447. return placeholder;
  10448. }
  10449. getTokenFromCode(code) {
  10450. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10451. this.finishOp(133, 2);
  10452. } else {
  10453. super.getTokenFromCode(code);
  10454. }
  10455. }
  10456. parseExprAtom(refExpressionErrors) {
  10457. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10458. }
  10459. parseIdentifier(liberal) {
  10460. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10461. }
  10462. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10463. if (word !== undefined) {
  10464. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10465. }
  10466. }
  10467. cloneIdentifier(node) {
  10468. const cloned = super.cloneIdentifier(node);
  10469. if (cloned.type === "Placeholder") {
  10470. cloned.expectedNode = node.expectedNode;
  10471. }
  10472. return cloned;
  10473. }
  10474. cloneStringLiteral(node) {
  10475. if (node.type === "Placeholder") {
  10476. return this.cloneIdentifier(node);
  10477. }
  10478. return super.cloneStringLiteral(node);
  10479. }
  10480. parseBindingAtom() {
  10481. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10482. }
  10483. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  10484. return type === "Placeholder" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  10485. }
  10486. toAssignable(node, isLHS) {
  10487. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10488. node.expectedNode = "Pattern";
  10489. } else {
  10490. super.toAssignable(node, isLHS);
  10491. }
  10492. }
  10493. chStartsBindingIdentifier(ch, pos) {
  10494. if (super.chStartsBindingIdentifier(ch, pos)) {
  10495. return true;
  10496. }
  10497. const next = this.nextTokenStart();
  10498. if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
  10499. return true;
  10500. }
  10501. return false;
  10502. }
  10503. verifyBreakContinue(node, isBreak) {
  10504. var _node$label;
  10505. if (((_node$label = node.label) == null ? void 0 : _node$label.type) === "Placeholder") return;
  10506. super.verifyBreakContinue(node, isBreak);
  10507. }
  10508. parseExpressionStatement(node, expr) {
  10509. var _expr$extra;
  10510. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10511. return super.parseExpressionStatement(node, expr);
  10512. }
  10513. if (this.match(14)) {
  10514. const stmt = node;
  10515. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10516. this.next();
  10517. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10518. return this.finishNode(stmt, "LabeledStatement");
  10519. }
  10520. this.semicolon();
  10521. const stmtPlaceholder = node;
  10522. stmtPlaceholder.name = expr.name;
  10523. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  10524. }
  10525. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10526. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10527. }
  10528. parseFunctionId(requireId) {
  10529. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10530. }
  10531. parseClass(node, isStatement, optionalId) {
  10532. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10533. this.next();
  10534. const oldStrict = this.state.strict;
  10535. const placeholder = this.parsePlaceholder("Identifier");
  10536. if (placeholder) {
  10537. if (this.match(81) || this.match(133) || this.match(5)) {
  10538. node.id = placeholder;
  10539. } else if (optionalId || !isStatement) {
  10540. node.id = null;
  10541. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10542. return this.finishNode(node, type);
  10543. } else {
  10544. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10545. }
  10546. } else {
  10547. this.parseClassId(node, isStatement, optionalId);
  10548. }
  10549. super.parseClassSuper(node);
  10550. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10551. return this.finishNode(node, type);
  10552. }
  10553. parseExport(node, decorators) {
  10554. const placeholder = this.parsePlaceholder("Identifier");
  10555. if (!placeholder) return super.parseExport(node, decorators);
  10556. const node2 = node;
  10557. if (!this.isContextual(98) && !this.match(12)) {
  10558. node2.specifiers = [];
  10559. node2.source = null;
  10560. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10561. return this.finishNode(node2, "ExportNamedDeclaration");
  10562. }
  10563. this.expectPlugin("exportDefaultFrom");
  10564. const specifier = this.startNode();
  10565. specifier.exported = placeholder;
  10566. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10567. return super.parseExport(node2, decorators);
  10568. }
  10569. isExportDefaultSpecifier() {
  10570. if (this.match(65)) {
  10571. const next = this.nextTokenStart();
  10572. if (this.isUnparsedContextual(next, "from")) {
  10573. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  10574. return true;
  10575. }
  10576. }
  10577. }
  10578. return super.isExportDefaultSpecifier();
  10579. }
  10580. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10581. var _specifiers;
  10582. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10583. return true;
  10584. }
  10585. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10586. }
  10587. checkExport(node) {
  10588. const {
  10589. specifiers
  10590. } = node;
  10591. if (specifiers != null && specifiers.length) {
  10592. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10593. }
  10594. super.checkExport(node);
  10595. node.specifiers = specifiers;
  10596. }
  10597. parseImport(node) {
  10598. const placeholder = this.parsePlaceholder("Identifier");
  10599. if (!placeholder) return super.parseImport(node);
  10600. node.specifiers = [];
  10601. if (!this.isContextual(98) && !this.match(12)) {
  10602. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10603. this.semicolon();
  10604. return this.finishNode(node, "ImportDeclaration");
  10605. }
  10606. const specifier = this.startNodeAtNode(placeholder);
  10607. specifier.local = placeholder;
  10608. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10609. if (this.eat(12)) {
  10610. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10611. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10612. }
  10613. this.expectContextual(98);
  10614. node.source = this.parseImportSource();
  10615. this.semicolon();
  10616. return this.finishNode(node, "ImportDeclaration");
  10617. }
  10618. parseImportSource() {
  10619. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10620. }
  10621. assertNoSpace() {
  10622. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  10623. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10624. }
  10625. }
  10626. };
  10627. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10628. parseV8Intrinsic() {
  10629. if (this.match(54)) {
  10630. const v8IntrinsicStartLoc = this.state.startLoc;
  10631. const node = this.startNode();
  10632. this.next();
  10633. if (tokenIsIdentifier(this.state.type)) {
  10634. const name = this.parseIdentifierName();
  10635. const identifier = this.createIdentifier(node, name);
  10636. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  10637. if (this.match(10)) {
  10638. return identifier;
  10639. }
  10640. }
  10641. this.unexpected(v8IntrinsicStartLoc);
  10642. }
  10643. }
  10644. parseExprAtom(refExpressionErrors) {
  10645. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10646. }
  10647. };
  10648. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10649. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10650. function validatePlugins(pluginsMap) {
  10651. if (pluginsMap.has("decorators")) {
  10652. if (pluginsMap.has("decorators-legacy")) {
  10653. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10654. }
  10655. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  10656. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10657. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10658. }
  10659. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  10660. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10661. throw new Error("'allowCallParenthesized' must be a boolean.");
  10662. }
  10663. }
  10664. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  10665. throw new Error("Cannot combine flow and typescript plugins.");
  10666. }
  10667. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  10668. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10669. }
  10670. if (pluginsMap.has("pipelineOperator")) {
  10671. var _pluginsMap$get2;
  10672. const proposal = pluginsMap.get("pipelineOperator").proposal;
  10673. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10674. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10675. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10676. }
  10677. if (proposal === "hack") {
  10678. var _pluginsMap$get;
  10679. if (pluginsMap.has("placeholders")) {
  10680. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10681. }
  10682. if (pluginsMap.has("v8intrinsic")) {
  10683. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10684. }
  10685. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  10686. if (!TOPIC_TOKENS.includes(topicToken)) {
  10687. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10688. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10689. }
  10690. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  10691. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10692. }
  10693. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  10694. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10695. }
  10696. }
  10697. if (pluginsMap.has("moduleAttributes")) {
  10698. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  10699. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  10700. }
  10701. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  10702. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10703. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10704. }
  10705. }
  10706. if (pluginsMap.has("importAssertions")) {
  10707. if (pluginsMap.has("deprecatedImportAssert")) {
  10708. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  10709. }
  10710. }
  10711. if (pluginsMap.has("deprecatedImportAssert")) ;else if (pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  10712. pluginsMap.set("deprecatedImportAssert", {});
  10713. }
  10714. if (pluginsMap.has("recordAndTuple")) {
  10715. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  10716. if (syntaxType != null) {
  10717. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10718. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  10719. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10720. }
  10721. }
  10722. }
  10723. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  10724. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10725. error.missingPlugins = "doExpressions";
  10726. throw error;
  10727. }
  10728. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  10729. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10730. }
  10731. if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
  10732. throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
  10733. }
  10734. }
  10735. const mixinPlugins = {
  10736. estree,
  10737. jsx,
  10738. flow,
  10739. typescript,
  10740. v8intrinsic,
  10741. placeholders
  10742. };
  10743. const mixinPluginNames = Object.keys(mixinPlugins);
  10744. class ExpressionParser extends LValParser {
  10745. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  10746. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10747. return sawProto;
  10748. }
  10749. const key = prop.key;
  10750. const name = key.type === "Identifier" ? key.name : key.value;
  10751. if (name === "__proto__") {
  10752. if (isRecord) {
  10753. this.raise(Errors.RecordNoProto, key);
  10754. return true;
  10755. }
  10756. if (sawProto) {
  10757. if (refExpressionErrors) {
  10758. if (refExpressionErrors.doubleProtoLoc === null) {
  10759. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10760. }
  10761. } else {
  10762. this.raise(Errors.DuplicateProto, key);
  10763. }
  10764. }
  10765. return true;
  10766. }
  10767. return sawProto;
  10768. }
  10769. shouldExitDescending(expr, potentialArrowAt) {
  10770. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  10771. }
  10772. getExpression() {
  10773. this.enterInitialScopes();
  10774. this.nextToken();
  10775. if (this.match(140)) {
  10776. throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
  10777. }
  10778. const expr = this.parseExpression();
  10779. if (!this.match(140)) {
  10780. throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
  10781. unexpected: this.input.codePointAt(this.state.start)
  10782. });
  10783. }
  10784. this.finalizeRemainingComments();
  10785. expr.comments = this.comments;
  10786. expr.errors = this.state.errors;
  10787. if (this.optionFlags & 256) {
  10788. expr.tokens = this.tokens;
  10789. }
  10790. return expr;
  10791. }
  10792. parseExpression(disallowIn, refExpressionErrors) {
  10793. if (disallowIn) {
  10794. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10795. }
  10796. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10797. }
  10798. parseExpressionBase(refExpressionErrors) {
  10799. const startLoc = this.state.startLoc;
  10800. const expr = this.parseMaybeAssign(refExpressionErrors);
  10801. if (this.match(12)) {
  10802. const node = this.startNodeAt(startLoc);
  10803. node.expressions = [expr];
  10804. while (this.eat(12)) {
  10805. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10806. }
  10807. this.toReferencedList(node.expressions);
  10808. return this.finishNode(node, "SequenceExpression");
  10809. }
  10810. return expr;
  10811. }
  10812. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10813. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10814. }
  10815. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10816. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10817. }
  10818. setOptionalParametersError(refExpressionErrors) {
  10819. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  10820. }
  10821. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10822. const startLoc = this.state.startLoc;
  10823. const isYield = this.isContextual(108);
  10824. if (isYield) {
  10825. if (this.prodParam.hasYield) {
  10826. this.next();
  10827. let left = this.parseYield(startLoc);
  10828. if (afterLeftParse) {
  10829. left = afterLeftParse.call(this, left, startLoc);
  10830. }
  10831. return left;
  10832. }
  10833. }
  10834. let ownExpressionErrors;
  10835. if (refExpressionErrors) {
  10836. ownExpressionErrors = false;
  10837. } else {
  10838. refExpressionErrors = new ExpressionErrors();
  10839. ownExpressionErrors = true;
  10840. }
  10841. const {
  10842. type
  10843. } = this.state;
  10844. if (type === 10 || tokenIsIdentifier(type)) {
  10845. this.state.potentialArrowAt = this.state.start;
  10846. }
  10847. let left = this.parseMaybeConditional(refExpressionErrors);
  10848. if (afterLeftParse) {
  10849. left = afterLeftParse.call(this, left, startLoc);
  10850. }
  10851. if (tokenIsAssignment(this.state.type)) {
  10852. const node = this.startNodeAt(startLoc);
  10853. const operator = this.state.value;
  10854. node.operator = operator;
  10855. if (this.match(29)) {
  10856. this.toAssignable(left, true);
  10857. node.left = left;
  10858. const startIndex = startLoc.index;
  10859. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10860. refExpressionErrors.doubleProtoLoc = null;
  10861. }
  10862. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10863. refExpressionErrors.shorthandAssignLoc = null;
  10864. }
  10865. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10866. this.checkDestructuringPrivate(refExpressionErrors);
  10867. refExpressionErrors.privateKeyLoc = null;
  10868. }
  10869. if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
  10870. refExpressionErrors.voidPatternLoc = null;
  10871. }
  10872. } else {
  10873. node.left = left;
  10874. }
  10875. this.next();
  10876. node.right = this.parseMaybeAssign();
  10877. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"), undefined, undefined, undefined, undefined, operator === "||=" || operator === "&&=" || operator === "??=");
  10878. return node;
  10879. } else if (ownExpressionErrors) {
  10880. this.checkExpressionErrors(refExpressionErrors, true);
  10881. }
  10882. if (isYield) {
  10883. const {
  10884. type
  10885. } = this.state;
  10886. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10887. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  10888. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  10889. return this.parseYield(startLoc);
  10890. }
  10891. }
  10892. return left;
  10893. }
  10894. parseMaybeConditional(refExpressionErrors) {
  10895. const startLoc = this.state.startLoc;
  10896. const potentialArrowAt = this.state.potentialArrowAt;
  10897. const expr = this.parseExprOps(refExpressionErrors);
  10898. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10899. return expr;
  10900. }
  10901. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10902. }
  10903. parseConditional(expr, startLoc, refExpressionErrors) {
  10904. if (this.eat(17)) {
  10905. const node = this.startNodeAt(startLoc);
  10906. node.test = expr;
  10907. node.consequent = this.parseMaybeAssignAllowIn();
  10908. this.expect(14);
  10909. node.alternate = this.parseMaybeAssign();
  10910. return this.finishNode(node, "ConditionalExpression");
  10911. }
  10912. return expr;
  10913. }
  10914. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10915. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10916. }
  10917. parseExprOps(refExpressionErrors) {
  10918. const startLoc = this.state.startLoc;
  10919. const potentialArrowAt = this.state.potentialArrowAt;
  10920. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10921. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10922. return expr;
  10923. }
  10924. return this.parseExprOp(expr, startLoc, -1);
  10925. }
  10926. parseExprOp(left, leftStartLoc, minPrec) {
  10927. if (this.isPrivateName(left)) {
  10928. const value = this.getPrivateNameSV(left);
  10929. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10930. this.raise(Errors.PrivateInExpectedIn, left, {
  10931. identifierName: value
  10932. });
  10933. }
  10934. this.classScope.usePrivateName(value, left.loc.start);
  10935. }
  10936. const op = this.state.type;
  10937. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10938. let prec = tokenOperatorPrecedence(op);
  10939. if (prec > minPrec) {
  10940. if (op === 39) {
  10941. this.expectPlugin("pipelineOperator");
  10942. if (this.state.inFSharpPipelineDirectBody) {
  10943. return left;
  10944. }
  10945. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10946. }
  10947. const node = this.startNodeAt(leftStartLoc);
  10948. node.left = left;
  10949. node.operator = this.state.value;
  10950. const logical = op === 41 || op === 42;
  10951. const coalesce = op === 40;
  10952. if (coalesce) {
  10953. prec = tokenOperatorPrecedence(42);
  10954. }
  10955. this.next();
  10956. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10957. proposal: "minimal"
  10958. }])) {
  10959. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10960. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  10961. }
  10962. }
  10963. node.right = this.parseExprOpRightExpr(op, prec);
  10964. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10965. const nextOp = this.state.type;
  10966. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10967. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  10968. }
  10969. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10970. }
  10971. }
  10972. return left;
  10973. }
  10974. parseExprOpRightExpr(op, prec) {
  10975. const startLoc = this.state.startLoc;
  10976. switch (op) {
  10977. case 39:
  10978. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10979. case "hack":
  10980. return this.withTopicBindingContext(() => {
  10981. return this.parseHackPipeBody();
  10982. });
  10983. case "fsharp":
  10984. return this.withSoloAwaitPermittingContext(() => {
  10985. return this.parseFSharpPipelineBody(prec);
  10986. });
  10987. }
  10988. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  10989. return this.withTopicBindingContext(() => {
  10990. if (this.prodParam.hasYield && this.isContextual(108)) {
  10991. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  10992. }
  10993. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10994. });
  10995. }
  10996. default:
  10997. return this.parseExprOpBaseRightExpr(op, prec);
  10998. }
  10999. }
  11000. parseExprOpBaseRightExpr(op, prec) {
  11001. const startLoc = this.state.startLoc;
  11002. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  11003. }
  11004. parseHackPipeBody() {
  11005. var _body$extra;
  11006. const {
  11007. startLoc
  11008. } = this.state;
  11009. const body = this.parseMaybeAssign();
  11010. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  11011. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  11012. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  11013. type: body.type
  11014. });
  11015. }
  11016. if (!this.topicReferenceWasUsedInCurrentContext()) {
  11017. this.raise(Errors.PipeTopicUnused, startLoc);
  11018. }
  11019. return body;
  11020. }
  11021. checkExponentialAfterUnary(node) {
  11022. if (this.match(57)) {
  11023. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  11024. }
  11025. }
  11026. parseMaybeUnary(refExpressionErrors, sawUnary) {
  11027. const startLoc = this.state.startLoc;
  11028. const isAwait = this.isContextual(96);
  11029. if (isAwait && this.recordAwaitIfAllowed()) {
  11030. this.next();
  11031. const expr = this.parseAwait(startLoc);
  11032. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  11033. return expr;
  11034. }
  11035. const update = this.match(34);
  11036. const node = this.startNode();
  11037. if (tokenIsPrefix(this.state.type)) {
  11038. node.operator = this.state.value;
  11039. node.prefix = true;
  11040. if (this.match(72)) {
  11041. this.expectPlugin("throwExpressions");
  11042. }
  11043. const isDelete = this.match(89);
  11044. this.next();
  11045. node.argument = this.parseMaybeUnary(null, true);
  11046. this.checkExpressionErrors(refExpressionErrors, true);
  11047. if (this.state.strict && isDelete) {
  11048. const arg = node.argument;
  11049. if (arg.type === "Identifier") {
  11050. this.raise(Errors.StrictDelete, node);
  11051. } else if (this.hasPropertyAsPrivateName(arg)) {
  11052. this.raise(Errors.DeletePrivateField, node);
  11053. }
  11054. }
  11055. if (!update) {
  11056. if (!sawUnary) {
  11057. this.checkExponentialAfterUnary(node);
  11058. }
  11059. return this.finishNode(node, "UnaryExpression");
  11060. }
  11061. }
  11062. const expr = this.parseUpdate(node, update, refExpressionErrors);
  11063. if (isAwait) {
  11064. const {
  11065. type
  11066. } = this.state;
  11067. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  11068. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  11069. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  11070. return this.parseAwait(startLoc);
  11071. }
  11072. }
  11073. return expr;
  11074. }
  11075. parseUpdate(node, update, refExpressionErrors) {
  11076. if (update) {
  11077. const updateExpressionNode = node;
  11078. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  11079. return node;
  11080. }
  11081. const startLoc = this.state.startLoc;
  11082. let expr = this.parseExprSubscripts(refExpressionErrors);
  11083. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  11084. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  11085. const node = this.startNodeAt(startLoc);
  11086. node.operator = this.state.value;
  11087. node.prefix = false;
  11088. node.argument = expr;
  11089. this.next();
  11090. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  11091. }
  11092. return expr;
  11093. }
  11094. parseExprSubscripts(refExpressionErrors) {
  11095. const startLoc = this.state.startLoc;
  11096. const potentialArrowAt = this.state.potentialArrowAt;
  11097. const expr = this.parseExprAtom(refExpressionErrors);
  11098. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11099. return expr;
  11100. }
  11101. return this.parseSubscripts(expr, startLoc);
  11102. }
  11103. parseSubscripts(base, startLoc, noCalls) {
  11104. const state = {
  11105. optionalChainMember: false,
  11106. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  11107. stop: false
  11108. };
  11109. do {
  11110. base = this.parseSubscript(base, startLoc, noCalls, state);
  11111. state.maybeAsyncArrow = false;
  11112. } while (!state.stop);
  11113. return base;
  11114. }
  11115. parseSubscript(base, startLoc, noCalls, state) {
  11116. const {
  11117. type
  11118. } = this.state;
  11119. if (!noCalls && type === 15) {
  11120. return this.parseBind(base, startLoc, noCalls, state);
  11121. } else if (tokenIsTemplate(type)) {
  11122. return this.parseTaggedTemplateExpression(base, startLoc, state);
  11123. }
  11124. let optional = false;
  11125. if (type === 18) {
  11126. if (noCalls) {
  11127. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  11128. if (this.lookaheadCharCode() === 40) {
  11129. return this.stopParseSubscript(base, state);
  11130. }
  11131. }
  11132. state.optionalChainMember = optional = true;
  11133. this.next();
  11134. }
  11135. if (!noCalls && this.match(10)) {
  11136. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  11137. } else {
  11138. const computed = this.eat(0);
  11139. if (computed || optional || this.eat(16)) {
  11140. return this.parseMember(base, startLoc, state, computed, optional);
  11141. } else {
  11142. return this.stopParseSubscript(base, state);
  11143. }
  11144. }
  11145. }
  11146. stopParseSubscript(base, state) {
  11147. state.stop = true;
  11148. return base;
  11149. }
  11150. parseMember(base, startLoc, state, computed, optional) {
  11151. const node = this.startNodeAt(startLoc);
  11152. node.object = base;
  11153. node.computed = computed;
  11154. if (computed) {
  11155. node.property = this.parseExpression();
  11156. this.expect(3);
  11157. } else if (this.match(139)) {
  11158. if (base.type === "Super") {
  11159. this.raise(Errors.SuperPrivateField, startLoc);
  11160. }
  11161. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  11162. node.property = this.parsePrivateName();
  11163. } else {
  11164. node.property = this.parseIdentifier(true);
  11165. }
  11166. if (state.optionalChainMember) {
  11167. node.optional = optional;
  11168. return this.finishNode(node, "OptionalMemberExpression");
  11169. } else {
  11170. return this.finishNode(node, "MemberExpression");
  11171. }
  11172. }
  11173. parseBind(base, startLoc, noCalls, state) {
  11174. const node = this.startNodeAt(startLoc);
  11175. node.object = base;
  11176. this.next();
  11177. node.callee = this.parseNoCallExpr();
  11178. state.stop = true;
  11179. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  11180. }
  11181. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  11182. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11183. let refExpressionErrors = null;
  11184. this.state.maybeInArrowParameters = true;
  11185. this.next();
  11186. const node = this.startNodeAt(startLoc);
  11187. node.callee = base;
  11188. const {
  11189. maybeAsyncArrow,
  11190. optionalChainMember
  11191. } = state;
  11192. if (maybeAsyncArrow) {
  11193. this.expressionScope.enter(newAsyncArrowScope());
  11194. refExpressionErrors = new ExpressionErrors();
  11195. }
  11196. if (optionalChainMember) {
  11197. node.optional = optional;
  11198. }
  11199. if (optional) {
  11200. node.arguments = this.parseCallExpressionArguments();
  11201. } else {
  11202. node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
  11203. }
  11204. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  11205. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  11206. state.stop = true;
  11207. this.checkDestructuringPrivate(refExpressionErrors);
  11208. this.expressionScope.validateAsPattern();
  11209. this.expressionScope.exit();
  11210. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  11211. } else {
  11212. if (maybeAsyncArrow) {
  11213. this.checkExpressionErrors(refExpressionErrors, true);
  11214. this.expressionScope.exit();
  11215. }
  11216. this.toReferencedArguments(finishedNode);
  11217. }
  11218. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11219. return finishedNode;
  11220. }
  11221. toReferencedArguments(node, isParenthesizedExpr) {
  11222. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11223. }
  11224. parseTaggedTemplateExpression(base, startLoc, state) {
  11225. const node = this.startNodeAt(startLoc);
  11226. node.tag = base;
  11227. node.quasi = this.parseTemplate(true);
  11228. if (state.optionalChainMember) {
  11229. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  11230. }
  11231. return this.finishNode(node, "TaggedTemplateExpression");
  11232. }
  11233. atPossibleAsyncArrow(base) {
  11234. 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;
  11235. }
  11236. finishCallExpression(node, optional) {
  11237. if (node.callee.type === "Import") {
  11238. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11239. this.raise(Errors.ImportCallArity, node);
  11240. } else {
  11241. for (const arg of node.arguments) {
  11242. if (arg.type === "SpreadElement") {
  11243. this.raise(Errors.ImportCallSpreadArgument, arg);
  11244. }
  11245. }
  11246. }
  11247. }
  11248. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11249. }
  11250. parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11251. const elts = [];
  11252. let first = true;
  11253. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11254. this.state.inFSharpPipelineDirectBody = false;
  11255. while (!this.eat(11)) {
  11256. if (first) {
  11257. first = false;
  11258. } else {
  11259. this.expect(12);
  11260. if (this.match(11)) {
  11261. if (nodeForExtra) {
  11262. this.addTrailingCommaExtraToNode(nodeForExtra);
  11263. }
  11264. this.next();
  11265. break;
  11266. }
  11267. }
  11268. elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
  11269. }
  11270. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11271. return elts;
  11272. }
  11273. shouldParseAsyncArrow() {
  11274. return this.match(19) && !this.canInsertSemicolon();
  11275. }
  11276. parseAsyncArrowFromCallExpression(node, call) {
  11277. var _call$extra;
  11278. this.resetPreviousNodeTrailingComments(call);
  11279. this.expect(19);
  11280. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11281. if (call.innerComments) {
  11282. setInnerComments(node, call.innerComments);
  11283. }
  11284. if (call.callee.trailingComments) {
  11285. setInnerComments(node, call.callee.trailingComments);
  11286. }
  11287. return node;
  11288. }
  11289. parseNoCallExpr() {
  11290. const startLoc = this.state.startLoc;
  11291. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11292. }
  11293. parseExprAtom(refExpressionErrors) {
  11294. let node;
  11295. let decorators = null;
  11296. const {
  11297. type
  11298. } = this.state;
  11299. switch (type) {
  11300. case 79:
  11301. return this.parseSuper();
  11302. case 83:
  11303. node = this.startNode();
  11304. this.next();
  11305. if (this.match(16)) {
  11306. return this.parseImportMetaPropertyOrPhaseCall(node);
  11307. }
  11308. if (this.match(10)) {
  11309. if (this.optionFlags & 512) {
  11310. return this.parseImportCall(node);
  11311. } else {
  11312. return this.finishNode(node, "Import");
  11313. }
  11314. } else {
  11315. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  11316. return this.finishNode(node, "Import");
  11317. }
  11318. case 78:
  11319. node = this.startNode();
  11320. this.next();
  11321. return this.finishNode(node, "ThisExpression");
  11322. case 90:
  11323. {
  11324. return this.parseDo(this.startNode(), false);
  11325. }
  11326. case 56:
  11327. case 31:
  11328. {
  11329. this.readRegexp();
  11330. return this.parseRegExpLiteral(this.state.value);
  11331. }
  11332. case 135:
  11333. return this.parseNumericLiteral(this.state.value);
  11334. case 136:
  11335. return this.parseBigIntLiteral(this.state.value);
  11336. case 134:
  11337. return this.parseStringLiteral(this.state.value);
  11338. case 84:
  11339. return this.parseNullLiteral();
  11340. case 85:
  11341. return this.parseBooleanLiteral(true);
  11342. case 86:
  11343. return this.parseBooleanLiteral(false);
  11344. case 10:
  11345. {
  11346. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11347. return this.parseParenAndDistinguishExpression(canBeArrow);
  11348. }
  11349. case 0:
  11350. {
  11351. return this.parseArrayLike(3, false, refExpressionErrors);
  11352. }
  11353. case 5:
  11354. {
  11355. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11356. }
  11357. case 68:
  11358. return this.parseFunctionOrFunctionSent();
  11359. case 26:
  11360. decorators = this.parseDecorators();
  11361. case 80:
  11362. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11363. case 77:
  11364. return this.parseNewOrNewTarget();
  11365. case 25:
  11366. case 24:
  11367. return this.parseTemplate(false);
  11368. case 15:
  11369. {
  11370. node = this.startNode();
  11371. this.next();
  11372. node.object = null;
  11373. const callee = node.callee = this.parseNoCallExpr();
  11374. if (callee.type === "MemberExpression") {
  11375. return this.finishNode(node, "BindExpression");
  11376. } else {
  11377. throw this.raise(Errors.UnsupportedBind, callee);
  11378. }
  11379. }
  11380. case 139:
  11381. {
  11382. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  11383. identifierName: this.state.value
  11384. });
  11385. return this.parsePrivateName();
  11386. }
  11387. case 33:
  11388. {
  11389. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11390. }
  11391. case 32:
  11392. {
  11393. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11394. }
  11395. case 37:
  11396. case 38:
  11397. {
  11398. return this.parseTopicReference("hack");
  11399. }
  11400. case 44:
  11401. case 54:
  11402. case 27:
  11403. {
  11404. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11405. if (pipeProposal) {
  11406. return this.parseTopicReference(pipeProposal);
  11407. }
  11408. throw this.unexpected();
  11409. }
  11410. case 47:
  11411. {
  11412. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11413. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11414. throw this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11415. }
  11416. throw this.unexpected();
  11417. }
  11418. default:
  11419. if (type === 137) {
  11420. return this.parseDecimalLiteral(this.state.value);
  11421. } else if (type === 2 || type === 1) {
  11422. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, true);
  11423. } else if (type === 6 || type === 7) {
  11424. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11425. }
  11426. if (tokenIsIdentifier(type)) {
  11427. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11428. return this.parseModuleExpression();
  11429. }
  11430. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11431. const containsEsc = this.state.containsEsc;
  11432. const id = this.parseIdentifier();
  11433. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11434. const {
  11435. type
  11436. } = this.state;
  11437. if (type === 68) {
  11438. this.resetPreviousNodeTrailingComments(id);
  11439. this.next();
  11440. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11441. } else if (tokenIsIdentifier(type)) {
  11442. if (canBeArrow && this.lookaheadCharCode() === 61) {
  11443. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11444. } else {
  11445. return id;
  11446. }
  11447. } else if (type === 90) {
  11448. this.resetPreviousNodeTrailingComments(id);
  11449. return this.parseDo(this.startNodeAtNode(id), true);
  11450. }
  11451. }
  11452. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11453. this.next();
  11454. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11455. }
  11456. return id;
  11457. } else {
  11458. throw this.unexpected();
  11459. }
  11460. }
  11461. }
  11462. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11463. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11464. if (pipeProposal) {
  11465. this.state.type = topicTokenType;
  11466. this.state.value = topicTokenValue;
  11467. this.state.pos--;
  11468. this.state.end--;
  11469. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11470. return this.parseTopicReference(pipeProposal);
  11471. }
  11472. throw this.unexpected();
  11473. }
  11474. parseTopicReference(pipeProposal) {
  11475. const node = this.startNode();
  11476. const startLoc = this.state.startLoc;
  11477. const tokenType = this.state.type;
  11478. this.next();
  11479. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11480. }
  11481. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11482. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11483. if (pipeProposal === "hack") {
  11484. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11485. this.raise(Errors.PipeTopicUnbound, startLoc);
  11486. }
  11487. this.registerTopicReference();
  11488. return this.finishNode(node, "TopicReference");
  11489. } else {
  11490. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11491. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  11492. }
  11493. this.registerTopicReference();
  11494. return this.finishNode(node, "PipelinePrimaryTopicReference");
  11495. }
  11496. } else {
  11497. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11498. token: tokenLabelName(tokenType)
  11499. });
  11500. }
  11501. }
  11502. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11503. switch (pipeProposal) {
  11504. case "hack":
  11505. {
  11506. return this.hasPlugin(["pipelineOperator", {
  11507. topicToken: tokenLabelName(tokenType)
  11508. }]);
  11509. }
  11510. case "smart":
  11511. return tokenType === 27;
  11512. default:
  11513. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11514. }
  11515. }
  11516. parseAsyncArrowUnaryFunction(node) {
  11517. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11518. const params = [this.parseIdentifier()];
  11519. this.prodParam.exit();
  11520. if (this.hasPrecedingLineBreak()) {
  11521. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11522. }
  11523. this.expect(19);
  11524. return this.parseArrowExpression(node, params, true);
  11525. }
  11526. parseDo(node, isAsync) {
  11527. this.expectPlugin("doExpressions");
  11528. if (isAsync) {
  11529. this.expectPlugin("asyncDoExpressions");
  11530. }
  11531. node.async = isAsync;
  11532. this.next();
  11533. const oldLabels = this.state.labels;
  11534. this.state.labels = [];
  11535. if (isAsync) {
  11536. this.prodParam.enter(2);
  11537. node.body = this.parseBlock();
  11538. this.prodParam.exit();
  11539. } else {
  11540. node.body = this.parseBlock();
  11541. }
  11542. this.state.labels = oldLabels;
  11543. return this.finishNode(node, "DoExpression");
  11544. }
  11545. parseSuper() {
  11546. const node = this.startNode();
  11547. this.next();
  11548. if (this.match(10) && !this.scope.allowDirectSuper) {
  11549. if (!(this.optionFlags & 16)) {
  11550. this.raise(Errors.SuperNotAllowed, node);
  11551. }
  11552. } else if (!this.scope.allowSuper) {
  11553. if (!(this.optionFlags & 16)) {
  11554. this.raise(Errors.UnexpectedSuper, node);
  11555. }
  11556. }
  11557. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11558. this.raise(Errors.UnsupportedSuper, node);
  11559. }
  11560. return this.finishNode(node, "Super");
  11561. }
  11562. parsePrivateName() {
  11563. const node = this.startNode();
  11564. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11565. const name = this.state.value;
  11566. this.next();
  11567. node.id = this.createIdentifier(id, name);
  11568. return this.finishNode(node, "PrivateName");
  11569. }
  11570. parseFunctionOrFunctionSent() {
  11571. const node = this.startNode();
  11572. this.next();
  11573. if (this.prodParam.hasYield && this.match(16)) {
  11574. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11575. this.next();
  11576. if (this.match(103)) {
  11577. this.expectPlugin("functionSent");
  11578. } else if (!this.hasPlugin("functionSent")) {
  11579. this.unexpected();
  11580. }
  11581. return this.parseMetaProperty(node, meta, "sent");
  11582. }
  11583. return this.parseFunction(node);
  11584. }
  11585. parseMetaProperty(node, meta, propertyName) {
  11586. node.meta = meta;
  11587. const containsEsc = this.state.containsEsc;
  11588. node.property = this.parseIdentifier(true);
  11589. if (node.property.name !== propertyName || containsEsc) {
  11590. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11591. target: meta.name,
  11592. onlyValidPropertyName: propertyName
  11593. });
  11594. }
  11595. return this.finishNode(node, "MetaProperty");
  11596. }
  11597. parseImportMetaPropertyOrPhaseCall(node) {
  11598. this.next();
  11599. if (this.isContextual(105) || this.isContextual(97)) {
  11600. const isSource = this.isContextual(105);
  11601. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11602. this.next();
  11603. node.phase = isSource ? "source" : "defer";
  11604. return this.parseImportCall(node);
  11605. } else {
  11606. const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
  11607. if (this.isContextual(101)) {
  11608. if (!this.inModule) {
  11609. this.raise(Errors.ImportMetaOutsideModule, id);
  11610. }
  11611. this.sawUnambiguousESM = true;
  11612. }
  11613. return this.parseMetaProperty(node, id, "meta");
  11614. }
  11615. }
  11616. parseLiteralAtNode(value, type, node) {
  11617. this.addExtra(node, "rawValue", value);
  11618. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11619. node.value = value;
  11620. this.next();
  11621. return this.finishNode(node, type);
  11622. }
  11623. parseLiteral(value, type) {
  11624. const node = this.startNode();
  11625. return this.parseLiteralAtNode(value, type, node);
  11626. }
  11627. parseStringLiteral(value) {
  11628. return this.parseLiteral(value, "StringLiteral");
  11629. }
  11630. parseNumericLiteral(value) {
  11631. return this.parseLiteral(value, "NumericLiteral");
  11632. }
  11633. parseBigIntLiteral(value) {
  11634. return this.parseLiteral(value, "BigIntLiteral");
  11635. }
  11636. parseDecimalLiteral(value) {
  11637. return this.parseLiteral(value, "DecimalLiteral");
  11638. }
  11639. parseRegExpLiteral(value) {
  11640. const node = this.startNode();
  11641. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11642. node.pattern = value.pattern;
  11643. node.flags = value.flags;
  11644. this.next();
  11645. return this.finishNode(node, "RegExpLiteral");
  11646. }
  11647. parseBooleanLiteral(value) {
  11648. const node = this.startNode();
  11649. node.value = value;
  11650. this.next();
  11651. return this.finishNode(node, "BooleanLiteral");
  11652. }
  11653. parseNullLiteral() {
  11654. const node = this.startNode();
  11655. this.next();
  11656. return this.finishNode(node, "NullLiteral");
  11657. }
  11658. parseParenAndDistinguishExpression(canBeArrow) {
  11659. const startLoc = this.state.startLoc;
  11660. let val;
  11661. this.next();
  11662. this.expressionScope.enter(newArrowHeadScope());
  11663. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11664. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11665. this.state.maybeInArrowParameters = true;
  11666. this.state.inFSharpPipelineDirectBody = false;
  11667. const innerStartLoc = this.state.startLoc;
  11668. const exprList = [];
  11669. const refExpressionErrors = new ExpressionErrors();
  11670. let first = true;
  11671. let spreadStartLoc;
  11672. let optionalCommaStartLoc;
  11673. while (!this.match(11)) {
  11674. if (first) {
  11675. first = false;
  11676. } else {
  11677. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11678. if (this.match(11)) {
  11679. optionalCommaStartLoc = this.state.startLoc;
  11680. break;
  11681. }
  11682. }
  11683. if (this.match(21)) {
  11684. const spreadNodeStartLoc = this.state.startLoc;
  11685. spreadStartLoc = this.state.startLoc;
  11686. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11687. if (!this.checkCommaAfterRest(41)) {
  11688. break;
  11689. }
  11690. } else {
  11691. exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
  11692. }
  11693. }
  11694. const innerEndLoc = this.state.lastTokEndLoc;
  11695. this.expect(11);
  11696. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11697. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11698. let arrowNode = this.startNodeAt(startLoc);
  11699. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11700. this.checkDestructuringPrivate(refExpressionErrors);
  11701. this.expressionScope.validateAsPattern();
  11702. this.expressionScope.exit();
  11703. this.parseArrowExpression(arrowNode, exprList, false);
  11704. return arrowNode;
  11705. }
  11706. this.expressionScope.exit();
  11707. if (!exprList.length) {
  11708. this.unexpected(this.state.lastTokStartLoc);
  11709. }
  11710. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11711. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11712. this.checkExpressionErrors(refExpressionErrors, true);
  11713. this.toReferencedListDeep(exprList, true);
  11714. if (exprList.length > 1) {
  11715. val = this.startNodeAt(innerStartLoc);
  11716. val.expressions = exprList;
  11717. this.finishNode(val, "SequenceExpression");
  11718. this.resetEndLocation(val, innerEndLoc);
  11719. } else {
  11720. val = exprList[0];
  11721. }
  11722. return this.wrapParenthesis(startLoc, val);
  11723. }
  11724. wrapParenthesis(startLoc, expression) {
  11725. if (!(this.optionFlags & 1024)) {
  11726. this.addExtra(expression, "parenthesized", true);
  11727. this.addExtra(expression, "parenStart", startLoc.index);
  11728. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11729. return expression;
  11730. }
  11731. const parenExpression = this.startNodeAt(startLoc);
  11732. parenExpression.expression = expression;
  11733. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11734. }
  11735. shouldParseArrow(params) {
  11736. return !this.canInsertSemicolon();
  11737. }
  11738. parseArrow(node) {
  11739. if (this.eat(19)) {
  11740. return node;
  11741. }
  11742. }
  11743. parseParenItem(node, startLoc) {
  11744. return node;
  11745. }
  11746. parseNewOrNewTarget() {
  11747. const node = this.startNode();
  11748. this.next();
  11749. if (this.match(16)) {
  11750. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11751. this.next();
  11752. const metaProp = this.parseMetaProperty(node, meta, "target");
  11753. if (!this.scope.allowNewTarget) {
  11754. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11755. }
  11756. return metaProp;
  11757. }
  11758. return this.parseNew(node);
  11759. }
  11760. parseNew(node) {
  11761. this.parseNewCallee(node);
  11762. if (this.eat(10)) {
  11763. const args = this.parseExprList(11);
  11764. this.toReferencedList(args);
  11765. node.arguments = args;
  11766. } else {
  11767. node.arguments = [];
  11768. }
  11769. return this.finishNode(node, "NewExpression");
  11770. }
  11771. parseNewCallee(node) {
  11772. const isImport = this.match(83);
  11773. const callee = this.parseNoCallExpr();
  11774. node.callee = callee;
  11775. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11776. this.raise(Errors.ImportCallNotNewExpression, callee);
  11777. }
  11778. }
  11779. parseTemplateElement(isTagged) {
  11780. const {
  11781. start,
  11782. startLoc,
  11783. end,
  11784. value
  11785. } = this.state;
  11786. const elemStart = start + 1;
  11787. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11788. if (value === null) {
  11789. if (!isTagged) {
  11790. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11791. }
  11792. }
  11793. const isTail = this.match(24);
  11794. const endOffset = isTail ? -1 : -2;
  11795. const elemEnd = end + endOffset;
  11796. elem.value = {
  11797. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11798. cooked: value === null ? null : value.slice(1, endOffset)
  11799. };
  11800. elem.tail = isTail;
  11801. this.next();
  11802. const finishedNode = this.finishNode(elem, "TemplateElement");
  11803. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11804. return finishedNode;
  11805. }
  11806. parseTemplate(isTagged) {
  11807. const node = this.startNode();
  11808. let curElt = this.parseTemplateElement(isTagged);
  11809. const quasis = [curElt];
  11810. const substitutions = [];
  11811. while (!curElt.tail) {
  11812. substitutions.push(this.parseTemplateSubstitution());
  11813. this.readTemplateContinuation();
  11814. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11815. }
  11816. node.expressions = substitutions;
  11817. node.quasis = quasis;
  11818. return this.finishNode(node, "TemplateLiteral");
  11819. }
  11820. parseTemplateSubstitution() {
  11821. return this.parseExpression();
  11822. }
  11823. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11824. if (isRecord) {
  11825. this.expectPlugin("recordAndTuple");
  11826. }
  11827. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11828. this.state.inFSharpPipelineDirectBody = false;
  11829. let sawProto = false;
  11830. let first = true;
  11831. const node = this.startNode();
  11832. node.properties = [];
  11833. this.next();
  11834. while (!this.match(close)) {
  11835. if (first) {
  11836. first = false;
  11837. } else {
  11838. this.expect(12);
  11839. if (this.match(close)) {
  11840. this.addTrailingCommaExtraToNode(node);
  11841. break;
  11842. }
  11843. }
  11844. let prop;
  11845. if (isPattern) {
  11846. prop = this.parseBindingProperty();
  11847. } else {
  11848. prop = this.parsePropertyDefinition(refExpressionErrors);
  11849. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  11850. }
  11851. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11852. this.raise(Errors.InvalidRecordProperty, prop);
  11853. }
  11854. if (prop.shorthand) {
  11855. this.addExtra(prop, "shorthand", true);
  11856. }
  11857. node.properties.push(prop);
  11858. }
  11859. this.next();
  11860. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11861. let type = "ObjectExpression";
  11862. if (isPattern) {
  11863. type = "ObjectPattern";
  11864. } else if (isRecord) {
  11865. type = "RecordExpression";
  11866. }
  11867. return this.finishNode(node, type);
  11868. }
  11869. addTrailingCommaExtraToNode(node) {
  11870. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11871. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11872. }
  11873. maybeAsyncOrAccessorProp(prop) {
  11874. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11875. }
  11876. parsePropertyDefinition(refExpressionErrors) {
  11877. let decorators = [];
  11878. if (this.match(26)) {
  11879. if (this.hasPlugin("decorators")) {
  11880. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11881. }
  11882. while (this.match(26)) {
  11883. decorators.push(this.parseDecorator());
  11884. }
  11885. }
  11886. const prop = this.startNode();
  11887. let isAsync = false;
  11888. let isAccessor = false;
  11889. let startLoc;
  11890. if (this.match(21)) {
  11891. if (decorators.length) this.unexpected();
  11892. return this.parseSpread();
  11893. }
  11894. if (decorators.length) {
  11895. prop.decorators = decorators;
  11896. decorators = [];
  11897. }
  11898. prop.method = false;
  11899. if (refExpressionErrors) {
  11900. startLoc = this.state.startLoc;
  11901. }
  11902. let isGenerator = this.eat(55);
  11903. this.parsePropertyNamePrefixOperator(prop);
  11904. const containsEsc = this.state.containsEsc;
  11905. this.parsePropertyName(prop, refExpressionErrors);
  11906. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11907. const {
  11908. key
  11909. } = prop;
  11910. const keyName = key.name;
  11911. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11912. isAsync = true;
  11913. this.resetPreviousNodeTrailingComments(key);
  11914. isGenerator = this.eat(55);
  11915. this.parsePropertyName(prop);
  11916. }
  11917. if (keyName === "get" || keyName === "set") {
  11918. isAccessor = true;
  11919. this.resetPreviousNodeTrailingComments(key);
  11920. prop.kind = keyName;
  11921. if (this.match(55)) {
  11922. isGenerator = true;
  11923. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11924. kind: keyName
  11925. });
  11926. this.next();
  11927. }
  11928. this.parsePropertyName(prop);
  11929. }
  11930. }
  11931. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11932. }
  11933. getGetterSetterExpectedParamCount(method) {
  11934. return method.kind === "get" ? 0 : 1;
  11935. }
  11936. getObjectOrClassMethodParams(method) {
  11937. return method.params;
  11938. }
  11939. checkGetterSetterParams(method) {
  11940. var _params;
  11941. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11942. const params = this.getObjectOrClassMethodParams(method);
  11943. if (params.length !== paramCount) {
  11944. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  11945. }
  11946. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11947. this.raise(Errors.BadSetterRestParameter, method);
  11948. }
  11949. }
  11950. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11951. if (isAccessor) {
  11952. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11953. this.checkGetterSetterParams(finishedProp);
  11954. return finishedProp;
  11955. }
  11956. if (isAsync || isGenerator || this.match(10)) {
  11957. if (isPattern) this.unexpected();
  11958. prop.kind = "method";
  11959. prop.method = true;
  11960. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11961. }
  11962. }
  11963. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11964. prop.shorthand = false;
  11965. if (this.eat(14)) {
  11966. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
  11967. return this.finishObjectProperty(prop);
  11968. }
  11969. if (!prop.computed && prop.key.type === "Identifier") {
  11970. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11971. if (isPattern) {
  11972. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  11973. } else if (this.match(29)) {
  11974. const shorthandAssignLoc = this.state.startLoc;
  11975. if (refExpressionErrors != null) {
  11976. if (refExpressionErrors.shorthandAssignLoc === null) {
  11977. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11978. }
  11979. } else {
  11980. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11981. }
  11982. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  11983. } else {
  11984. prop.value = this.cloneIdentifier(prop.key);
  11985. }
  11986. prop.shorthand = true;
  11987. return this.finishObjectProperty(prop);
  11988. }
  11989. }
  11990. finishObjectProperty(node) {
  11991. return this.finishNode(node, "ObjectProperty");
  11992. }
  11993. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11994. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11995. if (!node) this.unexpected();
  11996. return node;
  11997. }
  11998. parsePropertyName(prop, refExpressionErrors) {
  11999. if (this.eat(0)) {
  12000. prop.computed = true;
  12001. prop.key = this.parseMaybeAssignAllowIn();
  12002. this.expect(3);
  12003. } else {
  12004. const {
  12005. type,
  12006. value
  12007. } = this.state;
  12008. let key;
  12009. if (tokenIsKeywordOrIdentifier(type)) {
  12010. key = this.parseIdentifier(true);
  12011. } else {
  12012. switch (type) {
  12013. case 135:
  12014. key = this.parseNumericLiteral(value);
  12015. break;
  12016. case 134:
  12017. key = this.parseStringLiteral(value);
  12018. break;
  12019. case 136:
  12020. key = this.parseBigIntLiteral(value);
  12021. break;
  12022. case 139:
  12023. {
  12024. const privateKeyLoc = this.state.startLoc;
  12025. if (refExpressionErrors != null) {
  12026. if (refExpressionErrors.privateKeyLoc === null) {
  12027. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  12028. }
  12029. } else {
  12030. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  12031. }
  12032. key = this.parsePrivateName();
  12033. break;
  12034. }
  12035. default:
  12036. if (type === 137) {
  12037. key = this.parseDecimalLiteral(value);
  12038. break;
  12039. }
  12040. this.unexpected();
  12041. }
  12042. }
  12043. prop.key = key;
  12044. if (type !== 139) {
  12045. prop.computed = false;
  12046. }
  12047. }
  12048. }
  12049. initFunction(node, isAsync) {
  12050. node.id = null;
  12051. node.generator = false;
  12052. node.async = isAsync;
  12053. }
  12054. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  12055. this.initFunction(node, isAsync);
  12056. node.generator = isGenerator;
  12057. this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
  12058. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12059. this.parseFunctionParams(node, isConstructor);
  12060. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  12061. this.prodParam.exit();
  12062. this.scope.exit();
  12063. return finishedNode;
  12064. }
  12065. parseArrayLike(close, isTuple, refExpressionErrors) {
  12066. if (isTuple) {
  12067. this.expectPlugin("recordAndTuple");
  12068. }
  12069. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12070. this.state.inFSharpPipelineDirectBody = false;
  12071. const node = this.startNode();
  12072. this.next();
  12073. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  12074. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12075. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  12076. }
  12077. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  12078. this.scope.enter(514 | 4);
  12079. let flags = functionFlags(isAsync, false);
  12080. if (!this.match(5) && this.prodParam.hasIn) {
  12081. flags |= 8;
  12082. }
  12083. this.prodParam.enter(flags);
  12084. this.initFunction(node, isAsync);
  12085. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12086. if (params) {
  12087. this.state.maybeInArrowParameters = true;
  12088. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  12089. }
  12090. this.state.maybeInArrowParameters = false;
  12091. this.parseFunctionBody(node, true);
  12092. this.prodParam.exit();
  12093. this.scope.exit();
  12094. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12095. return this.finishNode(node, "ArrowFunctionExpression");
  12096. }
  12097. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  12098. this.toAssignableList(params, trailingCommaLoc, false);
  12099. node.params = params;
  12100. }
  12101. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  12102. this.parseFunctionBody(node, false, isMethod);
  12103. return this.finishNode(node, type);
  12104. }
  12105. parseFunctionBody(node, allowExpression, isMethod = false) {
  12106. const isExpression = allowExpression && !this.match(5);
  12107. this.expressionScope.enter(newExpressionScope());
  12108. if (isExpression) {
  12109. node.body = this.parseMaybeAssign();
  12110. this.checkParams(node, false, allowExpression, false);
  12111. } else {
  12112. const oldStrict = this.state.strict;
  12113. const oldLabels = this.state.labels;
  12114. this.state.labels = [];
  12115. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  12116. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  12117. const nonSimple = !this.isSimpleParamList(node.params);
  12118. if (hasStrictModeDirective && nonSimple) {
  12119. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  12120. }
  12121. const strictModeChanged = !oldStrict && this.state.strict;
  12122. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  12123. if (this.state.strict && node.id) {
  12124. this.checkIdentifier(node.id, 65, strictModeChanged);
  12125. }
  12126. });
  12127. this.prodParam.exit();
  12128. this.state.labels = oldLabels;
  12129. }
  12130. this.expressionScope.exit();
  12131. }
  12132. isSimpleParameter(node) {
  12133. return node.type === "Identifier";
  12134. }
  12135. isSimpleParamList(params) {
  12136. for (let i = 0, len = params.length; i < len; i++) {
  12137. if (!this.isSimpleParameter(params[i])) return false;
  12138. }
  12139. return true;
  12140. }
  12141. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  12142. const checkClashes = !allowDuplicates && new Set();
  12143. const formalParameters = {
  12144. type: "FormalParameters"
  12145. };
  12146. for (const param of node.params) {
  12147. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  12148. }
  12149. }
  12150. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  12151. const elts = [];
  12152. let first = true;
  12153. while (!this.eat(close)) {
  12154. if (first) {
  12155. first = false;
  12156. } else {
  12157. this.expect(12);
  12158. if (this.match(close)) {
  12159. if (nodeForExtra) {
  12160. this.addTrailingCommaExtraToNode(nodeForExtra);
  12161. }
  12162. this.next();
  12163. break;
  12164. }
  12165. }
  12166. elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
  12167. }
  12168. return elts;
  12169. }
  12170. parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
  12171. let elt;
  12172. if (this.match(12)) {
  12173. if (!allowEmpty) {
  12174. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  12175. unexpected: ","
  12176. });
  12177. }
  12178. elt = null;
  12179. } else if (this.match(21)) {
  12180. const spreadNodeStartLoc = this.state.startLoc;
  12181. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12182. } else if (this.match(17)) {
  12183. this.expectPlugin("partialApplication");
  12184. if (!allowPlaceholder) {
  12185. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  12186. }
  12187. const node = this.startNode();
  12188. this.next();
  12189. elt = this.finishNode(node, "ArgumentPlaceholder");
  12190. } else {
  12191. elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
  12192. }
  12193. return elt;
  12194. }
  12195. parseIdentifier(liberal) {
  12196. const node = this.startNode();
  12197. const name = this.parseIdentifierName(liberal);
  12198. return this.createIdentifier(node, name);
  12199. }
  12200. createIdentifier(node, name) {
  12201. node.name = name;
  12202. node.loc.identifierName = name;
  12203. return this.finishNode(node, "Identifier");
  12204. }
  12205. createIdentifierAt(node, name, endLoc) {
  12206. node.name = name;
  12207. node.loc.identifierName = name;
  12208. return this.finishNodeAt(node, "Identifier", endLoc);
  12209. }
  12210. parseIdentifierName(liberal) {
  12211. let name;
  12212. const {
  12213. startLoc,
  12214. type
  12215. } = this.state;
  12216. if (tokenIsKeywordOrIdentifier(type)) {
  12217. name = this.state.value;
  12218. } else {
  12219. this.unexpected();
  12220. }
  12221. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12222. if (liberal) {
  12223. if (tokenIsKeyword) {
  12224. this.replaceToken(132);
  12225. }
  12226. } else {
  12227. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12228. }
  12229. this.next();
  12230. return name;
  12231. }
  12232. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12233. if (word.length > 10) {
  12234. return;
  12235. }
  12236. if (!canBeReservedWord(word)) {
  12237. return;
  12238. }
  12239. if (checkKeywords && isKeyword(word)) {
  12240. this.raise(Errors.UnexpectedKeyword, startLoc, {
  12241. keyword: word
  12242. });
  12243. return;
  12244. }
  12245. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12246. if (reservedTest(word, this.inModule)) {
  12247. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  12248. reservedWord: word
  12249. });
  12250. return;
  12251. } else if (word === "yield") {
  12252. if (this.prodParam.hasYield) {
  12253. this.raise(Errors.YieldBindingIdentifier, startLoc);
  12254. return;
  12255. }
  12256. } else if (word === "await") {
  12257. if (this.prodParam.hasAwait) {
  12258. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  12259. return;
  12260. }
  12261. if (this.scope.inStaticBlock) {
  12262. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  12263. return;
  12264. }
  12265. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  12266. } else if (word === "arguments") {
  12267. if (this.scope.inClassAndNotInNonArrowFunction) {
  12268. this.raise(Errors.ArgumentsInClass, startLoc);
  12269. return;
  12270. }
  12271. }
  12272. }
  12273. recordAwaitIfAllowed() {
  12274. const isAwaitAllowed = this.prodParam.hasAwait;
  12275. if (isAwaitAllowed && !this.scope.inFunction) {
  12276. this.state.hasTopLevelAwait = true;
  12277. }
  12278. return isAwaitAllowed;
  12279. }
  12280. parseAwait(startLoc) {
  12281. const node = this.startNodeAt(startLoc);
  12282. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  12283. if (this.eat(55)) {
  12284. this.raise(Errors.ObsoleteAwaitStar, node);
  12285. }
  12286. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  12287. if (this.isAmbiguousPrefixOrIdentifier()) {
  12288. this.ambiguousScriptDifferentAst = true;
  12289. } else {
  12290. this.sawUnambiguousESM = true;
  12291. }
  12292. }
  12293. if (!this.state.soloAwait) {
  12294. node.argument = this.parseMaybeUnary(null, true);
  12295. }
  12296. return this.finishNode(node, "AwaitExpression");
  12297. }
  12298. isAmbiguousPrefixOrIdentifier() {
  12299. if (this.hasPrecedingLineBreak()) return true;
  12300. const {
  12301. type
  12302. } = this.state;
  12303. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12304. }
  12305. parseYield(startLoc) {
  12306. const node = this.startNodeAt(startLoc);
  12307. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  12308. let delegating = false;
  12309. let argument = null;
  12310. if (!this.hasPrecedingLineBreak()) {
  12311. delegating = this.eat(55);
  12312. switch (this.state.type) {
  12313. case 13:
  12314. case 140:
  12315. case 8:
  12316. case 11:
  12317. case 3:
  12318. case 9:
  12319. case 14:
  12320. case 12:
  12321. if (!delegating) break;
  12322. default:
  12323. argument = this.parseMaybeAssign();
  12324. }
  12325. }
  12326. node.delegate = delegating;
  12327. node.argument = argument;
  12328. return this.finishNode(node, "YieldExpression");
  12329. }
  12330. parseImportCall(node) {
  12331. this.next();
  12332. node.source = this.parseMaybeAssignAllowIn();
  12333. node.options = null;
  12334. if (this.eat(12)) {
  12335. if (!this.match(11)) {
  12336. node.options = this.parseMaybeAssignAllowIn();
  12337. if (this.eat(12)) {
  12338. this.addTrailingCommaExtraToNode(node.options);
  12339. if (!this.match(11)) {
  12340. do {
  12341. this.parseMaybeAssignAllowIn();
  12342. } while (this.eat(12) && !this.match(11));
  12343. this.raise(Errors.ImportCallArity, node);
  12344. }
  12345. }
  12346. } else {
  12347. this.addTrailingCommaExtraToNode(node.source);
  12348. }
  12349. }
  12350. this.expect(11);
  12351. return this.finishNode(node, "ImportExpression");
  12352. }
  12353. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12354. if (this.hasPlugin(["pipelineOperator", {
  12355. proposal: "smart"
  12356. }])) {
  12357. if (left.type === "SequenceExpression") {
  12358. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  12359. }
  12360. }
  12361. }
  12362. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12363. if (this.isSimpleReference(childExpr)) {
  12364. const bodyNode = this.startNodeAt(startLoc);
  12365. bodyNode.callee = childExpr;
  12366. return this.finishNode(bodyNode, "PipelineBareFunction");
  12367. } else {
  12368. const bodyNode = this.startNodeAt(startLoc);
  12369. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12370. bodyNode.expression = childExpr;
  12371. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12372. }
  12373. }
  12374. isSimpleReference(expression) {
  12375. switch (expression.type) {
  12376. case "MemberExpression":
  12377. return !expression.computed && this.isSimpleReference(expression.object);
  12378. case "Identifier":
  12379. return true;
  12380. default:
  12381. return false;
  12382. }
  12383. }
  12384. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12385. if (this.match(19)) {
  12386. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  12387. }
  12388. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12389. this.raise(Errors.PipelineTopicUnused, startLoc);
  12390. }
  12391. }
  12392. withTopicBindingContext(callback) {
  12393. const outerContextTopicState = this.state.topicContext;
  12394. this.state.topicContext = {
  12395. maxNumOfResolvableTopics: 1,
  12396. maxTopicIndex: null
  12397. };
  12398. try {
  12399. return callback();
  12400. } finally {
  12401. this.state.topicContext = outerContextTopicState;
  12402. }
  12403. }
  12404. withSmartMixTopicForbiddingContext(callback) {
  12405. if (this.hasPlugin(["pipelineOperator", {
  12406. proposal: "smart"
  12407. }])) {
  12408. const outerContextTopicState = this.state.topicContext;
  12409. this.state.topicContext = {
  12410. maxNumOfResolvableTopics: 0,
  12411. maxTopicIndex: null
  12412. };
  12413. try {
  12414. return callback();
  12415. } finally {
  12416. this.state.topicContext = outerContextTopicState;
  12417. }
  12418. } else {
  12419. return callback();
  12420. }
  12421. }
  12422. withSoloAwaitPermittingContext(callback) {
  12423. const outerContextSoloAwaitState = this.state.soloAwait;
  12424. this.state.soloAwait = true;
  12425. try {
  12426. return callback();
  12427. } finally {
  12428. this.state.soloAwait = outerContextSoloAwaitState;
  12429. }
  12430. }
  12431. allowInAnd(callback) {
  12432. const flags = this.prodParam.currentFlags();
  12433. const prodParamToSet = 8 & ~flags;
  12434. if (prodParamToSet) {
  12435. this.prodParam.enter(flags | 8);
  12436. try {
  12437. return callback();
  12438. } finally {
  12439. this.prodParam.exit();
  12440. }
  12441. }
  12442. return callback();
  12443. }
  12444. disallowInAnd(callback) {
  12445. const flags = this.prodParam.currentFlags();
  12446. const prodParamToClear = 8 & flags;
  12447. if (prodParamToClear) {
  12448. this.prodParam.enter(flags & ~8);
  12449. try {
  12450. return callback();
  12451. } finally {
  12452. this.prodParam.exit();
  12453. }
  12454. }
  12455. return callback();
  12456. }
  12457. registerTopicReference() {
  12458. this.state.topicContext.maxTopicIndex = 0;
  12459. }
  12460. topicReferenceIsAllowedInCurrentContext() {
  12461. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12462. }
  12463. topicReferenceWasUsedInCurrentContext() {
  12464. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12465. }
  12466. parseFSharpPipelineBody(prec) {
  12467. const startLoc = this.state.startLoc;
  12468. this.state.potentialArrowAt = this.state.start;
  12469. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12470. this.state.inFSharpPipelineDirectBody = true;
  12471. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12472. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12473. return ret;
  12474. }
  12475. parseModuleExpression() {
  12476. this.expectPlugin("moduleBlocks");
  12477. const node = this.startNode();
  12478. this.next();
  12479. if (!this.match(5)) {
  12480. this.unexpected(null, 5);
  12481. }
  12482. const program = this.startNodeAt(this.state.endLoc);
  12483. this.next();
  12484. const revertScopes = this.initializeScopes(true);
  12485. this.enterInitialScopes();
  12486. try {
  12487. node.body = this.parseProgram(program, 8, "module");
  12488. } finally {
  12489. revertScopes();
  12490. }
  12491. return this.finishNode(node, "ModuleExpression");
  12492. }
  12493. parseVoidPattern(refExpressionErrors) {
  12494. this.expectPlugin("discardBinding");
  12495. const node = this.startNode();
  12496. if (refExpressionErrors != null) {
  12497. refExpressionErrors.voidPatternLoc = this.state.startLoc;
  12498. }
  12499. this.next();
  12500. return this.finishNode(node, "VoidPattern");
  12501. }
  12502. parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
  12503. if (refExpressionErrors != null && this.match(88)) {
  12504. const nextCode = this.lookaheadCharCode();
  12505. if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
  12506. return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
  12507. }
  12508. }
  12509. return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
  12510. }
  12511. parsePropertyNamePrefixOperator(prop) {}
  12512. }
  12513. const loopLabel = {
  12514. kind: 1
  12515. },
  12516. switchLabel = {
  12517. kind: 2
  12518. };
  12519. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12520. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12521. function babel7CompatTokens(tokens, input, startIndex) {
  12522. for (let i = 0; i < tokens.length; i++) {
  12523. const token = tokens[i];
  12524. const {
  12525. type
  12526. } = token;
  12527. if (typeof type === "number") {
  12528. if (type === 139) {
  12529. const {
  12530. loc,
  12531. start,
  12532. value,
  12533. end
  12534. } = token;
  12535. const hashEndPos = start + 1;
  12536. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12537. tokens.splice(i, 1, new Token({
  12538. type: getExportedToken(27),
  12539. value: "#",
  12540. start: start,
  12541. end: hashEndPos,
  12542. startLoc: loc.start,
  12543. endLoc: hashEndLoc
  12544. }), new Token({
  12545. type: getExportedToken(132),
  12546. value: value,
  12547. start: hashEndPos,
  12548. end: end,
  12549. startLoc: hashEndLoc,
  12550. endLoc: loc.end
  12551. }));
  12552. i++;
  12553. continue;
  12554. }
  12555. if (tokenIsTemplate(type)) {
  12556. const {
  12557. loc,
  12558. start,
  12559. value,
  12560. end
  12561. } = token;
  12562. const backquoteEnd = start + 1;
  12563. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12564. let startToken;
  12565. if (input.charCodeAt(start - startIndex) === 96) {
  12566. startToken = new Token({
  12567. type: getExportedToken(22),
  12568. value: "`",
  12569. start: start,
  12570. end: backquoteEnd,
  12571. startLoc: loc.start,
  12572. endLoc: backquoteEndLoc
  12573. });
  12574. } else {
  12575. startToken = new Token({
  12576. type: getExportedToken(8),
  12577. value: "}",
  12578. start: start,
  12579. end: backquoteEnd,
  12580. startLoc: loc.start,
  12581. endLoc: backquoteEndLoc
  12582. });
  12583. }
  12584. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12585. if (type === 24) {
  12586. templateElementEnd = end - 1;
  12587. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12588. templateValue = value === null ? null : value.slice(1, -1);
  12589. endToken = new Token({
  12590. type: getExportedToken(22),
  12591. value: "`",
  12592. start: templateElementEnd,
  12593. end: end,
  12594. startLoc: templateElementEndLoc,
  12595. endLoc: loc.end
  12596. });
  12597. } else {
  12598. templateElementEnd = end - 2;
  12599. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12600. templateValue = value === null ? null : value.slice(1, -2);
  12601. endToken = new Token({
  12602. type: getExportedToken(23),
  12603. value: "${",
  12604. start: templateElementEnd,
  12605. end: end,
  12606. startLoc: templateElementEndLoc,
  12607. endLoc: loc.end
  12608. });
  12609. }
  12610. tokens.splice(i, 1, startToken, new Token({
  12611. type: getExportedToken(20),
  12612. value: templateValue,
  12613. start: backquoteEnd,
  12614. end: templateElementEnd,
  12615. startLoc: backquoteEndLoc,
  12616. endLoc: templateElementEndLoc
  12617. }), endToken);
  12618. i += 2;
  12619. continue;
  12620. }
  12621. token.type = getExportedToken(type);
  12622. }
  12623. }
  12624. return tokens;
  12625. }
  12626. class StatementParser extends ExpressionParser {
  12627. parseTopLevel(file, program) {
  12628. file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
  12629. file.comments = this.comments;
  12630. if (this.optionFlags & 256) {
  12631. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  12632. }
  12633. return this.finishNode(file, "File");
  12634. }
  12635. parseProgram(program, end, sourceType) {
  12636. program.sourceType = sourceType;
  12637. program.interpreter = this.parseInterpreterDirective();
  12638. this.parseBlockBody(program, true, true, end);
  12639. if (this.inModule) {
  12640. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  12641. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12642. this.raise(Errors.ModuleExportUndefined, at, {
  12643. localName
  12644. });
  12645. }
  12646. }
  12647. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  12648. }
  12649. let finishedProgram;
  12650. if (end === 140) {
  12651. finishedProgram = this.finishNode(program, "Program");
  12652. } else {
  12653. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12654. }
  12655. return finishedProgram;
  12656. }
  12657. stmtToDirective(stmt) {
  12658. const directive = this.castNodeTo(stmt, "Directive");
  12659. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  12660. const expressionValue = directiveLiteral.value;
  12661. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  12662. const val = directiveLiteral.value = raw.slice(1, -1);
  12663. this.addExtra(directiveLiteral, "raw", raw);
  12664. this.addExtra(directiveLiteral, "rawValue", val);
  12665. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12666. directive.value = directiveLiteral;
  12667. delete stmt.expression;
  12668. return directive;
  12669. }
  12670. parseInterpreterDirective() {
  12671. if (!this.match(28)) {
  12672. return null;
  12673. }
  12674. const node = this.startNode();
  12675. node.value = this.state.value;
  12676. this.next();
  12677. return this.finishNode(node, "InterpreterDirective");
  12678. }
  12679. isLet() {
  12680. if (!this.isContextual(100)) {
  12681. return false;
  12682. }
  12683. return this.hasFollowingBindingAtom();
  12684. }
  12685. isUsing() {
  12686. if (!this.isContextual(107)) {
  12687. return false;
  12688. }
  12689. return this.nextTokenIsIdentifierOnSameLine();
  12690. }
  12691. isForUsing() {
  12692. if (!this.isContextual(107)) {
  12693. return false;
  12694. }
  12695. const next = this.nextTokenInLineStart();
  12696. const nextCh = this.codePointAtPos(next);
  12697. if (this.isUnparsedContextual(next, "of")) {
  12698. const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
  12699. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  12700. return false;
  12701. }
  12702. }
  12703. if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
  12704. return true;
  12705. }
  12706. return false;
  12707. }
  12708. nextTokenIsIdentifierOnSameLine() {
  12709. const next = this.nextTokenInLineStart();
  12710. const nextCh = this.codePointAtPos(next);
  12711. return this.chStartsBindingIdentifier(nextCh, next);
  12712. }
  12713. isAwaitUsing() {
  12714. if (!this.isContextual(96)) {
  12715. return false;
  12716. }
  12717. let next = this.nextTokenInLineStart();
  12718. if (this.isUnparsedContextual(next, "using")) {
  12719. next = this.nextTokenInLineStartSince(next + 5);
  12720. const nextCh = this.codePointAtPos(next);
  12721. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12722. return true;
  12723. }
  12724. }
  12725. return false;
  12726. }
  12727. chStartsBindingIdentifier(ch, pos) {
  12728. if (isIdentifierStart(ch)) {
  12729. keywordRelationalOperator.lastIndex = pos;
  12730. if (keywordRelationalOperator.test(this.input)) {
  12731. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12732. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12733. return false;
  12734. }
  12735. }
  12736. return true;
  12737. } else if (ch === 92) {
  12738. return true;
  12739. } else {
  12740. return false;
  12741. }
  12742. }
  12743. chStartsBindingPattern(ch) {
  12744. return ch === 91 || ch === 123;
  12745. }
  12746. hasFollowingBindingAtom() {
  12747. const next = this.nextTokenStart();
  12748. const nextCh = this.codePointAtPos(next);
  12749. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12750. }
  12751. hasInLineFollowingBindingIdentifierOrBrace() {
  12752. const next = this.nextTokenInLineStart();
  12753. const nextCh = this.codePointAtPos(next);
  12754. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  12755. }
  12756. allowsUsing() {
  12757. return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
  12758. }
  12759. parseModuleItem() {
  12760. return this.parseStatementLike(1 | 2 | 4 | 8);
  12761. }
  12762. parseStatementListItem() {
  12763. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12764. }
  12765. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12766. let flags = 0;
  12767. if (this.options.annexB && !this.state.strict) {
  12768. flags |= 4;
  12769. if (allowLabeledFunction) {
  12770. flags |= 8;
  12771. }
  12772. }
  12773. return this.parseStatementLike(flags);
  12774. }
  12775. parseStatement() {
  12776. return this.parseStatementLike(0);
  12777. }
  12778. parseStatementLike(flags) {
  12779. let decorators = null;
  12780. if (this.match(26)) {
  12781. decorators = this.parseDecorators(true);
  12782. }
  12783. return this.parseStatementContent(flags, decorators);
  12784. }
  12785. parseStatementContent(flags, decorators) {
  12786. const startType = this.state.type;
  12787. const node = this.startNode();
  12788. const allowDeclaration = !!(flags & 2);
  12789. const allowFunctionDeclaration = !!(flags & 4);
  12790. const topLevel = flags & 1;
  12791. switch (startType) {
  12792. case 60:
  12793. return this.parseBreakContinueStatement(node, true);
  12794. case 63:
  12795. return this.parseBreakContinueStatement(node, false);
  12796. case 64:
  12797. return this.parseDebuggerStatement(node);
  12798. case 90:
  12799. return this.parseDoWhileStatement(node);
  12800. case 91:
  12801. return this.parseForStatement(node);
  12802. case 68:
  12803. if (this.lookaheadCharCode() === 46) break;
  12804. if (!allowFunctionDeclaration) {
  12805. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12806. }
  12807. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12808. case 80:
  12809. if (!allowDeclaration) this.unexpected();
  12810. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12811. case 69:
  12812. return this.parseIfStatement(node);
  12813. case 70:
  12814. return this.parseReturnStatement(node);
  12815. case 71:
  12816. return this.parseSwitchStatement(node);
  12817. case 72:
  12818. return this.parseThrowStatement(node);
  12819. case 73:
  12820. return this.parseTryStatement(node);
  12821. case 96:
  12822. if (this.isAwaitUsing()) {
  12823. if (!this.allowsUsing()) {
  12824. this.raise(Errors.UnexpectedUsingDeclaration, node);
  12825. } else if (!allowDeclaration) {
  12826. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12827. } else if (!this.recordAwaitIfAllowed()) {
  12828. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12829. }
  12830. this.next();
  12831. return this.parseVarStatement(node, "await using");
  12832. }
  12833. break;
  12834. case 107:
  12835. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  12836. break;
  12837. }
  12838. if (!this.allowsUsing()) {
  12839. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12840. } else if (!allowDeclaration) {
  12841. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12842. }
  12843. return this.parseVarStatement(node, "using");
  12844. case 100:
  12845. {
  12846. if (this.state.containsEsc) {
  12847. break;
  12848. }
  12849. const next = this.nextTokenStart();
  12850. const nextCh = this.codePointAtPos(next);
  12851. if (nextCh !== 91) {
  12852. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12853. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12854. break;
  12855. }
  12856. }
  12857. }
  12858. case 75:
  12859. {
  12860. if (!allowDeclaration) {
  12861. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12862. }
  12863. }
  12864. case 74:
  12865. {
  12866. const kind = this.state.value;
  12867. return this.parseVarStatement(node, kind);
  12868. }
  12869. case 92:
  12870. return this.parseWhileStatement(node);
  12871. case 76:
  12872. return this.parseWithStatement(node);
  12873. case 5:
  12874. return this.parseBlock();
  12875. case 13:
  12876. return this.parseEmptyStatement(node);
  12877. case 83:
  12878. {
  12879. const nextTokenCharCode = this.lookaheadCharCode();
  12880. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12881. break;
  12882. }
  12883. }
  12884. case 82:
  12885. {
  12886. if (!(this.optionFlags & 8) && !topLevel) {
  12887. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12888. }
  12889. this.next();
  12890. let result;
  12891. if (startType === 83) {
  12892. result = this.parseImport(node);
  12893. } else {
  12894. result = this.parseExport(node, decorators);
  12895. }
  12896. this.assertModuleNodeAllowed(result);
  12897. return result;
  12898. }
  12899. default:
  12900. {
  12901. if (this.isAsyncFunction()) {
  12902. if (!allowDeclaration) {
  12903. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12904. }
  12905. this.next();
  12906. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12907. }
  12908. }
  12909. }
  12910. const maybeName = this.state.value;
  12911. const expr = this.parseExpression();
  12912. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  12913. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12914. } else {
  12915. return this.parseExpressionStatement(node, expr, decorators);
  12916. }
  12917. }
  12918. assertModuleNodeAllowed(node) {
  12919. if (!(this.optionFlags & 8) && !this.inModule) {
  12920. this.raise(Errors.ImportOutsideModule, node);
  12921. }
  12922. }
  12923. decoratorsEnabledBeforeExport() {
  12924. if (this.hasPlugin("decorators-legacy")) return true;
  12925. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12926. }
  12927. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12928. if (maybeDecorators) {
  12929. var _classNode$decorators;
  12930. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  12931. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12932. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12933. }
  12934. classNode.decorators.unshift(...maybeDecorators);
  12935. } else {
  12936. classNode.decorators = maybeDecorators;
  12937. }
  12938. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12939. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12940. }
  12941. return classNode;
  12942. }
  12943. canHaveLeadingDecorator() {
  12944. return this.match(80);
  12945. }
  12946. parseDecorators(allowExport) {
  12947. const decorators = [];
  12948. do {
  12949. decorators.push(this.parseDecorator());
  12950. } while (this.match(26));
  12951. if (this.match(82)) {
  12952. if (!allowExport) {
  12953. this.unexpected();
  12954. }
  12955. if (!this.decoratorsEnabledBeforeExport()) {
  12956. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  12957. }
  12958. } else if (!this.canHaveLeadingDecorator()) {
  12959. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  12960. }
  12961. return decorators;
  12962. }
  12963. parseDecorator() {
  12964. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12965. const node = this.startNode();
  12966. this.next();
  12967. if (this.hasPlugin("decorators")) {
  12968. const startLoc = this.state.startLoc;
  12969. let expr;
  12970. if (this.match(10)) {
  12971. const startLoc = this.state.startLoc;
  12972. this.next();
  12973. expr = this.parseExpression();
  12974. this.expect(11);
  12975. expr = this.wrapParenthesis(startLoc, expr);
  12976. const paramsStartLoc = this.state.startLoc;
  12977. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12978. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12979. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  12980. }
  12981. } else {
  12982. expr = this.parseIdentifier(false);
  12983. while (this.eat(16)) {
  12984. const node = this.startNodeAt(startLoc);
  12985. node.object = expr;
  12986. if (this.match(139)) {
  12987. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12988. node.property = this.parsePrivateName();
  12989. } else {
  12990. node.property = this.parseIdentifier(true);
  12991. }
  12992. node.computed = false;
  12993. expr = this.finishNode(node, "MemberExpression");
  12994. }
  12995. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12996. }
  12997. } else {
  12998. node.expression = this.parseExprSubscripts();
  12999. }
  13000. return this.finishNode(node, "Decorator");
  13001. }
  13002. parseMaybeDecoratorArguments(expr, startLoc) {
  13003. if (this.eat(10)) {
  13004. const node = this.startNodeAt(startLoc);
  13005. node.callee = expr;
  13006. node.arguments = this.parseCallExpressionArguments();
  13007. this.toReferencedList(node.arguments);
  13008. return this.finishNode(node, "CallExpression");
  13009. }
  13010. return expr;
  13011. }
  13012. parseBreakContinueStatement(node, isBreak) {
  13013. this.next();
  13014. if (this.isLineTerminator()) {
  13015. node.label = null;
  13016. } else {
  13017. node.label = this.parseIdentifier();
  13018. this.semicolon();
  13019. }
  13020. this.verifyBreakContinue(node, isBreak);
  13021. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  13022. }
  13023. verifyBreakContinue(node, isBreak) {
  13024. let i;
  13025. for (i = 0; i < this.state.labels.length; ++i) {
  13026. const lab = this.state.labels[i];
  13027. if (node.label == null || lab.name === node.label.name) {
  13028. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  13029. break;
  13030. }
  13031. if (node.label && isBreak) break;
  13032. }
  13033. }
  13034. if (i === this.state.labels.length) {
  13035. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  13036. this.raise(Errors.IllegalBreakContinue, node, {
  13037. type
  13038. });
  13039. }
  13040. }
  13041. parseDebuggerStatement(node) {
  13042. this.next();
  13043. this.semicolon();
  13044. return this.finishNode(node, "DebuggerStatement");
  13045. }
  13046. parseHeaderExpression() {
  13047. this.expect(10);
  13048. const val = this.parseExpression();
  13049. this.expect(11);
  13050. return val;
  13051. }
  13052. parseDoWhileStatement(node) {
  13053. this.next();
  13054. this.state.labels.push(loopLabel);
  13055. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13056. this.state.labels.pop();
  13057. this.expect(92);
  13058. node.test = this.parseHeaderExpression();
  13059. this.eat(13);
  13060. return this.finishNode(node, "DoWhileStatement");
  13061. }
  13062. parseForStatement(node) {
  13063. this.next();
  13064. this.state.labels.push(loopLabel);
  13065. let awaitAt = null;
  13066. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  13067. awaitAt = this.state.startLoc;
  13068. this.next();
  13069. }
  13070. this.scope.enter(0);
  13071. this.expect(10);
  13072. if (this.match(13)) {
  13073. if (awaitAt !== null) {
  13074. this.unexpected(awaitAt);
  13075. }
  13076. return this.parseFor(node, null);
  13077. }
  13078. const startsWithLet = this.isContextual(100);
  13079. {
  13080. const startsWithAwaitUsing = this.isAwaitUsing();
  13081. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
  13082. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  13083. if (this.match(74) || this.match(75) || isLetOrUsing) {
  13084. const initNode = this.startNode();
  13085. let kind;
  13086. if (startsWithAwaitUsing) {
  13087. kind = "await using";
  13088. if (!this.recordAwaitIfAllowed()) {
  13089. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  13090. }
  13091. this.next();
  13092. } else {
  13093. kind = this.state.value;
  13094. }
  13095. this.next();
  13096. this.parseVar(initNode, true, kind);
  13097. const init = this.finishNode(initNode, "VariableDeclaration");
  13098. const isForIn = this.match(58);
  13099. if (isForIn && starsWithUsingDeclaration) {
  13100. this.raise(Errors.ForInUsing, init);
  13101. }
  13102. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  13103. return this.parseForIn(node, init, awaitAt);
  13104. }
  13105. if (awaitAt !== null) {
  13106. this.unexpected(awaitAt);
  13107. }
  13108. return this.parseFor(node, init);
  13109. }
  13110. }
  13111. const startsWithAsync = this.isContextual(95);
  13112. const refExpressionErrors = new ExpressionErrors();
  13113. const init = this.parseExpression(true, refExpressionErrors);
  13114. const isForOf = this.isContextual(102);
  13115. if (isForOf) {
  13116. if (startsWithLet) {
  13117. this.raise(Errors.ForOfLet, init);
  13118. }
  13119. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  13120. this.raise(Errors.ForOfAsync, init);
  13121. }
  13122. }
  13123. if (isForOf || this.match(58)) {
  13124. this.checkDestructuringPrivate(refExpressionErrors);
  13125. this.toAssignable(init, true);
  13126. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  13127. this.checkLVal(init, {
  13128. type
  13129. });
  13130. return this.parseForIn(node, init, awaitAt);
  13131. } else {
  13132. this.checkExpressionErrors(refExpressionErrors, true);
  13133. }
  13134. if (awaitAt !== null) {
  13135. this.unexpected(awaitAt);
  13136. }
  13137. return this.parseFor(node, init);
  13138. }
  13139. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  13140. this.next();
  13141. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  13142. }
  13143. parseIfStatement(node) {
  13144. this.next();
  13145. node.test = this.parseHeaderExpression();
  13146. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  13147. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  13148. return this.finishNode(node, "IfStatement");
  13149. }
  13150. parseReturnStatement(node) {
  13151. if (!this.prodParam.hasReturn) {
  13152. this.raise(Errors.IllegalReturn, this.state.startLoc);
  13153. }
  13154. this.next();
  13155. if (this.isLineTerminator()) {
  13156. node.argument = null;
  13157. } else {
  13158. node.argument = this.parseExpression();
  13159. this.semicolon();
  13160. }
  13161. return this.finishNode(node, "ReturnStatement");
  13162. }
  13163. parseSwitchStatement(node) {
  13164. this.next();
  13165. node.discriminant = this.parseHeaderExpression();
  13166. const cases = node.cases = [];
  13167. this.expect(5);
  13168. this.state.labels.push(switchLabel);
  13169. this.scope.enter(256);
  13170. let cur;
  13171. for (let sawDefault; !this.match(8);) {
  13172. if (this.match(61) || this.match(65)) {
  13173. const isCase = this.match(61);
  13174. if (cur) this.finishNode(cur, "SwitchCase");
  13175. cases.push(cur = this.startNode());
  13176. cur.consequent = [];
  13177. this.next();
  13178. if (isCase) {
  13179. cur.test = this.parseExpression();
  13180. } else {
  13181. if (sawDefault) {
  13182. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  13183. }
  13184. sawDefault = true;
  13185. cur.test = null;
  13186. }
  13187. this.expect(14);
  13188. } else {
  13189. if (cur) {
  13190. cur.consequent.push(this.parseStatementListItem());
  13191. } else {
  13192. this.unexpected();
  13193. }
  13194. }
  13195. }
  13196. this.scope.exit();
  13197. if (cur) this.finishNode(cur, "SwitchCase");
  13198. this.next();
  13199. this.state.labels.pop();
  13200. return this.finishNode(node, "SwitchStatement");
  13201. }
  13202. parseThrowStatement(node) {
  13203. this.next();
  13204. if (this.hasPrecedingLineBreak()) {
  13205. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  13206. }
  13207. node.argument = this.parseExpression();
  13208. this.semicolon();
  13209. return this.finishNode(node, "ThrowStatement");
  13210. }
  13211. parseCatchClauseParam() {
  13212. const param = this.parseBindingAtom();
  13213. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13214. this.checkLVal(param, {
  13215. type: "CatchClause"
  13216. }, 9);
  13217. return param;
  13218. }
  13219. parseTryStatement(node) {
  13220. this.next();
  13221. node.block = this.parseBlock();
  13222. node.handler = null;
  13223. if (this.match(62)) {
  13224. const clause = this.startNode();
  13225. this.next();
  13226. if (this.match(10)) {
  13227. this.expect(10);
  13228. clause.param = this.parseCatchClauseParam();
  13229. this.expect(11);
  13230. } else {
  13231. clause.param = null;
  13232. this.scope.enter(0);
  13233. }
  13234. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13235. this.scope.exit();
  13236. node.handler = this.finishNode(clause, "CatchClause");
  13237. }
  13238. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13239. if (!node.handler && !node.finalizer) {
  13240. this.raise(Errors.NoCatchOrFinally, node);
  13241. }
  13242. return this.finishNode(node, "TryStatement");
  13243. }
  13244. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13245. this.next();
  13246. this.parseVar(node, false, kind, allowMissingInitializer);
  13247. this.semicolon();
  13248. return this.finishNode(node, "VariableDeclaration");
  13249. }
  13250. parseWhileStatement(node) {
  13251. this.next();
  13252. node.test = this.parseHeaderExpression();
  13253. this.state.labels.push(loopLabel);
  13254. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13255. this.state.labels.pop();
  13256. return this.finishNode(node, "WhileStatement");
  13257. }
  13258. parseWithStatement(node) {
  13259. if (this.state.strict) {
  13260. this.raise(Errors.StrictWith, this.state.startLoc);
  13261. }
  13262. this.next();
  13263. node.object = this.parseHeaderExpression();
  13264. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13265. return this.finishNode(node, "WithStatement");
  13266. }
  13267. parseEmptyStatement(node) {
  13268. this.next();
  13269. return this.finishNode(node, "EmptyStatement");
  13270. }
  13271. parseLabeledStatement(node, maybeName, expr, flags) {
  13272. for (const label of this.state.labels) {
  13273. if (label.name === maybeName) {
  13274. this.raise(Errors.LabelRedeclaration, expr, {
  13275. labelName: maybeName
  13276. });
  13277. }
  13278. }
  13279. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  13280. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13281. const label = this.state.labels[i];
  13282. if (label.statementStart === node.start) {
  13283. label.statementStart = this.sourceToOffsetPos(this.state.start);
  13284. label.kind = kind;
  13285. } else {
  13286. break;
  13287. }
  13288. }
  13289. this.state.labels.push({
  13290. name: maybeName,
  13291. kind: kind,
  13292. statementStart: this.sourceToOffsetPos(this.state.start)
  13293. });
  13294. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13295. this.state.labels.pop();
  13296. node.label = expr;
  13297. return this.finishNode(node, "LabeledStatement");
  13298. }
  13299. parseExpressionStatement(node, expr, decorators) {
  13300. node.expression = expr;
  13301. this.semicolon();
  13302. return this.finishNode(node, "ExpressionStatement");
  13303. }
  13304. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13305. const node = this.startNode();
  13306. if (allowDirectives) {
  13307. this.state.strictErrors.clear();
  13308. }
  13309. this.expect(5);
  13310. if (createNewLexicalScope) {
  13311. this.scope.enter(0);
  13312. }
  13313. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13314. if (createNewLexicalScope) {
  13315. this.scope.exit();
  13316. }
  13317. return this.finishNode(node, "BlockStatement");
  13318. }
  13319. isValidDirective(stmt) {
  13320. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13321. }
  13322. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13323. const body = node.body = [];
  13324. const directives = node.directives = [];
  13325. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13326. }
  13327. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13328. const oldStrict = this.state.strict;
  13329. let hasStrictModeDirective = false;
  13330. let parsedNonDirective = false;
  13331. while (!this.match(end)) {
  13332. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13333. if (directives && !parsedNonDirective) {
  13334. if (this.isValidDirective(stmt)) {
  13335. const directive = this.stmtToDirective(stmt);
  13336. directives.push(directive);
  13337. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13338. hasStrictModeDirective = true;
  13339. this.setStrict(true);
  13340. }
  13341. continue;
  13342. }
  13343. parsedNonDirective = true;
  13344. this.state.strictErrors.clear();
  13345. }
  13346. body.push(stmt);
  13347. }
  13348. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  13349. if (!oldStrict) {
  13350. this.setStrict(false);
  13351. }
  13352. this.next();
  13353. }
  13354. parseFor(node, init) {
  13355. node.init = init;
  13356. this.semicolon(false);
  13357. node.test = this.match(13) ? null : this.parseExpression();
  13358. this.semicolon(false);
  13359. node.update = this.match(11) ? null : this.parseExpression();
  13360. this.expect(11);
  13361. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13362. this.scope.exit();
  13363. this.state.labels.pop();
  13364. return this.finishNode(node, "ForStatement");
  13365. }
  13366. parseForIn(node, init, awaitAt) {
  13367. const isForIn = this.match(58);
  13368. this.next();
  13369. if (isForIn) {
  13370. if (awaitAt !== null) this.unexpected(awaitAt);
  13371. } else {
  13372. node.await = awaitAt !== null;
  13373. }
  13374. 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")) {
  13375. this.raise(Errors.ForInOfLoopInitializer, init, {
  13376. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13377. });
  13378. }
  13379. if (init.type === "AssignmentPattern") {
  13380. this.raise(Errors.InvalidLhs, init, {
  13381. ancestor: {
  13382. type: "ForStatement"
  13383. }
  13384. });
  13385. }
  13386. node.left = init;
  13387. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13388. this.expect(11);
  13389. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13390. this.scope.exit();
  13391. this.state.labels.pop();
  13392. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13393. }
  13394. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13395. const declarations = node.declarations = [];
  13396. node.kind = kind;
  13397. for (;;) {
  13398. const decl = this.startNode();
  13399. this.parseVarId(decl, kind);
  13400. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13401. if (decl.init === null && !allowMissingInitializer) {
  13402. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13403. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13404. kind: "destructuring"
  13405. });
  13406. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  13407. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13408. kind
  13409. });
  13410. }
  13411. }
  13412. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13413. if (!this.eat(12)) break;
  13414. }
  13415. return node;
  13416. }
  13417. parseVarId(decl, kind) {
  13418. const id = this.parseBindingAtom();
  13419. if (kind === "using" || kind === "await using") {
  13420. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  13421. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  13422. }
  13423. } else {
  13424. if (id.type === "VoidPattern") {
  13425. this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
  13426. }
  13427. }
  13428. this.checkLVal(id, {
  13429. type: "VariableDeclarator"
  13430. }, kind === "var" ? 5 : 8201);
  13431. decl.id = id;
  13432. }
  13433. parseAsyncFunctionExpression(node) {
  13434. return this.parseFunction(node, 8);
  13435. }
  13436. parseFunction(node, flags = 0) {
  13437. const hangingDeclaration = flags & 2;
  13438. const isDeclaration = !!(flags & 1);
  13439. const requireId = isDeclaration && !(flags & 4);
  13440. const isAsync = !!(flags & 8);
  13441. this.initFunction(node, isAsync);
  13442. if (this.match(55)) {
  13443. if (hangingDeclaration) {
  13444. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  13445. }
  13446. this.next();
  13447. node.generator = true;
  13448. }
  13449. if (isDeclaration) {
  13450. node.id = this.parseFunctionId(requireId);
  13451. }
  13452. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13453. this.state.maybeInArrowParameters = false;
  13454. this.scope.enter(514);
  13455. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13456. if (!isDeclaration) {
  13457. node.id = this.parseFunctionId();
  13458. }
  13459. this.parseFunctionParams(node, false);
  13460. this.withSmartMixTopicForbiddingContext(() => {
  13461. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13462. });
  13463. this.prodParam.exit();
  13464. this.scope.exit();
  13465. if (isDeclaration && !hangingDeclaration) {
  13466. this.registerFunctionStatementId(node);
  13467. }
  13468. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13469. return node;
  13470. }
  13471. parseFunctionId(requireId) {
  13472. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13473. }
  13474. parseFunctionParams(node, isConstructor) {
  13475. this.expect(10);
  13476. this.expressionScope.enter(newParameterDeclarationScope());
  13477. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13478. this.expressionScope.exit();
  13479. }
  13480. registerFunctionStatementId(node) {
  13481. if (!node.id) return;
  13482. 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);
  13483. }
  13484. parseClass(node, isStatement, optionalId) {
  13485. this.next();
  13486. const oldStrict = this.state.strict;
  13487. this.state.strict = true;
  13488. this.parseClassId(node, isStatement, optionalId);
  13489. this.parseClassSuper(node);
  13490. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13491. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13492. }
  13493. isClassProperty() {
  13494. return this.match(29) || this.match(13) || this.match(8);
  13495. }
  13496. isClassMethod() {
  13497. return this.match(10);
  13498. }
  13499. nameIsConstructor(key) {
  13500. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  13501. }
  13502. isNonstaticConstructor(method) {
  13503. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  13504. }
  13505. parseClassBody(hadSuperClass, oldStrict) {
  13506. this.classScope.enter();
  13507. const state = {
  13508. hadConstructor: false,
  13509. hadSuperClass
  13510. };
  13511. let decorators = [];
  13512. const classBody = this.startNode();
  13513. classBody.body = [];
  13514. this.expect(5);
  13515. this.withSmartMixTopicForbiddingContext(() => {
  13516. while (!this.match(8)) {
  13517. if (this.eat(13)) {
  13518. if (decorators.length > 0) {
  13519. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  13520. }
  13521. continue;
  13522. }
  13523. if (this.match(26)) {
  13524. decorators.push(this.parseDecorator());
  13525. continue;
  13526. }
  13527. const member = this.startNode();
  13528. if (decorators.length) {
  13529. member.decorators = decorators;
  13530. this.resetStartLocationFromNode(member, decorators[0]);
  13531. decorators = [];
  13532. }
  13533. this.parseClassMember(classBody, member, state);
  13534. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13535. this.raise(Errors.DecoratorConstructor, member);
  13536. }
  13537. }
  13538. });
  13539. this.state.strict = oldStrict;
  13540. this.next();
  13541. if (decorators.length) {
  13542. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13543. }
  13544. this.classScope.exit();
  13545. return this.finishNode(classBody, "ClassBody");
  13546. }
  13547. parseClassMemberFromModifier(classBody, member) {
  13548. const key = this.parseIdentifier(true);
  13549. if (this.isClassMethod()) {
  13550. const method = member;
  13551. method.kind = "method";
  13552. method.computed = false;
  13553. method.key = key;
  13554. method.static = false;
  13555. this.pushClassMethod(classBody, method, false, false, false, false);
  13556. return true;
  13557. } else if (this.isClassProperty()) {
  13558. const prop = member;
  13559. prop.computed = false;
  13560. prop.key = key;
  13561. prop.static = false;
  13562. classBody.body.push(this.parseClassProperty(prop));
  13563. return true;
  13564. }
  13565. this.resetPreviousNodeTrailingComments(key);
  13566. return false;
  13567. }
  13568. parseClassMember(classBody, member, state) {
  13569. const isStatic = this.isContextual(106);
  13570. if (isStatic) {
  13571. if (this.parseClassMemberFromModifier(classBody, member)) {
  13572. return;
  13573. }
  13574. if (this.eat(5)) {
  13575. this.parseClassStaticBlock(classBody, member);
  13576. return;
  13577. }
  13578. }
  13579. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13580. }
  13581. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13582. const publicMethod = member;
  13583. const privateMethod = member;
  13584. const publicProp = member;
  13585. const privateProp = member;
  13586. const accessorProp = member;
  13587. const method = publicMethod;
  13588. const publicMember = publicMethod;
  13589. member.static = isStatic;
  13590. this.parsePropertyNamePrefixOperator(member);
  13591. if (this.eat(55)) {
  13592. method.kind = "method";
  13593. const isPrivateName = this.match(139);
  13594. this.parseClassElementName(method);
  13595. this.parsePostMemberNameModifiers(method);
  13596. if (isPrivateName) {
  13597. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13598. return;
  13599. }
  13600. if (this.isNonstaticConstructor(publicMethod)) {
  13601. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13602. }
  13603. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13604. return;
  13605. }
  13606. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13607. const key = this.parseClassElementName(member);
  13608. const maybeContextualKw = isContextual ? key.name : null;
  13609. const isPrivate = this.isPrivateName(key);
  13610. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13611. this.parsePostMemberNameModifiers(publicMember);
  13612. if (this.isClassMethod()) {
  13613. method.kind = "method";
  13614. if (isPrivate) {
  13615. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13616. return;
  13617. }
  13618. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13619. let allowsDirectSuper = false;
  13620. if (isConstructor) {
  13621. publicMethod.kind = "constructor";
  13622. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13623. this.raise(Errors.DuplicateConstructor, key);
  13624. }
  13625. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13626. this.raise(Errors.OverrideOnConstructor, key);
  13627. }
  13628. state.hadConstructor = true;
  13629. allowsDirectSuper = state.hadSuperClass;
  13630. }
  13631. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13632. } else if (this.isClassProperty()) {
  13633. if (isPrivate) {
  13634. this.pushClassPrivateProperty(classBody, privateProp);
  13635. } else {
  13636. this.pushClassProperty(classBody, publicProp);
  13637. }
  13638. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13639. this.resetPreviousNodeTrailingComments(key);
  13640. const isGenerator = this.eat(55);
  13641. if (publicMember.optional) {
  13642. this.unexpected(maybeQuestionTokenStartLoc);
  13643. }
  13644. method.kind = "method";
  13645. const isPrivate = this.match(139);
  13646. this.parseClassElementName(method);
  13647. this.parsePostMemberNameModifiers(publicMember);
  13648. if (isPrivate) {
  13649. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13650. } else {
  13651. if (this.isNonstaticConstructor(publicMethod)) {
  13652. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13653. }
  13654. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13655. }
  13656. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13657. this.resetPreviousNodeTrailingComments(key);
  13658. method.kind = maybeContextualKw;
  13659. const isPrivate = this.match(139);
  13660. this.parseClassElementName(publicMethod);
  13661. if (isPrivate) {
  13662. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13663. } else {
  13664. if (this.isNonstaticConstructor(publicMethod)) {
  13665. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13666. }
  13667. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13668. }
  13669. this.checkGetterSetterParams(publicMethod);
  13670. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13671. this.expectPlugin("decoratorAutoAccessors");
  13672. this.resetPreviousNodeTrailingComments(key);
  13673. const isPrivate = this.match(139);
  13674. this.parseClassElementName(publicProp);
  13675. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13676. } else if (this.isLineTerminator()) {
  13677. if (isPrivate) {
  13678. this.pushClassPrivateProperty(classBody, privateProp);
  13679. } else {
  13680. this.pushClassProperty(classBody, publicProp);
  13681. }
  13682. } else {
  13683. this.unexpected();
  13684. }
  13685. }
  13686. parseClassElementName(member) {
  13687. const {
  13688. type,
  13689. value
  13690. } = this.state;
  13691. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  13692. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13693. }
  13694. if (type === 139) {
  13695. if (value === "constructor") {
  13696. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13697. }
  13698. const key = this.parsePrivateName();
  13699. member.key = key;
  13700. return key;
  13701. }
  13702. this.parsePropertyName(member);
  13703. return member.key;
  13704. }
  13705. parseClassStaticBlock(classBody, member) {
  13706. var _member$decorators;
  13707. this.scope.enter(576 | 128 | 16);
  13708. const oldLabels = this.state.labels;
  13709. this.state.labels = [];
  13710. this.prodParam.enter(0);
  13711. const body = member.body = [];
  13712. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13713. this.prodParam.exit();
  13714. this.scope.exit();
  13715. this.state.labels = oldLabels;
  13716. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13717. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13718. this.raise(Errors.DecoratorStaticBlock, member);
  13719. }
  13720. }
  13721. pushClassProperty(classBody, prop) {
  13722. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13723. this.raise(Errors.ConstructorClassField, prop.key);
  13724. }
  13725. classBody.body.push(this.parseClassProperty(prop));
  13726. }
  13727. pushClassPrivateProperty(classBody, prop) {
  13728. const node = this.parseClassPrivateProperty(prop);
  13729. classBody.body.push(node);
  13730. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13731. }
  13732. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13733. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13734. this.raise(Errors.ConstructorClassField, prop.key);
  13735. }
  13736. const node = this.parseClassAccessorProperty(prop);
  13737. classBody.body.push(node);
  13738. if (isPrivate) {
  13739. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13740. }
  13741. }
  13742. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13743. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13744. }
  13745. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13746. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13747. classBody.body.push(node);
  13748. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13749. this.declareClassPrivateMethodInScope(node, kind);
  13750. }
  13751. declareClassPrivateMethodInScope(node, kind) {
  13752. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13753. }
  13754. parsePostMemberNameModifiers(methodOrProp) {}
  13755. parseClassPrivateProperty(node) {
  13756. this.parseInitializer(node);
  13757. this.semicolon();
  13758. return this.finishNode(node, "ClassPrivateProperty");
  13759. }
  13760. parseClassProperty(node) {
  13761. this.parseInitializer(node);
  13762. this.semicolon();
  13763. return this.finishNode(node, "ClassProperty");
  13764. }
  13765. parseClassAccessorProperty(node) {
  13766. this.parseInitializer(node);
  13767. this.semicolon();
  13768. return this.finishNode(node, "ClassAccessorProperty");
  13769. }
  13770. parseInitializer(node) {
  13771. this.scope.enter(576 | 16);
  13772. this.expressionScope.enter(newExpressionScope());
  13773. this.prodParam.enter(0);
  13774. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13775. this.expressionScope.exit();
  13776. this.prodParam.exit();
  13777. this.scope.exit();
  13778. }
  13779. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13780. if (tokenIsIdentifier(this.state.type)) {
  13781. node.id = this.parseIdentifier();
  13782. if (isStatement) {
  13783. this.declareNameFromIdentifier(node.id, bindingType);
  13784. }
  13785. } else {
  13786. if (optionalId || !isStatement) {
  13787. node.id = null;
  13788. } else {
  13789. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13790. }
  13791. }
  13792. }
  13793. parseClassSuper(node) {
  13794. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13795. }
  13796. parseExport(node, decorators) {
  13797. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13798. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13799. const parseAfterDefault = !hasDefault || this.eat(12);
  13800. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13801. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13802. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13803. const isFromRequired = hasDefault || hasStar;
  13804. if (hasStar && !hasNamespace) {
  13805. if (hasDefault) this.unexpected();
  13806. if (decorators) {
  13807. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13808. }
  13809. this.parseExportFrom(node, true);
  13810. this.sawUnambiguousESM = true;
  13811. return this.finishNode(node, "ExportAllDeclaration");
  13812. }
  13813. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13814. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13815. this.unexpected(null, 5);
  13816. }
  13817. if (hasNamespace && parseAfterNamespace) {
  13818. this.unexpected(null, 98);
  13819. }
  13820. let hasDeclaration;
  13821. if (isFromRequired || hasSpecifiers) {
  13822. hasDeclaration = false;
  13823. if (decorators) {
  13824. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13825. }
  13826. this.parseExportFrom(node, isFromRequired);
  13827. } else {
  13828. hasDeclaration = this.maybeParseExportDeclaration(node);
  13829. }
  13830. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13831. var _node2$declaration;
  13832. const node2 = node;
  13833. this.checkExport(node2, true, false, !!node2.source);
  13834. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13835. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13836. } else if (decorators) {
  13837. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13838. }
  13839. this.sawUnambiguousESM = true;
  13840. return this.finishNode(node2, "ExportNamedDeclaration");
  13841. }
  13842. if (this.eat(65)) {
  13843. const node2 = node;
  13844. const decl = this.parseExportDefaultExpression();
  13845. node2.declaration = decl;
  13846. if (decl.type === "ClassDeclaration") {
  13847. this.maybeTakeDecorators(decorators, decl, node2);
  13848. } else if (decorators) {
  13849. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13850. }
  13851. this.checkExport(node2, true, true);
  13852. this.sawUnambiguousESM = true;
  13853. return this.finishNode(node2, "ExportDefaultDeclaration");
  13854. }
  13855. throw this.unexpected(null, 5);
  13856. }
  13857. eatExportStar(node) {
  13858. return this.eat(55);
  13859. }
  13860. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13861. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13862. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13863. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13864. const specifier = this.startNodeAtNode(id);
  13865. specifier.exported = id;
  13866. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13867. return true;
  13868. }
  13869. return false;
  13870. }
  13871. maybeParseExportNamespaceSpecifier(node) {
  13872. if (this.isContextual(93)) {
  13873. var _ref, _ref$specifiers;
  13874. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13875. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13876. this.next();
  13877. specifier.exported = this.parseModuleExportName();
  13878. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13879. return true;
  13880. }
  13881. return false;
  13882. }
  13883. maybeParseExportNamedSpecifiers(node) {
  13884. if (this.match(5)) {
  13885. const node2 = node;
  13886. if (!node2.specifiers) node2.specifiers = [];
  13887. const isTypeExport = node2.exportKind === "type";
  13888. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13889. node2.source = null;
  13890. if (this.hasPlugin("importAssertions")) {
  13891. node2.assertions = [];
  13892. } else {
  13893. node2.attributes = [];
  13894. }
  13895. node2.declaration = null;
  13896. return true;
  13897. }
  13898. return false;
  13899. }
  13900. maybeParseExportDeclaration(node) {
  13901. if (this.shouldParseExportDeclaration()) {
  13902. node.specifiers = [];
  13903. node.source = null;
  13904. if (this.hasPlugin("importAssertions")) {
  13905. node.assertions = [];
  13906. } else {
  13907. node.attributes = [];
  13908. }
  13909. node.declaration = this.parseExportDeclaration(node);
  13910. return true;
  13911. }
  13912. return false;
  13913. }
  13914. isAsyncFunction() {
  13915. if (!this.isContextual(95)) return false;
  13916. const next = this.nextTokenInLineStart();
  13917. return this.isUnparsedContextual(next, "function");
  13918. }
  13919. parseExportDefaultExpression() {
  13920. const expr = this.startNode();
  13921. if (this.match(68)) {
  13922. this.next();
  13923. return this.parseFunction(expr, 1 | 4);
  13924. } else if (this.isAsyncFunction()) {
  13925. this.next();
  13926. this.next();
  13927. return this.parseFunction(expr, 1 | 4 | 8);
  13928. }
  13929. if (this.match(80)) {
  13930. return this.parseClass(expr, true, true);
  13931. }
  13932. if (this.match(26)) {
  13933. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13934. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13935. }
  13936. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13937. }
  13938. if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
  13939. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13940. }
  13941. const res = this.parseMaybeAssignAllowIn();
  13942. this.semicolon();
  13943. return res;
  13944. }
  13945. parseExportDeclaration(node) {
  13946. if (this.match(80)) {
  13947. const node = this.parseClass(this.startNode(), true, false);
  13948. return node;
  13949. }
  13950. return this.parseStatementListItem();
  13951. }
  13952. isExportDefaultSpecifier() {
  13953. const {
  13954. type
  13955. } = this.state;
  13956. if (tokenIsIdentifier(type)) {
  13957. if (type === 95 && !this.state.containsEsc || type === 100) {
  13958. return false;
  13959. }
  13960. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13961. const next = this.nextTokenStart();
  13962. const nextChar = this.input.charCodeAt(next);
  13963. if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
  13964. this.expectOnePlugin(["flow", "typescript"]);
  13965. return false;
  13966. }
  13967. }
  13968. } else if (!this.match(65)) {
  13969. return false;
  13970. }
  13971. const next = this.nextTokenStart();
  13972. const hasFrom = this.isUnparsedContextual(next, "from");
  13973. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13974. return true;
  13975. }
  13976. if (this.match(65) && hasFrom) {
  13977. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13978. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13979. }
  13980. return false;
  13981. }
  13982. parseExportFrom(node, expect) {
  13983. if (this.eatContextual(98)) {
  13984. node.source = this.parseImportSource();
  13985. this.checkExport(node);
  13986. this.maybeParseImportAttributes(node);
  13987. this.checkJSONModuleImport(node);
  13988. } else if (expect) {
  13989. this.unexpected();
  13990. }
  13991. this.semicolon();
  13992. }
  13993. shouldParseExportDeclaration() {
  13994. const {
  13995. type
  13996. } = this.state;
  13997. if (type === 26) {
  13998. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13999. if (this.hasPlugin("decorators")) {
  14000. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  14001. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  14002. }
  14003. return true;
  14004. }
  14005. }
  14006. if (this.isUsing()) {
  14007. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  14008. return true;
  14009. }
  14010. if (this.isAwaitUsing()) {
  14011. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  14012. return true;
  14013. }
  14014. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  14015. }
  14016. checkExport(node, checkNames, isDefault, isFrom) {
  14017. if (checkNames) {
  14018. var _node$specifiers;
  14019. if (isDefault) {
  14020. this.checkDuplicateExports(node, "default");
  14021. if (this.hasPlugin("exportDefaultFrom")) {
  14022. var _declaration$extra;
  14023. const declaration = node.declaration;
  14024. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  14025. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  14026. }
  14027. }
  14028. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  14029. for (const specifier of node.specifiers) {
  14030. const {
  14031. exported
  14032. } = specifier;
  14033. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  14034. this.checkDuplicateExports(specifier, exportName);
  14035. if (!isFrom && specifier.local) {
  14036. const {
  14037. local
  14038. } = specifier;
  14039. if (local.type !== "Identifier") {
  14040. this.raise(Errors.ExportBindingIsString, specifier, {
  14041. localName: local.value,
  14042. exportName
  14043. });
  14044. } else {
  14045. this.checkReservedWord(local.name, local.loc.start, true, false);
  14046. this.scope.checkLocalExport(local);
  14047. }
  14048. }
  14049. }
  14050. } else if (node.declaration) {
  14051. const decl = node.declaration;
  14052. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  14053. const {
  14054. id
  14055. } = decl;
  14056. if (!id) throw new Error("Assertion failure");
  14057. this.checkDuplicateExports(node, id.name);
  14058. } else if (decl.type === "VariableDeclaration") {
  14059. for (const declaration of decl.declarations) {
  14060. this.checkDeclaration(declaration.id);
  14061. }
  14062. }
  14063. }
  14064. }
  14065. }
  14066. checkDeclaration(node) {
  14067. if (node.type === "Identifier") {
  14068. this.checkDuplicateExports(node, node.name);
  14069. } else if (node.type === "ObjectPattern") {
  14070. for (const prop of node.properties) {
  14071. this.checkDeclaration(prop);
  14072. }
  14073. } else if (node.type === "ArrayPattern") {
  14074. for (const elem of node.elements) {
  14075. if (elem) {
  14076. this.checkDeclaration(elem);
  14077. }
  14078. }
  14079. } else if (node.type === "ObjectProperty") {
  14080. this.checkDeclaration(node.value);
  14081. } else if (node.type === "RestElement") {
  14082. this.checkDeclaration(node.argument);
  14083. } else if (node.type === "AssignmentPattern") {
  14084. this.checkDeclaration(node.left);
  14085. }
  14086. }
  14087. checkDuplicateExports(node, exportName) {
  14088. if (this.exportedIdentifiers.has(exportName)) {
  14089. if (exportName === "default") {
  14090. this.raise(Errors.DuplicateDefaultExport, node);
  14091. } else {
  14092. this.raise(Errors.DuplicateExport, node, {
  14093. exportName
  14094. });
  14095. }
  14096. }
  14097. this.exportedIdentifiers.add(exportName);
  14098. }
  14099. parseExportSpecifiers(isInTypeExport) {
  14100. const nodes = [];
  14101. let first = true;
  14102. this.expect(5);
  14103. while (!this.eat(8)) {
  14104. if (first) {
  14105. first = false;
  14106. } else {
  14107. this.expect(12);
  14108. if (this.eat(8)) break;
  14109. }
  14110. const isMaybeTypeOnly = this.isContextual(130);
  14111. const isString = this.match(134);
  14112. const node = this.startNode();
  14113. node.local = this.parseModuleExportName();
  14114. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  14115. }
  14116. return nodes;
  14117. }
  14118. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14119. if (this.eatContextual(93)) {
  14120. node.exported = this.parseModuleExportName();
  14121. } else if (isString) {
  14122. node.exported = this.cloneStringLiteral(node.local);
  14123. } else if (!node.exported) {
  14124. node.exported = this.cloneIdentifier(node.local);
  14125. }
  14126. return this.finishNode(node, "ExportSpecifier");
  14127. }
  14128. parseModuleExportName() {
  14129. if (this.match(134)) {
  14130. const result = this.parseStringLiteral(this.state.value);
  14131. const surrogate = loneSurrogate.exec(result.value);
  14132. if (surrogate) {
  14133. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  14134. surrogateCharCode: surrogate[0].charCodeAt(0)
  14135. });
  14136. }
  14137. return result;
  14138. }
  14139. return this.parseIdentifier(true);
  14140. }
  14141. isJSONModuleImport(node) {
  14142. if (node.assertions != null) {
  14143. return node.assertions.some(({
  14144. key,
  14145. value
  14146. }) => {
  14147. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14148. });
  14149. }
  14150. return false;
  14151. }
  14152. checkImportReflection(node) {
  14153. const {
  14154. specifiers
  14155. } = node;
  14156. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  14157. if (node.phase === "source") {
  14158. if (singleBindingType !== "ImportDefaultSpecifier") {
  14159. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  14160. }
  14161. } else if (node.phase === "defer") {
  14162. if (singleBindingType !== "ImportNamespaceSpecifier") {
  14163. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  14164. }
  14165. } else if (node.module) {
  14166. var _node$assertions;
  14167. if (singleBindingType !== "ImportDefaultSpecifier") {
  14168. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  14169. }
  14170. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14171. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  14172. }
  14173. }
  14174. }
  14175. checkJSONModuleImport(node) {
  14176. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14177. const {
  14178. specifiers
  14179. } = node;
  14180. if (specifiers != null) {
  14181. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14182. let imported;
  14183. if (specifier.type === "ExportSpecifier") {
  14184. imported = specifier.local;
  14185. } else if (specifier.type === "ImportSpecifier") {
  14186. imported = specifier.imported;
  14187. }
  14188. if (imported !== undefined) {
  14189. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14190. }
  14191. });
  14192. if (nonDefaultNamedSpecifier !== undefined) {
  14193. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  14194. }
  14195. }
  14196. }
  14197. }
  14198. isPotentialImportPhase(isExport) {
  14199. if (isExport) return false;
  14200. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  14201. }
  14202. applyImportPhase(node, isExport, phase, loc) {
  14203. if (isExport) {
  14204. return;
  14205. }
  14206. if (phase === "module") {
  14207. this.expectPlugin("importReflection", loc);
  14208. node.module = true;
  14209. } else if (this.hasPlugin("importReflection")) {
  14210. node.module = false;
  14211. }
  14212. if (phase === "source") {
  14213. this.expectPlugin("sourcePhaseImports", loc);
  14214. node.phase = "source";
  14215. } else if (phase === "defer") {
  14216. this.expectPlugin("deferredImportEvaluation", loc);
  14217. node.phase = "defer";
  14218. } else if (this.hasPlugin("sourcePhaseImports")) {
  14219. node.phase = null;
  14220. }
  14221. }
  14222. parseMaybeImportPhase(node, isExport) {
  14223. if (!this.isPotentialImportPhase(isExport)) {
  14224. this.applyImportPhase(node, isExport, null);
  14225. return null;
  14226. }
  14227. const phaseIdentifier = this.startNode();
  14228. const phaseIdentifierName = this.parseIdentifierName(true);
  14229. const {
  14230. type
  14231. } = this.state;
  14232. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14233. if (isImportPhase) {
  14234. this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
  14235. return null;
  14236. } else {
  14237. this.applyImportPhase(node, isExport, null);
  14238. return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
  14239. }
  14240. }
  14241. isPrecedingIdImportPhase(phase) {
  14242. const {
  14243. type
  14244. } = this.state;
  14245. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14246. }
  14247. parseImport(node) {
  14248. if (this.match(134)) {
  14249. return this.parseImportSourceAndAttributes(node);
  14250. }
  14251. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14252. }
  14253. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14254. node.specifiers = [];
  14255. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14256. const parseNext = !hasDefault || this.eat(12);
  14257. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14258. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14259. this.expectContextual(98);
  14260. return this.parseImportSourceAndAttributes(node);
  14261. }
  14262. parseImportSourceAndAttributes(node) {
  14263. var _node$specifiers2;
  14264. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14265. node.source = this.parseImportSource();
  14266. this.maybeParseImportAttributes(node);
  14267. this.checkImportReflection(node);
  14268. this.checkJSONModuleImport(node);
  14269. this.semicolon();
  14270. this.sawUnambiguousESM = true;
  14271. return this.finishNode(node, "ImportDeclaration");
  14272. }
  14273. parseImportSource() {
  14274. if (!this.match(134)) this.unexpected();
  14275. return this.parseExprAtom();
  14276. }
  14277. parseImportSpecifierLocal(node, specifier, type) {
  14278. specifier.local = this.parseIdentifier();
  14279. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14280. }
  14281. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14282. this.checkLVal(specifier.local, {
  14283. type
  14284. }, bindingType);
  14285. return this.finishNode(specifier, type);
  14286. }
  14287. parseImportAttributes() {
  14288. this.expect(5);
  14289. const attrs = [];
  14290. const attrNames = new Set();
  14291. do {
  14292. if (this.match(8)) {
  14293. break;
  14294. }
  14295. const node = this.startNode();
  14296. const keyName = this.state.value;
  14297. if (attrNames.has(keyName)) {
  14298. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  14299. key: keyName
  14300. });
  14301. }
  14302. attrNames.add(keyName);
  14303. if (this.match(134)) {
  14304. node.key = this.parseStringLiteral(keyName);
  14305. } else {
  14306. node.key = this.parseIdentifier(true);
  14307. }
  14308. this.expect(14);
  14309. if (!this.match(134)) {
  14310. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14311. }
  14312. node.value = this.parseStringLiteral(this.state.value);
  14313. attrs.push(this.finishNode(node, "ImportAttribute"));
  14314. } while (this.eat(12));
  14315. this.expect(8);
  14316. return attrs;
  14317. }
  14318. parseModuleAttributes() {
  14319. const attrs = [];
  14320. const attributes = new Set();
  14321. do {
  14322. const node = this.startNode();
  14323. node.key = this.parseIdentifier(true);
  14324. if (node.key.name !== "type") {
  14325. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  14326. }
  14327. if (attributes.has(node.key.name)) {
  14328. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  14329. key: node.key.name
  14330. });
  14331. }
  14332. attributes.add(node.key.name);
  14333. this.expect(14);
  14334. if (!this.match(134)) {
  14335. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14336. }
  14337. node.value = this.parseStringLiteral(this.state.value);
  14338. attrs.push(this.finishNode(node, "ImportAttribute"));
  14339. } while (this.eat(12));
  14340. return attrs;
  14341. }
  14342. maybeParseImportAttributes(node) {
  14343. let attributes;
  14344. var useWith = false;
  14345. if (this.match(76)) {
  14346. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14347. return;
  14348. }
  14349. this.next();
  14350. if (this.hasPlugin("moduleAttributes")) {
  14351. attributes = this.parseModuleAttributes();
  14352. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  14353. } else {
  14354. attributes = this.parseImportAttributes();
  14355. }
  14356. useWith = true;
  14357. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14358. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  14359. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  14360. }
  14361. if (!this.hasPlugin("importAssertions")) {
  14362. this.addExtra(node, "deprecatedAssertSyntax", true);
  14363. }
  14364. this.next();
  14365. attributes = this.parseImportAttributes();
  14366. } else {
  14367. attributes = [];
  14368. }
  14369. if (!useWith && this.hasPlugin("importAssertions")) {
  14370. node.assertions = attributes;
  14371. } else {
  14372. node.attributes = attributes;
  14373. }
  14374. }
  14375. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14376. if (maybeDefaultIdentifier) {
  14377. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14378. specifier.local = maybeDefaultIdentifier;
  14379. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14380. return true;
  14381. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14382. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14383. return true;
  14384. }
  14385. return false;
  14386. }
  14387. maybeParseStarImportSpecifier(node) {
  14388. if (this.match(55)) {
  14389. const specifier = this.startNode();
  14390. this.next();
  14391. this.expectContextual(93);
  14392. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14393. return true;
  14394. }
  14395. return false;
  14396. }
  14397. parseNamedImportSpecifiers(node) {
  14398. let first = true;
  14399. this.expect(5);
  14400. while (!this.eat(8)) {
  14401. if (first) {
  14402. first = false;
  14403. } else {
  14404. if (this.eat(14)) {
  14405. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  14406. }
  14407. this.expect(12);
  14408. if (this.eat(8)) break;
  14409. }
  14410. const specifier = this.startNode();
  14411. const importedIsString = this.match(134);
  14412. const isMaybeTypeOnly = this.isContextual(130);
  14413. specifier.imported = this.parseModuleExportName();
  14414. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14415. node.specifiers.push(importSpecifier);
  14416. }
  14417. }
  14418. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14419. if (this.eatContextual(93)) {
  14420. specifier.local = this.parseIdentifier();
  14421. } else {
  14422. const {
  14423. imported
  14424. } = specifier;
  14425. if (importedIsString) {
  14426. throw this.raise(Errors.ImportBindingIsString, specifier, {
  14427. importName: imported.value
  14428. });
  14429. }
  14430. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14431. if (!specifier.local) {
  14432. specifier.local = this.cloneIdentifier(imported);
  14433. }
  14434. }
  14435. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14436. }
  14437. isThisParam(param) {
  14438. return param.type === "Identifier" && param.name === "this";
  14439. }
  14440. }
  14441. class Parser extends StatementParser {
  14442. constructor(options, input, pluginsMap) {
  14443. const normalizedOptions = getOptions(options);
  14444. super(normalizedOptions, input);
  14445. this.options = normalizedOptions;
  14446. this.initializeScopes();
  14447. this.plugins = pluginsMap;
  14448. this.filename = normalizedOptions.sourceFilename;
  14449. this.startIndex = normalizedOptions.startIndex;
  14450. let optionFlags = 0;
  14451. if (normalizedOptions.allowAwaitOutsideFunction) {
  14452. optionFlags |= 1;
  14453. }
  14454. if (normalizedOptions.allowReturnOutsideFunction) {
  14455. optionFlags |= 2;
  14456. }
  14457. if (normalizedOptions.allowImportExportEverywhere) {
  14458. optionFlags |= 8;
  14459. }
  14460. if (normalizedOptions.allowSuperOutsideMethod) {
  14461. optionFlags |= 16;
  14462. }
  14463. if (normalizedOptions.allowUndeclaredExports) {
  14464. optionFlags |= 64;
  14465. }
  14466. if (normalizedOptions.allowNewTargetOutsideFunction) {
  14467. optionFlags |= 4;
  14468. }
  14469. if (normalizedOptions.allowYieldOutsideFunction) {
  14470. optionFlags |= 32;
  14471. }
  14472. if (normalizedOptions.ranges) {
  14473. optionFlags |= 128;
  14474. }
  14475. if (normalizedOptions.tokens) {
  14476. optionFlags |= 256;
  14477. }
  14478. if (normalizedOptions.createImportExpressions) {
  14479. optionFlags |= 512;
  14480. }
  14481. if (normalizedOptions.createParenthesizedExpressions) {
  14482. optionFlags |= 1024;
  14483. }
  14484. if (normalizedOptions.errorRecovery) {
  14485. optionFlags |= 2048;
  14486. }
  14487. if (normalizedOptions.attachComment) {
  14488. optionFlags |= 4096;
  14489. }
  14490. if (normalizedOptions.annexB) {
  14491. optionFlags |= 8192;
  14492. }
  14493. this.optionFlags = optionFlags;
  14494. }
  14495. getScopeHandler() {
  14496. return ScopeHandler;
  14497. }
  14498. parse() {
  14499. this.enterInitialScopes();
  14500. const file = this.startNode();
  14501. const program = this.startNode();
  14502. this.nextToken();
  14503. file.errors = null;
  14504. const result = this.parseTopLevel(file, program);
  14505. result.errors = this.state.errors;
  14506. result.comments.length = this.state.commentsLen;
  14507. return result;
  14508. }
  14509. }
  14510. function parse(input, options) {
  14511. var _options;
  14512. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14513. options = Object.assign({}, options);
  14514. try {
  14515. options.sourceType = "module";
  14516. const parser = getParser(options, input);
  14517. const ast = parser.parse();
  14518. if (parser.sawUnambiguousESM) {
  14519. return ast;
  14520. }
  14521. if (parser.ambiguousScriptDifferentAst) {
  14522. try {
  14523. options.sourceType = "script";
  14524. return getParser(options, input).parse();
  14525. } catch (_unused) {}
  14526. } else {
  14527. ast.program.sourceType = "script";
  14528. }
  14529. return ast;
  14530. } catch (moduleError) {
  14531. try {
  14532. options.sourceType = "script";
  14533. return getParser(options, input).parse();
  14534. } catch (_unused2) {}
  14535. throw moduleError;
  14536. }
  14537. } else {
  14538. return getParser(options, input).parse();
  14539. }
  14540. }
  14541. function parseExpression(input, options) {
  14542. const parser = getParser(options, input);
  14543. if (parser.options.strictMode) {
  14544. parser.state.strict = true;
  14545. }
  14546. return parser.getExpression();
  14547. }
  14548. function generateExportedTokenTypes(internalTokenTypes) {
  14549. const tokenTypes = {};
  14550. for (const typeName of Object.keys(internalTokenTypes)) {
  14551. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14552. }
  14553. return tokenTypes;
  14554. }
  14555. const tokTypes = generateExportedTokenTypes(tt);
  14556. function getParser(options, input) {
  14557. let cls = Parser;
  14558. const pluginsMap = new Map();
  14559. if (options != null && options.plugins) {
  14560. for (const plugin of options.plugins) {
  14561. let name, opts;
  14562. if (typeof plugin === "string") {
  14563. name = plugin;
  14564. } else {
  14565. [name, opts] = plugin;
  14566. }
  14567. if (!pluginsMap.has(name)) {
  14568. pluginsMap.set(name, opts || {});
  14569. }
  14570. }
  14571. validatePlugins(pluginsMap);
  14572. cls = getParserClass(pluginsMap);
  14573. }
  14574. return new cls(options, input, pluginsMap);
  14575. }
  14576. const parserClassCache = new Map();
  14577. function getParserClass(pluginsMap) {
  14578. const pluginList = [];
  14579. for (const name of mixinPluginNames) {
  14580. if (pluginsMap.has(name)) {
  14581. pluginList.push(name);
  14582. }
  14583. }
  14584. const key = pluginList.join("|");
  14585. let cls = parserClassCache.get(key);
  14586. if (!cls) {
  14587. cls = Parser;
  14588. for (const plugin of pluginList) {
  14589. cls = mixinPlugins[plugin](cls);
  14590. }
  14591. parserClassCache.set(key, cls);
  14592. }
  14593. return cls;
  14594. }
  14595. exports.parse = parse;
  14596. exports.parseExpression = parseExpression;
  14597. exports.tokTypes = tokTypes;
  14598. //# sourceMappingURL=index.js.map