index.js 500 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. function _objectWithoutPropertiesLoose(r, e) {
  6. if (null == r) return {};
  7. var t = {};
  8. for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
  9. if (-1 !== e.indexOf(n)) continue;
  10. t[n] = r[n];
  11. }
  12. return t;
  13. }
  14. class Position {
  15. constructor(line, col, index) {
  16. this.line = void 0;
  17. this.column = void 0;
  18. this.index = void 0;
  19. this.line = line;
  20. this.column = col;
  21. this.index = index;
  22. }
  23. }
  24. class SourceLocation {
  25. constructor(start, end) {
  26. this.start = void 0;
  27. this.end = void 0;
  28. this.filename = void 0;
  29. this.identifierName = void 0;
  30. this.start = start;
  31. this.end = end;
  32. }
  33. }
  34. function createPositionWithColumnOffset(position, columnOffset) {
  35. const {
  36. line,
  37. column,
  38. index
  39. } = position;
  40. return new Position(line, column + columnOffset, index + columnOffset);
  41. }
  42. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  43. var ModuleErrors = {
  44. ImportMetaOutsideModule: {
  45. message: `import.meta may appear only with 'sourceType: "module"'`,
  46. code
  47. },
  48. ImportOutsideModule: {
  49. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  50. code
  51. }
  52. };
  53. const NodeDescriptions = {
  54. ArrayPattern: "array destructuring pattern",
  55. AssignmentExpression: "assignment expression",
  56. AssignmentPattern: "assignment expression",
  57. ArrowFunctionExpression: "arrow function expression",
  58. ConditionalExpression: "conditional expression",
  59. CatchClause: "catch clause",
  60. ForOfStatement: "for-of statement",
  61. ForInStatement: "for-in statement",
  62. ForStatement: "for-loop",
  63. FormalParameters: "function parameter list",
  64. Identifier: "identifier",
  65. ImportSpecifier: "import specifier",
  66. ImportDefaultSpecifier: "import default specifier",
  67. ImportNamespaceSpecifier: "import namespace specifier",
  68. ObjectPattern: "object destructuring pattern",
  69. ParenthesizedExpression: "parenthesized expression",
  70. RestElement: "rest element",
  71. UpdateExpression: {
  72. true: "prefix operation",
  73. false: "postfix operation"
  74. },
  75. VariableDeclarator: "variable declaration",
  76. YieldExpression: "yield expression"
  77. };
  78. const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type];
  79. var StandardErrors = {
  80. AccessorIsGenerator: ({
  81. kind
  82. }) => `A ${kind}ter cannot be a generator.`,
  83. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  84. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  85. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  86. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  87. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  88. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  89. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  90. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  91. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  92. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  93. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  94. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  95. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  96. ConstructorIsAsync: "Constructor can't be an async function.",
  97. ConstructorIsGenerator: "Constructor can't be a generator.",
  98. DeclarationMissingInitializer: ({
  99. kind
  100. }) => `Missing initializer in ${kind} declaration.`,
  101. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  102. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  103. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  104. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  105. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  106. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  107. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  108. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  109. DeletePrivateField: "Deleting a private field is not allowed.",
  110. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  111. DuplicateConstructor: "Duplicate constructor in the same class.",
  112. DuplicateDefaultExport: "Only one default export allowed per module.",
  113. DuplicateExport: ({
  114. exportName
  115. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  116. DuplicateProto: "Redefinition of __proto__ property.",
  117. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  118. ElementAfterRest: "Rest element must be last element.",
  119. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  120. ExportBindingIsString: ({
  121. localName,
  122. exportName
  123. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  124. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  125. ForInOfLoopInitializer: ({
  126. type
  127. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  128. ForInUsing: "For-in loop may not start with 'using' declaration.",
  129. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  130. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  131. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  132. IllegalBreakContinue: ({
  133. type
  134. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  135. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  136. IllegalReturn: "'return' outside of function.",
  137. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedImportAssert` parser plugin to suppress this error.",
  138. ImportBindingIsString: ({
  139. importName
  140. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  141. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  142. ImportCallNotNewExpression: "Cannot use new with import(...).",
  143. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  144. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  145. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  146. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  147. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  148. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  149. InvalidCodePoint: "Code point out of bounds.",
  150. InvalidCoverDiscardElement: "'void' must be followed by an expression when not used in a binding position.",
  151. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  152. InvalidDecimal: "Invalid decimal.",
  153. InvalidDigit: ({
  154. radix
  155. }) => `Expected number in radix ${radix}.`,
  156. InvalidEscapeSequence: "Bad character escape sequence.",
  157. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  158. InvalidEscapedReservedWord: ({
  159. reservedWord
  160. }) => `Escape sequence in keyword ${reservedWord}.`,
  161. InvalidIdentifier: ({
  162. identifierName
  163. }) => `Invalid identifier ${identifierName}.`,
  164. InvalidLhs: ({
  165. ancestor
  166. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  167. InvalidLhsBinding: ({
  168. ancestor
  169. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  170. InvalidLhsOptionalChaining: ({
  171. ancestor
  172. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  173. InvalidNumber: "Invalid number.",
  174. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  175. InvalidOrUnexpectedToken: ({
  176. unexpected
  177. }) => `Unexpected character '${unexpected}'.`,
  178. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  179. InvalidPrivateFieldResolution: ({
  180. identifierName
  181. }) => `Private name #${identifierName} is not defined.`,
  182. InvalidPropertyBindingPattern: "Binding member expression.",
  183. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  184. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  185. LabelRedeclaration: ({
  186. labelName
  187. }) => `Label '${labelName}' is already declared.`,
  188. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  189. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  190. MalformedRegExpFlags: "Invalid regular expression flag.",
  191. MissingClassName: "A class name is required.",
  192. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  193. MissingSemicolon: "Missing semicolon.",
  194. MissingPlugin: ({
  195. missingPlugin
  196. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  197. MissingOneOfPlugins: ({
  198. missingPlugin
  199. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  200. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  201. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  202. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  203. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  204. ModuleAttributesWithDuplicateKeys: ({
  205. key
  206. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  207. ModuleExportNameHasLoneSurrogate: ({
  208. surrogateCharCode
  209. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  210. ModuleExportUndefined: ({
  211. localName
  212. }) => `Export '${localName}' is not defined.`,
  213. MultipleDefaultsInSwitch: "Multiple default clauses.",
  214. NewlineAfterThrow: "Illegal newline after throw.",
  215. NoCatchOrFinally: "Missing catch or finally clause.",
  216. NumberIdentifier: "Identifier directly after number.",
  217. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  218. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  219. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  220. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  221. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  222. ParamDupe: "Argument name clash.",
  223. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  224. PatternHasMethod: "Object pattern can't contain methods.",
  225. PrivateInExpectedIn: ({
  226. identifierName
  227. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  228. PrivateNameRedeclaration: ({
  229. identifierName
  230. }) => `Duplicate private name #${identifierName}.`,
  231. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  232. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  233. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  234. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  235. RestTrailingComma: "Unexpected trailing comma after rest element.",
  236. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  237. SloppyFunctionAnnexB: "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement.",
  238. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  239. StaticPrototype: "Classes may not have static property named prototype.",
  240. SuperNotAllowed: "`super()` is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class?",
  241. SuperPrivateField: "Private fields can't be accessed on super.",
  242. TrailingDecorator: "Decorators must be attached to a class element.",
  243. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  244. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  245. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  246. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  247. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  248. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  249. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  250. UnexpectedKeyword: ({
  251. keyword
  252. }) => `Unexpected keyword '${keyword}'.`,
  253. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  254. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  255. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  256. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  257. UnexpectedPrivateField: "Unexpected private name.",
  258. UnexpectedReservedWord: ({
  259. reservedWord
  260. }) => `Unexpected reserved word '${reservedWord}'.`,
  261. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  262. UnexpectedToken: ({
  263. expected,
  264. unexpected
  265. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  266. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  267. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement.",
  268. UnexpectedVoidPattern: "Unexpected void binding.",
  269. UnsupportedBind: "Binding should be performed on object property.",
  270. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  271. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  272. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  273. UnsupportedMetaProperty: ({
  274. target,
  275. onlyValidPropertyName
  276. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  277. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  278. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  279. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  280. UnterminatedComment: "Unterminated comment.",
  281. UnterminatedRegExp: "Unterminated regular expression.",
  282. UnterminatedString: "Unterminated string constant.",
  283. UnterminatedTemplate: "Unterminated template.",
  284. UsingDeclarationExport: "Using declaration cannot be exported.",
  285. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  286. VarRedeclaration: ({
  287. identifierName
  288. }) => `Identifier '${identifierName}' has already been declared.`,
  289. VoidPatternCatchClauseParam: "A void binding can not be the catch clause parameter. Use `try { ... } catch { ... }` if you want to discard the caught error.",
  290. VoidPatternInitializer: "A void binding may not have an initializer.",
  291. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  292. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  293. YieldNotInGeneratorFunction: "'yield' is only allowed within generator functions.",
  294. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  295. };
  296. var StrictModeErrors = {
  297. StrictDelete: "Deleting local variable in strict mode.",
  298. StrictEvalArguments: ({
  299. referenceName
  300. }) => `Assigning to '${referenceName}' in strict mode.`,
  301. StrictEvalArgumentsBinding: ({
  302. bindingName
  303. }) => `Binding '${bindingName}' in strict mode.`,
  304. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  305. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  306. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  307. StrictWith: "'with' in strict mode."
  308. };
  309. var ParseExpressionErrors = {
  310. ParseExpressionEmptyInput: "Unexpected parseExpression() input: The input is empty or contains only comments.",
  311. ParseExpressionExpectsEOF: ({
  312. unexpected
  313. }) => `Unexpected parseExpression() input: The input should contain exactly one expression, but the first expression is followed by the unexpected character \`${String.fromCodePoint(unexpected)}\`.`
  314. };
  315. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  316. var PipelineOperatorErrors = Object.assign({
  317. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  318. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  319. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  320. PipeTopicUnconfiguredToken: ({
  321. token
  322. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  323. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  324. PipeUnparenthesizedBody: ({
  325. type
  326. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  327. type
  328. })}; please wrap it in parentheses.`
  329. }, {
  330. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  331. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  332. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  333. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  334. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  335. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  336. });
  337. const _excluded = ["message"];
  338. function defineHidden(obj, key, value) {
  339. Object.defineProperty(obj, key, {
  340. enumerable: false,
  341. configurable: true,
  342. value
  343. });
  344. }
  345. function toParseErrorConstructor({
  346. toMessage,
  347. code,
  348. reasonCode,
  349. syntaxPlugin
  350. }) {
  351. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  352. {
  353. const oldReasonCodes = {
  354. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  355. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  356. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  357. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  358. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  359. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  360. };
  361. if (oldReasonCodes[reasonCode]) {
  362. reasonCode = oldReasonCodes[reasonCode];
  363. }
  364. }
  365. return function constructor(loc, details) {
  366. const error = new SyntaxError();
  367. error.code = code;
  368. error.reasonCode = reasonCode;
  369. error.loc = loc;
  370. error.pos = loc.index;
  371. error.syntaxPlugin = syntaxPlugin;
  372. if (hasMissingPlugin) {
  373. error.missingPlugin = details.missingPlugin;
  374. }
  375. defineHidden(error, "clone", function clone(overrides = {}) {
  376. var _overrides$loc;
  377. const {
  378. line,
  379. column,
  380. index
  381. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  382. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  383. });
  384. defineHidden(error, "details", details);
  385. Object.defineProperty(error, "message", {
  386. configurable: true,
  387. get() {
  388. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  389. this.message = message;
  390. return message;
  391. },
  392. set(value) {
  393. Object.defineProperty(this, "message", {
  394. value,
  395. writable: true
  396. });
  397. }
  398. });
  399. return error;
  400. };
  401. }
  402. function ParseErrorEnum(argument, syntaxPlugin) {
  403. if (Array.isArray(argument)) {
  404. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  405. }
  406. const ParseErrorConstructors = {};
  407. for (const reasonCode of Object.keys(argument)) {
  408. const template = argument[reasonCode];
  409. const _ref = typeof template === "string" ? {
  410. message: () => template
  411. } : typeof template === "function" ? {
  412. message: template
  413. } : template,
  414. {
  415. message
  416. } = _ref,
  417. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  418. const toMessage = typeof message === "string" ? () => message : message;
  419. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  420. code: "BABEL_PARSER_SYNTAX_ERROR",
  421. reasonCode,
  422. toMessage
  423. }, syntaxPlugin ? {
  424. syntaxPlugin
  425. } : {}, rest));
  426. }
  427. return ParseErrorConstructors;
  428. }
  429. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum(ParseExpressionErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  430. function createDefaultOptions() {
  431. return {
  432. sourceType: "script",
  433. sourceFilename: undefined,
  434. startIndex: 0,
  435. startColumn: 0,
  436. startLine: 1,
  437. allowAwaitOutsideFunction: false,
  438. allowReturnOutsideFunction: false,
  439. allowNewTargetOutsideFunction: false,
  440. allowImportExportEverywhere: false,
  441. allowSuperOutsideMethod: false,
  442. allowUndeclaredExports: false,
  443. allowYieldOutsideFunction: false,
  444. plugins: [],
  445. strictMode: undefined,
  446. ranges: false,
  447. tokens: false,
  448. createImportExpressions: false,
  449. createParenthesizedExpressions: false,
  450. errorRecovery: false,
  451. attachComment: true,
  452. annexB: true
  453. };
  454. }
  455. function getOptions(opts) {
  456. const options = createDefaultOptions();
  457. if (opts == null) {
  458. return options;
  459. }
  460. if (opts.annexB != null && opts.annexB !== false) {
  461. throw new Error("The `annexB` option can only be set to `false`.");
  462. }
  463. for (const key of Object.keys(options)) {
  464. if (opts[key] != null) options[key] = opts[key];
  465. }
  466. if (options.startLine === 1) {
  467. if (opts.startIndex == null && options.startColumn > 0) {
  468. options.startIndex = options.startColumn;
  469. } else if (opts.startColumn == null && options.startIndex > 0) {
  470. options.startColumn = options.startIndex;
  471. }
  472. } else if (opts.startColumn == null || opts.startIndex == null) {
  473. if (opts.startIndex != null) {
  474. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  475. }
  476. }
  477. if (options.sourceType === "commonjs") {
  478. if (opts.allowAwaitOutsideFunction != null) {
  479. throw new Error("The `allowAwaitOutsideFunction` option cannot be used with `sourceType: 'commonjs'`.");
  480. }
  481. if (opts.allowReturnOutsideFunction != null) {
  482. throw new Error("`sourceType: 'commonjs'` implies `allowReturnOutsideFunction: true`, please remove the `allowReturnOutsideFunction` option or use `sourceType: 'script'`.");
  483. }
  484. if (opts.allowNewTargetOutsideFunction != null) {
  485. throw new Error("`sourceType: 'commonjs'` implies `allowNewTargetOutsideFunction: true`, please remove the `allowNewTargetOutsideFunction` option or use `sourceType: 'script'`.");
  486. }
  487. }
  488. return options;
  489. }
  490. const {
  491. defineProperty
  492. } = Object;
  493. const toUnenumerable = (object, key) => {
  494. if (object) {
  495. defineProperty(object, key, {
  496. enumerable: false,
  497. value: object[key]
  498. });
  499. }
  500. };
  501. function toESTreeLocation(node) {
  502. toUnenumerable(node.loc.start, "index");
  503. toUnenumerable(node.loc.end, "index");
  504. return node;
  505. }
  506. var estree = superClass => class ESTreeParserMixin extends superClass {
  507. parse() {
  508. const file = toESTreeLocation(super.parse());
  509. if (this.optionFlags & 256) {
  510. file.tokens = file.tokens.map(toESTreeLocation);
  511. }
  512. return file;
  513. }
  514. parseRegExpLiteral({
  515. pattern,
  516. flags
  517. }) {
  518. let regex = null;
  519. try {
  520. regex = new RegExp(pattern, flags);
  521. } catch (_) {}
  522. const node = this.estreeParseLiteral(regex);
  523. node.regex = {
  524. pattern,
  525. flags
  526. };
  527. return node;
  528. }
  529. parseBigIntLiteral(value) {
  530. let bigInt;
  531. try {
  532. bigInt = BigInt(value);
  533. } catch (_unused) {
  534. bigInt = null;
  535. }
  536. const node = this.estreeParseLiteral(bigInt);
  537. node.bigint = String(node.value || value);
  538. return node;
  539. }
  540. parseDecimalLiteral(value) {
  541. const decimal = null;
  542. const node = this.estreeParseLiteral(decimal);
  543. node.decimal = String(node.value || value);
  544. return node;
  545. }
  546. estreeParseLiteral(value) {
  547. return this.parseLiteral(value, "Literal");
  548. }
  549. parseStringLiteral(value) {
  550. return this.estreeParseLiteral(value);
  551. }
  552. parseNumericLiteral(value) {
  553. return this.estreeParseLiteral(value);
  554. }
  555. parseNullLiteral() {
  556. return this.estreeParseLiteral(null);
  557. }
  558. parseBooleanLiteral(value) {
  559. return this.estreeParseLiteral(value);
  560. }
  561. estreeParseChainExpression(node, endLoc) {
  562. const chain = this.startNodeAtNode(node);
  563. chain.expression = node;
  564. return this.finishNodeAt(chain, "ChainExpression", endLoc);
  565. }
  566. directiveToStmt(directive) {
  567. const expression = directive.value;
  568. delete directive.value;
  569. this.castNodeTo(expression, "Literal");
  570. expression.raw = expression.extra.raw;
  571. expression.value = expression.extra.expressionValue;
  572. const stmt = this.castNodeTo(directive, "ExpressionStatement");
  573. stmt.expression = expression;
  574. stmt.directive = expression.extra.rawValue;
  575. delete expression.extra;
  576. return stmt;
  577. }
  578. fillOptionalPropertiesForTSESLint(node) {}
  579. cloneEstreeStringLiteral(node) {
  580. const {
  581. start,
  582. end,
  583. loc,
  584. range,
  585. raw,
  586. value
  587. } = node;
  588. const cloned = Object.create(node.constructor.prototype);
  589. cloned.type = "Literal";
  590. cloned.start = start;
  591. cloned.end = end;
  592. cloned.loc = loc;
  593. cloned.range = range;
  594. cloned.raw = raw;
  595. cloned.value = value;
  596. return cloned;
  597. }
  598. initFunction(node, isAsync) {
  599. super.initFunction(node, isAsync);
  600. node.expression = false;
  601. }
  602. checkDeclaration(node) {
  603. if (node != null && this.isObjectProperty(node)) {
  604. this.checkDeclaration(node.value);
  605. } else {
  606. super.checkDeclaration(node);
  607. }
  608. }
  609. getObjectOrClassMethodParams(method) {
  610. return method.value.params;
  611. }
  612. isValidDirective(stmt) {
  613. var _stmt$expression$extr;
  614. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  615. }
  616. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  617. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  618. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  619. node.body = directiveStatements.concat(node.body);
  620. delete node.directives;
  621. }
  622. parsePrivateName() {
  623. const node = super.parsePrivateName();
  624. {
  625. if (!this.getPluginOption("estree", "classFeatures")) {
  626. return node;
  627. }
  628. }
  629. return this.convertPrivateNameToPrivateIdentifier(node);
  630. }
  631. convertPrivateNameToPrivateIdentifier(node) {
  632. const name = super.getPrivateNameSV(node);
  633. delete node.id;
  634. node.name = name;
  635. return this.castNodeTo(node, "PrivateIdentifier");
  636. }
  637. isPrivateName(node) {
  638. {
  639. if (!this.getPluginOption("estree", "classFeatures")) {
  640. return super.isPrivateName(node);
  641. }
  642. }
  643. return node.type === "PrivateIdentifier";
  644. }
  645. getPrivateNameSV(node) {
  646. {
  647. if (!this.getPluginOption("estree", "classFeatures")) {
  648. return super.getPrivateNameSV(node);
  649. }
  650. }
  651. return node.name;
  652. }
  653. parseLiteral(value, type) {
  654. const node = super.parseLiteral(value, type);
  655. node.raw = node.extra.raw;
  656. delete node.extra;
  657. return node;
  658. }
  659. parseFunctionBody(node, allowExpression, isMethod = false) {
  660. super.parseFunctionBody(node, allowExpression, isMethod);
  661. node.expression = node.body.type !== "BlockStatement";
  662. }
  663. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  664. let funcNode = this.startNode();
  665. funcNode.kind = node.kind;
  666. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  667. delete funcNode.kind;
  668. const {
  669. typeParameters
  670. } = node;
  671. if (typeParameters) {
  672. delete node.typeParameters;
  673. funcNode.typeParameters = typeParameters;
  674. this.resetStartLocationFromNode(funcNode, typeParameters);
  675. }
  676. const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
  677. node.value = valueNode;
  678. if (type === "ClassPrivateMethod") {
  679. node.computed = false;
  680. }
  681. if (type === "ObjectMethod") {
  682. if (node.kind === "method") {
  683. node.kind = "init";
  684. }
  685. node.shorthand = false;
  686. return this.finishNode(node, "Property");
  687. } else {
  688. return this.finishNode(node, "MethodDefinition");
  689. }
  690. }
  691. nameIsConstructor(key) {
  692. if (key.type === "Literal") return key.value === "constructor";
  693. return super.nameIsConstructor(key);
  694. }
  695. parseClassProperty(...args) {
  696. const propertyNode = super.parseClassProperty(...args);
  697. {
  698. if (!this.getPluginOption("estree", "classFeatures")) {
  699. return propertyNode;
  700. }
  701. }
  702. {
  703. this.castNodeTo(propertyNode, "PropertyDefinition");
  704. }
  705. return propertyNode;
  706. }
  707. parseClassPrivateProperty(...args) {
  708. const propertyNode = super.parseClassPrivateProperty(...args);
  709. {
  710. if (!this.getPluginOption("estree", "classFeatures")) {
  711. return propertyNode;
  712. }
  713. }
  714. {
  715. this.castNodeTo(propertyNode, "PropertyDefinition");
  716. }
  717. propertyNode.computed = false;
  718. return propertyNode;
  719. }
  720. parseClassAccessorProperty(node) {
  721. const accessorPropertyNode = super.parseClassAccessorProperty(node);
  722. {
  723. if (!this.getPluginOption("estree", "classFeatures")) {
  724. return accessorPropertyNode;
  725. }
  726. }
  727. if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
  728. delete accessorPropertyNode.abstract;
  729. this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
  730. } else {
  731. this.castNodeTo(accessorPropertyNode, "AccessorProperty");
  732. }
  733. return accessorPropertyNode;
  734. }
  735. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  736. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  737. if (node) {
  738. node.kind = "init";
  739. this.castNodeTo(node, "Property");
  740. }
  741. return node;
  742. }
  743. finishObjectProperty(node) {
  744. node.kind = "init";
  745. return this.finishNode(node, "Property");
  746. }
  747. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  748. return type === "Property" ? "value" : super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  749. }
  750. isAssignable(node, isBinding) {
  751. if (node != null && this.isObjectProperty(node)) {
  752. return this.isAssignable(node.value, isBinding);
  753. }
  754. return super.isAssignable(node, isBinding);
  755. }
  756. toAssignable(node, isLHS = false) {
  757. if (node != null && this.isObjectProperty(node)) {
  758. const {
  759. key,
  760. value
  761. } = node;
  762. if (this.isPrivateName(key)) {
  763. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  764. }
  765. this.toAssignable(value, isLHS);
  766. } else {
  767. super.toAssignable(node, isLHS);
  768. }
  769. }
  770. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  771. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  772. this.raise(Errors.PatternHasAccessor, prop.key);
  773. } else if (prop.type === "Property" && prop.method) {
  774. this.raise(Errors.PatternHasMethod, prop.key);
  775. } else {
  776. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  777. }
  778. }
  779. finishCallExpression(unfinished, optional) {
  780. const node = super.finishCallExpression(unfinished, optional);
  781. if (node.callee.type === "Import") {
  782. var _ref;
  783. this.castNodeTo(node, "ImportExpression");
  784. node.source = node.arguments[0];
  785. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  786. {
  787. var _ref2;
  788. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  789. }
  790. delete node.arguments;
  791. delete node.callee;
  792. } else if (node.type === "OptionalCallExpression") {
  793. this.castNodeTo(node, "CallExpression");
  794. } else {
  795. node.optional = false;
  796. }
  797. return node;
  798. }
  799. toReferencedArguments(node) {
  800. if (node.type === "ImportExpression") {
  801. return;
  802. }
  803. super.toReferencedArguments(node);
  804. }
  805. parseExport(unfinished, decorators) {
  806. const exportStartLoc = this.state.lastTokStartLoc;
  807. const node = super.parseExport(unfinished, decorators);
  808. switch (node.type) {
  809. case "ExportAllDeclaration":
  810. node.exported = null;
  811. break;
  812. case "ExportNamedDeclaration":
  813. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  814. this.castNodeTo(node, "ExportAllDeclaration");
  815. node.exported = node.specifiers[0].exported;
  816. delete node.specifiers;
  817. }
  818. case "ExportDefaultDeclaration":
  819. {
  820. var _declaration$decorato;
  821. const {
  822. declaration
  823. } = node;
  824. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  825. this.resetStartLocation(node, exportStartLoc);
  826. }
  827. }
  828. break;
  829. }
  830. return node;
  831. }
  832. stopParseSubscript(base, state) {
  833. const node = super.stopParseSubscript(base, state);
  834. if (state.optionalChainMember) {
  835. return this.estreeParseChainExpression(node, base.loc.end);
  836. }
  837. return node;
  838. }
  839. parseMember(base, startLoc, state, computed, optional) {
  840. const node = super.parseMember(base, startLoc, state, computed, optional);
  841. if (node.type === "OptionalMemberExpression") {
  842. this.castNodeTo(node, "MemberExpression");
  843. } else {
  844. node.optional = false;
  845. }
  846. return node;
  847. }
  848. isOptionalMemberExpression(node) {
  849. if (node.type === "ChainExpression") {
  850. return node.expression.type === "MemberExpression";
  851. }
  852. return super.isOptionalMemberExpression(node);
  853. }
  854. hasPropertyAsPrivateName(node) {
  855. if (node.type === "ChainExpression") {
  856. node = node.expression;
  857. }
  858. return super.hasPropertyAsPrivateName(node);
  859. }
  860. isObjectProperty(node) {
  861. return node.type === "Property" && node.kind === "init" && !node.method;
  862. }
  863. isObjectMethod(node) {
  864. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  865. }
  866. castNodeTo(node, type) {
  867. const result = super.castNodeTo(node, type);
  868. this.fillOptionalPropertiesForTSESLint(result);
  869. return result;
  870. }
  871. cloneIdentifier(node) {
  872. const cloned = super.cloneIdentifier(node);
  873. this.fillOptionalPropertiesForTSESLint(cloned);
  874. return cloned;
  875. }
  876. cloneStringLiteral(node) {
  877. if (node.type === "Literal") {
  878. return this.cloneEstreeStringLiteral(node);
  879. }
  880. return super.cloneStringLiteral(node);
  881. }
  882. finishNodeAt(node, type, endLoc) {
  883. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  884. }
  885. finishNode(node, type) {
  886. const result = super.finishNode(node, type);
  887. this.fillOptionalPropertiesForTSESLint(result);
  888. return result;
  889. }
  890. resetStartLocation(node, startLoc) {
  891. super.resetStartLocation(node, startLoc);
  892. toESTreeLocation(node);
  893. }
  894. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  895. super.resetEndLocation(node, endLoc);
  896. toESTreeLocation(node);
  897. }
  898. };
  899. class TokContext {
  900. constructor(token, preserveSpace) {
  901. this.token = void 0;
  902. this.preserveSpace = void 0;
  903. this.token = token;
  904. this.preserveSpace = !!preserveSpace;
  905. }
  906. }
  907. const types = {
  908. brace: new TokContext("{"),
  909. j_oTag: new TokContext("<tag"),
  910. j_cTag: new TokContext("</tag"),
  911. j_expr: new TokContext("<tag>...</tag>", true)
  912. };
  913. {
  914. types.template = new TokContext("`", true);
  915. }
  916. const beforeExpr = true;
  917. const startsExpr = true;
  918. const isLoop = true;
  919. const isAssign = true;
  920. const prefix = true;
  921. const postfix = true;
  922. class ExportedTokenType {
  923. constructor(label, conf = {}) {
  924. this.label = void 0;
  925. this.keyword = void 0;
  926. this.beforeExpr = void 0;
  927. this.startsExpr = void 0;
  928. this.rightAssociative = void 0;
  929. this.isLoop = void 0;
  930. this.isAssign = void 0;
  931. this.prefix = void 0;
  932. this.postfix = void 0;
  933. this.binop = void 0;
  934. this.label = label;
  935. this.keyword = conf.keyword;
  936. this.beforeExpr = !!conf.beforeExpr;
  937. this.startsExpr = !!conf.startsExpr;
  938. this.rightAssociative = !!conf.rightAssociative;
  939. this.isLoop = !!conf.isLoop;
  940. this.isAssign = !!conf.isAssign;
  941. this.prefix = !!conf.prefix;
  942. this.postfix = !!conf.postfix;
  943. this.binop = conf.binop != null ? conf.binop : null;
  944. {
  945. this.updateContext = null;
  946. }
  947. }
  948. }
  949. const keywords$1 = new Map();
  950. function createKeyword(name, options = {}) {
  951. options.keyword = name;
  952. const token = createToken(name, options);
  953. keywords$1.set(name, token);
  954. return token;
  955. }
  956. function createBinop(name, binop) {
  957. return createToken(name, {
  958. beforeExpr,
  959. binop
  960. });
  961. }
  962. let tokenTypeCounter = -1;
  963. const tokenTypes = [];
  964. const tokenLabels = [];
  965. const tokenBinops = [];
  966. const tokenBeforeExprs = [];
  967. const tokenStartsExprs = [];
  968. const tokenPrefixes = [];
  969. function createToken(name, options = {}) {
  970. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  971. ++tokenTypeCounter;
  972. tokenLabels.push(name);
  973. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  974. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  975. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  976. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  977. tokenTypes.push(new ExportedTokenType(name, options));
  978. return tokenTypeCounter;
  979. }
  980. function createKeywordLike(name, options = {}) {
  981. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  982. ++tokenTypeCounter;
  983. keywords$1.set(name, tokenTypeCounter);
  984. tokenLabels.push(name);
  985. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  986. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  987. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  988. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  989. tokenTypes.push(new ExportedTokenType("name", options));
  990. return tokenTypeCounter;
  991. }
  992. const tt = {
  993. bracketL: createToken("[", {
  994. beforeExpr,
  995. startsExpr
  996. }),
  997. bracketHashL: createToken("#[", {
  998. beforeExpr,
  999. startsExpr
  1000. }),
  1001. bracketBarL: createToken("[|", {
  1002. beforeExpr,
  1003. startsExpr
  1004. }),
  1005. bracketR: createToken("]"),
  1006. bracketBarR: createToken("|]"),
  1007. braceL: createToken("{", {
  1008. beforeExpr,
  1009. startsExpr
  1010. }),
  1011. braceBarL: createToken("{|", {
  1012. beforeExpr,
  1013. startsExpr
  1014. }),
  1015. braceHashL: createToken("#{", {
  1016. beforeExpr,
  1017. startsExpr
  1018. }),
  1019. braceR: createToken("}"),
  1020. braceBarR: createToken("|}"),
  1021. parenL: createToken("(", {
  1022. beforeExpr,
  1023. startsExpr
  1024. }),
  1025. parenR: createToken(")"),
  1026. comma: createToken(",", {
  1027. beforeExpr
  1028. }),
  1029. semi: createToken(";", {
  1030. beforeExpr
  1031. }),
  1032. colon: createToken(":", {
  1033. beforeExpr
  1034. }),
  1035. doubleColon: createToken("::", {
  1036. beforeExpr
  1037. }),
  1038. dot: createToken("."),
  1039. question: createToken("?", {
  1040. beforeExpr
  1041. }),
  1042. questionDot: createToken("?."),
  1043. arrow: createToken("=>", {
  1044. beforeExpr
  1045. }),
  1046. template: createToken("template"),
  1047. ellipsis: createToken("...", {
  1048. beforeExpr
  1049. }),
  1050. backQuote: createToken("`", {
  1051. startsExpr
  1052. }),
  1053. dollarBraceL: createToken("${", {
  1054. beforeExpr,
  1055. startsExpr
  1056. }),
  1057. templateTail: createToken("...`", {
  1058. startsExpr
  1059. }),
  1060. templateNonTail: createToken("...${", {
  1061. beforeExpr,
  1062. startsExpr
  1063. }),
  1064. at: createToken("@"),
  1065. hash: createToken("#", {
  1066. startsExpr
  1067. }),
  1068. interpreterDirective: createToken("#!..."),
  1069. eq: createToken("=", {
  1070. beforeExpr,
  1071. isAssign
  1072. }),
  1073. assign: createToken("_=", {
  1074. beforeExpr,
  1075. isAssign
  1076. }),
  1077. slashAssign: createToken("_=", {
  1078. beforeExpr,
  1079. isAssign
  1080. }),
  1081. xorAssign: createToken("_=", {
  1082. beforeExpr,
  1083. isAssign
  1084. }),
  1085. moduloAssign: createToken("_=", {
  1086. beforeExpr,
  1087. isAssign
  1088. }),
  1089. incDec: createToken("++/--", {
  1090. prefix,
  1091. postfix,
  1092. startsExpr
  1093. }),
  1094. bang: createToken("!", {
  1095. beforeExpr,
  1096. prefix,
  1097. startsExpr
  1098. }),
  1099. tilde: createToken("~", {
  1100. beforeExpr,
  1101. prefix,
  1102. startsExpr
  1103. }),
  1104. doubleCaret: createToken("^^", {
  1105. startsExpr
  1106. }),
  1107. doubleAt: createToken("@@", {
  1108. startsExpr
  1109. }),
  1110. pipeline: createBinop("|>", 0),
  1111. nullishCoalescing: createBinop("??", 1),
  1112. logicalOR: createBinop("||", 1),
  1113. logicalAND: createBinop("&&", 2),
  1114. bitwiseOR: createBinop("|", 3),
  1115. bitwiseXOR: createBinop("^", 4),
  1116. bitwiseAND: createBinop("&", 5),
  1117. equality: createBinop("==/!=/===/!==", 6),
  1118. lt: createBinop("</>/<=/>=", 7),
  1119. gt: createBinop("</>/<=/>=", 7),
  1120. relational: createBinop("</>/<=/>=", 7),
  1121. bitShift: createBinop("<</>>/>>>", 8),
  1122. bitShiftL: createBinop("<</>>/>>>", 8),
  1123. bitShiftR: createBinop("<</>>/>>>", 8),
  1124. plusMin: createToken("+/-", {
  1125. beforeExpr,
  1126. binop: 9,
  1127. prefix,
  1128. startsExpr
  1129. }),
  1130. modulo: createToken("%", {
  1131. binop: 10,
  1132. startsExpr
  1133. }),
  1134. star: createToken("*", {
  1135. binop: 10
  1136. }),
  1137. slash: createBinop("/", 10),
  1138. exponent: createToken("**", {
  1139. beforeExpr,
  1140. binop: 11,
  1141. rightAssociative: true
  1142. }),
  1143. _in: createKeyword("in", {
  1144. beforeExpr,
  1145. binop: 7
  1146. }),
  1147. _instanceof: createKeyword("instanceof", {
  1148. beforeExpr,
  1149. binop: 7
  1150. }),
  1151. _break: createKeyword("break"),
  1152. _case: createKeyword("case", {
  1153. beforeExpr
  1154. }),
  1155. _catch: createKeyword("catch"),
  1156. _continue: createKeyword("continue"),
  1157. _debugger: createKeyword("debugger"),
  1158. _default: createKeyword("default", {
  1159. beforeExpr
  1160. }),
  1161. _else: createKeyword("else", {
  1162. beforeExpr
  1163. }),
  1164. _finally: createKeyword("finally"),
  1165. _function: createKeyword("function", {
  1166. startsExpr
  1167. }),
  1168. _if: createKeyword("if"),
  1169. _return: createKeyword("return", {
  1170. beforeExpr
  1171. }),
  1172. _switch: createKeyword("switch"),
  1173. _throw: createKeyword("throw", {
  1174. beforeExpr,
  1175. prefix,
  1176. startsExpr
  1177. }),
  1178. _try: createKeyword("try"),
  1179. _var: createKeyword("var"),
  1180. _const: createKeyword("const"),
  1181. _with: createKeyword("with"),
  1182. _new: createKeyword("new", {
  1183. beforeExpr,
  1184. startsExpr
  1185. }),
  1186. _this: createKeyword("this", {
  1187. startsExpr
  1188. }),
  1189. _super: createKeyword("super", {
  1190. startsExpr
  1191. }),
  1192. _class: createKeyword("class", {
  1193. startsExpr
  1194. }),
  1195. _extends: createKeyword("extends", {
  1196. beforeExpr
  1197. }),
  1198. _export: createKeyword("export"),
  1199. _import: createKeyword("import", {
  1200. startsExpr
  1201. }),
  1202. _null: createKeyword("null", {
  1203. startsExpr
  1204. }),
  1205. _true: createKeyword("true", {
  1206. startsExpr
  1207. }),
  1208. _false: createKeyword("false", {
  1209. startsExpr
  1210. }),
  1211. _typeof: createKeyword("typeof", {
  1212. beforeExpr,
  1213. prefix,
  1214. startsExpr
  1215. }),
  1216. _void: createKeyword("void", {
  1217. beforeExpr,
  1218. prefix,
  1219. startsExpr
  1220. }),
  1221. _delete: createKeyword("delete", {
  1222. beforeExpr,
  1223. prefix,
  1224. startsExpr
  1225. }),
  1226. _do: createKeyword("do", {
  1227. isLoop,
  1228. beforeExpr
  1229. }),
  1230. _for: createKeyword("for", {
  1231. isLoop
  1232. }),
  1233. _while: createKeyword("while", {
  1234. isLoop
  1235. }),
  1236. _as: createKeywordLike("as", {
  1237. startsExpr
  1238. }),
  1239. _assert: createKeywordLike("assert", {
  1240. startsExpr
  1241. }),
  1242. _async: createKeywordLike("async", {
  1243. startsExpr
  1244. }),
  1245. _await: createKeywordLike("await", {
  1246. startsExpr
  1247. }),
  1248. _defer: createKeywordLike("defer", {
  1249. startsExpr
  1250. }),
  1251. _from: createKeywordLike("from", {
  1252. startsExpr
  1253. }),
  1254. _get: createKeywordLike("get", {
  1255. startsExpr
  1256. }),
  1257. _let: createKeywordLike("let", {
  1258. startsExpr
  1259. }),
  1260. _meta: createKeywordLike("meta", {
  1261. startsExpr
  1262. }),
  1263. _of: createKeywordLike("of", {
  1264. startsExpr
  1265. }),
  1266. _sent: createKeywordLike("sent", {
  1267. startsExpr
  1268. }),
  1269. _set: createKeywordLike("set", {
  1270. startsExpr
  1271. }),
  1272. _source: createKeywordLike("source", {
  1273. startsExpr
  1274. }),
  1275. _static: createKeywordLike("static", {
  1276. startsExpr
  1277. }),
  1278. _using: createKeywordLike("using", {
  1279. startsExpr
  1280. }),
  1281. _yield: createKeywordLike("yield", {
  1282. startsExpr
  1283. }),
  1284. _asserts: createKeywordLike("asserts", {
  1285. startsExpr
  1286. }),
  1287. _checks: createKeywordLike("checks", {
  1288. startsExpr
  1289. }),
  1290. _exports: createKeywordLike("exports", {
  1291. startsExpr
  1292. }),
  1293. _global: createKeywordLike("global", {
  1294. startsExpr
  1295. }),
  1296. _implements: createKeywordLike("implements", {
  1297. startsExpr
  1298. }),
  1299. _intrinsic: createKeywordLike("intrinsic", {
  1300. startsExpr
  1301. }),
  1302. _infer: createKeywordLike("infer", {
  1303. startsExpr
  1304. }),
  1305. _is: createKeywordLike("is", {
  1306. startsExpr
  1307. }),
  1308. _mixins: createKeywordLike("mixins", {
  1309. startsExpr
  1310. }),
  1311. _proto: createKeywordLike("proto", {
  1312. startsExpr
  1313. }),
  1314. _require: createKeywordLike("require", {
  1315. startsExpr
  1316. }),
  1317. _satisfies: createKeywordLike("satisfies", {
  1318. startsExpr
  1319. }),
  1320. _keyof: createKeywordLike("keyof", {
  1321. startsExpr
  1322. }),
  1323. _readonly: createKeywordLike("readonly", {
  1324. startsExpr
  1325. }),
  1326. _unique: createKeywordLike("unique", {
  1327. startsExpr
  1328. }),
  1329. _abstract: createKeywordLike("abstract", {
  1330. startsExpr
  1331. }),
  1332. _declare: createKeywordLike("declare", {
  1333. startsExpr
  1334. }),
  1335. _enum: createKeywordLike("enum", {
  1336. startsExpr
  1337. }),
  1338. _module: createKeywordLike("module", {
  1339. startsExpr
  1340. }),
  1341. _namespace: createKeywordLike("namespace", {
  1342. startsExpr
  1343. }),
  1344. _interface: createKeywordLike("interface", {
  1345. startsExpr
  1346. }),
  1347. _type: createKeywordLike("type", {
  1348. startsExpr
  1349. }),
  1350. _opaque: createKeywordLike("opaque", {
  1351. startsExpr
  1352. }),
  1353. name: createToken("name", {
  1354. startsExpr
  1355. }),
  1356. placeholder: createToken("%%", {
  1357. startsExpr
  1358. }),
  1359. string: createToken("string", {
  1360. startsExpr
  1361. }),
  1362. num: createToken("num", {
  1363. startsExpr
  1364. }),
  1365. bigint: createToken("bigint", {
  1366. startsExpr
  1367. }),
  1368. decimal: createToken("decimal", {
  1369. startsExpr
  1370. }),
  1371. regexp: createToken("regexp", {
  1372. startsExpr
  1373. }),
  1374. privateName: createToken("#name", {
  1375. startsExpr
  1376. }),
  1377. eof: createToken("eof"),
  1378. jsxName: createToken("jsxName"),
  1379. jsxText: createToken("jsxText", {
  1380. beforeExpr
  1381. }),
  1382. jsxTagStart: createToken("jsxTagStart", {
  1383. startsExpr
  1384. }),
  1385. jsxTagEnd: createToken("jsxTagEnd")
  1386. };
  1387. function tokenIsIdentifier(token) {
  1388. return token >= 93 && token <= 133;
  1389. }
  1390. function tokenKeywordOrIdentifierIsKeyword(token) {
  1391. return token <= 92;
  1392. }
  1393. function tokenIsKeywordOrIdentifier(token) {
  1394. return token >= 58 && token <= 133;
  1395. }
  1396. function tokenIsLiteralPropertyName(token) {
  1397. return token >= 58 && token <= 137;
  1398. }
  1399. function tokenComesBeforeExpression(token) {
  1400. return tokenBeforeExprs[token];
  1401. }
  1402. function tokenCanStartExpression(token) {
  1403. return tokenStartsExprs[token];
  1404. }
  1405. function tokenIsAssignment(token) {
  1406. return token >= 29 && token <= 33;
  1407. }
  1408. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1409. return token >= 129 && token <= 131;
  1410. }
  1411. function tokenIsLoop(token) {
  1412. return token >= 90 && token <= 92;
  1413. }
  1414. function tokenIsKeyword(token) {
  1415. return token >= 58 && token <= 92;
  1416. }
  1417. function tokenIsOperator(token) {
  1418. return token >= 39 && token <= 59;
  1419. }
  1420. function tokenIsPostfix(token) {
  1421. return token === 34;
  1422. }
  1423. function tokenIsPrefix(token) {
  1424. return tokenPrefixes[token];
  1425. }
  1426. function tokenIsTSTypeOperator(token) {
  1427. return token >= 121 && token <= 123;
  1428. }
  1429. function tokenIsTSDeclarationStart(token) {
  1430. return token >= 124 && token <= 130;
  1431. }
  1432. function tokenLabelName(token) {
  1433. return tokenLabels[token];
  1434. }
  1435. function tokenOperatorPrecedence(token) {
  1436. return tokenBinops[token];
  1437. }
  1438. function tokenIsRightAssociative(token) {
  1439. return token === 57;
  1440. }
  1441. function tokenIsTemplate(token) {
  1442. return token >= 24 && token <= 25;
  1443. }
  1444. function getExportedToken(token) {
  1445. return tokenTypes[token];
  1446. }
  1447. {
  1448. tokenTypes[8].updateContext = context => {
  1449. context.pop();
  1450. };
  1451. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1452. context.push(types.brace);
  1453. };
  1454. tokenTypes[22].updateContext = context => {
  1455. if (context[context.length - 1] === types.template) {
  1456. context.pop();
  1457. } else {
  1458. context.push(types.template);
  1459. }
  1460. };
  1461. tokenTypes[143].updateContext = context => {
  1462. context.push(types.j_expr, types.j_oTag);
  1463. };
  1464. }
  1465. 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";
  1466. 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";
  1467. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1468. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1469. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1470. 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];
  1471. 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];
  1472. function isInAstralSet(code, set) {
  1473. let pos = 0x10000;
  1474. for (let i = 0, length = set.length; i < length; i += 2) {
  1475. pos += set[i];
  1476. if (pos > code) return false;
  1477. pos += set[i + 1];
  1478. if (pos >= code) return true;
  1479. }
  1480. return false;
  1481. }
  1482. function isIdentifierStart(code) {
  1483. if (code < 65) return code === 36;
  1484. if (code <= 90) return true;
  1485. if (code < 97) return code === 95;
  1486. if (code <= 122) return true;
  1487. if (code <= 0xffff) {
  1488. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1489. }
  1490. return isInAstralSet(code, astralIdentifierStartCodes);
  1491. }
  1492. function isIdentifierChar(code) {
  1493. if (code < 48) return code === 36;
  1494. if (code < 58) return true;
  1495. if (code < 65) return false;
  1496. if (code <= 90) return true;
  1497. if (code < 97) return code === 95;
  1498. if (code <= 122) return true;
  1499. if (code <= 0xffff) {
  1500. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1501. }
  1502. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1503. }
  1504. const reservedWords = {
  1505. 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"],
  1506. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1507. strictBind: ["eval", "arguments"]
  1508. };
  1509. const keywords = new Set(reservedWords.keyword);
  1510. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1511. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1512. function isReservedWord(word, inModule) {
  1513. return inModule && word === "await" || word === "enum";
  1514. }
  1515. function isStrictReservedWord(word, inModule) {
  1516. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1517. }
  1518. function isStrictBindOnlyReservedWord(word) {
  1519. return reservedWordsStrictBindSet.has(word);
  1520. }
  1521. function isStrictBindReservedWord(word, inModule) {
  1522. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1523. }
  1524. function isKeyword(word) {
  1525. return keywords.has(word);
  1526. }
  1527. function isIteratorStart(current, next, next2) {
  1528. return current === 64 && next === 64 && isIdentifierStart(next2);
  1529. }
  1530. 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"]);
  1531. function canBeReservedWord(word) {
  1532. return reservedWordLikeSet.has(word);
  1533. }
  1534. class Scope {
  1535. constructor(flags) {
  1536. this.flags = 0;
  1537. this.names = new Map();
  1538. this.firstLexicalName = "";
  1539. this.flags = flags;
  1540. }
  1541. }
  1542. class ScopeHandler {
  1543. constructor(parser, inModule) {
  1544. this.parser = void 0;
  1545. this.scopeStack = [];
  1546. this.inModule = void 0;
  1547. this.undefinedExports = new Map();
  1548. this.parser = parser;
  1549. this.inModule = inModule;
  1550. }
  1551. get inTopLevel() {
  1552. return (this.currentScope().flags & 1) > 0;
  1553. }
  1554. get inFunction() {
  1555. return (this.currentVarScopeFlags() & 2) > 0;
  1556. }
  1557. get allowSuper() {
  1558. return (this.currentThisScopeFlags() & 16) > 0;
  1559. }
  1560. get allowDirectSuper() {
  1561. return (this.currentThisScopeFlags() & 32) > 0;
  1562. }
  1563. get allowNewTarget() {
  1564. return (this.currentThisScopeFlags() & 512) > 0;
  1565. }
  1566. get inClass() {
  1567. return (this.currentThisScopeFlags() & 64) > 0;
  1568. }
  1569. get inClassAndNotInNonArrowFunction() {
  1570. const flags = this.currentThisScopeFlags();
  1571. return (flags & 64) > 0 && (flags & 2) === 0;
  1572. }
  1573. get inStaticBlock() {
  1574. for (let i = this.scopeStack.length - 1;; i--) {
  1575. const {
  1576. flags
  1577. } = this.scopeStack[i];
  1578. if (flags & 128) {
  1579. return true;
  1580. }
  1581. if (flags & (1667 | 64)) {
  1582. return false;
  1583. }
  1584. }
  1585. }
  1586. get inNonArrowFunction() {
  1587. return (this.currentThisScopeFlags() & 2) > 0;
  1588. }
  1589. get inBareCaseStatement() {
  1590. return (this.currentScope().flags & 256) > 0;
  1591. }
  1592. get treatFunctionsAsVar() {
  1593. return this.treatFunctionsAsVarInScope(this.currentScope());
  1594. }
  1595. createScope(flags) {
  1596. return new Scope(flags);
  1597. }
  1598. enter(flags) {
  1599. this.scopeStack.push(this.createScope(flags));
  1600. }
  1601. exit() {
  1602. const scope = this.scopeStack.pop();
  1603. return scope.flags;
  1604. }
  1605. treatFunctionsAsVarInScope(scope) {
  1606. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1607. }
  1608. declareName(name, bindingType, loc) {
  1609. let scope = this.currentScope();
  1610. if (bindingType & 8 || bindingType & 16) {
  1611. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1612. let type = scope.names.get(name) || 0;
  1613. if (bindingType & 16) {
  1614. type = type | 4;
  1615. } else {
  1616. if (!scope.firstLexicalName) {
  1617. scope.firstLexicalName = name;
  1618. }
  1619. type = type | 2;
  1620. }
  1621. scope.names.set(name, type);
  1622. if (bindingType & 8) {
  1623. this.maybeExportDefined(scope, name);
  1624. }
  1625. } else if (bindingType & 4) {
  1626. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1627. scope = this.scopeStack[i];
  1628. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1629. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1630. this.maybeExportDefined(scope, name);
  1631. if (scope.flags & 1667) break;
  1632. }
  1633. }
  1634. if (this.parser.inModule && scope.flags & 1) {
  1635. this.undefinedExports.delete(name);
  1636. }
  1637. }
  1638. maybeExportDefined(scope, name) {
  1639. if (this.parser.inModule && scope.flags & 1) {
  1640. this.undefinedExports.delete(name);
  1641. }
  1642. }
  1643. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1644. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1645. this.parser.raise(Errors.VarRedeclaration, loc, {
  1646. identifierName: name
  1647. });
  1648. }
  1649. }
  1650. isRedeclaredInScope(scope, name, bindingType) {
  1651. if (!(bindingType & 1)) return false;
  1652. if (bindingType & 8) {
  1653. return scope.names.has(name);
  1654. }
  1655. const type = scope.names.get(name) || 0;
  1656. if (bindingType & 16) {
  1657. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1658. }
  1659. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1660. }
  1661. checkLocalExport(id) {
  1662. const {
  1663. name
  1664. } = id;
  1665. const topLevelScope = this.scopeStack[0];
  1666. if (!topLevelScope.names.has(name)) {
  1667. this.undefinedExports.set(name, id.loc.start);
  1668. }
  1669. }
  1670. currentScope() {
  1671. return this.scopeStack[this.scopeStack.length - 1];
  1672. }
  1673. currentVarScopeFlags() {
  1674. for (let i = this.scopeStack.length - 1;; i--) {
  1675. const {
  1676. flags
  1677. } = this.scopeStack[i];
  1678. if (flags & 1667) {
  1679. return flags;
  1680. }
  1681. }
  1682. }
  1683. currentThisScopeFlags() {
  1684. for (let i = this.scopeStack.length - 1;; i--) {
  1685. const {
  1686. flags
  1687. } = this.scopeStack[i];
  1688. if (flags & (1667 | 64) && !(flags & 4)) {
  1689. return flags;
  1690. }
  1691. }
  1692. }
  1693. }
  1694. class FlowScope extends Scope {
  1695. constructor(...args) {
  1696. super(...args);
  1697. this.declareFunctions = new Set();
  1698. }
  1699. }
  1700. class FlowScopeHandler extends ScopeHandler {
  1701. createScope(flags) {
  1702. return new FlowScope(flags);
  1703. }
  1704. declareName(name, bindingType, loc) {
  1705. const scope = this.currentScope();
  1706. if (bindingType & 2048) {
  1707. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1708. this.maybeExportDefined(scope, name);
  1709. scope.declareFunctions.add(name);
  1710. return;
  1711. }
  1712. super.declareName(name, bindingType, loc);
  1713. }
  1714. isRedeclaredInScope(scope, name, bindingType) {
  1715. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1716. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1717. const type = scope.names.get(name);
  1718. return (type & 4) > 0 || (type & 2) > 0;
  1719. }
  1720. return false;
  1721. }
  1722. checkLocalExport(id) {
  1723. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1724. super.checkLocalExport(id);
  1725. }
  1726. }
  1727. }
  1728. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  1729. const FlowErrors = ParseErrorEnum`flow`({
  1730. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  1731. 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.",
  1732. AssignReservedType: ({
  1733. reservedType
  1734. }) => `Cannot overwrite reserved type ${reservedType}.`,
  1735. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  1736. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  1737. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  1738. EnumBooleanMemberNotInitialized: ({
  1739. memberName,
  1740. enumName
  1741. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  1742. EnumDuplicateMemberName: ({
  1743. memberName,
  1744. enumName
  1745. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  1746. EnumInconsistentMemberValues: ({
  1747. enumName
  1748. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  1749. EnumInvalidExplicitType: ({
  1750. invalidEnumType,
  1751. enumName
  1752. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1753. EnumInvalidExplicitTypeUnknownSupplied: ({
  1754. enumName
  1755. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  1756. EnumInvalidMemberInitializerPrimaryType: ({
  1757. enumName,
  1758. memberName,
  1759. explicitType
  1760. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  1761. EnumInvalidMemberInitializerSymbolType: ({
  1762. enumName,
  1763. memberName
  1764. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  1765. EnumInvalidMemberInitializerUnknownType: ({
  1766. enumName,
  1767. memberName
  1768. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  1769. EnumInvalidMemberName: ({
  1770. enumName,
  1771. memberName,
  1772. suggestion
  1773. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  1774. EnumNumberMemberNotInitialized: ({
  1775. enumName,
  1776. memberName
  1777. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  1778. EnumStringMemberInconsistentlyInitialized: ({
  1779. enumName
  1780. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  1781. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  1782. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  1783. 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.",
  1784. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  1785. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  1786. InexactVariance: "Explicit inexact syntax cannot have variance.",
  1787. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  1788. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  1789. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  1790. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  1791. PatternIsOptional: Object.assign({
  1792. message: "A binding pattern parameter cannot be optional in an implementation signature."
  1793. }, {
  1794. reasonCode: "OptionalBindingPattern"
  1795. }),
  1796. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  1797. SpreadVariance: "Spread properties cannot have variance.",
  1798. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  1799. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  1800. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  1801. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  1802. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  1803. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  1804. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  1805. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  1806. UnexpectedReservedType: ({
  1807. reservedType
  1808. }) => `Unexpected reserved type ${reservedType}.`,
  1809. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  1810. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  1811. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  1812. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  1813. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  1814. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  1815. UnsupportedDeclareExportKind: ({
  1816. unsupportedExportKind,
  1817. suggestion
  1818. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  1819. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  1820. UnterminatedFlowComment: "Unterminated flow-comment."
  1821. });
  1822. function isEsModuleType(bodyElement) {
  1823. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  1824. }
  1825. function hasTypeImportKind(node) {
  1826. return node.importKind === "type" || node.importKind === "typeof";
  1827. }
  1828. const exportSuggestions = {
  1829. const: "declare export var",
  1830. let: "declare export var",
  1831. type: "export type",
  1832. interface: "export interface"
  1833. };
  1834. function partition(list, test) {
  1835. const list1 = [];
  1836. const list2 = [];
  1837. for (let i = 0; i < list.length; i++) {
  1838. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  1839. }
  1840. return [list1, list2];
  1841. }
  1842. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  1843. var flow = superClass => class FlowParserMixin extends superClass {
  1844. constructor(...args) {
  1845. super(...args);
  1846. this.flowPragma = undefined;
  1847. }
  1848. getScopeHandler() {
  1849. return FlowScopeHandler;
  1850. }
  1851. shouldParseTypes() {
  1852. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  1853. }
  1854. finishToken(type, val) {
  1855. if (type !== 134 && type !== 13 && type !== 28) {
  1856. if (this.flowPragma === undefined) {
  1857. this.flowPragma = null;
  1858. }
  1859. }
  1860. super.finishToken(type, val);
  1861. }
  1862. addComment(comment) {
  1863. if (this.flowPragma === undefined) {
  1864. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  1865. if (!matches) ;else if (matches[1] === "flow") {
  1866. this.flowPragma = "flow";
  1867. } else if (matches[1] === "noflow") {
  1868. this.flowPragma = "noflow";
  1869. } else {
  1870. throw new Error("Unexpected flow pragma");
  1871. }
  1872. }
  1873. super.addComment(comment);
  1874. }
  1875. flowParseTypeInitialiser(tok) {
  1876. const oldInType = this.state.inType;
  1877. this.state.inType = true;
  1878. this.expect(tok || 14);
  1879. const type = this.flowParseType();
  1880. this.state.inType = oldInType;
  1881. return type;
  1882. }
  1883. flowParsePredicate() {
  1884. const node = this.startNode();
  1885. const moduloLoc = this.state.startLoc;
  1886. this.next();
  1887. this.expectContextual(110);
  1888. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  1889. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  1890. }
  1891. if (this.eat(10)) {
  1892. node.value = super.parseExpression();
  1893. this.expect(11);
  1894. return this.finishNode(node, "DeclaredPredicate");
  1895. } else {
  1896. return this.finishNode(node, "InferredPredicate");
  1897. }
  1898. }
  1899. flowParseTypeAndPredicateInitialiser() {
  1900. const oldInType = this.state.inType;
  1901. this.state.inType = true;
  1902. this.expect(14);
  1903. let type = null;
  1904. let predicate = null;
  1905. if (this.match(54)) {
  1906. this.state.inType = oldInType;
  1907. predicate = this.flowParsePredicate();
  1908. } else {
  1909. type = this.flowParseType();
  1910. this.state.inType = oldInType;
  1911. if (this.match(54)) {
  1912. predicate = this.flowParsePredicate();
  1913. }
  1914. }
  1915. return [type, predicate];
  1916. }
  1917. flowParseDeclareClass(node) {
  1918. this.next();
  1919. this.flowParseInterfaceish(node, true);
  1920. return this.finishNode(node, "DeclareClass");
  1921. }
  1922. flowParseDeclareFunction(node) {
  1923. this.next();
  1924. const id = node.id = this.parseIdentifier();
  1925. const typeNode = this.startNode();
  1926. const typeContainer = this.startNode();
  1927. if (this.match(47)) {
  1928. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  1929. } else {
  1930. typeNode.typeParameters = null;
  1931. }
  1932. this.expect(10);
  1933. const tmp = this.flowParseFunctionTypeParams();
  1934. typeNode.params = tmp.params;
  1935. typeNode.rest = tmp.rest;
  1936. typeNode.this = tmp._this;
  1937. this.expect(11);
  1938. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  1939. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  1940. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  1941. this.resetEndLocation(id);
  1942. this.semicolon();
  1943. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  1944. return this.finishNode(node, "DeclareFunction");
  1945. }
  1946. flowParseDeclare(node, insideModule) {
  1947. if (this.match(80)) {
  1948. return this.flowParseDeclareClass(node);
  1949. } else if (this.match(68)) {
  1950. return this.flowParseDeclareFunction(node);
  1951. } else if (this.match(74)) {
  1952. return this.flowParseDeclareVariable(node);
  1953. } else if (this.eatContextual(127)) {
  1954. if (this.match(16)) {
  1955. return this.flowParseDeclareModuleExports(node);
  1956. } else {
  1957. if (insideModule) {
  1958. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  1959. }
  1960. return this.flowParseDeclareModule(node);
  1961. }
  1962. } else if (this.isContextual(130)) {
  1963. return this.flowParseDeclareTypeAlias(node);
  1964. } else if (this.isContextual(131)) {
  1965. return this.flowParseDeclareOpaqueType(node);
  1966. } else if (this.isContextual(129)) {
  1967. return this.flowParseDeclareInterface(node);
  1968. } else if (this.match(82)) {
  1969. return this.flowParseDeclareExportDeclaration(node, insideModule);
  1970. }
  1971. throw this.unexpected();
  1972. }
  1973. flowParseDeclareVariable(node) {
  1974. this.next();
  1975. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  1976. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  1977. this.semicolon();
  1978. return this.finishNode(node, "DeclareVariable");
  1979. }
  1980. flowParseDeclareModule(node) {
  1981. this.scope.enter(0);
  1982. if (this.match(134)) {
  1983. node.id = super.parseExprAtom();
  1984. } else {
  1985. node.id = this.parseIdentifier();
  1986. }
  1987. const bodyNode = node.body = this.startNode();
  1988. const body = bodyNode.body = [];
  1989. this.expect(5);
  1990. while (!this.match(8)) {
  1991. const bodyNode = this.startNode();
  1992. if (this.match(83)) {
  1993. this.next();
  1994. if (!this.isContextual(130) && !this.match(87)) {
  1995. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  1996. }
  1997. body.push(super.parseImport(bodyNode));
  1998. } else {
  1999. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  2000. body.push(this.flowParseDeclare(bodyNode, true));
  2001. }
  2002. }
  2003. this.scope.exit();
  2004. this.expect(8);
  2005. this.finishNode(bodyNode, "BlockStatement");
  2006. let kind = null;
  2007. let hasModuleExport = false;
  2008. body.forEach(bodyElement => {
  2009. if (isEsModuleType(bodyElement)) {
  2010. if (kind === "CommonJS") {
  2011. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  2012. }
  2013. kind = "ES";
  2014. } else if (bodyElement.type === "DeclareModuleExports") {
  2015. if (hasModuleExport) {
  2016. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  2017. }
  2018. if (kind === "ES") {
  2019. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  2020. }
  2021. kind = "CommonJS";
  2022. hasModuleExport = true;
  2023. }
  2024. });
  2025. node.kind = kind || "CommonJS";
  2026. return this.finishNode(node, "DeclareModule");
  2027. }
  2028. flowParseDeclareExportDeclaration(node, insideModule) {
  2029. this.expect(82);
  2030. if (this.eat(65)) {
  2031. if (this.match(68) || this.match(80)) {
  2032. node.declaration = this.flowParseDeclare(this.startNode());
  2033. } else {
  2034. node.declaration = this.flowParseType();
  2035. this.semicolon();
  2036. }
  2037. node.default = true;
  2038. return this.finishNode(node, "DeclareExportDeclaration");
  2039. } else {
  2040. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  2041. const label = this.state.value;
  2042. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  2043. unsupportedExportKind: label,
  2044. suggestion: exportSuggestions[label]
  2045. });
  2046. }
  2047. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  2048. node.declaration = this.flowParseDeclare(this.startNode());
  2049. node.default = false;
  2050. return this.finishNode(node, "DeclareExportDeclaration");
  2051. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  2052. node = this.parseExport(node, null);
  2053. if (node.type === "ExportNamedDeclaration") {
  2054. node.default = false;
  2055. delete node.exportKind;
  2056. return this.castNodeTo(node, "DeclareExportDeclaration");
  2057. } else {
  2058. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  2059. }
  2060. }
  2061. }
  2062. throw this.unexpected();
  2063. }
  2064. flowParseDeclareModuleExports(node) {
  2065. this.next();
  2066. this.expectContextual(111);
  2067. node.typeAnnotation = this.flowParseTypeAnnotation();
  2068. this.semicolon();
  2069. return this.finishNode(node, "DeclareModuleExports");
  2070. }
  2071. flowParseDeclareTypeAlias(node) {
  2072. this.next();
  2073. const finished = this.flowParseTypeAlias(node);
  2074. this.castNodeTo(finished, "DeclareTypeAlias");
  2075. return finished;
  2076. }
  2077. flowParseDeclareOpaqueType(node) {
  2078. this.next();
  2079. const finished = this.flowParseOpaqueType(node, true);
  2080. this.castNodeTo(finished, "DeclareOpaqueType");
  2081. return finished;
  2082. }
  2083. flowParseDeclareInterface(node) {
  2084. this.next();
  2085. this.flowParseInterfaceish(node, false);
  2086. return this.finishNode(node, "DeclareInterface");
  2087. }
  2088. flowParseInterfaceish(node, isClass) {
  2089. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  2090. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  2091. if (this.match(47)) {
  2092. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2093. } else {
  2094. node.typeParameters = null;
  2095. }
  2096. node.extends = [];
  2097. if (this.eat(81)) {
  2098. do {
  2099. node.extends.push(this.flowParseInterfaceExtends());
  2100. } while (!isClass && this.eat(12));
  2101. }
  2102. if (isClass) {
  2103. node.implements = [];
  2104. node.mixins = [];
  2105. if (this.eatContextual(117)) {
  2106. do {
  2107. node.mixins.push(this.flowParseInterfaceExtends());
  2108. } while (this.eat(12));
  2109. }
  2110. if (this.eatContextual(113)) {
  2111. do {
  2112. node.implements.push(this.flowParseInterfaceExtends());
  2113. } while (this.eat(12));
  2114. }
  2115. }
  2116. node.body = this.flowParseObjectType({
  2117. allowStatic: isClass,
  2118. allowExact: false,
  2119. allowSpread: false,
  2120. allowProto: isClass,
  2121. allowInexact: false
  2122. });
  2123. }
  2124. flowParseInterfaceExtends() {
  2125. const node = this.startNode();
  2126. node.id = this.flowParseQualifiedTypeIdentifier();
  2127. if (this.match(47)) {
  2128. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2129. } else {
  2130. node.typeParameters = null;
  2131. }
  2132. return this.finishNode(node, "InterfaceExtends");
  2133. }
  2134. flowParseInterface(node) {
  2135. this.flowParseInterfaceish(node, false);
  2136. return this.finishNode(node, "InterfaceDeclaration");
  2137. }
  2138. checkNotUnderscore(word) {
  2139. if (word === "_") {
  2140. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  2141. }
  2142. }
  2143. checkReservedType(word, startLoc, declaration) {
  2144. if (!reservedTypes.has(word)) return;
  2145. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  2146. reservedType: word
  2147. });
  2148. }
  2149. flowParseRestrictedIdentifier(liberal, declaration) {
  2150. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  2151. return this.parseIdentifier(liberal);
  2152. }
  2153. flowParseTypeAlias(node) {
  2154. node.id = this.flowParseRestrictedIdentifier(false, true);
  2155. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2156. if (this.match(47)) {
  2157. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2158. } else {
  2159. node.typeParameters = null;
  2160. }
  2161. node.right = this.flowParseTypeInitialiser(29);
  2162. this.semicolon();
  2163. return this.finishNode(node, "TypeAlias");
  2164. }
  2165. flowParseOpaqueType(node, declare) {
  2166. this.expectContextual(130);
  2167. node.id = this.flowParseRestrictedIdentifier(true, true);
  2168. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  2169. if (this.match(47)) {
  2170. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2171. } else {
  2172. node.typeParameters = null;
  2173. }
  2174. node.supertype = null;
  2175. if (this.match(14)) {
  2176. node.supertype = this.flowParseTypeInitialiser(14);
  2177. }
  2178. node.impltype = null;
  2179. if (!declare) {
  2180. node.impltype = this.flowParseTypeInitialiser(29);
  2181. }
  2182. this.semicolon();
  2183. return this.finishNode(node, "OpaqueType");
  2184. }
  2185. flowParseTypeParameter(requireDefault = false) {
  2186. const nodeStartLoc = this.state.startLoc;
  2187. const node = this.startNode();
  2188. const variance = this.flowParseVariance();
  2189. const ident = this.flowParseTypeAnnotatableIdentifier();
  2190. node.name = ident.name;
  2191. node.variance = variance;
  2192. node.bound = ident.typeAnnotation;
  2193. if (this.match(29)) {
  2194. this.eat(29);
  2195. node.default = this.flowParseType();
  2196. } else {
  2197. if (requireDefault) {
  2198. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  2199. }
  2200. }
  2201. return this.finishNode(node, "TypeParameter");
  2202. }
  2203. flowParseTypeParameterDeclaration() {
  2204. const oldInType = this.state.inType;
  2205. const node = this.startNode();
  2206. node.params = [];
  2207. this.state.inType = true;
  2208. if (this.match(47) || this.match(143)) {
  2209. this.next();
  2210. } else {
  2211. this.unexpected();
  2212. }
  2213. let defaultRequired = false;
  2214. do {
  2215. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  2216. node.params.push(typeParameter);
  2217. if (typeParameter.default) {
  2218. defaultRequired = true;
  2219. }
  2220. if (!this.match(48)) {
  2221. this.expect(12);
  2222. }
  2223. } while (!this.match(48));
  2224. this.expect(48);
  2225. this.state.inType = oldInType;
  2226. return this.finishNode(node, "TypeParameterDeclaration");
  2227. }
  2228. flowInTopLevelContext(cb) {
  2229. if (this.curContext() !== types.brace) {
  2230. const oldContext = this.state.context;
  2231. this.state.context = [oldContext[0]];
  2232. try {
  2233. return cb();
  2234. } finally {
  2235. this.state.context = oldContext;
  2236. }
  2237. } else {
  2238. return cb();
  2239. }
  2240. }
  2241. flowParseTypeParameterInstantiationInExpression() {
  2242. if (this.reScan_lt() !== 47) return;
  2243. return this.flowParseTypeParameterInstantiation();
  2244. }
  2245. flowParseTypeParameterInstantiation() {
  2246. const node = this.startNode();
  2247. const oldInType = this.state.inType;
  2248. this.state.inType = true;
  2249. node.params = [];
  2250. this.flowInTopLevelContext(() => {
  2251. this.expect(47);
  2252. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2253. this.state.noAnonFunctionType = false;
  2254. while (!this.match(48)) {
  2255. node.params.push(this.flowParseType());
  2256. if (!this.match(48)) {
  2257. this.expect(12);
  2258. }
  2259. }
  2260. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2261. });
  2262. this.state.inType = oldInType;
  2263. if (!this.state.inType && this.curContext() === types.brace) {
  2264. this.reScan_lt_gt();
  2265. }
  2266. this.expect(48);
  2267. return this.finishNode(node, "TypeParameterInstantiation");
  2268. }
  2269. flowParseTypeParameterInstantiationCallOrNew() {
  2270. if (this.reScan_lt() !== 47) return null;
  2271. const node = this.startNode();
  2272. const oldInType = this.state.inType;
  2273. node.params = [];
  2274. this.state.inType = true;
  2275. this.expect(47);
  2276. while (!this.match(48)) {
  2277. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  2278. if (!this.match(48)) {
  2279. this.expect(12);
  2280. }
  2281. }
  2282. this.expect(48);
  2283. this.state.inType = oldInType;
  2284. return this.finishNode(node, "TypeParameterInstantiation");
  2285. }
  2286. flowParseInterfaceType() {
  2287. const node = this.startNode();
  2288. this.expectContextual(129);
  2289. node.extends = [];
  2290. if (this.eat(81)) {
  2291. do {
  2292. node.extends.push(this.flowParseInterfaceExtends());
  2293. } while (this.eat(12));
  2294. }
  2295. node.body = this.flowParseObjectType({
  2296. allowStatic: false,
  2297. allowExact: false,
  2298. allowSpread: false,
  2299. allowProto: false,
  2300. allowInexact: false
  2301. });
  2302. return this.finishNode(node, "InterfaceTypeAnnotation");
  2303. }
  2304. flowParseObjectPropertyKey() {
  2305. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  2306. }
  2307. flowParseObjectTypeIndexer(node, isStatic, variance) {
  2308. node.static = isStatic;
  2309. if (this.lookahead().type === 14) {
  2310. node.id = this.flowParseObjectPropertyKey();
  2311. node.key = this.flowParseTypeInitialiser();
  2312. } else {
  2313. node.id = null;
  2314. node.key = this.flowParseType();
  2315. }
  2316. this.expect(3);
  2317. node.value = this.flowParseTypeInitialiser();
  2318. node.variance = variance;
  2319. return this.finishNode(node, "ObjectTypeIndexer");
  2320. }
  2321. flowParseObjectTypeInternalSlot(node, isStatic) {
  2322. node.static = isStatic;
  2323. node.id = this.flowParseObjectPropertyKey();
  2324. this.expect(3);
  2325. this.expect(3);
  2326. if (this.match(47) || this.match(10)) {
  2327. node.method = true;
  2328. node.optional = false;
  2329. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2330. } else {
  2331. node.method = false;
  2332. if (this.eat(17)) {
  2333. node.optional = true;
  2334. }
  2335. node.value = this.flowParseTypeInitialiser();
  2336. }
  2337. return this.finishNode(node, "ObjectTypeInternalSlot");
  2338. }
  2339. flowParseObjectTypeMethodish(node) {
  2340. node.params = [];
  2341. node.rest = null;
  2342. node.typeParameters = null;
  2343. node.this = null;
  2344. if (this.match(47)) {
  2345. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2346. }
  2347. this.expect(10);
  2348. if (this.match(78)) {
  2349. node.this = this.flowParseFunctionTypeParam(true);
  2350. node.this.name = null;
  2351. if (!this.match(11)) {
  2352. this.expect(12);
  2353. }
  2354. }
  2355. while (!this.match(11) && !this.match(21)) {
  2356. node.params.push(this.flowParseFunctionTypeParam(false));
  2357. if (!this.match(11)) {
  2358. this.expect(12);
  2359. }
  2360. }
  2361. if (this.eat(21)) {
  2362. node.rest = this.flowParseFunctionTypeParam(false);
  2363. }
  2364. this.expect(11);
  2365. node.returnType = this.flowParseTypeInitialiser();
  2366. return this.finishNode(node, "FunctionTypeAnnotation");
  2367. }
  2368. flowParseObjectTypeCallProperty(node, isStatic) {
  2369. const valueNode = this.startNode();
  2370. node.static = isStatic;
  2371. node.value = this.flowParseObjectTypeMethodish(valueNode);
  2372. return this.finishNode(node, "ObjectTypeCallProperty");
  2373. }
  2374. flowParseObjectType({
  2375. allowStatic,
  2376. allowExact,
  2377. allowSpread,
  2378. allowProto,
  2379. allowInexact
  2380. }) {
  2381. const oldInType = this.state.inType;
  2382. this.state.inType = true;
  2383. const nodeStart = this.startNode();
  2384. nodeStart.callProperties = [];
  2385. nodeStart.properties = [];
  2386. nodeStart.indexers = [];
  2387. nodeStart.internalSlots = [];
  2388. let endDelim;
  2389. let exact;
  2390. let inexact = false;
  2391. if (allowExact && this.match(6)) {
  2392. this.expect(6);
  2393. endDelim = 9;
  2394. exact = true;
  2395. } else {
  2396. this.expect(5);
  2397. endDelim = 8;
  2398. exact = false;
  2399. }
  2400. nodeStart.exact = exact;
  2401. while (!this.match(endDelim)) {
  2402. let isStatic = false;
  2403. let protoStartLoc = null;
  2404. let inexactStartLoc = null;
  2405. const node = this.startNode();
  2406. if (allowProto && this.isContextual(118)) {
  2407. const lookahead = this.lookahead();
  2408. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2409. this.next();
  2410. protoStartLoc = this.state.startLoc;
  2411. allowStatic = false;
  2412. }
  2413. }
  2414. if (allowStatic && this.isContextual(106)) {
  2415. const lookahead = this.lookahead();
  2416. if (lookahead.type !== 14 && lookahead.type !== 17) {
  2417. this.next();
  2418. isStatic = true;
  2419. }
  2420. }
  2421. const variance = this.flowParseVariance();
  2422. if (this.eat(0)) {
  2423. if (protoStartLoc != null) {
  2424. this.unexpected(protoStartLoc);
  2425. }
  2426. if (this.eat(0)) {
  2427. if (variance) {
  2428. this.unexpected(variance.loc.start);
  2429. }
  2430. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  2431. } else {
  2432. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  2433. }
  2434. } else if (this.match(10) || this.match(47)) {
  2435. if (protoStartLoc != null) {
  2436. this.unexpected(protoStartLoc);
  2437. }
  2438. if (variance) {
  2439. this.unexpected(variance.loc.start);
  2440. }
  2441. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  2442. } else {
  2443. let kind = "init";
  2444. if (this.isContextual(99) || this.isContextual(104)) {
  2445. const lookahead = this.lookahead();
  2446. if (tokenIsLiteralPropertyName(lookahead.type)) {
  2447. kind = this.state.value;
  2448. this.next();
  2449. }
  2450. }
  2451. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  2452. if (propOrInexact === null) {
  2453. inexact = true;
  2454. inexactStartLoc = this.state.lastTokStartLoc;
  2455. } else {
  2456. nodeStart.properties.push(propOrInexact);
  2457. }
  2458. }
  2459. this.flowObjectTypeSemicolon();
  2460. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  2461. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  2462. }
  2463. }
  2464. this.expect(endDelim);
  2465. if (allowSpread) {
  2466. nodeStart.inexact = inexact;
  2467. }
  2468. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  2469. this.state.inType = oldInType;
  2470. return out;
  2471. }
  2472. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  2473. if (this.eat(21)) {
  2474. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  2475. if (isInexactToken) {
  2476. if (!allowSpread) {
  2477. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  2478. } else if (!allowInexact) {
  2479. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  2480. }
  2481. if (variance) {
  2482. this.raise(FlowErrors.InexactVariance, variance);
  2483. }
  2484. return null;
  2485. }
  2486. if (!allowSpread) {
  2487. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  2488. }
  2489. if (protoStartLoc != null) {
  2490. this.unexpected(protoStartLoc);
  2491. }
  2492. if (variance) {
  2493. this.raise(FlowErrors.SpreadVariance, variance);
  2494. }
  2495. node.argument = this.flowParseType();
  2496. return this.finishNode(node, "ObjectTypeSpreadProperty");
  2497. } else {
  2498. node.key = this.flowParseObjectPropertyKey();
  2499. node.static = isStatic;
  2500. node.proto = protoStartLoc != null;
  2501. node.kind = kind;
  2502. let optional = false;
  2503. if (this.match(47) || this.match(10)) {
  2504. node.method = true;
  2505. if (protoStartLoc != null) {
  2506. this.unexpected(protoStartLoc);
  2507. }
  2508. if (variance) {
  2509. this.unexpected(variance.loc.start);
  2510. }
  2511. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  2512. if (kind === "get" || kind === "set") {
  2513. this.flowCheckGetterSetterParams(node);
  2514. }
  2515. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  2516. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  2517. }
  2518. } else {
  2519. if (kind !== "init") this.unexpected();
  2520. node.method = false;
  2521. if (this.eat(17)) {
  2522. optional = true;
  2523. }
  2524. node.value = this.flowParseTypeInitialiser();
  2525. node.variance = variance;
  2526. }
  2527. node.optional = optional;
  2528. return this.finishNode(node, "ObjectTypeProperty");
  2529. }
  2530. }
  2531. flowCheckGetterSetterParams(property) {
  2532. const paramCount = property.kind === "get" ? 0 : 1;
  2533. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  2534. if (property.value.this) {
  2535. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  2536. }
  2537. if (length !== paramCount) {
  2538. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  2539. }
  2540. if (property.kind === "set" && property.value.rest) {
  2541. this.raise(Errors.BadSetterRestParameter, property);
  2542. }
  2543. }
  2544. flowObjectTypeSemicolon() {
  2545. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  2546. this.unexpected();
  2547. }
  2548. }
  2549. flowParseQualifiedTypeIdentifier(startLoc, id) {
  2550. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  2551. let node = id || this.flowParseRestrictedIdentifier(true);
  2552. while (this.eat(16)) {
  2553. const node2 = this.startNodeAt(startLoc);
  2554. node2.qualification = node;
  2555. node2.id = this.flowParseRestrictedIdentifier(true);
  2556. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  2557. }
  2558. return node;
  2559. }
  2560. flowParseGenericType(startLoc, id) {
  2561. const node = this.startNodeAt(startLoc);
  2562. node.typeParameters = null;
  2563. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  2564. if (this.match(47)) {
  2565. node.typeParameters = this.flowParseTypeParameterInstantiation();
  2566. }
  2567. return this.finishNode(node, "GenericTypeAnnotation");
  2568. }
  2569. flowParseTypeofType() {
  2570. const node = this.startNode();
  2571. this.expect(87);
  2572. node.argument = this.flowParsePrimaryType();
  2573. return this.finishNode(node, "TypeofTypeAnnotation");
  2574. }
  2575. flowParseTupleType() {
  2576. const node = this.startNode();
  2577. node.types = [];
  2578. this.expect(0);
  2579. while (this.state.pos < this.length && !this.match(3)) {
  2580. node.types.push(this.flowParseType());
  2581. if (this.match(3)) break;
  2582. this.expect(12);
  2583. }
  2584. this.expect(3);
  2585. return this.finishNode(node, "TupleTypeAnnotation");
  2586. }
  2587. flowParseFunctionTypeParam(first) {
  2588. let name = null;
  2589. let optional = false;
  2590. let typeAnnotation = null;
  2591. const node = this.startNode();
  2592. const lh = this.lookahead();
  2593. const isThis = this.state.type === 78;
  2594. if (lh.type === 14 || lh.type === 17) {
  2595. if (isThis && !first) {
  2596. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  2597. }
  2598. name = this.parseIdentifier(isThis);
  2599. if (this.eat(17)) {
  2600. optional = true;
  2601. if (isThis) {
  2602. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  2603. }
  2604. }
  2605. typeAnnotation = this.flowParseTypeInitialiser();
  2606. } else {
  2607. typeAnnotation = this.flowParseType();
  2608. }
  2609. node.name = name;
  2610. node.optional = optional;
  2611. node.typeAnnotation = typeAnnotation;
  2612. return this.finishNode(node, "FunctionTypeParam");
  2613. }
  2614. reinterpretTypeAsFunctionTypeParam(type) {
  2615. const node = this.startNodeAt(type.loc.start);
  2616. node.name = null;
  2617. node.optional = false;
  2618. node.typeAnnotation = type;
  2619. return this.finishNode(node, "FunctionTypeParam");
  2620. }
  2621. flowParseFunctionTypeParams(params = []) {
  2622. let rest = null;
  2623. let _this = null;
  2624. if (this.match(78)) {
  2625. _this = this.flowParseFunctionTypeParam(true);
  2626. _this.name = null;
  2627. if (!this.match(11)) {
  2628. this.expect(12);
  2629. }
  2630. }
  2631. while (!this.match(11) && !this.match(21)) {
  2632. params.push(this.flowParseFunctionTypeParam(false));
  2633. if (!this.match(11)) {
  2634. this.expect(12);
  2635. }
  2636. }
  2637. if (this.eat(21)) {
  2638. rest = this.flowParseFunctionTypeParam(false);
  2639. }
  2640. return {
  2641. params,
  2642. rest,
  2643. _this
  2644. };
  2645. }
  2646. flowIdentToTypeAnnotation(startLoc, node, id) {
  2647. switch (id.name) {
  2648. case "any":
  2649. return this.finishNode(node, "AnyTypeAnnotation");
  2650. case "bool":
  2651. case "boolean":
  2652. return this.finishNode(node, "BooleanTypeAnnotation");
  2653. case "mixed":
  2654. return this.finishNode(node, "MixedTypeAnnotation");
  2655. case "empty":
  2656. return this.finishNode(node, "EmptyTypeAnnotation");
  2657. case "number":
  2658. return this.finishNode(node, "NumberTypeAnnotation");
  2659. case "string":
  2660. return this.finishNode(node, "StringTypeAnnotation");
  2661. case "symbol":
  2662. return this.finishNode(node, "SymbolTypeAnnotation");
  2663. default:
  2664. this.checkNotUnderscore(id.name);
  2665. return this.flowParseGenericType(startLoc, id);
  2666. }
  2667. }
  2668. flowParsePrimaryType() {
  2669. const startLoc = this.state.startLoc;
  2670. const node = this.startNode();
  2671. let tmp;
  2672. let type;
  2673. let isGroupedType = false;
  2674. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  2675. switch (this.state.type) {
  2676. case 5:
  2677. return this.flowParseObjectType({
  2678. allowStatic: false,
  2679. allowExact: false,
  2680. allowSpread: true,
  2681. allowProto: false,
  2682. allowInexact: true
  2683. });
  2684. case 6:
  2685. return this.flowParseObjectType({
  2686. allowStatic: false,
  2687. allowExact: true,
  2688. allowSpread: true,
  2689. allowProto: false,
  2690. allowInexact: false
  2691. });
  2692. case 0:
  2693. this.state.noAnonFunctionType = false;
  2694. type = this.flowParseTupleType();
  2695. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2696. return type;
  2697. case 47:
  2698. {
  2699. const node = this.startNode();
  2700. node.typeParameters = this.flowParseTypeParameterDeclaration();
  2701. this.expect(10);
  2702. tmp = this.flowParseFunctionTypeParams();
  2703. node.params = tmp.params;
  2704. node.rest = tmp.rest;
  2705. node.this = tmp._this;
  2706. this.expect(11);
  2707. this.expect(19);
  2708. node.returnType = this.flowParseType();
  2709. return this.finishNode(node, "FunctionTypeAnnotation");
  2710. }
  2711. case 10:
  2712. {
  2713. const node = this.startNode();
  2714. this.next();
  2715. if (!this.match(11) && !this.match(21)) {
  2716. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  2717. const token = this.lookahead().type;
  2718. isGroupedType = token !== 17 && token !== 14;
  2719. } else {
  2720. isGroupedType = true;
  2721. }
  2722. }
  2723. if (isGroupedType) {
  2724. this.state.noAnonFunctionType = false;
  2725. type = this.flowParseType();
  2726. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  2727. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  2728. this.expect(11);
  2729. return type;
  2730. } else {
  2731. this.eat(12);
  2732. }
  2733. }
  2734. if (type) {
  2735. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  2736. } else {
  2737. tmp = this.flowParseFunctionTypeParams();
  2738. }
  2739. node.params = tmp.params;
  2740. node.rest = tmp.rest;
  2741. node.this = tmp._this;
  2742. this.expect(11);
  2743. this.expect(19);
  2744. node.returnType = this.flowParseType();
  2745. node.typeParameters = null;
  2746. return this.finishNode(node, "FunctionTypeAnnotation");
  2747. }
  2748. case 134:
  2749. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  2750. case 85:
  2751. case 86:
  2752. node.value = this.match(85);
  2753. this.next();
  2754. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  2755. case 53:
  2756. if (this.state.value === "-") {
  2757. this.next();
  2758. if (this.match(135)) {
  2759. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  2760. }
  2761. if (this.match(136)) {
  2762. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  2763. }
  2764. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  2765. }
  2766. throw this.unexpected();
  2767. case 135:
  2768. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  2769. case 136:
  2770. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  2771. case 88:
  2772. this.next();
  2773. return this.finishNode(node, "VoidTypeAnnotation");
  2774. case 84:
  2775. this.next();
  2776. return this.finishNode(node, "NullLiteralTypeAnnotation");
  2777. case 78:
  2778. this.next();
  2779. return this.finishNode(node, "ThisTypeAnnotation");
  2780. case 55:
  2781. this.next();
  2782. return this.finishNode(node, "ExistsTypeAnnotation");
  2783. case 87:
  2784. return this.flowParseTypeofType();
  2785. default:
  2786. if (tokenIsKeyword(this.state.type)) {
  2787. const label = tokenLabelName(this.state.type);
  2788. this.next();
  2789. return super.createIdentifier(node, label);
  2790. } else if (tokenIsIdentifier(this.state.type)) {
  2791. if (this.isContextual(129)) {
  2792. return this.flowParseInterfaceType();
  2793. }
  2794. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  2795. }
  2796. }
  2797. throw this.unexpected();
  2798. }
  2799. flowParsePostfixType() {
  2800. const startLoc = this.state.startLoc;
  2801. let type = this.flowParsePrimaryType();
  2802. let seenOptionalIndexedAccess = false;
  2803. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  2804. const node = this.startNodeAt(startLoc);
  2805. const optional = this.eat(18);
  2806. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  2807. this.expect(0);
  2808. if (!optional && this.match(3)) {
  2809. node.elementType = type;
  2810. this.next();
  2811. type = this.finishNode(node, "ArrayTypeAnnotation");
  2812. } else {
  2813. node.objectType = type;
  2814. node.indexType = this.flowParseType();
  2815. this.expect(3);
  2816. if (seenOptionalIndexedAccess) {
  2817. node.optional = optional;
  2818. type = this.finishNode(node, "OptionalIndexedAccessType");
  2819. } else {
  2820. type = this.finishNode(node, "IndexedAccessType");
  2821. }
  2822. }
  2823. }
  2824. return type;
  2825. }
  2826. flowParsePrefixType() {
  2827. const node = this.startNode();
  2828. if (this.eat(17)) {
  2829. node.typeAnnotation = this.flowParsePrefixType();
  2830. return this.finishNode(node, "NullableTypeAnnotation");
  2831. } else {
  2832. return this.flowParsePostfixType();
  2833. }
  2834. }
  2835. flowParseAnonFunctionWithoutParens() {
  2836. const param = this.flowParsePrefixType();
  2837. if (!this.state.noAnonFunctionType && this.eat(19)) {
  2838. const node = this.startNodeAt(param.loc.start);
  2839. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  2840. node.rest = null;
  2841. node.this = null;
  2842. node.returnType = this.flowParseType();
  2843. node.typeParameters = null;
  2844. return this.finishNode(node, "FunctionTypeAnnotation");
  2845. }
  2846. return param;
  2847. }
  2848. flowParseIntersectionType() {
  2849. const node = this.startNode();
  2850. this.eat(45);
  2851. const type = this.flowParseAnonFunctionWithoutParens();
  2852. node.types = [type];
  2853. while (this.eat(45)) {
  2854. node.types.push(this.flowParseAnonFunctionWithoutParens());
  2855. }
  2856. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  2857. }
  2858. flowParseUnionType() {
  2859. const node = this.startNode();
  2860. this.eat(43);
  2861. const type = this.flowParseIntersectionType();
  2862. node.types = [type];
  2863. while (this.eat(43)) {
  2864. node.types.push(this.flowParseIntersectionType());
  2865. }
  2866. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  2867. }
  2868. flowParseType() {
  2869. const oldInType = this.state.inType;
  2870. this.state.inType = true;
  2871. const type = this.flowParseUnionType();
  2872. this.state.inType = oldInType;
  2873. return type;
  2874. }
  2875. flowParseTypeOrImplicitInstantiation() {
  2876. if (this.state.type === 132 && this.state.value === "_") {
  2877. const startLoc = this.state.startLoc;
  2878. const node = this.parseIdentifier();
  2879. return this.flowParseGenericType(startLoc, node);
  2880. } else {
  2881. return this.flowParseType();
  2882. }
  2883. }
  2884. flowParseTypeAnnotation() {
  2885. const node = this.startNode();
  2886. node.typeAnnotation = this.flowParseTypeInitialiser();
  2887. return this.finishNode(node, "TypeAnnotation");
  2888. }
  2889. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  2890. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  2891. if (this.match(14)) {
  2892. ident.typeAnnotation = this.flowParseTypeAnnotation();
  2893. this.resetEndLocation(ident);
  2894. }
  2895. return ident;
  2896. }
  2897. typeCastToParameter(node) {
  2898. node.expression.typeAnnotation = node.typeAnnotation;
  2899. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  2900. return node.expression;
  2901. }
  2902. flowParseVariance() {
  2903. let variance = null;
  2904. if (this.match(53)) {
  2905. variance = this.startNode();
  2906. if (this.state.value === "+") {
  2907. variance.kind = "plus";
  2908. } else {
  2909. variance.kind = "minus";
  2910. }
  2911. this.next();
  2912. return this.finishNode(variance, "Variance");
  2913. }
  2914. return variance;
  2915. }
  2916. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  2917. if (allowExpressionBody) {
  2918. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  2919. return;
  2920. }
  2921. super.parseFunctionBody(node, false, isMethod);
  2922. }
  2923. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  2924. if (this.match(14)) {
  2925. const typeNode = this.startNode();
  2926. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  2927. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  2928. }
  2929. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  2930. }
  2931. parseStatementLike(flags) {
  2932. if (this.state.strict && this.isContextual(129)) {
  2933. const lookahead = this.lookahead();
  2934. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  2935. const node = this.startNode();
  2936. this.next();
  2937. return this.flowParseInterface(node);
  2938. }
  2939. } else if (this.isContextual(126)) {
  2940. const node = this.startNode();
  2941. this.next();
  2942. return this.flowParseEnumDeclaration(node);
  2943. }
  2944. const stmt = super.parseStatementLike(flags);
  2945. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  2946. this.flowPragma = null;
  2947. }
  2948. return stmt;
  2949. }
  2950. parseExpressionStatement(node, expr, decorators) {
  2951. if (expr.type === "Identifier") {
  2952. if (expr.name === "declare") {
  2953. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  2954. return this.flowParseDeclare(node);
  2955. }
  2956. } else if (tokenIsIdentifier(this.state.type)) {
  2957. if (expr.name === "interface") {
  2958. return this.flowParseInterface(node);
  2959. } else if (expr.name === "type") {
  2960. return this.flowParseTypeAlias(node);
  2961. } else if (expr.name === "opaque") {
  2962. return this.flowParseOpaqueType(node, false);
  2963. }
  2964. }
  2965. }
  2966. return super.parseExpressionStatement(node, expr, decorators);
  2967. }
  2968. shouldParseExportDeclaration() {
  2969. const {
  2970. type
  2971. } = this.state;
  2972. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2973. return !this.state.containsEsc;
  2974. }
  2975. return super.shouldParseExportDeclaration();
  2976. }
  2977. isExportDefaultSpecifier() {
  2978. const {
  2979. type
  2980. } = this.state;
  2981. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  2982. return this.state.containsEsc;
  2983. }
  2984. return super.isExportDefaultSpecifier();
  2985. }
  2986. parseExportDefaultExpression() {
  2987. if (this.isContextual(126)) {
  2988. const node = this.startNode();
  2989. this.next();
  2990. return this.flowParseEnumDeclaration(node);
  2991. }
  2992. return super.parseExportDefaultExpression();
  2993. }
  2994. parseConditional(expr, startLoc, refExpressionErrors) {
  2995. if (!this.match(17)) return expr;
  2996. if (this.state.maybeInArrowParameters) {
  2997. const nextCh = this.lookaheadCharCode();
  2998. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  2999. this.setOptionalParametersError(refExpressionErrors);
  3000. return expr;
  3001. }
  3002. }
  3003. this.expect(17);
  3004. const state = this.state.clone();
  3005. const originalNoArrowAt = this.state.noArrowAt;
  3006. const node = this.startNodeAt(startLoc);
  3007. let {
  3008. consequent,
  3009. failed
  3010. } = this.tryParseConditionalConsequent();
  3011. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  3012. if (failed || invalid.length > 0) {
  3013. const noArrowAt = [...originalNoArrowAt];
  3014. if (invalid.length > 0) {
  3015. this.state = state;
  3016. this.state.noArrowAt = noArrowAt;
  3017. for (let i = 0; i < invalid.length; i++) {
  3018. noArrowAt.push(invalid[i].start);
  3019. }
  3020. ({
  3021. consequent,
  3022. failed
  3023. } = this.tryParseConditionalConsequent());
  3024. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  3025. }
  3026. if (failed && valid.length > 1) {
  3027. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  3028. }
  3029. if (failed && valid.length === 1) {
  3030. this.state = state;
  3031. noArrowAt.push(valid[0].start);
  3032. this.state.noArrowAt = noArrowAt;
  3033. ({
  3034. consequent,
  3035. failed
  3036. } = this.tryParseConditionalConsequent());
  3037. }
  3038. }
  3039. this.getArrowLikeExpressions(consequent, true);
  3040. this.state.noArrowAt = originalNoArrowAt;
  3041. this.expect(14);
  3042. node.test = expr;
  3043. node.consequent = consequent;
  3044. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  3045. return this.finishNode(node, "ConditionalExpression");
  3046. }
  3047. tryParseConditionalConsequent() {
  3048. this.state.noArrowParamsConversionAt.push(this.state.start);
  3049. const consequent = this.parseMaybeAssignAllowIn();
  3050. const failed = !this.match(14);
  3051. this.state.noArrowParamsConversionAt.pop();
  3052. return {
  3053. consequent,
  3054. failed
  3055. };
  3056. }
  3057. getArrowLikeExpressions(node, disallowInvalid) {
  3058. const stack = [node];
  3059. const arrows = [];
  3060. while (stack.length !== 0) {
  3061. const node = stack.pop();
  3062. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  3063. if (node.typeParameters || !node.returnType) {
  3064. this.finishArrowValidation(node);
  3065. } else {
  3066. arrows.push(node);
  3067. }
  3068. stack.push(node.body);
  3069. } else if (node.type === "ConditionalExpression") {
  3070. stack.push(node.consequent);
  3071. stack.push(node.alternate);
  3072. }
  3073. }
  3074. if (disallowInvalid) {
  3075. arrows.forEach(node => this.finishArrowValidation(node));
  3076. return [arrows, []];
  3077. }
  3078. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  3079. }
  3080. finishArrowValidation(node) {
  3081. var _node$extra;
  3082. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  3083. this.scope.enter(514 | 4);
  3084. super.checkParams(node, false, true);
  3085. this.scope.exit();
  3086. }
  3087. forwardNoArrowParamsConversionAt(node, parse) {
  3088. let result;
  3089. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3090. this.state.noArrowParamsConversionAt.push(this.state.start);
  3091. result = parse();
  3092. this.state.noArrowParamsConversionAt.pop();
  3093. } else {
  3094. result = parse();
  3095. }
  3096. return result;
  3097. }
  3098. parseParenItem(node, startLoc) {
  3099. const newNode = super.parseParenItem(node, startLoc);
  3100. if (this.eat(17)) {
  3101. newNode.optional = true;
  3102. this.resetEndLocation(node);
  3103. }
  3104. if (this.match(14)) {
  3105. const typeCastNode = this.startNodeAt(startLoc);
  3106. typeCastNode.expression = newNode;
  3107. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  3108. return this.finishNode(typeCastNode, "TypeCastExpression");
  3109. }
  3110. return newNode;
  3111. }
  3112. assertModuleNodeAllowed(node) {
  3113. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  3114. return;
  3115. }
  3116. super.assertModuleNodeAllowed(node);
  3117. }
  3118. parseExportDeclaration(node) {
  3119. if (this.isContextual(130)) {
  3120. node.exportKind = "type";
  3121. const declarationNode = this.startNode();
  3122. this.next();
  3123. if (this.match(5)) {
  3124. node.specifiers = this.parseExportSpecifiers(true);
  3125. super.parseExportFrom(node);
  3126. return null;
  3127. } else {
  3128. return this.flowParseTypeAlias(declarationNode);
  3129. }
  3130. } else if (this.isContextual(131)) {
  3131. node.exportKind = "type";
  3132. const declarationNode = this.startNode();
  3133. this.next();
  3134. return this.flowParseOpaqueType(declarationNode, false);
  3135. } else if (this.isContextual(129)) {
  3136. node.exportKind = "type";
  3137. const declarationNode = this.startNode();
  3138. this.next();
  3139. return this.flowParseInterface(declarationNode);
  3140. } else if (this.isContextual(126)) {
  3141. node.exportKind = "value";
  3142. const declarationNode = this.startNode();
  3143. this.next();
  3144. return this.flowParseEnumDeclaration(declarationNode);
  3145. } else {
  3146. return super.parseExportDeclaration(node);
  3147. }
  3148. }
  3149. eatExportStar(node) {
  3150. if (super.eatExportStar(node)) return true;
  3151. if (this.isContextual(130) && this.lookahead().type === 55) {
  3152. node.exportKind = "type";
  3153. this.next();
  3154. this.next();
  3155. return true;
  3156. }
  3157. return false;
  3158. }
  3159. maybeParseExportNamespaceSpecifier(node) {
  3160. const {
  3161. startLoc
  3162. } = this.state;
  3163. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  3164. if (hasNamespace && node.exportKind === "type") {
  3165. this.unexpected(startLoc);
  3166. }
  3167. return hasNamespace;
  3168. }
  3169. parseClassId(node, isStatement, optionalId) {
  3170. super.parseClassId(node, isStatement, optionalId);
  3171. if (this.match(47)) {
  3172. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3173. }
  3174. }
  3175. parseClassMember(classBody, member, state) {
  3176. const {
  3177. startLoc
  3178. } = this.state;
  3179. if (this.isContextual(125)) {
  3180. if (super.parseClassMemberFromModifier(classBody, member)) {
  3181. return;
  3182. }
  3183. member.declare = true;
  3184. }
  3185. super.parseClassMember(classBody, member, state);
  3186. if (member.declare) {
  3187. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  3188. this.raise(FlowErrors.DeclareClassElement, startLoc);
  3189. } else if (member.value) {
  3190. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  3191. }
  3192. }
  3193. }
  3194. isIterator(word) {
  3195. return word === "iterator" || word === "asyncIterator";
  3196. }
  3197. readIterator() {
  3198. const word = super.readWord1();
  3199. const fullWord = "@@" + word;
  3200. if (!this.isIterator(word) || !this.state.inType) {
  3201. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  3202. identifierName: fullWord
  3203. });
  3204. }
  3205. this.finishToken(132, fullWord);
  3206. }
  3207. getTokenFromCode(code) {
  3208. const next = this.input.charCodeAt(this.state.pos + 1);
  3209. if (code === 123 && next === 124) {
  3210. this.finishOp(6, 2);
  3211. } else if (this.state.inType && (code === 62 || code === 60)) {
  3212. this.finishOp(code === 62 ? 48 : 47, 1);
  3213. } else if (this.state.inType && code === 63) {
  3214. if (next === 46) {
  3215. this.finishOp(18, 2);
  3216. } else {
  3217. this.finishOp(17, 1);
  3218. }
  3219. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  3220. this.state.pos += 2;
  3221. this.readIterator();
  3222. } else {
  3223. super.getTokenFromCode(code);
  3224. }
  3225. }
  3226. isAssignable(node, isBinding) {
  3227. if (node.type === "TypeCastExpression") {
  3228. return this.isAssignable(node.expression, isBinding);
  3229. } else {
  3230. return super.isAssignable(node, isBinding);
  3231. }
  3232. }
  3233. toAssignable(node, isLHS = false) {
  3234. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  3235. node.left = this.typeCastToParameter(node.left);
  3236. }
  3237. super.toAssignable(node, isLHS);
  3238. }
  3239. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  3240. for (let i = 0; i < exprList.length; i++) {
  3241. const expr = exprList[i];
  3242. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  3243. exprList[i] = this.typeCastToParameter(expr);
  3244. }
  3245. }
  3246. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  3247. }
  3248. toReferencedList(exprList, isParenthesizedExpr) {
  3249. for (let i = 0; i < exprList.length; i++) {
  3250. var _expr$extra;
  3251. const expr = exprList[i];
  3252. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  3253. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  3254. }
  3255. }
  3256. return exprList;
  3257. }
  3258. parseArrayLike(close, isTuple, refExpressionErrors) {
  3259. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  3260. if (refExpressionErrors != null && !this.state.maybeInArrowParameters) {
  3261. this.toReferencedList(node.elements);
  3262. }
  3263. return node;
  3264. }
  3265. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  3266. return type === "TypeCastExpression" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  3267. }
  3268. parseClassProperty(node) {
  3269. if (this.match(14)) {
  3270. node.typeAnnotation = this.flowParseTypeAnnotation();
  3271. }
  3272. return super.parseClassProperty(node);
  3273. }
  3274. parseClassPrivateProperty(node) {
  3275. if (this.match(14)) {
  3276. node.typeAnnotation = this.flowParseTypeAnnotation();
  3277. }
  3278. return super.parseClassPrivateProperty(node);
  3279. }
  3280. isClassMethod() {
  3281. return this.match(47) || super.isClassMethod();
  3282. }
  3283. isClassProperty() {
  3284. return this.match(14) || super.isClassProperty();
  3285. }
  3286. isNonstaticConstructor(method) {
  3287. return !this.match(14) && super.isNonstaticConstructor(method);
  3288. }
  3289. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  3290. if (method.variance) {
  3291. this.unexpected(method.variance.loc.start);
  3292. }
  3293. delete method.variance;
  3294. if (this.match(47)) {
  3295. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3296. }
  3297. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  3298. if (method.params && isConstructor) {
  3299. const params = method.params;
  3300. if (params.length > 0 && this.isThisParam(params[0])) {
  3301. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3302. }
  3303. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  3304. const params = method.value.params;
  3305. if (params.length > 0 && this.isThisParam(params[0])) {
  3306. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  3307. }
  3308. }
  3309. }
  3310. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  3311. if (method.variance) {
  3312. this.unexpected(method.variance.loc.start);
  3313. }
  3314. delete method.variance;
  3315. if (this.match(47)) {
  3316. method.typeParameters = this.flowParseTypeParameterDeclaration();
  3317. }
  3318. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  3319. }
  3320. parseClassSuper(node) {
  3321. super.parseClassSuper(node);
  3322. if (node.superClass && (this.match(47) || this.match(51))) {
  3323. {
  3324. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  3325. }
  3326. }
  3327. if (this.isContextual(113)) {
  3328. this.next();
  3329. const implemented = node.implements = [];
  3330. do {
  3331. const node = this.startNode();
  3332. node.id = this.flowParseRestrictedIdentifier(true);
  3333. if (this.match(47)) {
  3334. node.typeParameters = this.flowParseTypeParameterInstantiation();
  3335. } else {
  3336. node.typeParameters = null;
  3337. }
  3338. implemented.push(this.finishNode(node, "ClassImplements"));
  3339. } while (this.eat(12));
  3340. }
  3341. }
  3342. checkGetterSetterParams(method) {
  3343. super.checkGetterSetterParams(method);
  3344. const params = this.getObjectOrClassMethodParams(method);
  3345. if (params.length > 0) {
  3346. const param = params[0];
  3347. if (this.isThisParam(param) && method.kind === "get") {
  3348. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  3349. } else if (this.isThisParam(param)) {
  3350. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  3351. }
  3352. }
  3353. }
  3354. parsePropertyNamePrefixOperator(node) {
  3355. node.variance = this.flowParseVariance();
  3356. }
  3357. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  3358. if (prop.variance) {
  3359. this.unexpected(prop.variance.loc.start);
  3360. }
  3361. delete prop.variance;
  3362. let typeParameters;
  3363. if (this.match(47) && !isAccessor) {
  3364. typeParameters = this.flowParseTypeParameterDeclaration();
  3365. if (!this.match(10)) this.unexpected();
  3366. }
  3367. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  3368. if (typeParameters) {
  3369. (result.value || result).typeParameters = typeParameters;
  3370. }
  3371. return result;
  3372. }
  3373. parseFunctionParamType(param) {
  3374. if (this.eat(17)) {
  3375. if (param.type !== "Identifier") {
  3376. this.raise(FlowErrors.PatternIsOptional, param);
  3377. }
  3378. if (this.isThisParam(param)) {
  3379. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  3380. }
  3381. param.optional = true;
  3382. }
  3383. if (this.match(14)) {
  3384. param.typeAnnotation = this.flowParseTypeAnnotation();
  3385. } else if (this.isThisParam(param)) {
  3386. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  3387. }
  3388. if (this.match(29) && this.isThisParam(param)) {
  3389. this.raise(FlowErrors.ThisParamNoDefault, param);
  3390. }
  3391. this.resetEndLocation(param);
  3392. return param;
  3393. }
  3394. parseMaybeDefault(startLoc, left) {
  3395. const node = super.parseMaybeDefault(startLoc, left);
  3396. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  3397. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  3398. }
  3399. return node;
  3400. }
  3401. checkImportReflection(node) {
  3402. super.checkImportReflection(node);
  3403. if (node.module && node.importKind !== "value") {
  3404. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  3405. }
  3406. }
  3407. parseImportSpecifierLocal(node, specifier, type) {
  3408. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  3409. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  3410. }
  3411. isPotentialImportPhase(isExport) {
  3412. if (super.isPotentialImportPhase(isExport)) return true;
  3413. if (this.isContextual(130)) {
  3414. if (!isExport) return true;
  3415. const ch = this.lookaheadCharCode();
  3416. return ch === 123 || ch === 42;
  3417. }
  3418. return !isExport && this.isContextual(87);
  3419. }
  3420. applyImportPhase(node, isExport, phase, loc) {
  3421. super.applyImportPhase(node, isExport, phase, loc);
  3422. if (isExport) {
  3423. if (!phase && this.match(65)) {
  3424. return;
  3425. }
  3426. node.exportKind = phase === "type" ? phase : "value";
  3427. } else {
  3428. if (phase === "type" && this.match(55)) this.unexpected();
  3429. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  3430. }
  3431. }
  3432. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  3433. const firstIdent = specifier.imported;
  3434. let specifierTypeKind = null;
  3435. if (firstIdent.type === "Identifier") {
  3436. if (firstIdent.name === "type") {
  3437. specifierTypeKind = "type";
  3438. } else if (firstIdent.name === "typeof") {
  3439. specifierTypeKind = "typeof";
  3440. }
  3441. }
  3442. let isBinding = false;
  3443. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  3444. const as_ident = this.parseIdentifier(true);
  3445. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  3446. specifier.imported = as_ident;
  3447. specifier.importKind = specifierTypeKind;
  3448. specifier.local = this.cloneIdentifier(as_ident);
  3449. } else {
  3450. specifier.imported = firstIdent;
  3451. specifier.importKind = null;
  3452. specifier.local = this.parseIdentifier();
  3453. }
  3454. } else {
  3455. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  3456. specifier.imported = this.parseIdentifier(true);
  3457. specifier.importKind = specifierTypeKind;
  3458. } else {
  3459. if (importedIsString) {
  3460. throw this.raise(Errors.ImportBindingIsString, specifier, {
  3461. importName: firstIdent.value
  3462. });
  3463. }
  3464. specifier.imported = firstIdent;
  3465. specifier.importKind = null;
  3466. }
  3467. if (this.eatContextual(93)) {
  3468. specifier.local = this.parseIdentifier();
  3469. } else {
  3470. isBinding = true;
  3471. specifier.local = this.cloneIdentifier(specifier.imported);
  3472. }
  3473. }
  3474. const specifierIsTypeImport = hasTypeImportKind(specifier);
  3475. if (isInTypeOnlyImport && specifierIsTypeImport) {
  3476. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  3477. }
  3478. if (isInTypeOnlyImport || specifierIsTypeImport) {
  3479. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  3480. }
  3481. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  3482. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  3483. }
  3484. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  3485. }
  3486. parseBindingAtom() {
  3487. switch (this.state.type) {
  3488. case 78:
  3489. return this.parseIdentifier(true);
  3490. default:
  3491. return super.parseBindingAtom();
  3492. }
  3493. }
  3494. parseFunctionParams(node, isConstructor) {
  3495. const kind = node.kind;
  3496. if (kind !== "get" && kind !== "set" && this.match(47)) {
  3497. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3498. }
  3499. super.parseFunctionParams(node, isConstructor);
  3500. }
  3501. parseVarId(decl, kind) {
  3502. super.parseVarId(decl, kind);
  3503. if (this.match(14)) {
  3504. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  3505. this.resetEndLocation(decl.id);
  3506. }
  3507. }
  3508. parseAsyncArrowFromCallExpression(node, call) {
  3509. if (this.match(14)) {
  3510. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3511. this.state.noAnonFunctionType = true;
  3512. node.returnType = this.flowParseTypeAnnotation();
  3513. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3514. }
  3515. return super.parseAsyncArrowFromCallExpression(node, call);
  3516. }
  3517. shouldParseAsyncArrow() {
  3518. return this.match(14) || super.shouldParseAsyncArrow();
  3519. }
  3520. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  3521. var _jsx;
  3522. let state = null;
  3523. let jsx;
  3524. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  3525. state = this.state.clone();
  3526. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  3527. if (!jsx.error) return jsx.node;
  3528. const {
  3529. context
  3530. } = this.state;
  3531. const currentContext = context[context.length - 1];
  3532. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  3533. context.pop();
  3534. }
  3535. }
  3536. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  3537. var _jsx2, _jsx3;
  3538. state = state || this.state.clone();
  3539. let typeParameters;
  3540. const arrow = this.tryParse(abort => {
  3541. var _arrowExpression$extr;
  3542. typeParameters = this.flowParseTypeParameterDeclaration();
  3543. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  3544. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3545. this.resetStartLocationFromNode(result, typeParameters);
  3546. return result;
  3547. });
  3548. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  3549. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  3550. if (expr.type !== "ArrowFunctionExpression") abort();
  3551. expr.typeParameters = typeParameters;
  3552. this.resetStartLocationFromNode(expr, typeParameters);
  3553. return arrowExpression;
  3554. }, state);
  3555. let arrowExpression = null;
  3556. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  3557. if (!arrow.error && !arrow.aborted) {
  3558. if (arrow.node.async) {
  3559. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  3560. }
  3561. return arrow.node;
  3562. }
  3563. arrowExpression = arrow.node;
  3564. }
  3565. if ((_jsx2 = jsx) != null && _jsx2.node) {
  3566. this.state = jsx.failState;
  3567. return jsx.node;
  3568. }
  3569. if (arrowExpression) {
  3570. this.state = arrow.failState;
  3571. return arrowExpression;
  3572. }
  3573. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  3574. if (arrow.thrown) throw arrow.error;
  3575. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  3576. }
  3577. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  3578. }
  3579. parseArrow(node) {
  3580. if (this.match(14)) {
  3581. const result = this.tryParse(() => {
  3582. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3583. this.state.noAnonFunctionType = true;
  3584. const typeNode = this.startNode();
  3585. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  3586. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3587. if (this.canInsertSemicolon()) this.unexpected();
  3588. if (!this.match(19)) this.unexpected();
  3589. return typeNode;
  3590. });
  3591. if (result.thrown) return null;
  3592. if (result.error) this.state = result.failState;
  3593. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  3594. }
  3595. return super.parseArrow(node);
  3596. }
  3597. shouldParseArrow(params) {
  3598. return this.match(14) || super.shouldParseArrow(params);
  3599. }
  3600. setArrowFunctionParameters(node, params) {
  3601. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3602. node.params = params;
  3603. } else {
  3604. super.setArrowFunctionParameters(node, params);
  3605. }
  3606. }
  3607. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  3608. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  3609. return;
  3610. }
  3611. for (let i = 0; i < node.params.length; i++) {
  3612. if (this.isThisParam(node.params[i]) && i > 0) {
  3613. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  3614. }
  3615. }
  3616. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  3617. }
  3618. parseParenAndDistinguishExpression(canBeArrow) {
  3619. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  3620. }
  3621. parseSubscripts(base, startLoc, noCalls) {
  3622. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  3623. this.next();
  3624. const node = this.startNodeAt(startLoc);
  3625. node.callee = base;
  3626. node.arguments = super.parseCallExpressionArguments();
  3627. base = this.finishNode(node, "CallExpression");
  3628. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  3629. const state = this.state.clone();
  3630. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  3631. if (!arrow.error && !arrow.aborted) return arrow.node;
  3632. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  3633. if (result.node && !result.error) return result.node;
  3634. if (arrow.node) {
  3635. this.state = arrow.failState;
  3636. return arrow.node;
  3637. }
  3638. if (result.node) {
  3639. this.state = result.failState;
  3640. return result.node;
  3641. }
  3642. throw arrow.error || result.error;
  3643. }
  3644. return super.parseSubscripts(base, startLoc, noCalls);
  3645. }
  3646. parseSubscript(base, startLoc, noCalls, subscriptState) {
  3647. if (this.match(18) && this.isLookaheadToken_lt()) {
  3648. subscriptState.optionalChainMember = true;
  3649. if (noCalls) {
  3650. subscriptState.stop = true;
  3651. return base;
  3652. }
  3653. this.next();
  3654. const node = this.startNodeAt(startLoc);
  3655. node.callee = base;
  3656. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  3657. this.expect(10);
  3658. node.arguments = this.parseCallExpressionArguments();
  3659. node.optional = true;
  3660. return this.finishCallExpression(node, true);
  3661. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  3662. const node = this.startNodeAt(startLoc);
  3663. node.callee = base;
  3664. const result = this.tryParse(() => {
  3665. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  3666. this.expect(10);
  3667. node.arguments = super.parseCallExpressionArguments();
  3668. if (subscriptState.optionalChainMember) {
  3669. node.optional = false;
  3670. }
  3671. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  3672. });
  3673. if (result.node) {
  3674. if (result.error) this.state = result.failState;
  3675. return result.node;
  3676. }
  3677. }
  3678. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  3679. }
  3680. parseNewCallee(node) {
  3681. super.parseNewCallee(node);
  3682. let targs = null;
  3683. if (this.shouldParseTypes() && this.match(47)) {
  3684. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  3685. }
  3686. node.typeArguments = targs;
  3687. }
  3688. parseAsyncArrowWithTypeParameters(startLoc) {
  3689. const node = this.startNodeAt(startLoc);
  3690. this.parseFunctionParams(node, false);
  3691. if (!this.parseArrow(node)) return;
  3692. return super.parseArrowExpression(node, undefined, true);
  3693. }
  3694. readToken_mult_modulo(code) {
  3695. const next = this.input.charCodeAt(this.state.pos + 1);
  3696. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  3697. this.state.hasFlowComment = false;
  3698. this.state.pos += 2;
  3699. this.nextToken();
  3700. return;
  3701. }
  3702. super.readToken_mult_modulo(code);
  3703. }
  3704. readToken_pipe_amp(code) {
  3705. const next = this.input.charCodeAt(this.state.pos + 1);
  3706. if (code === 124 && next === 125) {
  3707. this.finishOp(9, 2);
  3708. return;
  3709. }
  3710. super.readToken_pipe_amp(code);
  3711. }
  3712. parseTopLevel(file, program) {
  3713. const fileNode = super.parseTopLevel(file, program);
  3714. if (this.state.hasFlowComment) {
  3715. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  3716. }
  3717. return fileNode;
  3718. }
  3719. skipBlockComment() {
  3720. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  3721. if (this.state.hasFlowComment) {
  3722. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  3723. }
  3724. this.hasFlowCommentCompletion();
  3725. const commentSkip = this.skipFlowComment();
  3726. if (commentSkip) {
  3727. this.state.pos += commentSkip;
  3728. this.state.hasFlowComment = true;
  3729. }
  3730. return;
  3731. }
  3732. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  3733. }
  3734. skipFlowComment() {
  3735. const {
  3736. pos
  3737. } = this.state;
  3738. let shiftToFirstNonWhiteSpace = 2;
  3739. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  3740. shiftToFirstNonWhiteSpace++;
  3741. }
  3742. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  3743. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  3744. if (ch2 === 58 && ch3 === 58) {
  3745. return shiftToFirstNonWhiteSpace + 2;
  3746. }
  3747. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  3748. return shiftToFirstNonWhiteSpace + 12;
  3749. }
  3750. if (ch2 === 58 && ch3 !== 58) {
  3751. return shiftToFirstNonWhiteSpace;
  3752. }
  3753. return false;
  3754. }
  3755. hasFlowCommentCompletion() {
  3756. const end = this.input.indexOf("*/", this.state.pos);
  3757. if (end === -1) {
  3758. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  3759. }
  3760. }
  3761. flowEnumErrorBooleanMemberNotInitialized(loc, {
  3762. enumName,
  3763. memberName
  3764. }) {
  3765. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  3766. memberName,
  3767. enumName
  3768. });
  3769. }
  3770. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  3771. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  3772. }
  3773. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  3774. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  3775. }
  3776. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  3777. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  3778. }
  3779. flowEnumMemberInit() {
  3780. const startLoc = this.state.startLoc;
  3781. const endOfInit = () => this.match(12) || this.match(8);
  3782. switch (this.state.type) {
  3783. case 135:
  3784. {
  3785. const literal = this.parseNumericLiteral(this.state.value);
  3786. if (endOfInit()) {
  3787. return {
  3788. type: "number",
  3789. loc: literal.loc.start,
  3790. value: literal
  3791. };
  3792. }
  3793. return {
  3794. type: "invalid",
  3795. loc: startLoc
  3796. };
  3797. }
  3798. case 134:
  3799. {
  3800. const literal = this.parseStringLiteral(this.state.value);
  3801. if (endOfInit()) {
  3802. return {
  3803. type: "string",
  3804. loc: literal.loc.start,
  3805. value: literal
  3806. };
  3807. }
  3808. return {
  3809. type: "invalid",
  3810. loc: startLoc
  3811. };
  3812. }
  3813. case 85:
  3814. case 86:
  3815. {
  3816. const literal = this.parseBooleanLiteral(this.match(85));
  3817. if (endOfInit()) {
  3818. return {
  3819. type: "boolean",
  3820. loc: literal.loc.start,
  3821. value: literal
  3822. };
  3823. }
  3824. return {
  3825. type: "invalid",
  3826. loc: startLoc
  3827. };
  3828. }
  3829. default:
  3830. return {
  3831. type: "invalid",
  3832. loc: startLoc
  3833. };
  3834. }
  3835. }
  3836. flowEnumMemberRaw() {
  3837. const loc = this.state.startLoc;
  3838. const id = this.parseIdentifier(true);
  3839. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  3840. type: "none",
  3841. loc
  3842. };
  3843. return {
  3844. id,
  3845. init
  3846. };
  3847. }
  3848. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  3849. const {
  3850. explicitType
  3851. } = context;
  3852. if (explicitType === null) {
  3853. return;
  3854. }
  3855. if (explicitType !== expectedType) {
  3856. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  3857. }
  3858. }
  3859. flowEnumMembers({
  3860. enumName,
  3861. explicitType
  3862. }) {
  3863. const seenNames = new Set();
  3864. const members = {
  3865. booleanMembers: [],
  3866. numberMembers: [],
  3867. stringMembers: [],
  3868. defaultedMembers: []
  3869. };
  3870. let hasUnknownMembers = false;
  3871. while (!this.match(8)) {
  3872. if (this.eat(21)) {
  3873. hasUnknownMembers = true;
  3874. break;
  3875. }
  3876. const memberNode = this.startNode();
  3877. const {
  3878. id,
  3879. init
  3880. } = this.flowEnumMemberRaw();
  3881. const memberName = id.name;
  3882. if (memberName === "") {
  3883. continue;
  3884. }
  3885. if (/^[a-z]/.test(memberName)) {
  3886. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  3887. memberName,
  3888. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  3889. enumName
  3890. });
  3891. }
  3892. if (seenNames.has(memberName)) {
  3893. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  3894. memberName,
  3895. enumName
  3896. });
  3897. }
  3898. seenNames.add(memberName);
  3899. const context = {
  3900. enumName,
  3901. explicitType,
  3902. memberName
  3903. };
  3904. memberNode.id = id;
  3905. switch (init.type) {
  3906. case "boolean":
  3907. {
  3908. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  3909. memberNode.init = init.value;
  3910. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  3911. break;
  3912. }
  3913. case "number":
  3914. {
  3915. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  3916. memberNode.init = init.value;
  3917. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  3918. break;
  3919. }
  3920. case "string":
  3921. {
  3922. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  3923. memberNode.init = init.value;
  3924. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  3925. break;
  3926. }
  3927. case "invalid":
  3928. {
  3929. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  3930. }
  3931. case "none":
  3932. {
  3933. switch (explicitType) {
  3934. case "boolean":
  3935. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  3936. break;
  3937. case "number":
  3938. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  3939. break;
  3940. default:
  3941. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  3942. }
  3943. }
  3944. }
  3945. if (!this.match(8)) {
  3946. this.expect(12);
  3947. }
  3948. }
  3949. return {
  3950. members,
  3951. hasUnknownMembers
  3952. };
  3953. }
  3954. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  3955. enumName
  3956. }) {
  3957. if (initializedMembers.length === 0) {
  3958. return defaultedMembers;
  3959. } else if (defaultedMembers.length === 0) {
  3960. return initializedMembers;
  3961. } else if (defaultedMembers.length > initializedMembers.length) {
  3962. for (const member of initializedMembers) {
  3963. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3964. enumName
  3965. });
  3966. }
  3967. return defaultedMembers;
  3968. } else {
  3969. for (const member of defaultedMembers) {
  3970. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  3971. enumName
  3972. });
  3973. }
  3974. return initializedMembers;
  3975. }
  3976. }
  3977. flowEnumParseExplicitType({
  3978. enumName
  3979. }) {
  3980. if (!this.eatContextual(102)) return null;
  3981. if (!tokenIsIdentifier(this.state.type)) {
  3982. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  3983. enumName
  3984. });
  3985. }
  3986. const {
  3987. value
  3988. } = this.state;
  3989. this.next();
  3990. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  3991. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  3992. enumName,
  3993. invalidEnumType: value
  3994. });
  3995. }
  3996. return value;
  3997. }
  3998. flowEnumBody(node, id) {
  3999. const enumName = id.name;
  4000. const nameLoc = id.loc.start;
  4001. const explicitType = this.flowEnumParseExplicitType({
  4002. enumName
  4003. });
  4004. this.expect(5);
  4005. const {
  4006. members,
  4007. hasUnknownMembers
  4008. } = this.flowEnumMembers({
  4009. enumName,
  4010. explicitType
  4011. });
  4012. node.hasUnknownMembers = hasUnknownMembers;
  4013. switch (explicitType) {
  4014. case "boolean":
  4015. node.explicitType = true;
  4016. node.members = members.booleanMembers;
  4017. this.expect(8);
  4018. return this.finishNode(node, "EnumBooleanBody");
  4019. case "number":
  4020. node.explicitType = true;
  4021. node.members = members.numberMembers;
  4022. this.expect(8);
  4023. return this.finishNode(node, "EnumNumberBody");
  4024. case "string":
  4025. node.explicitType = true;
  4026. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4027. enumName
  4028. });
  4029. this.expect(8);
  4030. return this.finishNode(node, "EnumStringBody");
  4031. case "symbol":
  4032. node.members = members.defaultedMembers;
  4033. this.expect(8);
  4034. return this.finishNode(node, "EnumSymbolBody");
  4035. default:
  4036. {
  4037. const empty = () => {
  4038. node.members = [];
  4039. this.expect(8);
  4040. return this.finishNode(node, "EnumStringBody");
  4041. };
  4042. node.explicitType = false;
  4043. const boolsLen = members.booleanMembers.length;
  4044. const numsLen = members.numberMembers.length;
  4045. const strsLen = members.stringMembers.length;
  4046. const defaultedLen = members.defaultedMembers.length;
  4047. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  4048. return empty();
  4049. } else if (!boolsLen && !numsLen) {
  4050. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  4051. enumName
  4052. });
  4053. this.expect(8);
  4054. return this.finishNode(node, "EnumStringBody");
  4055. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  4056. for (const member of members.defaultedMembers) {
  4057. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  4058. enumName,
  4059. memberName: member.id.name
  4060. });
  4061. }
  4062. node.members = members.booleanMembers;
  4063. this.expect(8);
  4064. return this.finishNode(node, "EnumBooleanBody");
  4065. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  4066. for (const member of members.defaultedMembers) {
  4067. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  4068. enumName,
  4069. memberName: member.id.name
  4070. });
  4071. }
  4072. node.members = members.numberMembers;
  4073. this.expect(8);
  4074. return this.finishNode(node, "EnumNumberBody");
  4075. } else {
  4076. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  4077. enumName
  4078. });
  4079. return empty();
  4080. }
  4081. }
  4082. }
  4083. }
  4084. flowParseEnumDeclaration(node) {
  4085. const id = this.parseIdentifier();
  4086. node.id = id;
  4087. node.body = this.flowEnumBody(this.startNode(), id);
  4088. return this.finishNode(node, "EnumDeclaration");
  4089. }
  4090. jsxParseOpeningElementAfterName(node) {
  4091. if (this.shouldParseTypes()) {
  4092. if (this.match(47) || this.match(51)) {
  4093. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  4094. }
  4095. }
  4096. return super.jsxParseOpeningElementAfterName(node);
  4097. }
  4098. isLookaheadToken_lt() {
  4099. const next = this.nextTokenStart();
  4100. if (this.input.charCodeAt(next) === 60) {
  4101. const afterNext = this.input.charCodeAt(next + 1);
  4102. return afterNext !== 60 && afterNext !== 61;
  4103. }
  4104. return false;
  4105. }
  4106. reScan_lt_gt() {
  4107. const {
  4108. type
  4109. } = this.state;
  4110. if (type === 47) {
  4111. this.state.pos -= 1;
  4112. this.readToken_lt();
  4113. } else if (type === 48) {
  4114. this.state.pos -= 1;
  4115. this.readToken_gt();
  4116. }
  4117. }
  4118. reScan_lt() {
  4119. const {
  4120. type
  4121. } = this.state;
  4122. if (type === 51) {
  4123. this.state.pos -= 2;
  4124. this.finishOp(47, 1);
  4125. return 47;
  4126. }
  4127. return type;
  4128. }
  4129. maybeUnwrapTypeCastExpression(node) {
  4130. return node.type === "TypeCastExpression" ? node.expression : node;
  4131. }
  4132. };
  4133. const entities = {
  4134. __proto__: null,
  4135. quot: "\u0022",
  4136. amp: "&",
  4137. apos: "\u0027",
  4138. lt: "<",
  4139. gt: ">",
  4140. nbsp: "\u00A0",
  4141. iexcl: "\u00A1",
  4142. cent: "\u00A2",
  4143. pound: "\u00A3",
  4144. curren: "\u00A4",
  4145. yen: "\u00A5",
  4146. brvbar: "\u00A6",
  4147. sect: "\u00A7",
  4148. uml: "\u00A8",
  4149. copy: "\u00A9",
  4150. ordf: "\u00AA",
  4151. laquo: "\u00AB",
  4152. not: "\u00AC",
  4153. shy: "\u00AD",
  4154. reg: "\u00AE",
  4155. macr: "\u00AF",
  4156. deg: "\u00B0",
  4157. plusmn: "\u00B1",
  4158. sup2: "\u00B2",
  4159. sup3: "\u00B3",
  4160. acute: "\u00B4",
  4161. micro: "\u00B5",
  4162. para: "\u00B6",
  4163. middot: "\u00B7",
  4164. cedil: "\u00B8",
  4165. sup1: "\u00B9",
  4166. ordm: "\u00BA",
  4167. raquo: "\u00BB",
  4168. frac14: "\u00BC",
  4169. frac12: "\u00BD",
  4170. frac34: "\u00BE",
  4171. iquest: "\u00BF",
  4172. Agrave: "\u00C0",
  4173. Aacute: "\u00C1",
  4174. Acirc: "\u00C2",
  4175. Atilde: "\u00C3",
  4176. Auml: "\u00C4",
  4177. Aring: "\u00C5",
  4178. AElig: "\u00C6",
  4179. Ccedil: "\u00C7",
  4180. Egrave: "\u00C8",
  4181. Eacute: "\u00C9",
  4182. Ecirc: "\u00CA",
  4183. Euml: "\u00CB",
  4184. Igrave: "\u00CC",
  4185. Iacute: "\u00CD",
  4186. Icirc: "\u00CE",
  4187. Iuml: "\u00CF",
  4188. ETH: "\u00D0",
  4189. Ntilde: "\u00D1",
  4190. Ograve: "\u00D2",
  4191. Oacute: "\u00D3",
  4192. Ocirc: "\u00D4",
  4193. Otilde: "\u00D5",
  4194. Ouml: "\u00D6",
  4195. times: "\u00D7",
  4196. Oslash: "\u00D8",
  4197. Ugrave: "\u00D9",
  4198. Uacute: "\u00DA",
  4199. Ucirc: "\u00DB",
  4200. Uuml: "\u00DC",
  4201. Yacute: "\u00DD",
  4202. THORN: "\u00DE",
  4203. szlig: "\u00DF",
  4204. agrave: "\u00E0",
  4205. aacute: "\u00E1",
  4206. acirc: "\u00E2",
  4207. atilde: "\u00E3",
  4208. auml: "\u00E4",
  4209. aring: "\u00E5",
  4210. aelig: "\u00E6",
  4211. ccedil: "\u00E7",
  4212. egrave: "\u00E8",
  4213. eacute: "\u00E9",
  4214. ecirc: "\u00EA",
  4215. euml: "\u00EB",
  4216. igrave: "\u00EC",
  4217. iacute: "\u00ED",
  4218. icirc: "\u00EE",
  4219. iuml: "\u00EF",
  4220. eth: "\u00F0",
  4221. ntilde: "\u00F1",
  4222. ograve: "\u00F2",
  4223. oacute: "\u00F3",
  4224. ocirc: "\u00F4",
  4225. otilde: "\u00F5",
  4226. ouml: "\u00F6",
  4227. divide: "\u00F7",
  4228. oslash: "\u00F8",
  4229. ugrave: "\u00F9",
  4230. uacute: "\u00FA",
  4231. ucirc: "\u00FB",
  4232. uuml: "\u00FC",
  4233. yacute: "\u00FD",
  4234. thorn: "\u00FE",
  4235. yuml: "\u00FF",
  4236. OElig: "\u0152",
  4237. oelig: "\u0153",
  4238. Scaron: "\u0160",
  4239. scaron: "\u0161",
  4240. Yuml: "\u0178",
  4241. fnof: "\u0192",
  4242. circ: "\u02C6",
  4243. tilde: "\u02DC",
  4244. Alpha: "\u0391",
  4245. Beta: "\u0392",
  4246. Gamma: "\u0393",
  4247. Delta: "\u0394",
  4248. Epsilon: "\u0395",
  4249. Zeta: "\u0396",
  4250. Eta: "\u0397",
  4251. Theta: "\u0398",
  4252. Iota: "\u0399",
  4253. Kappa: "\u039A",
  4254. Lambda: "\u039B",
  4255. Mu: "\u039C",
  4256. Nu: "\u039D",
  4257. Xi: "\u039E",
  4258. Omicron: "\u039F",
  4259. Pi: "\u03A0",
  4260. Rho: "\u03A1",
  4261. Sigma: "\u03A3",
  4262. Tau: "\u03A4",
  4263. Upsilon: "\u03A5",
  4264. Phi: "\u03A6",
  4265. Chi: "\u03A7",
  4266. Psi: "\u03A8",
  4267. Omega: "\u03A9",
  4268. alpha: "\u03B1",
  4269. beta: "\u03B2",
  4270. gamma: "\u03B3",
  4271. delta: "\u03B4",
  4272. epsilon: "\u03B5",
  4273. zeta: "\u03B6",
  4274. eta: "\u03B7",
  4275. theta: "\u03B8",
  4276. iota: "\u03B9",
  4277. kappa: "\u03BA",
  4278. lambda: "\u03BB",
  4279. mu: "\u03BC",
  4280. nu: "\u03BD",
  4281. xi: "\u03BE",
  4282. omicron: "\u03BF",
  4283. pi: "\u03C0",
  4284. rho: "\u03C1",
  4285. sigmaf: "\u03C2",
  4286. sigma: "\u03C3",
  4287. tau: "\u03C4",
  4288. upsilon: "\u03C5",
  4289. phi: "\u03C6",
  4290. chi: "\u03C7",
  4291. psi: "\u03C8",
  4292. omega: "\u03C9",
  4293. thetasym: "\u03D1",
  4294. upsih: "\u03D2",
  4295. piv: "\u03D6",
  4296. ensp: "\u2002",
  4297. emsp: "\u2003",
  4298. thinsp: "\u2009",
  4299. zwnj: "\u200C",
  4300. zwj: "\u200D",
  4301. lrm: "\u200E",
  4302. rlm: "\u200F",
  4303. ndash: "\u2013",
  4304. mdash: "\u2014",
  4305. lsquo: "\u2018",
  4306. rsquo: "\u2019",
  4307. sbquo: "\u201A",
  4308. ldquo: "\u201C",
  4309. rdquo: "\u201D",
  4310. bdquo: "\u201E",
  4311. dagger: "\u2020",
  4312. Dagger: "\u2021",
  4313. bull: "\u2022",
  4314. hellip: "\u2026",
  4315. permil: "\u2030",
  4316. prime: "\u2032",
  4317. Prime: "\u2033",
  4318. lsaquo: "\u2039",
  4319. rsaquo: "\u203A",
  4320. oline: "\u203E",
  4321. frasl: "\u2044",
  4322. euro: "\u20AC",
  4323. image: "\u2111",
  4324. weierp: "\u2118",
  4325. real: "\u211C",
  4326. trade: "\u2122",
  4327. alefsym: "\u2135",
  4328. larr: "\u2190",
  4329. uarr: "\u2191",
  4330. rarr: "\u2192",
  4331. darr: "\u2193",
  4332. harr: "\u2194",
  4333. crarr: "\u21B5",
  4334. lArr: "\u21D0",
  4335. uArr: "\u21D1",
  4336. rArr: "\u21D2",
  4337. dArr: "\u21D3",
  4338. hArr: "\u21D4",
  4339. forall: "\u2200",
  4340. part: "\u2202",
  4341. exist: "\u2203",
  4342. empty: "\u2205",
  4343. nabla: "\u2207",
  4344. isin: "\u2208",
  4345. notin: "\u2209",
  4346. ni: "\u220B",
  4347. prod: "\u220F",
  4348. sum: "\u2211",
  4349. minus: "\u2212",
  4350. lowast: "\u2217",
  4351. radic: "\u221A",
  4352. prop: "\u221D",
  4353. infin: "\u221E",
  4354. ang: "\u2220",
  4355. and: "\u2227",
  4356. or: "\u2228",
  4357. cap: "\u2229",
  4358. cup: "\u222A",
  4359. int: "\u222B",
  4360. there4: "\u2234",
  4361. sim: "\u223C",
  4362. cong: "\u2245",
  4363. asymp: "\u2248",
  4364. ne: "\u2260",
  4365. equiv: "\u2261",
  4366. le: "\u2264",
  4367. ge: "\u2265",
  4368. sub: "\u2282",
  4369. sup: "\u2283",
  4370. nsub: "\u2284",
  4371. sube: "\u2286",
  4372. supe: "\u2287",
  4373. oplus: "\u2295",
  4374. otimes: "\u2297",
  4375. perp: "\u22A5",
  4376. sdot: "\u22C5",
  4377. lceil: "\u2308",
  4378. rceil: "\u2309",
  4379. lfloor: "\u230A",
  4380. rfloor: "\u230B",
  4381. lang: "\u2329",
  4382. rang: "\u232A",
  4383. loz: "\u25CA",
  4384. spades: "\u2660",
  4385. clubs: "\u2663",
  4386. hearts: "\u2665",
  4387. diams: "\u2666"
  4388. };
  4389. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  4390. const lineBreakG = new RegExp(lineBreak.source, "g");
  4391. function isNewLine(code) {
  4392. switch (code) {
  4393. case 10:
  4394. case 13:
  4395. case 8232:
  4396. case 8233:
  4397. return true;
  4398. default:
  4399. return false;
  4400. }
  4401. }
  4402. function hasNewLine(input, start, end) {
  4403. for (let i = start; i < end; i++) {
  4404. if (isNewLine(input.charCodeAt(i))) {
  4405. return true;
  4406. }
  4407. }
  4408. return false;
  4409. }
  4410. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  4411. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  4412. function isWhitespace(code) {
  4413. switch (code) {
  4414. case 0x0009:
  4415. case 0x000b:
  4416. case 0x000c:
  4417. case 32:
  4418. case 160:
  4419. case 5760:
  4420. case 0x2000:
  4421. case 0x2001:
  4422. case 0x2002:
  4423. case 0x2003:
  4424. case 0x2004:
  4425. case 0x2005:
  4426. case 0x2006:
  4427. case 0x2007:
  4428. case 0x2008:
  4429. case 0x2009:
  4430. case 0x200a:
  4431. case 0x202f:
  4432. case 0x205f:
  4433. case 0x3000:
  4434. case 0xfeff:
  4435. return true;
  4436. default:
  4437. return false;
  4438. }
  4439. }
  4440. const JsxErrors = ParseErrorEnum`jsx`({
  4441. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  4442. MissingClosingTagElement: ({
  4443. openingTagName
  4444. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  4445. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  4446. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  4447. UnexpectedToken: ({
  4448. unexpected,
  4449. HTMLEntity
  4450. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  4451. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  4452. UnterminatedJsxContent: "Unterminated JSX contents.",
  4453. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  4454. });
  4455. function isFragment(object) {
  4456. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  4457. }
  4458. function getQualifiedJSXName(object) {
  4459. if (object.type === "JSXIdentifier") {
  4460. return object.name;
  4461. }
  4462. if (object.type === "JSXNamespacedName") {
  4463. return object.namespace.name + ":" + object.name.name;
  4464. }
  4465. if (object.type === "JSXMemberExpression") {
  4466. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  4467. }
  4468. throw new Error("Node had unexpected type: " + object.type);
  4469. }
  4470. var jsx = superClass => class JSXParserMixin extends superClass {
  4471. jsxReadToken() {
  4472. let out = "";
  4473. let chunkStart = this.state.pos;
  4474. for (;;) {
  4475. if (this.state.pos >= this.length) {
  4476. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  4477. }
  4478. const ch = this.input.charCodeAt(this.state.pos);
  4479. switch (ch) {
  4480. case 60:
  4481. case 123:
  4482. if (this.state.pos === this.state.start) {
  4483. if (ch === 60 && this.state.canStartJSXElement) {
  4484. ++this.state.pos;
  4485. this.finishToken(143);
  4486. } else {
  4487. super.getTokenFromCode(ch);
  4488. }
  4489. return;
  4490. }
  4491. out += this.input.slice(chunkStart, this.state.pos);
  4492. this.finishToken(142, out);
  4493. return;
  4494. case 38:
  4495. out += this.input.slice(chunkStart, this.state.pos);
  4496. out += this.jsxReadEntity();
  4497. chunkStart = this.state.pos;
  4498. break;
  4499. case 62:
  4500. case 125:
  4501. default:
  4502. if (isNewLine(ch)) {
  4503. out += this.input.slice(chunkStart, this.state.pos);
  4504. out += this.jsxReadNewLine(true);
  4505. chunkStart = this.state.pos;
  4506. } else {
  4507. ++this.state.pos;
  4508. }
  4509. }
  4510. }
  4511. }
  4512. jsxReadNewLine(normalizeCRLF) {
  4513. const ch = this.input.charCodeAt(this.state.pos);
  4514. let out;
  4515. ++this.state.pos;
  4516. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  4517. ++this.state.pos;
  4518. out = normalizeCRLF ? "\n" : "\r\n";
  4519. } else {
  4520. out = String.fromCharCode(ch);
  4521. }
  4522. ++this.state.curLine;
  4523. this.state.lineStart = this.state.pos;
  4524. return out;
  4525. }
  4526. jsxReadString(quote) {
  4527. let out = "";
  4528. let chunkStart = ++this.state.pos;
  4529. for (;;) {
  4530. if (this.state.pos >= this.length) {
  4531. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  4532. }
  4533. const ch = this.input.charCodeAt(this.state.pos);
  4534. if (ch === quote) break;
  4535. if (ch === 38) {
  4536. out += this.input.slice(chunkStart, this.state.pos);
  4537. out += this.jsxReadEntity();
  4538. chunkStart = this.state.pos;
  4539. } else if (isNewLine(ch)) {
  4540. out += this.input.slice(chunkStart, this.state.pos);
  4541. out += this.jsxReadNewLine(false);
  4542. chunkStart = this.state.pos;
  4543. } else {
  4544. ++this.state.pos;
  4545. }
  4546. }
  4547. out += this.input.slice(chunkStart, this.state.pos++);
  4548. this.finishToken(134, out);
  4549. }
  4550. jsxReadEntity() {
  4551. const startPos = ++this.state.pos;
  4552. if (this.codePointAtPos(this.state.pos) === 35) {
  4553. ++this.state.pos;
  4554. let radix = 10;
  4555. if (this.codePointAtPos(this.state.pos) === 120) {
  4556. radix = 16;
  4557. ++this.state.pos;
  4558. }
  4559. const codePoint = this.readInt(radix, undefined, false, "bail");
  4560. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  4561. ++this.state.pos;
  4562. return String.fromCodePoint(codePoint);
  4563. }
  4564. } else {
  4565. let count = 0;
  4566. let semi = false;
  4567. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  4568. ++this.state.pos;
  4569. }
  4570. if (semi) {
  4571. const desc = this.input.slice(startPos, this.state.pos);
  4572. const entity = entities[desc];
  4573. ++this.state.pos;
  4574. if (entity) {
  4575. return entity;
  4576. }
  4577. }
  4578. }
  4579. this.state.pos = startPos;
  4580. return "&";
  4581. }
  4582. jsxReadWord() {
  4583. let ch;
  4584. const start = this.state.pos;
  4585. do {
  4586. ch = this.input.charCodeAt(++this.state.pos);
  4587. } while (isIdentifierChar(ch) || ch === 45);
  4588. this.finishToken(141, this.input.slice(start, this.state.pos));
  4589. }
  4590. jsxParseIdentifier() {
  4591. const node = this.startNode();
  4592. if (this.match(141)) {
  4593. node.name = this.state.value;
  4594. } else if (tokenIsKeyword(this.state.type)) {
  4595. node.name = tokenLabelName(this.state.type);
  4596. } else {
  4597. this.unexpected();
  4598. }
  4599. this.next();
  4600. return this.finishNode(node, "JSXIdentifier");
  4601. }
  4602. jsxParseNamespacedName() {
  4603. const startLoc = this.state.startLoc;
  4604. const name = this.jsxParseIdentifier();
  4605. if (!this.eat(14)) return name;
  4606. const node = this.startNodeAt(startLoc);
  4607. node.namespace = name;
  4608. node.name = this.jsxParseIdentifier();
  4609. return this.finishNode(node, "JSXNamespacedName");
  4610. }
  4611. jsxParseElementName() {
  4612. const startLoc = this.state.startLoc;
  4613. let node = this.jsxParseNamespacedName();
  4614. if (node.type === "JSXNamespacedName") {
  4615. return node;
  4616. }
  4617. while (this.eat(16)) {
  4618. const newNode = this.startNodeAt(startLoc);
  4619. newNode.object = node;
  4620. newNode.property = this.jsxParseIdentifier();
  4621. node = this.finishNode(newNode, "JSXMemberExpression");
  4622. }
  4623. return node;
  4624. }
  4625. jsxParseAttributeValue() {
  4626. let node;
  4627. switch (this.state.type) {
  4628. case 5:
  4629. node = this.startNode();
  4630. this.setContext(types.brace);
  4631. this.next();
  4632. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  4633. if (node.expression.type === "JSXEmptyExpression") {
  4634. this.raise(JsxErrors.AttributeIsEmpty, node);
  4635. }
  4636. return node;
  4637. case 143:
  4638. case 134:
  4639. return this.parseExprAtom();
  4640. default:
  4641. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  4642. }
  4643. }
  4644. jsxParseEmptyExpression() {
  4645. const node = this.startNodeAt(this.state.lastTokEndLoc);
  4646. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  4647. }
  4648. jsxParseSpreadChild(node) {
  4649. this.next();
  4650. node.expression = this.parseExpression();
  4651. this.setContext(types.j_expr);
  4652. this.state.canStartJSXElement = true;
  4653. this.expect(8);
  4654. return this.finishNode(node, "JSXSpreadChild");
  4655. }
  4656. jsxParseExpressionContainer(node, previousContext) {
  4657. if (this.match(8)) {
  4658. node.expression = this.jsxParseEmptyExpression();
  4659. } else {
  4660. const expression = this.parseExpression();
  4661. node.expression = expression;
  4662. }
  4663. this.setContext(previousContext);
  4664. this.state.canStartJSXElement = true;
  4665. this.expect(8);
  4666. return this.finishNode(node, "JSXExpressionContainer");
  4667. }
  4668. jsxParseAttribute() {
  4669. const node = this.startNode();
  4670. if (this.match(5)) {
  4671. this.setContext(types.brace);
  4672. this.next();
  4673. this.expect(21);
  4674. node.argument = this.parseMaybeAssignAllowIn();
  4675. this.setContext(types.j_oTag);
  4676. this.state.canStartJSXElement = true;
  4677. this.expect(8);
  4678. return this.finishNode(node, "JSXSpreadAttribute");
  4679. }
  4680. node.name = this.jsxParseNamespacedName();
  4681. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  4682. return this.finishNode(node, "JSXAttribute");
  4683. }
  4684. jsxParseOpeningElementAt(startLoc) {
  4685. const node = this.startNodeAt(startLoc);
  4686. if (this.eat(144)) {
  4687. return this.finishNode(node, "JSXOpeningFragment");
  4688. }
  4689. node.name = this.jsxParseElementName();
  4690. return this.jsxParseOpeningElementAfterName(node);
  4691. }
  4692. jsxParseOpeningElementAfterName(node) {
  4693. const attributes = [];
  4694. while (!this.match(56) && !this.match(144)) {
  4695. attributes.push(this.jsxParseAttribute());
  4696. }
  4697. node.attributes = attributes;
  4698. node.selfClosing = this.eat(56);
  4699. this.expect(144);
  4700. return this.finishNode(node, "JSXOpeningElement");
  4701. }
  4702. jsxParseClosingElementAt(startLoc) {
  4703. const node = this.startNodeAt(startLoc);
  4704. if (this.eat(144)) {
  4705. return this.finishNode(node, "JSXClosingFragment");
  4706. }
  4707. node.name = this.jsxParseElementName();
  4708. this.expect(144);
  4709. return this.finishNode(node, "JSXClosingElement");
  4710. }
  4711. jsxParseElementAt(startLoc) {
  4712. const node = this.startNodeAt(startLoc);
  4713. const children = [];
  4714. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  4715. let closingElement = null;
  4716. if (!openingElement.selfClosing) {
  4717. contents: for (;;) {
  4718. switch (this.state.type) {
  4719. case 143:
  4720. startLoc = this.state.startLoc;
  4721. this.next();
  4722. if (this.eat(56)) {
  4723. closingElement = this.jsxParseClosingElementAt(startLoc);
  4724. break contents;
  4725. }
  4726. children.push(this.jsxParseElementAt(startLoc));
  4727. break;
  4728. case 142:
  4729. children.push(this.parseLiteral(this.state.value, "JSXText"));
  4730. break;
  4731. case 5:
  4732. {
  4733. const node = this.startNode();
  4734. this.setContext(types.brace);
  4735. this.next();
  4736. if (this.match(21)) {
  4737. children.push(this.jsxParseSpreadChild(node));
  4738. } else {
  4739. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  4740. }
  4741. break;
  4742. }
  4743. default:
  4744. this.unexpected();
  4745. }
  4746. }
  4747. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  4748. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  4749. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  4750. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4751. openingTagName: getQualifiedJSXName(openingElement.name)
  4752. });
  4753. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  4754. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  4755. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  4756. openingTagName: getQualifiedJSXName(openingElement.name)
  4757. });
  4758. }
  4759. }
  4760. }
  4761. if (isFragment(openingElement)) {
  4762. node.openingFragment = openingElement;
  4763. node.closingFragment = closingElement;
  4764. } else {
  4765. node.openingElement = openingElement;
  4766. node.closingElement = closingElement;
  4767. }
  4768. node.children = children;
  4769. if (this.match(47)) {
  4770. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  4771. }
  4772. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  4773. }
  4774. jsxParseElement() {
  4775. const startLoc = this.state.startLoc;
  4776. this.next();
  4777. return this.jsxParseElementAt(startLoc);
  4778. }
  4779. setContext(newContext) {
  4780. const {
  4781. context
  4782. } = this.state;
  4783. context[context.length - 1] = newContext;
  4784. }
  4785. parseExprAtom(refExpressionErrors) {
  4786. if (this.match(143)) {
  4787. return this.jsxParseElement();
  4788. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  4789. this.replaceToken(143);
  4790. return this.jsxParseElement();
  4791. } else {
  4792. return super.parseExprAtom(refExpressionErrors);
  4793. }
  4794. }
  4795. skipSpace() {
  4796. const curContext = this.curContext();
  4797. if (!curContext.preserveSpace) super.skipSpace();
  4798. }
  4799. getTokenFromCode(code) {
  4800. const context = this.curContext();
  4801. if (context === types.j_expr) {
  4802. this.jsxReadToken();
  4803. return;
  4804. }
  4805. if (context === types.j_oTag || context === types.j_cTag) {
  4806. if (isIdentifierStart(code)) {
  4807. this.jsxReadWord();
  4808. return;
  4809. }
  4810. if (code === 62) {
  4811. ++this.state.pos;
  4812. this.finishToken(144);
  4813. return;
  4814. }
  4815. if ((code === 34 || code === 39) && context === types.j_oTag) {
  4816. this.jsxReadString(code);
  4817. return;
  4818. }
  4819. }
  4820. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  4821. ++this.state.pos;
  4822. this.finishToken(143);
  4823. return;
  4824. }
  4825. super.getTokenFromCode(code);
  4826. }
  4827. updateContext(prevType) {
  4828. const {
  4829. context,
  4830. type
  4831. } = this.state;
  4832. if (type === 56 && prevType === 143) {
  4833. context.splice(-2, 2, types.j_cTag);
  4834. this.state.canStartJSXElement = false;
  4835. } else if (type === 143) {
  4836. context.push(types.j_oTag);
  4837. } else if (type === 144) {
  4838. const out = context[context.length - 1];
  4839. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  4840. context.pop();
  4841. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  4842. } else {
  4843. this.setContext(types.j_expr);
  4844. this.state.canStartJSXElement = true;
  4845. }
  4846. } else {
  4847. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  4848. }
  4849. }
  4850. };
  4851. class TypeScriptScope extends Scope {
  4852. constructor(...args) {
  4853. super(...args);
  4854. this.tsNames = new Map();
  4855. }
  4856. }
  4857. class TypeScriptScopeHandler extends ScopeHandler {
  4858. constructor(...args) {
  4859. super(...args);
  4860. this.importsStack = [];
  4861. }
  4862. createScope(flags) {
  4863. this.importsStack.push(new Set());
  4864. return new TypeScriptScope(flags);
  4865. }
  4866. enter(flags) {
  4867. if (flags === 1024) {
  4868. this.importsStack.push(new Set());
  4869. }
  4870. super.enter(flags);
  4871. }
  4872. exit() {
  4873. const flags = super.exit();
  4874. if (flags === 1024) {
  4875. this.importsStack.pop();
  4876. }
  4877. return flags;
  4878. }
  4879. hasImport(name, allowShadow) {
  4880. const len = this.importsStack.length;
  4881. if (this.importsStack[len - 1].has(name)) {
  4882. return true;
  4883. }
  4884. if (!allowShadow && len > 1) {
  4885. for (let i = 0; i < len - 1; i++) {
  4886. if (this.importsStack[i].has(name)) return true;
  4887. }
  4888. }
  4889. return false;
  4890. }
  4891. declareName(name, bindingType, loc) {
  4892. if (bindingType & 4096) {
  4893. if (this.hasImport(name, true)) {
  4894. this.parser.raise(Errors.VarRedeclaration, loc, {
  4895. identifierName: name
  4896. });
  4897. }
  4898. this.importsStack[this.importsStack.length - 1].add(name);
  4899. return;
  4900. }
  4901. const scope = this.currentScope();
  4902. let type = scope.tsNames.get(name) || 0;
  4903. if (bindingType & 1024) {
  4904. this.maybeExportDefined(scope, name);
  4905. scope.tsNames.set(name, type | 16);
  4906. return;
  4907. }
  4908. super.declareName(name, bindingType, loc);
  4909. if (bindingType & 2) {
  4910. if (!(bindingType & 1)) {
  4911. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4912. this.maybeExportDefined(scope, name);
  4913. }
  4914. type = type | 1;
  4915. }
  4916. if (bindingType & 256) {
  4917. type = type | 2;
  4918. }
  4919. if (bindingType & 512) {
  4920. type = type | 4;
  4921. }
  4922. if (bindingType & 128) {
  4923. type = type | 8;
  4924. }
  4925. if (type) scope.tsNames.set(name, type);
  4926. }
  4927. isRedeclaredInScope(scope, name, bindingType) {
  4928. const type = scope.tsNames.get(name);
  4929. if ((type & 2) > 0) {
  4930. if (bindingType & 256) {
  4931. const isConst = !!(bindingType & 512);
  4932. const wasConst = (type & 4) > 0;
  4933. return isConst !== wasConst;
  4934. }
  4935. return true;
  4936. }
  4937. if (bindingType & 128 && (type & 8) > 0) {
  4938. if (scope.names.get(name) & 2) {
  4939. return !!(bindingType & 1);
  4940. } else {
  4941. return false;
  4942. }
  4943. }
  4944. if (bindingType & 2 && (type & 1) > 0) {
  4945. return true;
  4946. }
  4947. return super.isRedeclaredInScope(scope, name, bindingType);
  4948. }
  4949. checkLocalExport(id) {
  4950. const {
  4951. name
  4952. } = id;
  4953. if (this.hasImport(name)) return;
  4954. const len = this.scopeStack.length;
  4955. for (let i = len - 1; i >= 0; i--) {
  4956. const scope = this.scopeStack[i];
  4957. const type = scope.tsNames.get(name);
  4958. if ((type & 1) > 0 || (type & 16) > 0) {
  4959. return;
  4960. }
  4961. }
  4962. super.checkLocalExport(id);
  4963. }
  4964. }
  4965. class ProductionParameterHandler {
  4966. constructor() {
  4967. this.stacks = [];
  4968. }
  4969. enter(flags) {
  4970. this.stacks.push(flags);
  4971. }
  4972. exit() {
  4973. this.stacks.pop();
  4974. }
  4975. currentFlags() {
  4976. return this.stacks[this.stacks.length - 1];
  4977. }
  4978. get hasAwait() {
  4979. return (this.currentFlags() & 2) > 0;
  4980. }
  4981. get hasYield() {
  4982. return (this.currentFlags() & 1) > 0;
  4983. }
  4984. get hasReturn() {
  4985. return (this.currentFlags() & 4) > 0;
  4986. }
  4987. get hasIn() {
  4988. return (this.currentFlags() & 8) > 0;
  4989. }
  4990. }
  4991. function functionFlags(isAsync, isGenerator) {
  4992. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  4993. }
  4994. class BaseParser {
  4995. constructor() {
  4996. this.sawUnambiguousESM = false;
  4997. this.ambiguousScriptDifferentAst = false;
  4998. }
  4999. sourceToOffsetPos(sourcePos) {
  5000. return sourcePos + this.startIndex;
  5001. }
  5002. offsetToSourcePos(offsetPos) {
  5003. return offsetPos - this.startIndex;
  5004. }
  5005. hasPlugin(pluginConfig) {
  5006. if (typeof pluginConfig === "string") {
  5007. return this.plugins.has(pluginConfig);
  5008. } else {
  5009. const [pluginName, pluginOptions] = pluginConfig;
  5010. if (!this.hasPlugin(pluginName)) {
  5011. return false;
  5012. }
  5013. const actualOptions = this.plugins.get(pluginName);
  5014. for (const key of Object.keys(pluginOptions)) {
  5015. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  5016. return false;
  5017. }
  5018. }
  5019. return true;
  5020. }
  5021. }
  5022. getPluginOption(plugin, name) {
  5023. var _this$plugins$get;
  5024. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  5025. }
  5026. }
  5027. function setTrailingComments(node, comments) {
  5028. if (node.trailingComments === undefined) {
  5029. node.trailingComments = comments;
  5030. } else {
  5031. node.trailingComments.unshift(...comments);
  5032. }
  5033. }
  5034. function setLeadingComments(node, comments) {
  5035. if (node.leadingComments === undefined) {
  5036. node.leadingComments = comments;
  5037. } else {
  5038. node.leadingComments.unshift(...comments);
  5039. }
  5040. }
  5041. function setInnerComments(node, comments) {
  5042. if (node.innerComments === undefined) {
  5043. node.innerComments = comments;
  5044. } else {
  5045. node.innerComments.unshift(...comments);
  5046. }
  5047. }
  5048. function adjustInnerComments(node, elements, commentWS) {
  5049. let lastElement = null;
  5050. let i = elements.length;
  5051. while (lastElement === null && i > 0) {
  5052. lastElement = elements[--i];
  5053. }
  5054. if (lastElement === null || lastElement.start > commentWS.start) {
  5055. setInnerComments(node, commentWS.comments);
  5056. } else {
  5057. setTrailingComments(lastElement, commentWS.comments);
  5058. }
  5059. }
  5060. class CommentsParser extends BaseParser {
  5061. addComment(comment) {
  5062. if (this.filename) comment.loc.filename = this.filename;
  5063. const {
  5064. commentsLen
  5065. } = this.state;
  5066. if (this.comments.length !== commentsLen) {
  5067. this.comments.length = commentsLen;
  5068. }
  5069. this.comments.push(comment);
  5070. this.state.commentsLen++;
  5071. }
  5072. processComment(node) {
  5073. const {
  5074. commentStack
  5075. } = this.state;
  5076. const commentStackLength = commentStack.length;
  5077. if (commentStackLength === 0) return;
  5078. let i = commentStackLength - 1;
  5079. const lastCommentWS = commentStack[i];
  5080. if (lastCommentWS.start === node.end) {
  5081. lastCommentWS.leadingNode = node;
  5082. i--;
  5083. }
  5084. const {
  5085. start: nodeStart
  5086. } = node;
  5087. for (; i >= 0; i--) {
  5088. const commentWS = commentStack[i];
  5089. const commentEnd = commentWS.end;
  5090. if (commentEnd > nodeStart) {
  5091. commentWS.containingNode = node;
  5092. this.finalizeComment(commentWS);
  5093. commentStack.splice(i, 1);
  5094. } else {
  5095. if (commentEnd === nodeStart) {
  5096. commentWS.trailingNode = node;
  5097. }
  5098. break;
  5099. }
  5100. }
  5101. }
  5102. finalizeComment(commentWS) {
  5103. var _node$options;
  5104. const {
  5105. comments
  5106. } = commentWS;
  5107. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  5108. if (commentWS.leadingNode !== null) {
  5109. setTrailingComments(commentWS.leadingNode, comments);
  5110. }
  5111. if (commentWS.trailingNode !== null) {
  5112. setLeadingComments(commentWS.trailingNode, comments);
  5113. }
  5114. } else {
  5115. const node = commentWS.containingNode;
  5116. const commentStart = commentWS.start;
  5117. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  5118. switch (node.type) {
  5119. case "ObjectExpression":
  5120. case "ObjectPattern":
  5121. case "RecordExpression":
  5122. adjustInnerComments(node, node.properties, commentWS);
  5123. break;
  5124. case "CallExpression":
  5125. case "OptionalCallExpression":
  5126. adjustInnerComments(node, node.arguments, commentWS);
  5127. break;
  5128. case "ImportExpression":
  5129. adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
  5130. break;
  5131. case "FunctionDeclaration":
  5132. case "FunctionExpression":
  5133. case "ArrowFunctionExpression":
  5134. case "ObjectMethod":
  5135. case "ClassMethod":
  5136. case "ClassPrivateMethod":
  5137. adjustInnerComments(node, node.params, commentWS);
  5138. break;
  5139. case "ArrayExpression":
  5140. case "ArrayPattern":
  5141. case "TupleExpression":
  5142. adjustInnerComments(node, node.elements, commentWS);
  5143. break;
  5144. case "ExportNamedDeclaration":
  5145. case "ImportDeclaration":
  5146. adjustInnerComments(node, node.specifiers, commentWS);
  5147. break;
  5148. case "TSEnumDeclaration":
  5149. {
  5150. adjustInnerComments(node, node.members, commentWS);
  5151. }
  5152. break;
  5153. case "TSEnumBody":
  5154. adjustInnerComments(node, node.members, commentWS);
  5155. break;
  5156. default:
  5157. {
  5158. setInnerComments(node, comments);
  5159. }
  5160. }
  5161. } else {
  5162. setInnerComments(node, comments);
  5163. }
  5164. }
  5165. }
  5166. finalizeRemainingComments() {
  5167. const {
  5168. commentStack
  5169. } = this.state;
  5170. for (let i = commentStack.length - 1; i >= 0; i--) {
  5171. this.finalizeComment(commentStack[i]);
  5172. }
  5173. this.state.commentStack = [];
  5174. }
  5175. resetPreviousNodeTrailingComments(node) {
  5176. const {
  5177. commentStack
  5178. } = this.state;
  5179. const {
  5180. length
  5181. } = commentStack;
  5182. if (length === 0) return;
  5183. const commentWS = commentStack[length - 1];
  5184. if (commentWS.leadingNode === node) {
  5185. commentWS.leadingNode = null;
  5186. }
  5187. }
  5188. takeSurroundingComments(node, start, end) {
  5189. const {
  5190. commentStack
  5191. } = this.state;
  5192. const commentStackLength = commentStack.length;
  5193. if (commentStackLength === 0) return;
  5194. let i = commentStackLength - 1;
  5195. for (; i >= 0; i--) {
  5196. const commentWS = commentStack[i];
  5197. const commentEnd = commentWS.end;
  5198. const commentStart = commentWS.start;
  5199. if (commentStart === end) {
  5200. commentWS.leadingNode = node;
  5201. } else if (commentEnd === start) {
  5202. commentWS.trailingNode = node;
  5203. } else if (commentEnd < start) {
  5204. break;
  5205. }
  5206. }
  5207. }
  5208. }
  5209. class State {
  5210. constructor() {
  5211. this.flags = 1024;
  5212. this.startIndex = void 0;
  5213. this.curLine = void 0;
  5214. this.lineStart = void 0;
  5215. this.startLoc = void 0;
  5216. this.endLoc = void 0;
  5217. this.errors = [];
  5218. this.potentialArrowAt = -1;
  5219. this.noArrowAt = [];
  5220. this.noArrowParamsConversionAt = [];
  5221. this.topicContext = {
  5222. maxNumOfResolvableTopics: 0,
  5223. maxTopicIndex: null
  5224. };
  5225. this.labels = [];
  5226. this.commentsLen = 0;
  5227. this.commentStack = [];
  5228. this.pos = 0;
  5229. this.type = 140;
  5230. this.value = null;
  5231. this.start = 0;
  5232. this.end = 0;
  5233. this.lastTokEndLoc = null;
  5234. this.lastTokStartLoc = null;
  5235. this.context = [types.brace];
  5236. this.firstInvalidTemplateEscapePos = null;
  5237. this.strictErrors = new Map();
  5238. this.tokensLength = 0;
  5239. }
  5240. get strict() {
  5241. return (this.flags & 1) > 0;
  5242. }
  5243. set strict(v) {
  5244. if (v) this.flags |= 1;else this.flags &= -2;
  5245. }
  5246. init({
  5247. strictMode,
  5248. sourceType,
  5249. startIndex,
  5250. startLine,
  5251. startColumn
  5252. }) {
  5253. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  5254. this.startIndex = startIndex;
  5255. this.curLine = startLine;
  5256. this.lineStart = -startColumn;
  5257. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  5258. }
  5259. get maybeInArrowParameters() {
  5260. return (this.flags & 2) > 0;
  5261. }
  5262. set maybeInArrowParameters(v) {
  5263. if (v) this.flags |= 2;else this.flags &= -3;
  5264. }
  5265. get inType() {
  5266. return (this.flags & 4) > 0;
  5267. }
  5268. set inType(v) {
  5269. if (v) this.flags |= 4;else this.flags &= -5;
  5270. }
  5271. get noAnonFunctionType() {
  5272. return (this.flags & 8) > 0;
  5273. }
  5274. set noAnonFunctionType(v) {
  5275. if (v) this.flags |= 8;else this.flags &= -9;
  5276. }
  5277. get hasFlowComment() {
  5278. return (this.flags & 16) > 0;
  5279. }
  5280. set hasFlowComment(v) {
  5281. if (v) this.flags |= 16;else this.flags &= -17;
  5282. }
  5283. get isAmbientContext() {
  5284. return (this.flags & 32) > 0;
  5285. }
  5286. set isAmbientContext(v) {
  5287. if (v) this.flags |= 32;else this.flags &= -33;
  5288. }
  5289. get inAbstractClass() {
  5290. return (this.flags & 64) > 0;
  5291. }
  5292. set inAbstractClass(v) {
  5293. if (v) this.flags |= 64;else this.flags &= -65;
  5294. }
  5295. get inDisallowConditionalTypesContext() {
  5296. return (this.flags & 128) > 0;
  5297. }
  5298. set inDisallowConditionalTypesContext(v) {
  5299. if (v) this.flags |= 128;else this.flags &= -129;
  5300. }
  5301. get soloAwait() {
  5302. return (this.flags & 256) > 0;
  5303. }
  5304. set soloAwait(v) {
  5305. if (v) this.flags |= 256;else this.flags &= -257;
  5306. }
  5307. get inFSharpPipelineDirectBody() {
  5308. return (this.flags & 512) > 0;
  5309. }
  5310. set inFSharpPipelineDirectBody(v) {
  5311. if (v) this.flags |= 512;else this.flags &= -513;
  5312. }
  5313. get canStartJSXElement() {
  5314. return (this.flags & 1024) > 0;
  5315. }
  5316. set canStartJSXElement(v) {
  5317. if (v) this.flags |= 1024;else this.flags &= -1025;
  5318. }
  5319. get containsEsc() {
  5320. return (this.flags & 2048) > 0;
  5321. }
  5322. set containsEsc(v) {
  5323. if (v) this.flags |= 2048;else this.flags &= -2049;
  5324. }
  5325. get hasTopLevelAwait() {
  5326. return (this.flags & 4096) > 0;
  5327. }
  5328. set hasTopLevelAwait(v) {
  5329. if (v) this.flags |= 4096;else this.flags &= -4097;
  5330. }
  5331. curPosition() {
  5332. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  5333. }
  5334. clone() {
  5335. const state = new State();
  5336. state.flags = this.flags;
  5337. state.startIndex = this.startIndex;
  5338. state.curLine = this.curLine;
  5339. state.lineStart = this.lineStart;
  5340. state.startLoc = this.startLoc;
  5341. state.endLoc = this.endLoc;
  5342. state.errors = this.errors.slice();
  5343. state.potentialArrowAt = this.potentialArrowAt;
  5344. state.noArrowAt = this.noArrowAt.slice();
  5345. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  5346. state.topicContext = this.topicContext;
  5347. state.labels = this.labels.slice();
  5348. state.commentsLen = this.commentsLen;
  5349. state.commentStack = this.commentStack.slice();
  5350. state.pos = this.pos;
  5351. state.type = this.type;
  5352. state.value = this.value;
  5353. state.start = this.start;
  5354. state.end = this.end;
  5355. state.lastTokEndLoc = this.lastTokEndLoc;
  5356. state.lastTokStartLoc = this.lastTokStartLoc;
  5357. state.context = this.context.slice();
  5358. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  5359. state.strictErrors = this.strictErrors;
  5360. state.tokensLength = this.tokensLength;
  5361. return state;
  5362. }
  5363. }
  5364. var _isDigit = function isDigit(code) {
  5365. return code >= 48 && code <= 57;
  5366. };
  5367. const forbiddenNumericSeparatorSiblings = {
  5368. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  5369. hex: new Set([46, 88, 95, 120])
  5370. };
  5371. const isAllowedNumericSeparatorSibling = {
  5372. bin: ch => ch === 48 || ch === 49,
  5373. oct: ch => ch >= 48 && ch <= 55,
  5374. dec: ch => ch >= 48 && ch <= 57,
  5375. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  5376. };
  5377. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  5378. const initialPos = pos;
  5379. const initialLineStart = lineStart;
  5380. const initialCurLine = curLine;
  5381. let out = "";
  5382. let firstInvalidLoc = null;
  5383. let chunkStart = pos;
  5384. const {
  5385. length
  5386. } = input;
  5387. for (;;) {
  5388. if (pos >= length) {
  5389. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5390. out += input.slice(chunkStart, pos);
  5391. break;
  5392. }
  5393. const ch = input.charCodeAt(pos);
  5394. if (isStringEnd(type, ch, input, pos)) {
  5395. out += input.slice(chunkStart, pos);
  5396. break;
  5397. }
  5398. if (ch === 92) {
  5399. out += input.slice(chunkStart, pos);
  5400. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  5401. if (res.ch === null && !firstInvalidLoc) {
  5402. firstInvalidLoc = {
  5403. pos,
  5404. lineStart,
  5405. curLine
  5406. };
  5407. } else {
  5408. out += res.ch;
  5409. }
  5410. ({
  5411. pos,
  5412. lineStart,
  5413. curLine
  5414. } = res);
  5415. chunkStart = pos;
  5416. } else if (ch === 8232 || ch === 8233) {
  5417. ++pos;
  5418. ++curLine;
  5419. lineStart = pos;
  5420. } else if (ch === 10 || ch === 13) {
  5421. if (type === "template") {
  5422. out += input.slice(chunkStart, pos) + "\n";
  5423. ++pos;
  5424. if (ch === 13 && input.charCodeAt(pos) === 10) {
  5425. ++pos;
  5426. }
  5427. ++curLine;
  5428. chunkStart = lineStart = pos;
  5429. } else {
  5430. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  5431. }
  5432. } else {
  5433. ++pos;
  5434. }
  5435. }
  5436. return {
  5437. pos,
  5438. str: out,
  5439. firstInvalidLoc,
  5440. lineStart,
  5441. curLine,
  5442. containsInvalid: !!firstInvalidLoc
  5443. };
  5444. }
  5445. function isStringEnd(type, ch, input, pos) {
  5446. if (type === "template") {
  5447. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  5448. }
  5449. return ch === (type === "double" ? 34 : 39);
  5450. }
  5451. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  5452. const throwOnInvalid = !inTemplate;
  5453. pos++;
  5454. const res = ch => ({
  5455. pos,
  5456. ch,
  5457. lineStart,
  5458. curLine
  5459. });
  5460. const ch = input.charCodeAt(pos++);
  5461. switch (ch) {
  5462. case 110:
  5463. return res("\n");
  5464. case 114:
  5465. return res("\r");
  5466. case 120:
  5467. {
  5468. let code;
  5469. ({
  5470. code,
  5471. pos
  5472. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  5473. return res(code === null ? null : String.fromCharCode(code));
  5474. }
  5475. case 117:
  5476. {
  5477. let code;
  5478. ({
  5479. code,
  5480. pos
  5481. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  5482. return res(code === null ? null : String.fromCodePoint(code));
  5483. }
  5484. case 116:
  5485. return res("\t");
  5486. case 98:
  5487. return res("\b");
  5488. case 118:
  5489. return res("\u000b");
  5490. case 102:
  5491. return res("\f");
  5492. case 13:
  5493. if (input.charCodeAt(pos) === 10) {
  5494. ++pos;
  5495. }
  5496. case 10:
  5497. lineStart = pos;
  5498. ++curLine;
  5499. case 8232:
  5500. case 8233:
  5501. return res("");
  5502. case 56:
  5503. case 57:
  5504. if (inTemplate) {
  5505. return res(null);
  5506. } else {
  5507. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  5508. }
  5509. default:
  5510. if (ch >= 48 && ch <= 55) {
  5511. const startPos = pos - 1;
  5512. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  5513. let octalStr = match[0];
  5514. let octal = parseInt(octalStr, 8);
  5515. if (octal > 255) {
  5516. octalStr = octalStr.slice(0, -1);
  5517. octal = parseInt(octalStr, 8);
  5518. }
  5519. pos += octalStr.length - 1;
  5520. const next = input.charCodeAt(pos);
  5521. if (octalStr !== "0" || next === 56 || next === 57) {
  5522. if (inTemplate) {
  5523. return res(null);
  5524. } else {
  5525. errors.strictNumericEscape(startPos, lineStart, curLine);
  5526. }
  5527. }
  5528. return res(String.fromCharCode(octal));
  5529. }
  5530. return res(String.fromCharCode(ch));
  5531. }
  5532. }
  5533. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  5534. const initialPos = pos;
  5535. let n;
  5536. ({
  5537. n,
  5538. pos
  5539. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  5540. if (n === null) {
  5541. if (throwOnInvalid) {
  5542. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  5543. } else {
  5544. pos = initialPos - 1;
  5545. }
  5546. }
  5547. return {
  5548. code: n,
  5549. pos
  5550. };
  5551. }
  5552. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  5553. const start = pos;
  5554. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  5555. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  5556. let invalid = false;
  5557. let total = 0;
  5558. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  5559. const code = input.charCodeAt(pos);
  5560. let val;
  5561. if (code === 95 && allowNumSeparator !== "bail") {
  5562. const prev = input.charCodeAt(pos - 1);
  5563. const next = input.charCodeAt(pos + 1);
  5564. if (!allowNumSeparator) {
  5565. if (bailOnError) return {
  5566. n: null,
  5567. pos
  5568. };
  5569. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  5570. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  5571. if (bailOnError) return {
  5572. n: null,
  5573. pos
  5574. };
  5575. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  5576. }
  5577. ++pos;
  5578. continue;
  5579. }
  5580. if (code >= 97) {
  5581. val = code - 97 + 10;
  5582. } else if (code >= 65) {
  5583. val = code - 65 + 10;
  5584. } else if (_isDigit(code)) {
  5585. val = code - 48;
  5586. } else {
  5587. val = Infinity;
  5588. }
  5589. if (val >= radix) {
  5590. if (val <= 9 && bailOnError) {
  5591. return {
  5592. n: null,
  5593. pos
  5594. };
  5595. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  5596. val = 0;
  5597. } else if (forceLen) {
  5598. val = 0;
  5599. invalid = true;
  5600. } else {
  5601. break;
  5602. }
  5603. }
  5604. ++pos;
  5605. total = total * radix + val;
  5606. }
  5607. if (pos === start || len != null && pos - start !== len || invalid) {
  5608. return {
  5609. n: null,
  5610. pos
  5611. };
  5612. }
  5613. return {
  5614. n: total,
  5615. pos
  5616. };
  5617. }
  5618. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  5619. const ch = input.charCodeAt(pos);
  5620. let code;
  5621. if (ch === 123) {
  5622. ++pos;
  5623. ({
  5624. code,
  5625. pos
  5626. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  5627. ++pos;
  5628. if (code !== null && code > 0x10ffff) {
  5629. if (throwOnInvalid) {
  5630. errors.invalidCodePoint(pos, lineStart, curLine);
  5631. } else {
  5632. return {
  5633. code: null,
  5634. pos
  5635. };
  5636. }
  5637. }
  5638. } else {
  5639. ({
  5640. code,
  5641. pos
  5642. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  5643. }
  5644. return {
  5645. code,
  5646. pos
  5647. };
  5648. }
  5649. function buildPosition(pos, lineStart, curLine) {
  5650. return new Position(curLine, pos - lineStart, pos);
  5651. }
  5652. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  5653. class Token {
  5654. constructor(state) {
  5655. const startIndex = state.startIndex || 0;
  5656. this.type = state.type;
  5657. this.value = state.value;
  5658. this.start = startIndex + state.start;
  5659. this.end = startIndex + state.end;
  5660. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  5661. }
  5662. }
  5663. class Tokenizer extends CommentsParser {
  5664. constructor(options, input) {
  5665. super();
  5666. this.isLookahead = void 0;
  5667. this.tokens = [];
  5668. this.errorHandlers_readInt = {
  5669. invalidDigit: (pos, lineStart, curLine, radix) => {
  5670. if (!(this.optionFlags & 2048)) return false;
  5671. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  5672. radix
  5673. });
  5674. return true;
  5675. },
  5676. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  5677. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  5678. };
  5679. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  5680. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  5681. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  5682. });
  5683. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  5684. strictNumericEscape: (pos, lineStart, curLine) => {
  5685. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  5686. },
  5687. unterminated: (pos, lineStart, curLine) => {
  5688. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  5689. }
  5690. });
  5691. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  5692. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  5693. unterminated: (pos, lineStart, curLine) => {
  5694. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  5695. }
  5696. });
  5697. this.state = new State();
  5698. this.state.init(options);
  5699. this.input = input;
  5700. this.length = input.length;
  5701. this.comments = [];
  5702. this.isLookahead = false;
  5703. }
  5704. pushToken(token) {
  5705. this.tokens.length = this.state.tokensLength;
  5706. this.tokens.push(token);
  5707. ++this.state.tokensLength;
  5708. }
  5709. next() {
  5710. this.checkKeywordEscapes();
  5711. if (this.optionFlags & 256) {
  5712. this.pushToken(new Token(this.state));
  5713. }
  5714. this.state.lastTokEndLoc = this.state.endLoc;
  5715. this.state.lastTokStartLoc = this.state.startLoc;
  5716. this.nextToken();
  5717. }
  5718. eat(type) {
  5719. if (this.match(type)) {
  5720. this.next();
  5721. return true;
  5722. } else {
  5723. return false;
  5724. }
  5725. }
  5726. match(type) {
  5727. return this.state.type === type;
  5728. }
  5729. createLookaheadState(state) {
  5730. return {
  5731. pos: state.pos,
  5732. value: null,
  5733. type: state.type,
  5734. start: state.start,
  5735. end: state.end,
  5736. context: [this.curContext()],
  5737. inType: state.inType,
  5738. startLoc: state.startLoc,
  5739. lastTokEndLoc: state.lastTokEndLoc,
  5740. curLine: state.curLine,
  5741. lineStart: state.lineStart,
  5742. curPosition: state.curPosition
  5743. };
  5744. }
  5745. lookahead() {
  5746. const old = this.state;
  5747. this.state = this.createLookaheadState(old);
  5748. this.isLookahead = true;
  5749. this.nextToken();
  5750. this.isLookahead = false;
  5751. const curr = this.state;
  5752. this.state = old;
  5753. return curr;
  5754. }
  5755. nextTokenStart() {
  5756. return this.nextTokenStartSince(this.state.pos);
  5757. }
  5758. nextTokenStartSince(pos) {
  5759. skipWhiteSpace.lastIndex = pos;
  5760. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  5761. }
  5762. lookaheadCharCode() {
  5763. return this.lookaheadCharCodeSince(this.state.pos);
  5764. }
  5765. lookaheadCharCodeSince(pos) {
  5766. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  5767. }
  5768. nextTokenInLineStart() {
  5769. return this.nextTokenInLineStartSince(this.state.pos);
  5770. }
  5771. nextTokenInLineStartSince(pos) {
  5772. skipWhiteSpaceInLine.lastIndex = pos;
  5773. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  5774. }
  5775. lookaheadInLineCharCode() {
  5776. return this.input.charCodeAt(this.nextTokenInLineStart());
  5777. }
  5778. codePointAtPos(pos) {
  5779. let cp = this.input.charCodeAt(pos);
  5780. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  5781. const trail = this.input.charCodeAt(pos);
  5782. if ((trail & 0xfc00) === 0xdc00) {
  5783. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  5784. }
  5785. }
  5786. return cp;
  5787. }
  5788. setStrict(strict) {
  5789. this.state.strict = strict;
  5790. if (strict) {
  5791. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  5792. this.state.strictErrors.clear();
  5793. }
  5794. }
  5795. curContext() {
  5796. return this.state.context[this.state.context.length - 1];
  5797. }
  5798. nextToken() {
  5799. this.skipSpace();
  5800. this.state.start = this.state.pos;
  5801. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  5802. if (this.state.pos >= this.length) {
  5803. this.finishToken(140);
  5804. return;
  5805. }
  5806. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  5807. }
  5808. skipBlockComment(commentEnd) {
  5809. let startLoc;
  5810. if (!this.isLookahead) startLoc = this.state.curPosition();
  5811. const start = this.state.pos;
  5812. const end = this.input.indexOf(commentEnd, start + 2);
  5813. if (end === -1) {
  5814. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5815. }
  5816. this.state.pos = end + commentEnd.length;
  5817. lineBreakG.lastIndex = start + 2;
  5818. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  5819. ++this.state.curLine;
  5820. this.state.lineStart = lineBreakG.lastIndex;
  5821. }
  5822. if (this.isLookahead) return;
  5823. const comment = {
  5824. type: "CommentBlock",
  5825. value: this.input.slice(start + 2, end),
  5826. start: this.sourceToOffsetPos(start),
  5827. end: this.sourceToOffsetPos(end + commentEnd.length),
  5828. loc: new SourceLocation(startLoc, this.state.curPosition())
  5829. };
  5830. if (this.optionFlags & 256) this.pushToken(comment);
  5831. return comment;
  5832. }
  5833. skipLineComment(startSkip) {
  5834. const start = this.state.pos;
  5835. let startLoc;
  5836. if (!this.isLookahead) startLoc = this.state.curPosition();
  5837. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  5838. if (this.state.pos < this.length) {
  5839. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  5840. ch = this.input.charCodeAt(this.state.pos);
  5841. }
  5842. }
  5843. if (this.isLookahead) return;
  5844. const end = this.state.pos;
  5845. const value = this.input.slice(start + startSkip, end);
  5846. const comment = {
  5847. type: "CommentLine",
  5848. value,
  5849. start: this.sourceToOffsetPos(start),
  5850. end: this.sourceToOffsetPos(end),
  5851. loc: new SourceLocation(startLoc, this.state.curPosition())
  5852. };
  5853. if (this.optionFlags & 256) this.pushToken(comment);
  5854. return comment;
  5855. }
  5856. skipSpace() {
  5857. const spaceStart = this.state.pos;
  5858. const comments = this.optionFlags & 4096 ? [] : null;
  5859. loop: while (this.state.pos < this.length) {
  5860. const ch = this.input.charCodeAt(this.state.pos);
  5861. switch (ch) {
  5862. case 32:
  5863. case 160:
  5864. case 9:
  5865. ++this.state.pos;
  5866. break;
  5867. case 13:
  5868. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  5869. ++this.state.pos;
  5870. }
  5871. case 10:
  5872. case 8232:
  5873. case 8233:
  5874. ++this.state.pos;
  5875. ++this.state.curLine;
  5876. this.state.lineStart = this.state.pos;
  5877. break;
  5878. case 47:
  5879. switch (this.input.charCodeAt(this.state.pos + 1)) {
  5880. case 42:
  5881. {
  5882. const comment = this.skipBlockComment("*/");
  5883. if (comment !== undefined) {
  5884. this.addComment(comment);
  5885. comments == null || comments.push(comment);
  5886. }
  5887. break;
  5888. }
  5889. case 47:
  5890. {
  5891. const comment = this.skipLineComment(2);
  5892. if (comment !== undefined) {
  5893. this.addComment(comment);
  5894. comments == null || comments.push(comment);
  5895. }
  5896. break;
  5897. }
  5898. default:
  5899. break loop;
  5900. }
  5901. break;
  5902. default:
  5903. if (isWhitespace(ch)) {
  5904. ++this.state.pos;
  5905. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  5906. const pos = this.state.pos;
  5907. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  5908. const comment = this.skipLineComment(3);
  5909. if (comment !== undefined) {
  5910. this.addComment(comment);
  5911. comments == null || comments.push(comment);
  5912. }
  5913. } else {
  5914. break loop;
  5915. }
  5916. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  5917. const pos = this.state.pos;
  5918. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  5919. const comment = this.skipLineComment(4);
  5920. if (comment !== undefined) {
  5921. this.addComment(comment);
  5922. comments == null || comments.push(comment);
  5923. }
  5924. } else {
  5925. break loop;
  5926. }
  5927. } else {
  5928. break loop;
  5929. }
  5930. }
  5931. }
  5932. if ((comments == null ? void 0 : comments.length) > 0) {
  5933. const end = this.state.pos;
  5934. const commentWhitespace = {
  5935. start: this.sourceToOffsetPos(spaceStart),
  5936. end: this.sourceToOffsetPos(end),
  5937. comments: comments,
  5938. leadingNode: null,
  5939. trailingNode: null,
  5940. containingNode: null
  5941. };
  5942. this.state.commentStack.push(commentWhitespace);
  5943. }
  5944. }
  5945. finishToken(type, val) {
  5946. this.state.end = this.state.pos;
  5947. this.state.endLoc = this.state.curPosition();
  5948. const prevType = this.state.type;
  5949. this.state.type = type;
  5950. this.state.value = val;
  5951. if (!this.isLookahead) {
  5952. this.updateContext(prevType);
  5953. }
  5954. }
  5955. replaceToken(type) {
  5956. this.state.type = type;
  5957. this.updateContext();
  5958. }
  5959. readToken_numberSign() {
  5960. if (this.state.pos === 0 && this.readToken_interpreter()) {
  5961. return;
  5962. }
  5963. const nextPos = this.state.pos + 1;
  5964. const next = this.codePointAtPos(nextPos);
  5965. if (next >= 48 && next <= 57) {
  5966. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  5967. }
  5968. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  5969. this.expectPlugin("recordAndTuple");
  5970. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  5971. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  5972. }
  5973. this.state.pos += 2;
  5974. if (next === 123) {
  5975. this.finishToken(7);
  5976. } else {
  5977. this.finishToken(1);
  5978. }
  5979. } else if (isIdentifierStart(next)) {
  5980. ++this.state.pos;
  5981. this.finishToken(139, this.readWord1(next));
  5982. } else if (next === 92) {
  5983. ++this.state.pos;
  5984. this.finishToken(139, this.readWord1());
  5985. } else {
  5986. this.finishOp(27, 1);
  5987. }
  5988. }
  5989. readToken_dot() {
  5990. const next = this.input.charCodeAt(this.state.pos + 1);
  5991. if (next >= 48 && next <= 57) {
  5992. this.readNumber(true);
  5993. return;
  5994. }
  5995. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  5996. this.state.pos += 3;
  5997. this.finishToken(21);
  5998. } else {
  5999. ++this.state.pos;
  6000. this.finishToken(16);
  6001. }
  6002. }
  6003. readToken_slash() {
  6004. const next = this.input.charCodeAt(this.state.pos + 1);
  6005. if (next === 61) {
  6006. this.finishOp(31, 2);
  6007. } else {
  6008. this.finishOp(56, 1);
  6009. }
  6010. }
  6011. readToken_interpreter() {
  6012. if (this.state.pos !== 0 || this.length < 2) return false;
  6013. let ch = this.input.charCodeAt(this.state.pos + 1);
  6014. if (ch !== 33) return false;
  6015. const start = this.state.pos;
  6016. this.state.pos += 1;
  6017. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  6018. ch = this.input.charCodeAt(this.state.pos);
  6019. }
  6020. const value = this.input.slice(start + 2, this.state.pos);
  6021. this.finishToken(28, value);
  6022. return true;
  6023. }
  6024. readToken_mult_modulo(code) {
  6025. let type = code === 42 ? 55 : 54;
  6026. let width = 1;
  6027. let next = this.input.charCodeAt(this.state.pos + 1);
  6028. if (code === 42 && next === 42) {
  6029. width++;
  6030. next = this.input.charCodeAt(this.state.pos + 2);
  6031. type = 57;
  6032. }
  6033. if (next === 61 && !this.state.inType) {
  6034. width++;
  6035. type = code === 37 ? 33 : 30;
  6036. }
  6037. this.finishOp(type, width);
  6038. }
  6039. readToken_pipe_amp(code) {
  6040. const next = this.input.charCodeAt(this.state.pos + 1);
  6041. if (next === code) {
  6042. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  6043. this.finishOp(30, 3);
  6044. } else {
  6045. this.finishOp(code === 124 ? 41 : 42, 2);
  6046. }
  6047. return;
  6048. }
  6049. if (code === 124) {
  6050. if (next === 62) {
  6051. this.finishOp(39, 2);
  6052. return;
  6053. }
  6054. if (this.hasPlugin("recordAndTuple") && next === 125) {
  6055. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6056. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6057. }
  6058. this.state.pos += 2;
  6059. this.finishToken(9);
  6060. return;
  6061. }
  6062. if (this.hasPlugin("recordAndTuple") && next === 93) {
  6063. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6064. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  6065. }
  6066. this.state.pos += 2;
  6067. this.finishToken(4);
  6068. return;
  6069. }
  6070. }
  6071. if (next === 61) {
  6072. this.finishOp(30, 2);
  6073. return;
  6074. }
  6075. this.finishOp(code === 124 ? 43 : 45, 1);
  6076. }
  6077. readToken_caret() {
  6078. const next = this.input.charCodeAt(this.state.pos + 1);
  6079. if (next === 61 && !this.state.inType) {
  6080. this.finishOp(32, 2);
  6081. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  6082. proposal: "hack",
  6083. topicToken: "^^"
  6084. }])) {
  6085. this.finishOp(37, 2);
  6086. const lookaheadCh = this.input.codePointAt(this.state.pos);
  6087. if (lookaheadCh === 94) {
  6088. this.unexpected();
  6089. }
  6090. } else {
  6091. this.finishOp(44, 1);
  6092. }
  6093. }
  6094. readToken_atSign() {
  6095. const next = this.input.charCodeAt(this.state.pos + 1);
  6096. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  6097. proposal: "hack",
  6098. topicToken: "@@"
  6099. }])) {
  6100. this.finishOp(38, 2);
  6101. } else {
  6102. this.finishOp(26, 1);
  6103. }
  6104. }
  6105. readToken_plus_min(code) {
  6106. const next = this.input.charCodeAt(this.state.pos + 1);
  6107. if (next === code) {
  6108. this.finishOp(34, 2);
  6109. return;
  6110. }
  6111. if (next === 61) {
  6112. this.finishOp(30, 2);
  6113. } else {
  6114. this.finishOp(53, 1);
  6115. }
  6116. }
  6117. readToken_lt() {
  6118. const {
  6119. pos
  6120. } = this.state;
  6121. const next = this.input.charCodeAt(pos + 1);
  6122. if (next === 60) {
  6123. if (this.input.charCodeAt(pos + 2) === 61) {
  6124. this.finishOp(30, 3);
  6125. return;
  6126. }
  6127. this.finishOp(51, 2);
  6128. return;
  6129. }
  6130. if (next === 61) {
  6131. this.finishOp(49, 2);
  6132. return;
  6133. }
  6134. this.finishOp(47, 1);
  6135. }
  6136. readToken_gt() {
  6137. const {
  6138. pos
  6139. } = this.state;
  6140. const next = this.input.charCodeAt(pos + 1);
  6141. if (next === 62) {
  6142. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  6143. if (this.input.charCodeAt(pos + size) === 61) {
  6144. this.finishOp(30, size + 1);
  6145. return;
  6146. }
  6147. this.finishOp(52, size);
  6148. return;
  6149. }
  6150. if (next === 61) {
  6151. this.finishOp(49, 2);
  6152. return;
  6153. }
  6154. this.finishOp(48, 1);
  6155. }
  6156. readToken_eq_excl(code) {
  6157. const next = this.input.charCodeAt(this.state.pos + 1);
  6158. if (next === 61) {
  6159. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  6160. return;
  6161. }
  6162. if (code === 61 && next === 62) {
  6163. this.state.pos += 2;
  6164. this.finishToken(19);
  6165. return;
  6166. }
  6167. this.finishOp(code === 61 ? 29 : 35, 1);
  6168. }
  6169. readToken_question() {
  6170. const next = this.input.charCodeAt(this.state.pos + 1);
  6171. const next2 = this.input.charCodeAt(this.state.pos + 2);
  6172. if (next === 63) {
  6173. if (next2 === 61) {
  6174. this.finishOp(30, 3);
  6175. } else {
  6176. this.finishOp(40, 2);
  6177. }
  6178. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  6179. this.state.pos += 2;
  6180. this.finishToken(18);
  6181. } else {
  6182. ++this.state.pos;
  6183. this.finishToken(17);
  6184. }
  6185. }
  6186. getTokenFromCode(code) {
  6187. switch (code) {
  6188. case 46:
  6189. this.readToken_dot();
  6190. return;
  6191. case 40:
  6192. ++this.state.pos;
  6193. this.finishToken(10);
  6194. return;
  6195. case 41:
  6196. ++this.state.pos;
  6197. this.finishToken(11);
  6198. return;
  6199. case 59:
  6200. ++this.state.pos;
  6201. this.finishToken(13);
  6202. return;
  6203. case 44:
  6204. ++this.state.pos;
  6205. this.finishToken(12);
  6206. return;
  6207. case 91:
  6208. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6209. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6210. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6211. }
  6212. this.state.pos += 2;
  6213. this.finishToken(2);
  6214. } else {
  6215. ++this.state.pos;
  6216. this.finishToken(0);
  6217. }
  6218. return;
  6219. case 93:
  6220. ++this.state.pos;
  6221. this.finishToken(3);
  6222. return;
  6223. case 123:
  6224. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  6225. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  6226. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  6227. }
  6228. this.state.pos += 2;
  6229. this.finishToken(6);
  6230. } else {
  6231. ++this.state.pos;
  6232. this.finishToken(5);
  6233. }
  6234. return;
  6235. case 125:
  6236. ++this.state.pos;
  6237. this.finishToken(8);
  6238. return;
  6239. case 58:
  6240. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  6241. this.finishOp(15, 2);
  6242. } else {
  6243. ++this.state.pos;
  6244. this.finishToken(14);
  6245. }
  6246. return;
  6247. case 63:
  6248. this.readToken_question();
  6249. return;
  6250. case 96:
  6251. this.readTemplateToken();
  6252. return;
  6253. case 48:
  6254. {
  6255. const next = this.input.charCodeAt(this.state.pos + 1);
  6256. if (next === 120 || next === 88) {
  6257. this.readRadixNumber(16);
  6258. return;
  6259. }
  6260. if (next === 111 || next === 79) {
  6261. this.readRadixNumber(8);
  6262. return;
  6263. }
  6264. if (next === 98 || next === 66) {
  6265. this.readRadixNumber(2);
  6266. return;
  6267. }
  6268. }
  6269. case 49:
  6270. case 50:
  6271. case 51:
  6272. case 52:
  6273. case 53:
  6274. case 54:
  6275. case 55:
  6276. case 56:
  6277. case 57:
  6278. this.readNumber(false);
  6279. return;
  6280. case 34:
  6281. case 39:
  6282. this.readString(code);
  6283. return;
  6284. case 47:
  6285. this.readToken_slash();
  6286. return;
  6287. case 37:
  6288. case 42:
  6289. this.readToken_mult_modulo(code);
  6290. return;
  6291. case 124:
  6292. case 38:
  6293. this.readToken_pipe_amp(code);
  6294. return;
  6295. case 94:
  6296. this.readToken_caret();
  6297. return;
  6298. case 43:
  6299. case 45:
  6300. this.readToken_plus_min(code);
  6301. return;
  6302. case 60:
  6303. this.readToken_lt();
  6304. return;
  6305. case 62:
  6306. this.readToken_gt();
  6307. return;
  6308. case 61:
  6309. case 33:
  6310. this.readToken_eq_excl(code);
  6311. return;
  6312. case 126:
  6313. this.finishOp(36, 1);
  6314. return;
  6315. case 64:
  6316. this.readToken_atSign();
  6317. return;
  6318. case 35:
  6319. this.readToken_numberSign();
  6320. return;
  6321. case 92:
  6322. this.readWord();
  6323. return;
  6324. default:
  6325. if (isIdentifierStart(code)) {
  6326. this.readWord(code);
  6327. return;
  6328. }
  6329. }
  6330. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  6331. unexpected: String.fromCodePoint(code)
  6332. });
  6333. }
  6334. finishOp(type, size) {
  6335. const str = this.input.slice(this.state.pos, this.state.pos + size);
  6336. this.state.pos += size;
  6337. this.finishToken(type, str);
  6338. }
  6339. readRegexp() {
  6340. const startLoc = this.state.startLoc;
  6341. const start = this.state.start + 1;
  6342. let escaped, inClass;
  6343. let {
  6344. pos
  6345. } = this.state;
  6346. for (;; ++pos) {
  6347. if (pos >= this.length) {
  6348. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6349. }
  6350. const ch = this.input.charCodeAt(pos);
  6351. if (isNewLine(ch)) {
  6352. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  6353. }
  6354. if (escaped) {
  6355. escaped = false;
  6356. } else {
  6357. if (ch === 91) {
  6358. inClass = true;
  6359. } else if (ch === 93 && inClass) {
  6360. inClass = false;
  6361. } else if (ch === 47 && !inClass) {
  6362. break;
  6363. }
  6364. escaped = ch === 92;
  6365. }
  6366. }
  6367. const content = this.input.slice(start, pos);
  6368. ++pos;
  6369. let mods = "";
  6370. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  6371. while (pos < this.length) {
  6372. const cp = this.codePointAtPos(pos);
  6373. const char = String.fromCharCode(cp);
  6374. if (VALID_REGEX_FLAGS.has(cp)) {
  6375. if (cp === 118) {
  6376. if (mods.includes("u")) {
  6377. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6378. }
  6379. } else if (cp === 117) {
  6380. if (mods.includes("v")) {
  6381. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  6382. }
  6383. }
  6384. if (mods.includes(char)) {
  6385. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  6386. }
  6387. } else if (isIdentifierChar(cp) || cp === 92) {
  6388. this.raise(Errors.MalformedRegExpFlags, nextPos());
  6389. } else {
  6390. break;
  6391. }
  6392. ++pos;
  6393. mods += char;
  6394. }
  6395. this.state.pos = pos;
  6396. this.finishToken(138, {
  6397. pattern: content,
  6398. flags: mods
  6399. });
  6400. }
  6401. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  6402. const {
  6403. n,
  6404. pos
  6405. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  6406. this.state.pos = pos;
  6407. return n;
  6408. }
  6409. readRadixNumber(radix) {
  6410. const start = this.state.pos;
  6411. const startLoc = this.state.curPosition();
  6412. let isBigInt = false;
  6413. this.state.pos += 2;
  6414. const val = this.readInt(radix);
  6415. if (val == null) {
  6416. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  6417. radix
  6418. });
  6419. }
  6420. const next = this.input.charCodeAt(this.state.pos);
  6421. if (next === 110) {
  6422. ++this.state.pos;
  6423. isBigInt = true;
  6424. } else if (next === 109) {
  6425. throw this.raise(Errors.InvalidDecimal, startLoc);
  6426. }
  6427. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6428. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6429. }
  6430. if (isBigInt) {
  6431. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  6432. this.finishToken(136, str);
  6433. return;
  6434. }
  6435. this.finishToken(135, val);
  6436. }
  6437. readNumber(startsWithDot) {
  6438. const start = this.state.pos;
  6439. const startLoc = this.state.curPosition();
  6440. let isFloat = false;
  6441. let isBigInt = false;
  6442. let hasExponent = false;
  6443. let isOctal = false;
  6444. if (!startsWithDot && this.readInt(10) === null) {
  6445. this.raise(Errors.InvalidNumber, this.state.curPosition());
  6446. }
  6447. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  6448. if (hasLeadingZero) {
  6449. const integer = this.input.slice(start, this.state.pos);
  6450. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  6451. if (!this.state.strict) {
  6452. const underscorePos = integer.indexOf("_");
  6453. if (underscorePos > 0) {
  6454. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  6455. }
  6456. }
  6457. isOctal = hasLeadingZero && !/[89]/.test(integer);
  6458. }
  6459. let next = this.input.charCodeAt(this.state.pos);
  6460. if (next === 46 && !isOctal) {
  6461. ++this.state.pos;
  6462. this.readInt(10);
  6463. isFloat = true;
  6464. next = this.input.charCodeAt(this.state.pos);
  6465. }
  6466. if ((next === 69 || next === 101) && !isOctal) {
  6467. next = this.input.charCodeAt(++this.state.pos);
  6468. if (next === 43 || next === 45) {
  6469. ++this.state.pos;
  6470. }
  6471. if (this.readInt(10) === null) {
  6472. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  6473. }
  6474. isFloat = true;
  6475. hasExponent = true;
  6476. next = this.input.charCodeAt(this.state.pos);
  6477. }
  6478. if (next === 110) {
  6479. if (isFloat || hasLeadingZero) {
  6480. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  6481. }
  6482. ++this.state.pos;
  6483. isBigInt = true;
  6484. }
  6485. if (next === 109) {
  6486. this.expectPlugin("decimal", this.state.curPosition());
  6487. if (hasExponent || hasLeadingZero) {
  6488. this.raise(Errors.InvalidDecimal, startLoc);
  6489. }
  6490. ++this.state.pos;
  6491. var isDecimal = true;
  6492. }
  6493. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  6494. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  6495. }
  6496. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  6497. if (isBigInt) {
  6498. this.finishToken(136, str);
  6499. return;
  6500. }
  6501. if (isDecimal) {
  6502. this.finishToken(137, str);
  6503. return;
  6504. }
  6505. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  6506. this.finishToken(135, val);
  6507. }
  6508. readCodePoint(throwOnInvalid) {
  6509. const {
  6510. code,
  6511. pos
  6512. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  6513. this.state.pos = pos;
  6514. return code;
  6515. }
  6516. readString(quote) {
  6517. const {
  6518. str,
  6519. pos,
  6520. curLine,
  6521. lineStart
  6522. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  6523. this.state.pos = pos + 1;
  6524. this.state.lineStart = lineStart;
  6525. this.state.curLine = curLine;
  6526. this.finishToken(134, str);
  6527. }
  6528. readTemplateContinuation() {
  6529. if (!this.match(8)) {
  6530. this.unexpected(null, 8);
  6531. }
  6532. this.state.pos--;
  6533. this.readTemplateToken();
  6534. }
  6535. readTemplateToken() {
  6536. const opening = this.input[this.state.pos];
  6537. const {
  6538. str,
  6539. firstInvalidLoc,
  6540. pos,
  6541. curLine,
  6542. lineStart
  6543. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  6544. this.state.pos = pos + 1;
  6545. this.state.lineStart = lineStart;
  6546. this.state.curLine = curLine;
  6547. if (firstInvalidLoc) {
  6548. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  6549. }
  6550. if (this.input.codePointAt(pos) === 96) {
  6551. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  6552. } else {
  6553. this.state.pos++;
  6554. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  6555. }
  6556. }
  6557. recordStrictModeErrors(toParseError, at) {
  6558. const index = at.index;
  6559. if (this.state.strict && !this.state.strictErrors.has(index)) {
  6560. this.raise(toParseError, at);
  6561. } else {
  6562. this.state.strictErrors.set(index, [toParseError, at]);
  6563. }
  6564. }
  6565. readWord1(firstCode) {
  6566. this.state.containsEsc = false;
  6567. let word = "";
  6568. const start = this.state.pos;
  6569. let chunkStart = this.state.pos;
  6570. if (firstCode !== undefined) {
  6571. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  6572. }
  6573. while (this.state.pos < this.length) {
  6574. const ch = this.codePointAtPos(this.state.pos);
  6575. if (isIdentifierChar(ch)) {
  6576. this.state.pos += ch <= 0xffff ? 1 : 2;
  6577. } else if (ch === 92) {
  6578. this.state.containsEsc = true;
  6579. word += this.input.slice(chunkStart, this.state.pos);
  6580. const escStart = this.state.curPosition();
  6581. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  6582. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  6583. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  6584. chunkStart = this.state.pos - 1;
  6585. continue;
  6586. }
  6587. ++this.state.pos;
  6588. const esc = this.readCodePoint(true);
  6589. if (esc !== null) {
  6590. if (!identifierCheck(esc)) {
  6591. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  6592. }
  6593. word += String.fromCodePoint(esc);
  6594. }
  6595. chunkStart = this.state.pos;
  6596. } else {
  6597. break;
  6598. }
  6599. }
  6600. return word + this.input.slice(chunkStart, this.state.pos);
  6601. }
  6602. readWord(firstCode) {
  6603. const word = this.readWord1(firstCode);
  6604. const type = keywords$1.get(word);
  6605. if (type !== undefined) {
  6606. this.finishToken(type, tokenLabelName(type));
  6607. } else {
  6608. this.finishToken(132, word);
  6609. }
  6610. }
  6611. checkKeywordEscapes() {
  6612. const {
  6613. type
  6614. } = this.state;
  6615. if (tokenIsKeyword(type) && this.state.containsEsc) {
  6616. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  6617. reservedWord: tokenLabelName(type)
  6618. });
  6619. }
  6620. }
  6621. raise(toParseError, at, details = {}) {
  6622. const loc = at instanceof Position ? at : at.loc.start;
  6623. const error = toParseError(loc, details);
  6624. if (!(this.optionFlags & 2048)) throw error;
  6625. if (!this.isLookahead) this.state.errors.push(error);
  6626. return error;
  6627. }
  6628. raiseOverwrite(toParseError, at, details = {}) {
  6629. const loc = at instanceof Position ? at : at.loc.start;
  6630. const pos = loc.index;
  6631. const errors = this.state.errors;
  6632. for (let i = errors.length - 1; i >= 0; i--) {
  6633. const error = errors[i];
  6634. if (error.loc.index === pos) {
  6635. return errors[i] = toParseError(loc, details);
  6636. }
  6637. if (error.loc.index < pos) break;
  6638. }
  6639. return this.raise(toParseError, at, details);
  6640. }
  6641. updateContext(prevType) {}
  6642. unexpected(loc, type) {
  6643. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  6644. expected: type ? tokenLabelName(type) : null
  6645. });
  6646. }
  6647. expectPlugin(pluginName, loc) {
  6648. if (this.hasPlugin(pluginName)) {
  6649. return true;
  6650. }
  6651. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  6652. missingPlugin: [pluginName]
  6653. });
  6654. }
  6655. expectOnePlugin(pluginNames) {
  6656. if (!pluginNames.some(name => this.hasPlugin(name))) {
  6657. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  6658. missingPlugin: pluginNames
  6659. });
  6660. }
  6661. }
  6662. errorBuilder(error) {
  6663. return (pos, lineStart, curLine) => {
  6664. this.raise(error, buildPosition(pos, lineStart, curLine));
  6665. };
  6666. }
  6667. }
  6668. class ClassScope {
  6669. constructor() {
  6670. this.privateNames = new Set();
  6671. this.loneAccessors = new Map();
  6672. this.undefinedPrivateNames = new Map();
  6673. }
  6674. }
  6675. class ClassScopeHandler {
  6676. constructor(parser) {
  6677. this.parser = void 0;
  6678. this.stack = [];
  6679. this.undefinedPrivateNames = new Map();
  6680. this.parser = parser;
  6681. }
  6682. current() {
  6683. return this.stack[this.stack.length - 1];
  6684. }
  6685. enter() {
  6686. this.stack.push(new ClassScope());
  6687. }
  6688. exit() {
  6689. const oldClassScope = this.stack.pop();
  6690. const current = this.current();
  6691. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  6692. if (current) {
  6693. if (!current.undefinedPrivateNames.has(name)) {
  6694. current.undefinedPrivateNames.set(name, loc);
  6695. }
  6696. } else {
  6697. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6698. identifierName: name
  6699. });
  6700. }
  6701. }
  6702. }
  6703. declarePrivateName(name, elementType, loc) {
  6704. const {
  6705. privateNames,
  6706. loneAccessors,
  6707. undefinedPrivateNames
  6708. } = this.current();
  6709. let redefined = privateNames.has(name);
  6710. if (elementType & 3) {
  6711. const accessor = redefined && loneAccessors.get(name);
  6712. if (accessor) {
  6713. const oldStatic = accessor & 4;
  6714. const newStatic = elementType & 4;
  6715. const oldKind = accessor & 3;
  6716. const newKind = elementType & 3;
  6717. redefined = oldKind === newKind || oldStatic !== newStatic;
  6718. if (!redefined) loneAccessors.delete(name);
  6719. } else if (!redefined) {
  6720. loneAccessors.set(name, elementType);
  6721. }
  6722. }
  6723. if (redefined) {
  6724. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  6725. identifierName: name
  6726. });
  6727. }
  6728. privateNames.add(name);
  6729. undefinedPrivateNames.delete(name);
  6730. }
  6731. usePrivateName(name, loc) {
  6732. let classScope;
  6733. for (classScope of this.stack) {
  6734. if (classScope.privateNames.has(name)) return;
  6735. }
  6736. if (classScope) {
  6737. classScope.undefinedPrivateNames.set(name, loc);
  6738. } else {
  6739. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  6740. identifierName: name
  6741. });
  6742. }
  6743. }
  6744. }
  6745. class ExpressionScope {
  6746. constructor(type = 0) {
  6747. this.type = type;
  6748. }
  6749. canBeArrowParameterDeclaration() {
  6750. return this.type === 2 || this.type === 1;
  6751. }
  6752. isCertainlyParameterDeclaration() {
  6753. return this.type === 3;
  6754. }
  6755. }
  6756. class ArrowHeadParsingScope extends ExpressionScope {
  6757. constructor(type) {
  6758. super(type);
  6759. this.declarationErrors = new Map();
  6760. }
  6761. recordDeclarationError(ParsingErrorClass, at) {
  6762. const index = at.index;
  6763. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  6764. }
  6765. clearDeclarationError(index) {
  6766. this.declarationErrors.delete(index);
  6767. }
  6768. iterateErrors(iterator) {
  6769. this.declarationErrors.forEach(iterator);
  6770. }
  6771. }
  6772. class ExpressionScopeHandler {
  6773. constructor(parser) {
  6774. this.parser = void 0;
  6775. this.stack = [new ExpressionScope()];
  6776. this.parser = parser;
  6777. }
  6778. enter(scope) {
  6779. this.stack.push(scope);
  6780. }
  6781. exit() {
  6782. this.stack.pop();
  6783. }
  6784. recordParameterInitializerError(toParseError, node) {
  6785. const origin = node.loc.start;
  6786. const {
  6787. stack
  6788. } = this;
  6789. let i = stack.length - 1;
  6790. let scope = stack[i];
  6791. while (!scope.isCertainlyParameterDeclaration()) {
  6792. if (scope.canBeArrowParameterDeclaration()) {
  6793. scope.recordDeclarationError(toParseError, origin);
  6794. } else {
  6795. return;
  6796. }
  6797. scope = stack[--i];
  6798. }
  6799. this.parser.raise(toParseError, origin);
  6800. }
  6801. recordArrowParameterBindingError(error, node) {
  6802. const {
  6803. stack
  6804. } = this;
  6805. const scope = stack[stack.length - 1];
  6806. const origin = node.loc.start;
  6807. if (scope.isCertainlyParameterDeclaration()) {
  6808. this.parser.raise(error, origin);
  6809. } else if (scope.canBeArrowParameterDeclaration()) {
  6810. scope.recordDeclarationError(error, origin);
  6811. } else {
  6812. return;
  6813. }
  6814. }
  6815. recordAsyncArrowParametersError(at) {
  6816. const {
  6817. stack
  6818. } = this;
  6819. let i = stack.length - 1;
  6820. let scope = stack[i];
  6821. while (scope.canBeArrowParameterDeclaration()) {
  6822. if (scope.type === 2) {
  6823. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  6824. }
  6825. scope = stack[--i];
  6826. }
  6827. }
  6828. validateAsPattern() {
  6829. const {
  6830. stack
  6831. } = this;
  6832. const currentScope = stack[stack.length - 1];
  6833. if (!currentScope.canBeArrowParameterDeclaration()) return;
  6834. currentScope.iterateErrors(([toParseError, loc]) => {
  6835. this.parser.raise(toParseError, loc);
  6836. let i = stack.length - 2;
  6837. let scope = stack[i];
  6838. while (scope.canBeArrowParameterDeclaration()) {
  6839. scope.clearDeclarationError(loc.index);
  6840. scope = stack[--i];
  6841. }
  6842. });
  6843. }
  6844. }
  6845. function newParameterDeclarationScope() {
  6846. return new ExpressionScope(3);
  6847. }
  6848. function newArrowHeadScope() {
  6849. return new ArrowHeadParsingScope(1);
  6850. }
  6851. function newAsyncArrowScope() {
  6852. return new ArrowHeadParsingScope(2);
  6853. }
  6854. function newExpressionScope() {
  6855. return new ExpressionScope();
  6856. }
  6857. class UtilParser extends Tokenizer {
  6858. addExtra(node, key, value, enumerable = true) {
  6859. if (!node) return;
  6860. let {
  6861. extra
  6862. } = node;
  6863. if (extra == null) {
  6864. extra = {};
  6865. node.extra = extra;
  6866. }
  6867. if (enumerable) {
  6868. extra[key] = value;
  6869. } else {
  6870. Object.defineProperty(extra, key, {
  6871. enumerable,
  6872. value
  6873. });
  6874. }
  6875. }
  6876. isContextual(token) {
  6877. return this.state.type === token && !this.state.containsEsc;
  6878. }
  6879. isUnparsedContextual(nameStart, name) {
  6880. if (this.input.startsWith(name, nameStart)) {
  6881. const nextCh = this.input.charCodeAt(nameStart + name.length);
  6882. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  6883. }
  6884. return false;
  6885. }
  6886. isLookaheadContextual(name) {
  6887. const next = this.nextTokenStart();
  6888. return this.isUnparsedContextual(next, name);
  6889. }
  6890. eatContextual(token) {
  6891. if (this.isContextual(token)) {
  6892. this.next();
  6893. return true;
  6894. }
  6895. return false;
  6896. }
  6897. expectContextual(token, toParseError) {
  6898. if (!this.eatContextual(token)) {
  6899. if (toParseError != null) {
  6900. throw this.raise(toParseError, this.state.startLoc);
  6901. }
  6902. this.unexpected(null, token);
  6903. }
  6904. }
  6905. canInsertSemicolon() {
  6906. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  6907. }
  6908. hasPrecedingLineBreak() {
  6909. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  6910. }
  6911. hasFollowingLineBreak() {
  6912. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  6913. }
  6914. isLineTerminator() {
  6915. return this.eat(13) || this.canInsertSemicolon();
  6916. }
  6917. semicolon(allowAsi = true) {
  6918. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  6919. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  6920. }
  6921. expect(type, loc) {
  6922. if (!this.eat(type)) {
  6923. this.unexpected(loc, type);
  6924. }
  6925. }
  6926. tryParse(fn, oldState = this.state.clone()) {
  6927. const abortSignal = {
  6928. node: null
  6929. };
  6930. try {
  6931. const node = fn((node = null) => {
  6932. abortSignal.node = node;
  6933. throw abortSignal;
  6934. });
  6935. if (this.state.errors.length > oldState.errors.length) {
  6936. const failState = this.state;
  6937. this.state = oldState;
  6938. this.state.tokensLength = failState.tokensLength;
  6939. return {
  6940. node,
  6941. error: failState.errors[oldState.errors.length],
  6942. thrown: false,
  6943. aborted: false,
  6944. failState
  6945. };
  6946. }
  6947. return {
  6948. node: node,
  6949. error: null,
  6950. thrown: false,
  6951. aborted: false,
  6952. failState: null
  6953. };
  6954. } catch (error) {
  6955. const failState = this.state;
  6956. this.state = oldState;
  6957. if (error instanceof SyntaxError) {
  6958. return {
  6959. node: null,
  6960. error,
  6961. thrown: true,
  6962. aborted: false,
  6963. failState
  6964. };
  6965. }
  6966. if (error === abortSignal) {
  6967. return {
  6968. node: abortSignal.node,
  6969. error: null,
  6970. thrown: false,
  6971. aborted: true,
  6972. failState
  6973. };
  6974. }
  6975. throw error;
  6976. }
  6977. }
  6978. checkExpressionErrors(refExpressionErrors, andThrow) {
  6979. if (!refExpressionErrors) return false;
  6980. const {
  6981. shorthandAssignLoc,
  6982. doubleProtoLoc,
  6983. privateKeyLoc,
  6984. optionalParametersLoc,
  6985. voidPatternLoc
  6986. } = refExpressionErrors;
  6987. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
  6988. if (!andThrow) {
  6989. return hasErrors;
  6990. }
  6991. if (shorthandAssignLoc != null) {
  6992. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  6993. }
  6994. if (doubleProtoLoc != null) {
  6995. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  6996. }
  6997. if (privateKeyLoc != null) {
  6998. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  6999. }
  7000. if (optionalParametersLoc != null) {
  7001. this.unexpected(optionalParametersLoc);
  7002. }
  7003. if (voidPatternLoc != null) {
  7004. this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
  7005. }
  7006. }
  7007. isLiteralPropertyName() {
  7008. return tokenIsLiteralPropertyName(this.state.type);
  7009. }
  7010. isPrivateName(node) {
  7011. return node.type === "PrivateName";
  7012. }
  7013. getPrivateNameSV(node) {
  7014. return node.id.name;
  7015. }
  7016. hasPropertyAsPrivateName(node) {
  7017. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  7018. }
  7019. isObjectProperty(node) {
  7020. return node.type === "ObjectProperty";
  7021. }
  7022. isObjectMethod(node) {
  7023. return node.type === "ObjectMethod";
  7024. }
  7025. initializeScopes(inModule = this.options.sourceType === "module") {
  7026. const oldLabels = this.state.labels;
  7027. this.state.labels = [];
  7028. const oldExportedIdentifiers = this.exportedIdentifiers;
  7029. this.exportedIdentifiers = new Set();
  7030. const oldInModule = this.inModule;
  7031. this.inModule = inModule;
  7032. const oldScope = this.scope;
  7033. const ScopeHandler = this.getScopeHandler();
  7034. this.scope = new ScopeHandler(this, inModule);
  7035. const oldProdParam = this.prodParam;
  7036. this.prodParam = new ProductionParameterHandler();
  7037. const oldClassScope = this.classScope;
  7038. this.classScope = new ClassScopeHandler(this);
  7039. const oldExpressionScope = this.expressionScope;
  7040. this.expressionScope = new ExpressionScopeHandler(this);
  7041. return () => {
  7042. this.state.labels = oldLabels;
  7043. this.exportedIdentifiers = oldExportedIdentifiers;
  7044. this.inModule = oldInModule;
  7045. this.scope = oldScope;
  7046. this.prodParam = oldProdParam;
  7047. this.classScope = oldClassScope;
  7048. this.expressionScope = oldExpressionScope;
  7049. };
  7050. }
  7051. enterInitialScopes() {
  7052. let paramFlags = 0;
  7053. if (this.inModule || this.optionFlags & 1) {
  7054. paramFlags |= 2;
  7055. }
  7056. if (this.optionFlags & 32) {
  7057. paramFlags |= 1;
  7058. }
  7059. const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
  7060. if (isCommonJS || this.optionFlags & 2) {
  7061. paramFlags |= 4;
  7062. }
  7063. this.prodParam.enter(paramFlags);
  7064. let scopeFlags = isCommonJS ? 514 : 1;
  7065. if (this.optionFlags & 4) {
  7066. scopeFlags |= 512;
  7067. }
  7068. this.scope.enter(scopeFlags);
  7069. }
  7070. checkDestructuringPrivate(refExpressionErrors) {
  7071. const {
  7072. privateKeyLoc
  7073. } = refExpressionErrors;
  7074. if (privateKeyLoc !== null) {
  7075. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  7076. }
  7077. }
  7078. }
  7079. class ExpressionErrors {
  7080. constructor() {
  7081. this.shorthandAssignLoc = null;
  7082. this.doubleProtoLoc = null;
  7083. this.privateKeyLoc = null;
  7084. this.optionalParametersLoc = null;
  7085. this.voidPatternLoc = null;
  7086. }
  7087. }
  7088. class Node {
  7089. constructor(parser, pos, loc) {
  7090. this.type = "";
  7091. this.start = pos;
  7092. this.end = 0;
  7093. this.loc = new SourceLocation(loc);
  7094. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  7095. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  7096. }
  7097. }
  7098. const NodePrototype = Node.prototype;
  7099. {
  7100. NodePrototype.__clone = function () {
  7101. const newNode = new Node(undefined, this.start, this.loc.start);
  7102. const keys = Object.keys(this);
  7103. for (let i = 0, length = keys.length; i < length; i++) {
  7104. const key = keys[i];
  7105. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  7106. newNode[key] = this[key];
  7107. }
  7108. }
  7109. return newNode;
  7110. };
  7111. }
  7112. class NodeUtils extends UtilParser {
  7113. startNode() {
  7114. const loc = this.state.startLoc;
  7115. return new Node(this, loc.index, loc);
  7116. }
  7117. startNodeAt(loc) {
  7118. return new Node(this, loc.index, loc);
  7119. }
  7120. startNodeAtNode(type) {
  7121. return this.startNodeAt(type.loc.start);
  7122. }
  7123. finishNode(node, type) {
  7124. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  7125. }
  7126. finishNodeAt(node, type, endLoc) {
  7127. node.type = type;
  7128. node.end = endLoc.index;
  7129. node.loc.end = endLoc;
  7130. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7131. if (this.optionFlags & 4096) {
  7132. this.processComment(node);
  7133. }
  7134. return node;
  7135. }
  7136. resetStartLocation(node, startLoc) {
  7137. node.start = startLoc.index;
  7138. node.loc.start = startLoc;
  7139. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  7140. }
  7141. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  7142. node.end = endLoc.index;
  7143. node.loc.end = endLoc;
  7144. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  7145. }
  7146. resetStartLocationFromNode(node, locationNode) {
  7147. this.resetStartLocation(node, locationNode.loc.start);
  7148. }
  7149. castNodeTo(node, type) {
  7150. node.type = type;
  7151. return node;
  7152. }
  7153. cloneIdentifier(node) {
  7154. const {
  7155. type,
  7156. start,
  7157. end,
  7158. loc,
  7159. range,
  7160. name
  7161. } = node;
  7162. const cloned = Object.create(NodePrototype);
  7163. cloned.type = type;
  7164. cloned.start = start;
  7165. cloned.end = end;
  7166. cloned.loc = loc;
  7167. cloned.range = range;
  7168. cloned.name = name;
  7169. if (node.extra) cloned.extra = node.extra;
  7170. return cloned;
  7171. }
  7172. cloneStringLiteral(node) {
  7173. const {
  7174. type,
  7175. start,
  7176. end,
  7177. loc,
  7178. range,
  7179. extra
  7180. } = node;
  7181. const cloned = Object.create(NodePrototype);
  7182. cloned.type = type;
  7183. cloned.start = start;
  7184. cloned.end = end;
  7185. cloned.loc = loc;
  7186. cloned.range = range;
  7187. cloned.extra = extra;
  7188. cloned.value = node.value;
  7189. return cloned;
  7190. }
  7191. }
  7192. const unwrapParenthesizedExpression = node => {
  7193. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7194. };
  7195. class LValParser extends NodeUtils {
  7196. toAssignable(node, isLHS = false) {
  7197. var _node$extra, _node$extra3;
  7198. let parenthesized = undefined;
  7199. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7200. parenthesized = unwrapParenthesizedExpression(node);
  7201. if (isLHS) {
  7202. if (parenthesized.type === "Identifier") {
  7203. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7204. } else if (parenthesized.type !== "CallExpression" && parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7205. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7206. }
  7207. } else {
  7208. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7209. }
  7210. }
  7211. switch (node.type) {
  7212. case "Identifier":
  7213. case "ObjectPattern":
  7214. case "ArrayPattern":
  7215. case "AssignmentPattern":
  7216. case "RestElement":
  7217. case "VoidPattern":
  7218. break;
  7219. case "ObjectExpression":
  7220. this.castNodeTo(node, "ObjectPattern");
  7221. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7222. var _node$extra2;
  7223. const prop = node.properties[i];
  7224. const isLast = i === last;
  7225. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7226. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7227. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7228. }
  7229. }
  7230. break;
  7231. case "ObjectProperty":
  7232. {
  7233. const {
  7234. key,
  7235. value
  7236. } = node;
  7237. if (this.isPrivateName(key)) {
  7238. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7239. }
  7240. this.toAssignable(value, isLHS);
  7241. break;
  7242. }
  7243. case "SpreadElement":
  7244. {
  7245. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7246. }
  7247. case "ArrayExpression":
  7248. this.castNodeTo(node, "ArrayPattern");
  7249. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7250. break;
  7251. case "AssignmentExpression":
  7252. if (node.operator !== "=") {
  7253. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7254. }
  7255. this.castNodeTo(node, "AssignmentPattern");
  7256. delete node.operator;
  7257. if (node.left.type === "VoidPattern") {
  7258. this.raise(Errors.VoidPatternInitializer, node.left);
  7259. }
  7260. this.toAssignable(node.left, isLHS);
  7261. break;
  7262. case "ParenthesizedExpression":
  7263. this.toAssignable(parenthesized, isLHS);
  7264. break;
  7265. }
  7266. }
  7267. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7268. if (prop.type === "ObjectMethod") {
  7269. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7270. } else if (prop.type === "SpreadElement") {
  7271. this.castNodeTo(prop, "RestElement");
  7272. const arg = prop.argument;
  7273. this.checkToRestConversion(arg, false);
  7274. this.toAssignable(arg, isLHS);
  7275. if (!isLast) {
  7276. this.raise(Errors.RestTrailingComma, prop);
  7277. }
  7278. } else {
  7279. this.toAssignable(prop, isLHS);
  7280. }
  7281. }
  7282. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7283. const end = exprList.length - 1;
  7284. for (let i = 0; i <= end; i++) {
  7285. const elt = exprList[i];
  7286. if (!elt) continue;
  7287. this.toAssignableListItem(exprList, i, isLHS);
  7288. if (elt.type === "RestElement") {
  7289. if (i < end) {
  7290. this.raise(Errors.RestTrailingComma, elt);
  7291. } else if (trailingCommaLoc) {
  7292. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7293. }
  7294. }
  7295. }
  7296. }
  7297. toAssignableListItem(exprList, index, isLHS) {
  7298. const node = exprList[index];
  7299. if (node.type === "SpreadElement") {
  7300. this.castNodeTo(node, "RestElement");
  7301. const arg = node.argument;
  7302. this.checkToRestConversion(arg, true);
  7303. this.toAssignable(arg, isLHS);
  7304. } else {
  7305. this.toAssignable(node, isLHS);
  7306. }
  7307. }
  7308. isAssignable(node, isBinding) {
  7309. switch (node.type) {
  7310. case "Identifier":
  7311. case "ObjectPattern":
  7312. case "ArrayPattern":
  7313. case "AssignmentPattern":
  7314. case "RestElement":
  7315. case "VoidPattern":
  7316. return true;
  7317. case "ObjectExpression":
  7318. {
  7319. const last = node.properties.length - 1;
  7320. return node.properties.every((prop, i) => {
  7321. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7322. });
  7323. }
  7324. case "ObjectProperty":
  7325. return this.isAssignable(node.value);
  7326. case "SpreadElement":
  7327. return this.isAssignable(node.argument);
  7328. case "ArrayExpression":
  7329. return node.elements.every(element => element === null || this.isAssignable(element));
  7330. case "AssignmentExpression":
  7331. return node.operator === "=";
  7332. case "ParenthesizedExpression":
  7333. return this.isAssignable(node.expression);
  7334. case "MemberExpression":
  7335. case "OptionalMemberExpression":
  7336. return !isBinding;
  7337. default:
  7338. return false;
  7339. }
  7340. }
  7341. toReferencedList(exprList, isParenthesizedExpr) {
  7342. return exprList;
  7343. }
  7344. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7345. this.toReferencedList(exprList, isParenthesizedExpr);
  7346. for (const expr of exprList) {
  7347. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7348. this.toReferencedListDeep(expr.elements);
  7349. }
  7350. }
  7351. }
  7352. parseSpread(refExpressionErrors) {
  7353. const node = this.startNode();
  7354. this.next();
  7355. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7356. return this.finishNode(node, "SpreadElement");
  7357. }
  7358. parseRestBinding() {
  7359. const node = this.startNode();
  7360. this.next();
  7361. const argument = this.parseBindingAtom();
  7362. if (argument.type === "VoidPattern") {
  7363. this.raise(Errors.UnexpectedVoidPattern, argument);
  7364. }
  7365. node.argument = argument;
  7366. return this.finishNode(node, "RestElement");
  7367. }
  7368. parseBindingAtom() {
  7369. switch (this.state.type) {
  7370. case 0:
  7371. {
  7372. const node = this.startNode();
  7373. this.next();
  7374. node.elements = this.parseBindingList(3, 93, 1);
  7375. return this.finishNode(node, "ArrayPattern");
  7376. }
  7377. case 5:
  7378. return this.parseObjectLike(8, true);
  7379. case 88:
  7380. return this.parseVoidPattern(null);
  7381. }
  7382. return this.parseIdentifier();
  7383. }
  7384. parseBindingList(close, closeCharCode, flags) {
  7385. const allowEmpty = flags & 1;
  7386. const elts = [];
  7387. let first = true;
  7388. while (!this.eat(close)) {
  7389. if (first) {
  7390. first = false;
  7391. } else {
  7392. this.expect(12);
  7393. }
  7394. if (allowEmpty && this.match(12)) {
  7395. elts.push(null);
  7396. } else if (this.eat(close)) {
  7397. break;
  7398. } else if (this.match(21)) {
  7399. let rest = this.parseRestBinding();
  7400. if (this.hasPlugin("flow") || flags & 2) {
  7401. rest = this.parseFunctionParamType(rest);
  7402. }
  7403. elts.push(rest);
  7404. if (!this.checkCommaAfterRest(closeCharCode)) {
  7405. this.expect(close);
  7406. break;
  7407. }
  7408. } else {
  7409. const decorators = [];
  7410. if (flags & 2) {
  7411. if (this.match(26) && this.hasPlugin("decorators")) {
  7412. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7413. }
  7414. while (this.match(26)) {
  7415. decorators.push(this.parseDecorator());
  7416. }
  7417. }
  7418. elts.push(this.parseBindingElement(flags, decorators));
  7419. }
  7420. }
  7421. return elts;
  7422. }
  7423. parseBindingRestProperty(prop) {
  7424. this.next();
  7425. if (this.hasPlugin("discardBinding") && this.match(88)) {
  7426. prop.argument = this.parseVoidPattern(null);
  7427. this.raise(Errors.UnexpectedVoidPattern, prop.argument);
  7428. } else {
  7429. prop.argument = this.parseIdentifier();
  7430. }
  7431. this.checkCommaAfterRest(125);
  7432. return this.finishNode(prop, "RestElement");
  7433. }
  7434. parseBindingProperty() {
  7435. const {
  7436. type,
  7437. startLoc
  7438. } = this.state;
  7439. if (type === 21) {
  7440. return this.parseBindingRestProperty(this.startNode());
  7441. }
  7442. const prop = this.startNode();
  7443. if (type === 139) {
  7444. this.expectPlugin("destructuringPrivate", startLoc);
  7445. this.classScope.usePrivateName(this.state.value, startLoc);
  7446. prop.key = this.parsePrivateName();
  7447. } else {
  7448. this.parsePropertyName(prop);
  7449. }
  7450. prop.method = false;
  7451. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7452. }
  7453. parseBindingElement(flags, decorators) {
  7454. const left = this.parseMaybeDefault();
  7455. if (this.hasPlugin("flow") || flags & 2) {
  7456. this.parseFunctionParamType(left);
  7457. }
  7458. if (decorators.length) {
  7459. left.decorators = decorators;
  7460. this.resetStartLocationFromNode(left, decorators[0]);
  7461. }
  7462. const elt = this.parseMaybeDefault(left.loc.start, left);
  7463. return elt;
  7464. }
  7465. parseFunctionParamType(param) {
  7466. return param;
  7467. }
  7468. parseMaybeDefault(startLoc, left) {
  7469. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  7470. left = left != null ? left : this.parseBindingAtom();
  7471. if (!this.eat(29)) return left;
  7472. const node = this.startNodeAt(startLoc);
  7473. if (left.type === "VoidPattern") {
  7474. this.raise(Errors.VoidPatternInitializer, left);
  7475. }
  7476. node.left = left;
  7477. node.right = this.parseMaybeAssignAllowIn();
  7478. return this.finishNode(node, "AssignmentPattern");
  7479. }
  7480. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  7481. switch (type) {
  7482. case "AssignmentPattern":
  7483. return "left";
  7484. case "RestElement":
  7485. return "argument";
  7486. case "ObjectProperty":
  7487. return "value";
  7488. case "ParenthesizedExpression":
  7489. return "expression";
  7490. case "ArrayPattern":
  7491. return "elements";
  7492. case "ObjectPattern":
  7493. return "properties";
  7494. case "VoidPattern":
  7495. return true;
  7496. case "CallExpression":
  7497. if (!disallowCallExpression && !this.state.strict && this.optionFlags & 8192) {
  7498. return true;
  7499. }
  7500. }
  7501. return false;
  7502. }
  7503. isOptionalMemberExpression(expression) {
  7504. return expression.type === "OptionalMemberExpression";
  7505. }
  7506. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false, disallowCallExpression = false) {
  7507. var _expression$extra;
  7508. const type = expression.type;
  7509. if (this.isObjectMethod(expression)) return;
  7510. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7511. if (isOptionalMemberExpression || type === "MemberExpression") {
  7512. if (isOptionalMemberExpression) {
  7513. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7514. if (ancestor.type !== "AssignmentExpression") {
  7515. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7516. ancestor
  7517. });
  7518. }
  7519. }
  7520. if (binding !== 64) {
  7521. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7522. }
  7523. return;
  7524. }
  7525. if (type === "Identifier") {
  7526. this.checkIdentifier(expression, binding, strictModeChanged);
  7527. const {
  7528. name
  7529. } = expression;
  7530. if (checkClashes) {
  7531. if (checkClashes.has(name)) {
  7532. this.raise(Errors.ParamDupe, expression);
  7533. } else {
  7534. checkClashes.add(name);
  7535. }
  7536. }
  7537. return;
  7538. } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
  7539. this.raise(Errors.VoidPatternCatchClauseParam, expression);
  7540. }
  7541. const unwrappedExpression = unwrapParenthesizedExpression(expression);
  7542. disallowCallExpression || (disallowCallExpression = unwrappedExpression.type === "CallExpression" && (unwrappedExpression.callee.type === "Import" || unwrappedExpression.callee.type === "Super"));
  7543. const validity = this.isValidLVal(type, disallowCallExpression, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7544. if (validity === true) return;
  7545. if (validity === false) {
  7546. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7547. this.raise(ParseErrorClass, expression, {
  7548. ancestor
  7549. });
  7550. return;
  7551. }
  7552. let key, isParenthesizedExpression;
  7553. if (typeof validity === "string") {
  7554. key = validity;
  7555. isParenthesizedExpression = type === "ParenthesizedExpression";
  7556. } else {
  7557. [key, isParenthesizedExpression] = validity;
  7558. }
  7559. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7560. type
  7561. } : ancestor;
  7562. const val = expression[key];
  7563. if (Array.isArray(val)) {
  7564. for (const child of val) {
  7565. if (child) {
  7566. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, true);
  7567. }
  7568. }
  7569. } else if (val) {
  7570. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, disallowCallExpression);
  7571. }
  7572. }
  7573. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7574. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7575. if (bindingType === 64) {
  7576. this.raise(Errors.StrictEvalArguments, at, {
  7577. referenceName: at.name
  7578. });
  7579. } else {
  7580. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  7581. bindingName: at.name
  7582. });
  7583. }
  7584. }
  7585. if (bindingType & 8192 && at.name === "let") {
  7586. this.raise(Errors.LetInLexicalBinding, at);
  7587. }
  7588. if (!(bindingType & 64)) {
  7589. this.declareNameFromIdentifier(at, bindingType);
  7590. }
  7591. }
  7592. declareNameFromIdentifier(identifier, binding) {
  7593. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7594. }
  7595. checkToRestConversion(node, allowPattern) {
  7596. switch (node.type) {
  7597. case "ParenthesizedExpression":
  7598. this.checkToRestConversion(node.expression, allowPattern);
  7599. break;
  7600. case "Identifier":
  7601. case "MemberExpression":
  7602. break;
  7603. case "ArrayExpression":
  7604. case "ObjectExpression":
  7605. if (allowPattern) break;
  7606. default:
  7607. this.raise(Errors.InvalidRestAssignmentPattern, node);
  7608. }
  7609. }
  7610. checkCommaAfterRest(close) {
  7611. if (!this.match(12)) {
  7612. return false;
  7613. }
  7614. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  7615. return true;
  7616. }
  7617. }
  7618. const keywordAndTSRelationalOperator = /in(?:stanceof)?|as|satisfies/y;
  7619. function nonNull(x) {
  7620. if (x == null) {
  7621. throw new Error(`Unexpected ${x} value.`);
  7622. }
  7623. return x;
  7624. }
  7625. function assert(x) {
  7626. if (!x) {
  7627. throw new Error("Assert fail");
  7628. }
  7629. }
  7630. const TSErrors = ParseErrorEnum`typescript`({
  7631. AbstractMethodHasImplementation: ({
  7632. methodName
  7633. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7634. AbstractPropertyHasInitializer: ({
  7635. propertyName
  7636. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7637. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7638. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7639. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7640. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7641. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7642. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7643. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7644. DeclareAccessor: ({
  7645. kind
  7646. }) => `'declare' is not allowed in ${kind}ters.`,
  7647. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7648. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7649. DuplicateAccessibilityModifier: ({
  7650. modifier
  7651. }) => `Accessibility modifier already seen: '${modifier}'.`,
  7652. DuplicateModifier: ({
  7653. modifier
  7654. }) => `Duplicate modifier: '${modifier}'.`,
  7655. EmptyHeritageClauseType: ({
  7656. token
  7657. }) => `'${token}' list cannot be empty.`,
  7658. EmptyTypeArguments: "Type argument list cannot be empty.",
  7659. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7660. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7661. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7662. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7663. IncompatibleModifiers: ({
  7664. modifiers
  7665. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7666. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7667. IndexSignatureHasAccessibility: ({
  7668. modifier
  7669. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7670. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7671. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7672. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7673. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7674. InvalidHeritageClauseType: ({
  7675. token
  7676. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  7677. InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
  7678. InvalidModifierOnTypeMember: ({
  7679. modifier
  7680. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7681. InvalidModifierOnTypeParameter: ({
  7682. modifier
  7683. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7684. InvalidModifierOnTypeParameterPositions: ({
  7685. modifier
  7686. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7687. InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
  7688. InvalidModifiersOrder: ({
  7689. orderedModifiers
  7690. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7691. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7692. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7693. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7694. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7695. NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7696. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7697. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7698. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7699. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7700. PrivateElementHasAccessibility: ({
  7701. modifier
  7702. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7703. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7704. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7705. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7706. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7707. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7708. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7709. SingleTypeParameterWithoutTrailingComma: ({
  7710. typeParameterName
  7711. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7712. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7713. 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?`).",
  7714. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7715. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7716. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7717. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7718. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7719. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7720. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7721. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7722. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7723. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7724. UnsupportedSignatureParameterKind: ({
  7725. type
  7726. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
  7727. UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
  7728. });
  7729. function keywordTypeFromName(value) {
  7730. switch (value) {
  7731. case "any":
  7732. return "TSAnyKeyword";
  7733. case "boolean":
  7734. return "TSBooleanKeyword";
  7735. case "bigint":
  7736. return "TSBigIntKeyword";
  7737. case "never":
  7738. return "TSNeverKeyword";
  7739. case "number":
  7740. return "TSNumberKeyword";
  7741. case "object":
  7742. return "TSObjectKeyword";
  7743. case "string":
  7744. return "TSStringKeyword";
  7745. case "symbol":
  7746. return "TSSymbolKeyword";
  7747. case "undefined":
  7748. return "TSUndefinedKeyword";
  7749. case "unknown":
  7750. return "TSUnknownKeyword";
  7751. default:
  7752. return undefined;
  7753. }
  7754. }
  7755. function tsIsAccessModifier(modifier) {
  7756. return modifier === "private" || modifier === "public" || modifier === "protected";
  7757. }
  7758. function tsIsVarianceAnnotations(modifier) {
  7759. return modifier === "in" || modifier === "out";
  7760. }
  7761. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7762. constructor(...args) {
  7763. super(...args);
  7764. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7765. allowedModifiers: ["in", "out"],
  7766. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7767. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7768. });
  7769. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7770. allowedModifiers: ["const"],
  7771. disallowedModifiers: ["in", "out"],
  7772. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7773. });
  7774. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7775. allowedModifiers: ["in", "out", "const"],
  7776. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7777. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7778. });
  7779. }
  7780. getScopeHandler() {
  7781. return TypeScriptScopeHandler;
  7782. }
  7783. tsIsIdentifier() {
  7784. return tokenIsIdentifier(this.state.type);
  7785. }
  7786. tsTokenCanFollowModifier() {
  7787. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  7788. }
  7789. tsNextTokenOnSameLineAndCanFollowModifier() {
  7790. this.next();
  7791. if (this.hasPrecedingLineBreak()) {
  7792. return false;
  7793. }
  7794. return this.tsTokenCanFollowModifier();
  7795. }
  7796. tsNextTokenCanFollowModifier() {
  7797. if (this.match(106)) {
  7798. this.next();
  7799. return this.tsTokenCanFollowModifier();
  7800. }
  7801. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  7802. }
  7803. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
  7804. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7805. return undefined;
  7806. }
  7807. const modifier = this.state.value;
  7808. if (allowedModifiers.includes(modifier)) {
  7809. if (hasSeenStaticModifier && this.match(106)) {
  7810. return undefined;
  7811. }
  7812. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7813. return undefined;
  7814. }
  7815. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7816. return modifier;
  7817. }
  7818. }
  7819. return undefined;
  7820. }
  7821. tsParseModifiers({
  7822. allowedModifiers,
  7823. disallowedModifiers,
  7824. stopOnStartOfClassStaticBlock,
  7825. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7826. }, modified) {
  7827. const enforceOrder = (loc, modifier, before, after) => {
  7828. if (modifier === before && modified[after]) {
  7829. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7830. orderedModifiers: [before, after]
  7831. });
  7832. }
  7833. };
  7834. const incompatible = (loc, modifier, mod1, mod2) => {
  7835. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7836. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7837. modifiers: [mod1, mod2]
  7838. });
  7839. }
  7840. };
  7841. for (;;) {
  7842. const {
  7843. startLoc
  7844. } = this.state;
  7845. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
  7846. if (!modifier) break;
  7847. if (tsIsAccessModifier(modifier)) {
  7848. if (modified.accessibility) {
  7849. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7850. modifier
  7851. });
  7852. } else {
  7853. enforceOrder(startLoc, modifier, modifier, "override");
  7854. enforceOrder(startLoc, modifier, modifier, "static");
  7855. enforceOrder(startLoc, modifier, modifier, "readonly");
  7856. modified.accessibility = modifier;
  7857. }
  7858. } else if (tsIsVarianceAnnotations(modifier)) {
  7859. if (modified[modifier]) {
  7860. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7861. modifier
  7862. });
  7863. }
  7864. modified[modifier] = true;
  7865. enforceOrder(startLoc, modifier, "in", "out");
  7866. } else {
  7867. if (hasOwnProperty.call(modified, modifier)) {
  7868. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7869. modifier
  7870. });
  7871. } else {
  7872. enforceOrder(startLoc, modifier, "static", "readonly");
  7873. enforceOrder(startLoc, modifier, "static", "override");
  7874. enforceOrder(startLoc, modifier, "override", "readonly");
  7875. enforceOrder(startLoc, modifier, "abstract", "override");
  7876. incompatible(startLoc, modifier, "declare", "override");
  7877. incompatible(startLoc, modifier, "static", "abstract");
  7878. }
  7879. modified[modifier] = true;
  7880. }
  7881. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7882. this.raise(errorTemplate, startLoc, {
  7883. modifier
  7884. });
  7885. }
  7886. }
  7887. }
  7888. tsIsListTerminator(kind) {
  7889. switch (kind) {
  7890. case "EnumMembers":
  7891. case "TypeMembers":
  7892. return this.match(8);
  7893. case "HeritageClauseElement":
  7894. return this.match(5);
  7895. case "TupleElementTypes":
  7896. return this.match(3);
  7897. case "TypeParametersOrArguments":
  7898. return this.match(48);
  7899. }
  7900. }
  7901. tsParseList(kind, parseElement) {
  7902. const result = [];
  7903. while (!this.tsIsListTerminator(kind)) {
  7904. result.push(parseElement());
  7905. }
  7906. return result;
  7907. }
  7908. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7909. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7910. }
  7911. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7912. const result = [];
  7913. let trailingCommaPos = -1;
  7914. for (;;) {
  7915. if (this.tsIsListTerminator(kind)) {
  7916. break;
  7917. }
  7918. trailingCommaPos = -1;
  7919. const element = parseElement();
  7920. if (element == null) {
  7921. return undefined;
  7922. }
  7923. result.push(element);
  7924. if (this.eat(12)) {
  7925. trailingCommaPos = this.state.lastTokStartLoc.index;
  7926. continue;
  7927. }
  7928. if (this.tsIsListTerminator(kind)) {
  7929. break;
  7930. }
  7931. if (expectSuccess) {
  7932. this.expect(12);
  7933. }
  7934. return undefined;
  7935. }
  7936. if (refTrailingCommaPos) {
  7937. refTrailingCommaPos.value = trailingCommaPos;
  7938. }
  7939. return result;
  7940. }
  7941. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7942. if (!skipFirstToken) {
  7943. if (bracket) {
  7944. this.expect(0);
  7945. } else {
  7946. this.expect(47);
  7947. }
  7948. }
  7949. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7950. if (bracket) {
  7951. this.expect(3);
  7952. } else {
  7953. this.expect(48);
  7954. }
  7955. return result;
  7956. }
  7957. tsParseImportType() {
  7958. const node = this.startNode();
  7959. this.expect(83);
  7960. this.expect(10);
  7961. if (!this.match(134)) {
  7962. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7963. {
  7964. node.argument = super.parseExprAtom();
  7965. }
  7966. } else {
  7967. {
  7968. node.argument = this.parseStringLiteral(this.state.value);
  7969. }
  7970. }
  7971. if (this.eat(12)) {
  7972. node.options = this.tsParseImportTypeOptions();
  7973. } else {
  7974. node.options = null;
  7975. }
  7976. this.expect(11);
  7977. if (this.eat(16)) {
  7978. node.qualifier = this.tsParseEntityName(1 | 2);
  7979. }
  7980. if (this.match(47)) {
  7981. {
  7982. node.typeParameters = this.tsParseTypeArguments();
  7983. }
  7984. }
  7985. return this.finishNode(node, "TSImportType");
  7986. }
  7987. tsParseImportTypeOptions() {
  7988. const node = this.startNode();
  7989. this.expect(5);
  7990. const withProperty = this.startNode();
  7991. if (this.isContextual(76)) {
  7992. withProperty.method = false;
  7993. withProperty.key = this.parseIdentifier(true);
  7994. withProperty.computed = false;
  7995. withProperty.shorthand = false;
  7996. } else {
  7997. this.unexpected(null, 76);
  7998. }
  7999. this.expect(14);
  8000. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  8001. node.properties = [this.finishObjectProperty(withProperty)];
  8002. this.eat(12);
  8003. this.expect(8);
  8004. return this.finishNode(node, "ObjectExpression");
  8005. }
  8006. tsParseImportTypeWithPropertyValue() {
  8007. const node = this.startNode();
  8008. const properties = [];
  8009. this.expect(5);
  8010. while (!this.match(8)) {
  8011. const type = this.state.type;
  8012. if (tokenIsIdentifier(type) || type === 134) {
  8013. properties.push(super.parsePropertyDefinition(null));
  8014. } else {
  8015. this.unexpected();
  8016. }
  8017. this.eat(12);
  8018. }
  8019. node.properties = properties;
  8020. this.next();
  8021. return this.finishNode(node, "ObjectExpression");
  8022. }
  8023. tsParseEntityName(flags) {
  8024. let entity;
  8025. if (flags & 1 && this.match(78)) {
  8026. if (flags & 2) {
  8027. entity = this.parseIdentifier(true);
  8028. } else {
  8029. const node = this.startNode();
  8030. this.next();
  8031. entity = this.finishNode(node, "ThisExpression");
  8032. }
  8033. } else {
  8034. entity = this.parseIdentifier(!!(flags & 1));
  8035. }
  8036. while (this.eat(16)) {
  8037. const node = this.startNodeAtNode(entity);
  8038. node.left = entity;
  8039. node.right = this.parseIdentifier(!!(flags & 1));
  8040. entity = this.finishNode(node, "TSQualifiedName");
  8041. }
  8042. return entity;
  8043. }
  8044. tsParseTypeReference() {
  8045. const node = this.startNode();
  8046. node.typeName = this.tsParseEntityName(1);
  8047. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8048. {
  8049. node.typeParameters = this.tsParseTypeArguments();
  8050. }
  8051. }
  8052. return this.finishNode(node, "TSTypeReference");
  8053. }
  8054. tsParseThisTypePredicate(lhs) {
  8055. this.next();
  8056. const node = this.startNodeAtNode(lhs);
  8057. node.parameterName = lhs;
  8058. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  8059. node.asserts = false;
  8060. return this.finishNode(node, "TSTypePredicate");
  8061. }
  8062. tsParseThisTypeNode() {
  8063. const node = this.startNode();
  8064. this.next();
  8065. return this.finishNode(node, "TSThisType");
  8066. }
  8067. tsParseTypeQuery() {
  8068. const node = this.startNode();
  8069. this.expect(87);
  8070. if (this.match(83)) {
  8071. node.exprName = this.tsParseImportType();
  8072. } else {
  8073. {
  8074. node.exprName = this.tsParseEntityName(1 | 2);
  8075. }
  8076. }
  8077. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8078. {
  8079. node.typeParameters = this.tsParseTypeArguments();
  8080. }
  8081. }
  8082. return this.finishNode(node, "TSTypeQuery");
  8083. }
  8084. tsParseTypeParameter(parseModifiers) {
  8085. const node = this.startNode();
  8086. parseModifiers(node);
  8087. node.name = this.tsParseTypeParameterName();
  8088. node.constraint = this.tsEatThenParseType(81);
  8089. node.default = this.tsEatThenParseType(29);
  8090. return this.finishNode(node, "TSTypeParameter");
  8091. }
  8092. tsTryParseTypeParameters(parseModifiers) {
  8093. if (this.match(47)) {
  8094. return this.tsParseTypeParameters(parseModifiers);
  8095. }
  8096. }
  8097. tsParseTypeParameters(parseModifiers) {
  8098. const node = this.startNode();
  8099. if (this.match(47) || this.match(143)) {
  8100. this.next();
  8101. } else {
  8102. this.unexpected();
  8103. }
  8104. const refTrailingCommaPos = {
  8105. value: -1
  8106. };
  8107. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  8108. if (node.params.length === 0) {
  8109. this.raise(TSErrors.EmptyTypeParameters, node);
  8110. }
  8111. if (refTrailingCommaPos.value !== -1) {
  8112. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  8113. }
  8114. return this.finishNode(node, "TSTypeParameterDeclaration");
  8115. }
  8116. tsFillSignature(returnToken, signature) {
  8117. const returnTokenRequired = returnToken === 19;
  8118. const paramsKey = "parameters";
  8119. const returnTypeKey = "typeAnnotation";
  8120. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  8121. this.expect(10);
  8122. signature[paramsKey] = this.tsParseBindingListForSignature();
  8123. if (returnTokenRequired) {
  8124. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8125. } else if (this.match(returnToken)) {
  8126. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8127. }
  8128. }
  8129. tsParseBindingListForSignature() {
  8130. const list = super.parseBindingList(11, 41, 2);
  8131. for (const pattern of list) {
  8132. const {
  8133. type
  8134. } = pattern;
  8135. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  8136. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  8137. type
  8138. });
  8139. }
  8140. }
  8141. return list;
  8142. }
  8143. tsParseTypeMemberSemicolon() {
  8144. if (!this.eat(12) && !this.isLineTerminator()) {
  8145. this.expect(13);
  8146. }
  8147. }
  8148. tsParseSignatureMember(kind, node) {
  8149. this.tsFillSignature(14, node);
  8150. this.tsParseTypeMemberSemicolon();
  8151. return this.finishNode(node, kind);
  8152. }
  8153. tsIsUnambiguouslyIndexSignature() {
  8154. this.next();
  8155. if (tokenIsIdentifier(this.state.type)) {
  8156. this.next();
  8157. return this.match(14);
  8158. }
  8159. return false;
  8160. }
  8161. tsTryParseIndexSignature(node) {
  8162. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8163. return;
  8164. }
  8165. this.expect(0);
  8166. const id = this.parseIdentifier();
  8167. id.typeAnnotation = this.tsParseTypeAnnotation();
  8168. this.resetEndLocation(id);
  8169. this.expect(3);
  8170. node.parameters = [id];
  8171. const type = this.tsTryParseTypeAnnotation();
  8172. if (type) node.typeAnnotation = type;
  8173. this.tsParseTypeMemberSemicolon();
  8174. return this.finishNode(node, "TSIndexSignature");
  8175. }
  8176. tsParsePropertyOrMethodSignature(node, readonly) {
  8177. if (this.eat(17)) node.optional = true;
  8178. if (this.match(10) || this.match(47)) {
  8179. if (readonly) {
  8180. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  8181. }
  8182. const method = node;
  8183. if (method.kind && this.match(47)) {
  8184. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  8185. }
  8186. this.tsFillSignature(14, method);
  8187. this.tsParseTypeMemberSemicolon();
  8188. const paramsKey = "parameters";
  8189. const returnTypeKey = "typeAnnotation";
  8190. if (method.kind === "get") {
  8191. if (method[paramsKey].length > 0) {
  8192. this.raise(Errors.BadGetterArity, this.state.curPosition());
  8193. if (this.isThisParam(method[paramsKey][0])) {
  8194. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8195. }
  8196. }
  8197. } else if (method.kind === "set") {
  8198. if (method[paramsKey].length !== 1) {
  8199. this.raise(Errors.BadSetterArity, this.state.curPosition());
  8200. } else {
  8201. const firstParameter = method[paramsKey][0];
  8202. if (this.isThisParam(firstParameter)) {
  8203. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8204. }
  8205. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8206. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  8207. }
  8208. if (firstParameter.type === "RestElement") {
  8209. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  8210. }
  8211. }
  8212. if (method[returnTypeKey]) {
  8213. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  8214. }
  8215. } else {
  8216. method.kind = "method";
  8217. }
  8218. return this.finishNode(method, "TSMethodSignature");
  8219. } else {
  8220. const property = node;
  8221. if (readonly) property.readonly = true;
  8222. const type = this.tsTryParseTypeAnnotation();
  8223. if (type) property.typeAnnotation = type;
  8224. this.tsParseTypeMemberSemicolon();
  8225. return this.finishNode(property, "TSPropertySignature");
  8226. }
  8227. }
  8228. tsParseTypeMember() {
  8229. const node = this.startNode();
  8230. if (this.match(10) || this.match(47)) {
  8231. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8232. }
  8233. if (this.match(77)) {
  8234. const id = this.startNode();
  8235. this.next();
  8236. if (this.match(10) || this.match(47)) {
  8237. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8238. } else {
  8239. node.key = this.createIdentifier(id, "new");
  8240. return this.tsParsePropertyOrMethodSignature(node, false);
  8241. }
  8242. }
  8243. this.tsParseModifiers({
  8244. allowedModifiers: ["readonly"],
  8245. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8246. }, node);
  8247. const idx = this.tsTryParseIndexSignature(node);
  8248. if (idx) {
  8249. return idx;
  8250. }
  8251. super.parsePropertyName(node);
  8252. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8253. node.kind = node.key.name;
  8254. super.parsePropertyName(node);
  8255. if (!this.match(10) && !this.match(47)) {
  8256. this.unexpected(null, 10);
  8257. }
  8258. }
  8259. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8260. }
  8261. tsParseTypeLiteral() {
  8262. const node = this.startNode();
  8263. node.members = this.tsParseObjectTypeMembers();
  8264. return this.finishNode(node, "TSTypeLiteral");
  8265. }
  8266. tsParseObjectTypeMembers() {
  8267. this.expect(5);
  8268. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8269. this.expect(8);
  8270. return members;
  8271. }
  8272. tsIsStartOfMappedType() {
  8273. this.next();
  8274. if (this.eat(53)) {
  8275. return this.isContextual(122);
  8276. }
  8277. if (this.isContextual(122)) {
  8278. this.next();
  8279. }
  8280. if (!this.match(0)) {
  8281. return false;
  8282. }
  8283. this.next();
  8284. if (!this.tsIsIdentifier()) {
  8285. return false;
  8286. }
  8287. this.next();
  8288. return this.match(58);
  8289. }
  8290. tsParseMappedType() {
  8291. const node = this.startNode();
  8292. this.expect(5);
  8293. if (this.match(53)) {
  8294. node.readonly = this.state.value;
  8295. this.next();
  8296. this.expectContextual(122);
  8297. } else if (this.eatContextual(122)) {
  8298. node.readonly = true;
  8299. }
  8300. this.expect(0);
  8301. {
  8302. const typeParameter = this.startNode();
  8303. typeParameter.name = this.tsParseTypeParameterName();
  8304. typeParameter.constraint = this.tsExpectThenParseType(58);
  8305. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8306. }
  8307. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8308. this.expect(3);
  8309. if (this.match(53)) {
  8310. node.optional = this.state.value;
  8311. this.next();
  8312. this.expect(17);
  8313. } else if (this.eat(17)) {
  8314. node.optional = true;
  8315. }
  8316. node.typeAnnotation = this.tsTryParseType();
  8317. this.semicolon();
  8318. this.expect(8);
  8319. return this.finishNode(node, "TSMappedType");
  8320. }
  8321. tsParseTupleType() {
  8322. const node = this.startNode();
  8323. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8324. let seenOptionalElement = false;
  8325. node.elementTypes.forEach(elementNode => {
  8326. const {
  8327. type
  8328. } = elementNode;
  8329. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8330. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8331. }
  8332. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8333. });
  8334. return this.finishNode(node, "TSTupleType");
  8335. }
  8336. tsParseTupleElementType() {
  8337. const restStartLoc = this.state.startLoc;
  8338. const rest = this.eat(21);
  8339. const {
  8340. startLoc
  8341. } = this.state;
  8342. let labeled;
  8343. let label;
  8344. let optional;
  8345. let type;
  8346. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8347. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8348. if (chAfterWord === 58) {
  8349. labeled = true;
  8350. optional = false;
  8351. label = this.parseIdentifier(true);
  8352. this.expect(14);
  8353. type = this.tsParseType();
  8354. } else if (chAfterWord === 63) {
  8355. optional = true;
  8356. const wordName = this.state.value;
  8357. const typeOrLabel = this.tsParseNonArrayType();
  8358. if (this.lookaheadCharCode() === 58) {
  8359. labeled = true;
  8360. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8361. this.expect(17);
  8362. this.expect(14);
  8363. type = this.tsParseType();
  8364. } else {
  8365. labeled = false;
  8366. type = typeOrLabel;
  8367. this.expect(17);
  8368. }
  8369. } else {
  8370. type = this.tsParseType();
  8371. optional = this.eat(17);
  8372. labeled = this.eat(14);
  8373. }
  8374. if (labeled) {
  8375. let labeledNode;
  8376. if (label) {
  8377. labeledNode = this.startNodeAt(startLoc);
  8378. labeledNode.optional = optional;
  8379. labeledNode.label = label;
  8380. labeledNode.elementType = type;
  8381. if (this.eat(17)) {
  8382. labeledNode.optional = true;
  8383. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8384. }
  8385. } else {
  8386. labeledNode = this.startNodeAt(startLoc);
  8387. labeledNode.optional = optional;
  8388. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8389. labeledNode.label = type;
  8390. labeledNode.elementType = this.tsParseType();
  8391. }
  8392. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8393. } else if (optional) {
  8394. const optionalTypeNode = this.startNodeAt(startLoc);
  8395. optionalTypeNode.typeAnnotation = type;
  8396. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8397. }
  8398. if (rest) {
  8399. const restNode = this.startNodeAt(restStartLoc);
  8400. restNode.typeAnnotation = type;
  8401. type = this.finishNode(restNode, "TSRestType");
  8402. }
  8403. return type;
  8404. }
  8405. tsParseParenthesizedType() {
  8406. const node = this.startNode();
  8407. this.expect(10);
  8408. node.typeAnnotation = this.tsParseType();
  8409. this.expect(11);
  8410. return this.finishNode(node, "TSParenthesizedType");
  8411. }
  8412. tsParseFunctionOrConstructorType(type, abstract) {
  8413. const node = this.startNode();
  8414. if (type === "TSConstructorType") {
  8415. node.abstract = !!abstract;
  8416. if (abstract) this.next();
  8417. this.next();
  8418. }
  8419. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8420. return this.finishNode(node, type);
  8421. }
  8422. tsParseLiteralTypeNode() {
  8423. const node = this.startNode();
  8424. switch (this.state.type) {
  8425. case 135:
  8426. case 136:
  8427. case 134:
  8428. case 85:
  8429. case 86:
  8430. node.literal = super.parseExprAtom();
  8431. break;
  8432. default:
  8433. this.unexpected();
  8434. }
  8435. return this.finishNode(node, "TSLiteralType");
  8436. }
  8437. tsParseTemplateLiteralType() {
  8438. {
  8439. const node = this.startNode();
  8440. node.literal = super.parseTemplate(false);
  8441. return this.finishNode(node, "TSLiteralType");
  8442. }
  8443. }
  8444. parseTemplateSubstitution() {
  8445. if (this.state.inType) return this.tsParseType();
  8446. return super.parseTemplateSubstitution();
  8447. }
  8448. tsParseThisTypeOrThisTypePredicate() {
  8449. const thisKeyword = this.tsParseThisTypeNode();
  8450. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8451. return this.tsParseThisTypePredicate(thisKeyword);
  8452. } else {
  8453. return thisKeyword;
  8454. }
  8455. }
  8456. tsParseNonArrayType() {
  8457. switch (this.state.type) {
  8458. case 134:
  8459. case 135:
  8460. case 136:
  8461. case 85:
  8462. case 86:
  8463. return this.tsParseLiteralTypeNode();
  8464. case 53:
  8465. if (this.state.value === "-") {
  8466. const node = this.startNode();
  8467. const nextToken = this.lookahead();
  8468. if (nextToken.type !== 135 && nextToken.type !== 136) {
  8469. this.unexpected();
  8470. }
  8471. node.literal = this.parseMaybeUnary();
  8472. return this.finishNode(node, "TSLiteralType");
  8473. }
  8474. break;
  8475. case 78:
  8476. return this.tsParseThisTypeOrThisTypePredicate();
  8477. case 87:
  8478. return this.tsParseTypeQuery();
  8479. case 83:
  8480. return this.tsParseImportType();
  8481. case 5:
  8482. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8483. case 0:
  8484. return this.tsParseTupleType();
  8485. case 10:
  8486. return this.tsParseParenthesizedType();
  8487. case 25:
  8488. case 24:
  8489. return this.tsParseTemplateLiteralType();
  8490. default:
  8491. {
  8492. const {
  8493. type
  8494. } = this.state;
  8495. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8496. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8497. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8498. const node = this.startNode();
  8499. this.next();
  8500. return this.finishNode(node, nodeType);
  8501. }
  8502. return this.tsParseTypeReference();
  8503. }
  8504. }
  8505. }
  8506. throw this.unexpected();
  8507. }
  8508. tsParseArrayTypeOrHigher() {
  8509. const {
  8510. startLoc
  8511. } = this.state;
  8512. let type = this.tsParseNonArrayType();
  8513. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8514. if (this.match(3)) {
  8515. const node = this.startNodeAt(startLoc);
  8516. node.elementType = type;
  8517. this.expect(3);
  8518. type = this.finishNode(node, "TSArrayType");
  8519. } else {
  8520. const node = this.startNodeAt(startLoc);
  8521. node.objectType = type;
  8522. node.indexType = this.tsParseType();
  8523. this.expect(3);
  8524. type = this.finishNode(node, "TSIndexedAccessType");
  8525. }
  8526. }
  8527. return type;
  8528. }
  8529. tsParseTypeOperator() {
  8530. const node = this.startNode();
  8531. const operator = this.state.value;
  8532. this.next();
  8533. node.operator = operator;
  8534. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8535. if (operator === "readonly") {
  8536. this.tsCheckTypeAnnotationForReadOnly(node);
  8537. }
  8538. return this.finishNode(node, "TSTypeOperator");
  8539. }
  8540. tsCheckTypeAnnotationForReadOnly(node) {
  8541. switch (node.typeAnnotation.type) {
  8542. case "TSTupleType":
  8543. case "TSArrayType":
  8544. return;
  8545. default:
  8546. this.raise(TSErrors.UnexpectedReadonly, node);
  8547. }
  8548. }
  8549. tsParseInferType() {
  8550. const node = this.startNode();
  8551. this.expectContextual(115);
  8552. const typeParameter = this.startNode();
  8553. typeParameter.name = this.tsParseTypeParameterName();
  8554. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8555. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8556. return this.finishNode(node, "TSInferType");
  8557. }
  8558. tsParseConstraintForInferType() {
  8559. if (this.eat(81)) {
  8560. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8561. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8562. return constraint;
  8563. }
  8564. }
  8565. }
  8566. tsParseTypeOperatorOrHigher() {
  8567. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8568. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8569. }
  8570. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8571. const node = this.startNode();
  8572. const hasLeadingOperator = this.eat(operator);
  8573. const types = [];
  8574. do {
  8575. types.push(parseConstituentType());
  8576. } while (this.eat(operator));
  8577. if (types.length === 1 && !hasLeadingOperator) {
  8578. return types[0];
  8579. }
  8580. node.types = types;
  8581. return this.finishNode(node, kind);
  8582. }
  8583. tsParseIntersectionTypeOrHigher() {
  8584. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8585. }
  8586. tsParseUnionTypeOrHigher() {
  8587. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8588. }
  8589. tsIsStartOfFunctionType() {
  8590. if (this.match(47)) {
  8591. return true;
  8592. }
  8593. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8594. }
  8595. tsSkipParameterStart() {
  8596. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8597. this.next();
  8598. return true;
  8599. }
  8600. if (this.match(5)) {
  8601. const {
  8602. errors
  8603. } = this.state;
  8604. const previousErrorCount = errors.length;
  8605. try {
  8606. this.parseObjectLike(8, true);
  8607. return errors.length === previousErrorCount;
  8608. } catch (_unused) {
  8609. return false;
  8610. }
  8611. }
  8612. if (this.match(0)) {
  8613. this.next();
  8614. const {
  8615. errors
  8616. } = this.state;
  8617. const previousErrorCount = errors.length;
  8618. try {
  8619. super.parseBindingList(3, 93, 1);
  8620. return errors.length === previousErrorCount;
  8621. } catch (_unused2) {
  8622. return false;
  8623. }
  8624. }
  8625. return false;
  8626. }
  8627. tsIsUnambiguouslyStartOfFunctionType() {
  8628. this.next();
  8629. if (this.match(11) || this.match(21)) {
  8630. return true;
  8631. }
  8632. if (this.tsSkipParameterStart()) {
  8633. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8634. return true;
  8635. }
  8636. if (this.match(11)) {
  8637. this.next();
  8638. if (this.match(19)) {
  8639. return true;
  8640. }
  8641. }
  8642. }
  8643. return false;
  8644. }
  8645. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8646. return this.tsInType(() => {
  8647. const t = this.startNode();
  8648. this.expect(returnToken);
  8649. const node = this.startNode();
  8650. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8651. if (asserts && this.match(78)) {
  8652. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8653. if (thisTypePredicate.type === "TSThisType") {
  8654. node.parameterName = thisTypePredicate;
  8655. node.asserts = true;
  8656. node.typeAnnotation = null;
  8657. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8658. } else {
  8659. this.resetStartLocationFromNode(thisTypePredicate, node);
  8660. thisTypePredicate.asserts = true;
  8661. }
  8662. t.typeAnnotation = thisTypePredicate;
  8663. return this.finishNode(t, "TSTypeAnnotation");
  8664. }
  8665. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8666. if (!typePredicateVariable) {
  8667. if (!asserts) {
  8668. return this.tsParseTypeAnnotation(false, t);
  8669. }
  8670. node.parameterName = this.parseIdentifier();
  8671. node.asserts = asserts;
  8672. node.typeAnnotation = null;
  8673. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8674. return this.finishNode(t, "TSTypeAnnotation");
  8675. }
  8676. const type = this.tsParseTypeAnnotation(false);
  8677. node.parameterName = typePredicateVariable;
  8678. node.typeAnnotation = type;
  8679. node.asserts = asserts;
  8680. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8681. return this.finishNode(t, "TSTypeAnnotation");
  8682. });
  8683. }
  8684. tsTryParseTypeOrTypePredicateAnnotation() {
  8685. if (this.match(14)) {
  8686. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8687. }
  8688. }
  8689. tsTryParseTypeAnnotation() {
  8690. if (this.match(14)) {
  8691. return this.tsParseTypeAnnotation();
  8692. }
  8693. }
  8694. tsTryParseType() {
  8695. return this.tsEatThenParseType(14);
  8696. }
  8697. tsParseTypePredicatePrefix() {
  8698. const id = this.parseIdentifier();
  8699. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8700. this.next();
  8701. return id;
  8702. }
  8703. }
  8704. tsParseTypePredicateAsserts() {
  8705. if (this.state.type !== 109) {
  8706. return false;
  8707. }
  8708. const containsEsc = this.state.containsEsc;
  8709. this.next();
  8710. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8711. return false;
  8712. }
  8713. if (containsEsc) {
  8714. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8715. reservedWord: "asserts"
  8716. });
  8717. }
  8718. return true;
  8719. }
  8720. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8721. this.tsInType(() => {
  8722. if (eatColon) this.expect(14);
  8723. t.typeAnnotation = this.tsParseType();
  8724. });
  8725. return this.finishNode(t, "TSTypeAnnotation");
  8726. }
  8727. tsParseType() {
  8728. assert(this.state.inType);
  8729. const type = this.tsParseNonConditionalType();
  8730. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8731. return type;
  8732. }
  8733. const node = this.startNodeAtNode(type);
  8734. node.checkType = type;
  8735. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8736. this.expect(17);
  8737. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8738. this.expect(14);
  8739. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8740. return this.finishNode(node, "TSConditionalType");
  8741. }
  8742. isAbstractConstructorSignature() {
  8743. return this.isContextual(124) && this.isLookaheadContextual("new");
  8744. }
  8745. tsParseNonConditionalType() {
  8746. if (this.tsIsStartOfFunctionType()) {
  8747. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8748. }
  8749. if (this.match(77)) {
  8750. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8751. } else if (this.isAbstractConstructorSignature()) {
  8752. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8753. }
  8754. return this.tsParseUnionTypeOrHigher();
  8755. }
  8756. tsParseTypeAssertion() {
  8757. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8758. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8759. }
  8760. const node = this.startNode();
  8761. node.typeAnnotation = this.tsInType(() => {
  8762. this.next();
  8763. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8764. });
  8765. this.expect(48);
  8766. node.expression = this.parseMaybeUnary();
  8767. return this.finishNode(node, "TSTypeAssertion");
  8768. }
  8769. tsParseHeritageClause(token) {
  8770. const originalStartLoc = this.state.startLoc;
  8771. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8772. {
  8773. const node = this.startNode();
  8774. node.expression = this.tsParseEntityName(1 | 2);
  8775. if (this.match(47)) {
  8776. node.typeParameters = this.tsParseTypeArguments();
  8777. }
  8778. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8779. }
  8780. });
  8781. if (!delimitedList.length) {
  8782. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8783. token
  8784. });
  8785. }
  8786. return delimitedList;
  8787. }
  8788. tsParseInterfaceDeclaration(node, properties = {}) {
  8789. if (this.hasFollowingLineBreak()) return null;
  8790. this.expectContextual(129);
  8791. if (properties.declare) node.declare = true;
  8792. if (tokenIsIdentifier(this.state.type)) {
  8793. node.id = this.parseIdentifier();
  8794. this.checkIdentifier(node.id, 130);
  8795. } else {
  8796. node.id = null;
  8797. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8798. }
  8799. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8800. if (this.eat(81)) {
  8801. node.extends = this.tsParseHeritageClause("extends");
  8802. }
  8803. const body = this.startNode();
  8804. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8805. node.body = this.finishNode(body, "TSInterfaceBody");
  8806. return this.finishNode(node, "TSInterfaceDeclaration");
  8807. }
  8808. tsParseTypeAliasDeclaration(node) {
  8809. node.id = this.parseIdentifier();
  8810. this.checkIdentifier(node.id, 2);
  8811. node.typeAnnotation = this.tsInType(() => {
  8812. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8813. this.expect(29);
  8814. if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
  8815. const node = this.startNode();
  8816. this.next();
  8817. return this.finishNode(node, "TSIntrinsicKeyword");
  8818. }
  8819. return this.tsParseType();
  8820. });
  8821. this.semicolon();
  8822. return this.finishNode(node, "TSTypeAliasDeclaration");
  8823. }
  8824. tsInTopLevelContext(cb) {
  8825. if (this.curContext() !== types.brace) {
  8826. const oldContext = this.state.context;
  8827. this.state.context = [oldContext[0]];
  8828. try {
  8829. return cb();
  8830. } finally {
  8831. this.state.context = oldContext;
  8832. }
  8833. } else {
  8834. return cb();
  8835. }
  8836. }
  8837. tsInType(cb) {
  8838. const oldInType = this.state.inType;
  8839. this.state.inType = true;
  8840. try {
  8841. return cb();
  8842. } finally {
  8843. this.state.inType = oldInType;
  8844. }
  8845. }
  8846. tsInDisallowConditionalTypesContext(cb) {
  8847. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8848. this.state.inDisallowConditionalTypesContext = true;
  8849. try {
  8850. return cb();
  8851. } finally {
  8852. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8853. }
  8854. }
  8855. tsInAllowConditionalTypesContext(cb) {
  8856. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8857. this.state.inDisallowConditionalTypesContext = false;
  8858. try {
  8859. return cb();
  8860. } finally {
  8861. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8862. }
  8863. }
  8864. tsEatThenParseType(token) {
  8865. if (this.match(token)) {
  8866. return this.tsNextThenParseType();
  8867. }
  8868. }
  8869. tsExpectThenParseType(token) {
  8870. return this.tsInType(() => {
  8871. this.expect(token);
  8872. return this.tsParseType();
  8873. });
  8874. }
  8875. tsNextThenParseType() {
  8876. return this.tsInType(() => {
  8877. this.next();
  8878. return this.tsParseType();
  8879. });
  8880. }
  8881. tsParseEnumMember() {
  8882. const node = this.startNode();
  8883. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8884. if (this.eat(29)) {
  8885. node.initializer = super.parseMaybeAssignAllowIn();
  8886. }
  8887. return this.finishNode(node, "TSEnumMember");
  8888. }
  8889. tsParseEnumDeclaration(node, properties = {}) {
  8890. if (properties.const) node.const = true;
  8891. if (properties.declare) node.declare = true;
  8892. this.expectContextual(126);
  8893. node.id = this.parseIdentifier();
  8894. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8895. {
  8896. this.expect(5);
  8897. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8898. this.expect(8);
  8899. }
  8900. return this.finishNode(node, "TSEnumDeclaration");
  8901. }
  8902. tsParseEnumBody() {
  8903. const node = this.startNode();
  8904. this.expect(5);
  8905. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8906. this.expect(8);
  8907. return this.finishNode(node, "TSEnumBody");
  8908. }
  8909. tsParseModuleBlock() {
  8910. const node = this.startNode();
  8911. this.scope.enter(0);
  8912. this.expect(5);
  8913. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8914. this.scope.exit();
  8915. return this.finishNode(node, "TSModuleBlock");
  8916. }
  8917. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8918. node.id = this.parseIdentifier();
  8919. if (!nested) {
  8920. this.checkIdentifier(node.id, 1024);
  8921. }
  8922. if (this.eat(16)) {
  8923. const inner = this.startNode();
  8924. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8925. node.body = inner;
  8926. } else {
  8927. this.scope.enter(1024);
  8928. this.prodParam.enter(0);
  8929. node.body = this.tsParseModuleBlock();
  8930. this.prodParam.exit();
  8931. this.scope.exit();
  8932. }
  8933. return this.finishNode(node, "TSModuleDeclaration");
  8934. }
  8935. tsParseAmbientExternalModuleDeclaration(node) {
  8936. if (this.isContextual(112)) {
  8937. node.kind = "global";
  8938. {
  8939. node.global = true;
  8940. }
  8941. node.id = this.parseIdentifier();
  8942. } else if (this.match(134)) {
  8943. node.kind = "module";
  8944. node.id = super.parseStringLiteral(this.state.value);
  8945. } else {
  8946. this.unexpected();
  8947. }
  8948. if (this.match(5)) {
  8949. this.scope.enter(1024);
  8950. this.prodParam.enter(0);
  8951. node.body = this.tsParseModuleBlock();
  8952. this.prodParam.exit();
  8953. this.scope.exit();
  8954. } else {
  8955. this.semicolon();
  8956. }
  8957. return this.finishNode(node, "TSModuleDeclaration");
  8958. }
  8959. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8960. {
  8961. node.isExport = isExport || false;
  8962. }
  8963. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8964. this.checkIdentifier(node.id, 4096);
  8965. this.expect(29);
  8966. const moduleReference = this.tsParseModuleReference();
  8967. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8968. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8969. }
  8970. node.moduleReference = moduleReference;
  8971. this.semicolon();
  8972. return this.finishNode(node, "TSImportEqualsDeclaration");
  8973. }
  8974. tsIsExternalModuleReference() {
  8975. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8976. }
  8977. tsParseModuleReference() {
  8978. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  8979. }
  8980. tsParseExternalModuleReference() {
  8981. const node = this.startNode();
  8982. this.expectContextual(119);
  8983. this.expect(10);
  8984. if (!this.match(134)) {
  8985. this.unexpected();
  8986. }
  8987. node.expression = super.parseExprAtom();
  8988. this.expect(11);
  8989. this.sawUnambiguousESM = true;
  8990. return this.finishNode(node, "TSExternalModuleReference");
  8991. }
  8992. tsLookAhead(f) {
  8993. const state = this.state.clone();
  8994. const res = f();
  8995. this.state = state;
  8996. return res;
  8997. }
  8998. tsTryParseAndCatch(f) {
  8999. const result = this.tryParse(abort => f() || abort());
  9000. if (result.aborted || !result.node) return;
  9001. if (result.error) this.state = result.failState;
  9002. return result.node;
  9003. }
  9004. tsTryParse(f) {
  9005. const state = this.state.clone();
  9006. const result = f();
  9007. if (result !== undefined && result !== false) {
  9008. return result;
  9009. }
  9010. this.state = state;
  9011. }
  9012. tsTryParseDeclare(node) {
  9013. if (this.isLineTerminator()) {
  9014. return;
  9015. }
  9016. const startType = this.state.type;
  9017. return this.tsInAmbientContext(() => {
  9018. switch (startType) {
  9019. case 68:
  9020. node.declare = true;
  9021. return super.parseFunctionStatement(node, false, false);
  9022. case 80:
  9023. node.declare = true;
  9024. return this.parseClass(node, true, false);
  9025. case 126:
  9026. return this.tsParseEnumDeclaration(node, {
  9027. declare: true
  9028. });
  9029. case 112:
  9030. return this.tsParseAmbientExternalModuleDeclaration(node);
  9031. case 100:
  9032. if (this.state.containsEsc) {
  9033. return;
  9034. }
  9035. case 75:
  9036. case 74:
  9037. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  9038. node.declare = true;
  9039. return this.parseVarStatement(node, this.state.value, true);
  9040. }
  9041. this.expect(75);
  9042. return this.tsParseEnumDeclaration(node, {
  9043. const: true,
  9044. declare: true
  9045. });
  9046. case 107:
  9047. if (this.isUsing()) {
  9048. this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
  9049. node.declare = true;
  9050. return this.parseVarStatement(node, "using", true);
  9051. }
  9052. break;
  9053. case 96:
  9054. if (this.isAwaitUsing()) {
  9055. this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
  9056. node.declare = true;
  9057. this.next();
  9058. return this.parseVarStatement(node, "await using", true);
  9059. }
  9060. break;
  9061. case 129:
  9062. {
  9063. const result = this.tsParseInterfaceDeclaration(node, {
  9064. declare: true
  9065. });
  9066. if (result) return result;
  9067. }
  9068. default:
  9069. if (tokenIsIdentifier(startType)) {
  9070. return this.tsParseDeclaration(node, this.state.type, true, null);
  9071. }
  9072. }
  9073. });
  9074. }
  9075. tsTryParseExportDeclaration() {
  9076. return this.tsParseDeclaration(this.startNode(), this.state.type, true, null);
  9077. }
  9078. tsParseDeclaration(node, type, next, decorators) {
  9079. switch (type) {
  9080. case 124:
  9081. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  9082. return this.tsParseAbstractDeclaration(node, decorators);
  9083. }
  9084. break;
  9085. case 127:
  9086. if (this.tsCheckLineTerminator(next)) {
  9087. if (this.match(134)) {
  9088. return this.tsParseAmbientExternalModuleDeclaration(node);
  9089. } else if (tokenIsIdentifier(this.state.type)) {
  9090. node.kind = "module";
  9091. return this.tsParseModuleOrNamespaceDeclaration(node);
  9092. }
  9093. }
  9094. break;
  9095. case 128:
  9096. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9097. node.kind = "namespace";
  9098. return this.tsParseModuleOrNamespaceDeclaration(node);
  9099. }
  9100. break;
  9101. case 130:
  9102. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9103. return this.tsParseTypeAliasDeclaration(node);
  9104. }
  9105. break;
  9106. }
  9107. }
  9108. tsCheckLineTerminator(next) {
  9109. if (next) {
  9110. if (this.hasFollowingLineBreak()) return false;
  9111. this.next();
  9112. return true;
  9113. }
  9114. return !this.isLineTerminator();
  9115. }
  9116. tsTryParseGenericAsyncArrowFunction(startLoc) {
  9117. if (!this.match(47)) return;
  9118. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9119. this.state.maybeInArrowParameters = true;
  9120. const res = this.tsTryParseAndCatch(() => {
  9121. const node = this.startNodeAt(startLoc);
  9122. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9123. super.parseFunctionParams(node);
  9124. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9125. this.expect(19);
  9126. return node;
  9127. });
  9128. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9129. if (!res) return;
  9130. return super.parseArrowExpression(res, null, true);
  9131. }
  9132. tsParseTypeArgumentsInExpression() {
  9133. if (this.reScan_lt() !== 47) return;
  9134. return this.tsParseTypeArguments();
  9135. }
  9136. tsParseTypeArguments() {
  9137. const node = this.startNode();
  9138. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  9139. this.expect(47);
  9140. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9141. }));
  9142. if (node.params.length === 0) {
  9143. this.raise(TSErrors.EmptyTypeArguments, node);
  9144. } else if (!this.state.inType && this.curContext() === types.brace) {
  9145. this.reScan_lt_gt();
  9146. }
  9147. this.expect(48);
  9148. return this.finishNode(node, "TSTypeParameterInstantiation");
  9149. }
  9150. tsIsDeclarationStart() {
  9151. return tokenIsTSDeclarationStart(this.state.type);
  9152. }
  9153. isExportDefaultSpecifier() {
  9154. if (this.tsIsDeclarationStart()) return false;
  9155. return super.isExportDefaultSpecifier();
  9156. }
  9157. parseBindingElement(flags, decorators) {
  9158. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  9159. const modified = {};
  9160. this.tsParseModifiers({
  9161. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9162. }, modified);
  9163. const accessibility = modified.accessibility;
  9164. const override = modified.override;
  9165. const readonly = modified.readonly;
  9166. if (!(flags & 4) && (accessibility || readonly || override)) {
  9167. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  9168. }
  9169. const left = this.parseMaybeDefault();
  9170. if (flags & 2) {
  9171. this.parseFunctionParamType(left);
  9172. }
  9173. const elt = this.parseMaybeDefault(left.loc.start, left);
  9174. if (accessibility || readonly || override) {
  9175. const pp = this.startNodeAt(startLoc);
  9176. if (decorators.length) {
  9177. pp.decorators = decorators;
  9178. }
  9179. if (accessibility) pp.accessibility = accessibility;
  9180. if (readonly) pp.readonly = readonly;
  9181. if (override) pp.override = override;
  9182. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9183. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  9184. }
  9185. pp.parameter = elt;
  9186. return this.finishNode(pp, "TSParameterProperty");
  9187. }
  9188. if (decorators.length) {
  9189. left.decorators = decorators;
  9190. }
  9191. return elt;
  9192. }
  9193. isSimpleParameter(node) {
  9194. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9195. }
  9196. tsDisallowOptionalPattern(node) {
  9197. for (const param of node.params) {
  9198. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9199. this.raise(TSErrors.PatternIsOptional, param);
  9200. }
  9201. }
  9202. }
  9203. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9204. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9205. this.tsDisallowOptionalPattern(node);
  9206. }
  9207. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9208. if (this.match(14)) {
  9209. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9210. }
  9211. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9212. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9213. return this.finishNode(node, bodilessType);
  9214. }
  9215. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9216. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  9217. if (node.declare) {
  9218. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9219. }
  9220. }
  9221. this.tsDisallowOptionalPattern(node);
  9222. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9223. }
  9224. registerFunctionStatementId(node) {
  9225. if (!node.body && node.id) {
  9226. this.checkIdentifier(node.id, 1024);
  9227. } else {
  9228. super.registerFunctionStatementId(node);
  9229. }
  9230. }
  9231. tsCheckForInvalidTypeCasts(items) {
  9232. items.forEach(node => {
  9233. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9234. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  9235. }
  9236. });
  9237. }
  9238. toReferencedList(exprList, isInParens) {
  9239. this.tsCheckForInvalidTypeCasts(exprList);
  9240. return exprList;
  9241. }
  9242. parseArrayLike(close, isTuple, refExpressionErrors) {
  9243. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  9244. if (node.type === "ArrayExpression") {
  9245. this.tsCheckForInvalidTypeCasts(node.elements);
  9246. }
  9247. return node;
  9248. }
  9249. parseSubscript(base, startLoc, noCalls, state) {
  9250. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9251. this.state.canStartJSXElement = false;
  9252. this.next();
  9253. const nonNullExpression = this.startNodeAt(startLoc);
  9254. nonNullExpression.expression = base;
  9255. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9256. }
  9257. let isOptionalCall = false;
  9258. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9259. if (noCalls) {
  9260. state.stop = true;
  9261. return base;
  9262. }
  9263. state.optionalChainMember = isOptionalCall = true;
  9264. this.next();
  9265. }
  9266. if (this.match(47) || this.match(51)) {
  9267. let missingParenErrorLoc;
  9268. const result = this.tsTryParseAndCatch(() => {
  9269. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9270. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9271. if (asyncArrowFn) {
  9272. state.stop = true;
  9273. return asyncArrowFn;
  9274. }
  9275. }
  9276. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9277. if (!typeArguments) return;
  9278. if (isOptionalCall && !this.match(10)) {
  9279. missingParenErrorLoc = this.state.curPosition();
  9280. return;
  9281. }
  9282. if (tokenIsTemplate(this.state.type)) {
  9283. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9284. {
  9285. result.typeParameters = typeArguments;
  9286. }
  9287. return result;
  9288. }
  9289. if (!noCalls && this.eat(10)) {
  9290. const node = this.startNodeAt(startLoc);
  9291. node.callee = base;
  9292. node.arguments = this.parseCallExpressionArguments();
  9293. this.tsCheckForInvalidTypeCasts(node.arguments);
  9294. {
  9295. node.typeParameters = typeArguments;
  9296. }
  9297. if (state.optionalChainMember) {
  9298. node.optional = isOptionalCall;
  9299. }
  9300. return this.finishCallExpression(node, state.optionalChainMember);
  9301. }
  9302. const tokenType = this.state.type;
  9303. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9304. return;
  9305. }
  9306. const node = this.startNodeAt(startLoc);
  9307. node.expression = base;
  9308. {
  9309. node.typeParameters = typeArguments;
  9310. }
  9311. return this.finishNode(node, "TSInstantiationExpression");
  9312. });
  9313. if (missingParenErrorLoc) {
  9314. this.unexpected(missingParenErrorLoc, 10);
  9315. }
  9316. if (result) {
  9317. if (result.type === "TSInstantiationExpression") {
  9318. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  9319. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  9320. }
  9321. if (!this.match(16) && !this.match(18)) {
  9322. result.expression = super.stopParseSubscript(base, state);
  9323. }
  9324. }
  9325. return result;
  9326. }
  9327. }
  9328. return super.parseSubscript(base, startLoc, noCalls, state);
  9329. }
  9330. parseNewCallee(node) {
  9331. var _callee$extra;
  9332. super.parseNewCallee(node);
  9333. const {
  9334. callee
  9335. } = node;
  9336. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9337. {
  9338. node.typeParameters = callee.typeParameters;
  9339. }
  9340. node.callee = callee.expression;
  9341. }
  9342. }
  9343. parseExprOp(left, leftStartLoc, minPrec) {
  9344. let isSatisfies;
  9345. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9346. const node = this.startNodeAt(leftStartLoc);
  9347. node.expression = left;
  9348. node.typeAnnotation = this.tsInType(() => {
  9349. this.next();
  9350. if (this.match(75)) {
  9351. if (isSatisfies) {
  9352. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9353. keyword: "const"
  9354. });
  9355. }
  9356. return this.tsParseTypeReference();
  9357. }
  9358. return this.tsParseType();
  9359. });
  9360. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9361. this.reScan_lt_gt();
  9362. return this.parseExprOp(node, leftStartLoc, minPrec);
  9363. }
  9364. return super.parseExprOp(left, leftStartLoc, minPrec);
  9365. }
  9366. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9367. if (!this.state.isAmbientContext) {
  9368. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9369. }
  9370. }
  9371. checkImportReflection(node) {
  9372. super.checkImportReflection(node);
  9373. if (node.module && node.importKind !== "value") {
  9374. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9375. }
  9376. }
  9377. checkDuplicateExports() {}
  9378. isPotentialImportPhase(isExport) {
  9379. if (super.isPotentialImportPhase(isExport)) return true;
  9380. if (this.isContextual(130)) {
  9381. const ch = this.lookaheadCharCode();
  9382. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9383. }
  9384. return !isExport && this.isContextual(87);
  9385. }
  9386. applyImportPhase(node, isExport, phase, loc) {
  9387. super.applyImportPhase(node, isExport, phase, loc);
  9388. if (isExport) {
  9389. node.exportKind = phase === "type" ? "type" : "value";
  9390. } else {
  9391. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9392. }
  9393. }
  9394. parseImport(node) {
  9395. if (this.match(134)) {
  9396. node.importKind = "value";
  9397. return super.parseImport(node);
  9398. }
  9399. let importNode;
  9400. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9401. node.importKind = "value";
  9402. return this.tsParseImportEqualsDeclaration(node);
  9403. } else if (this.isContextual(130)) {
  9404. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9405. if (this.lookaheadCharCode() === 61) {
  9406. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9407. } else {
  9408. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9409. }
  9410. } else {
  9411. importNode = super.parseImport(node);
  9412. }
  9413. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9414. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9415. }
  9416. return importNode;
  9417. }
  9418. parseExport(node, decorators) {
  9419. if (this.match(83)) {
  9420. const nodeImportEquals = node;
  9421. this.next();
  9422. let maybeDefaultIdentifier = null;
  9423. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9424. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9425. } else {
  9426. nodeImportEquals.importKind = "value";
  9427. }
  9428. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9429. {
  9430. return declaration;
  9431. }
  9432. } else if (this.eat(29)) {
  9433. const assign = node;
  9434. assign.expression = super.parseExpression();
  9435. this.semicolon();
  9436. this.sawUnambiguousESM = true;
  9437. return this.finishNode(assign, "TSExportAssignment");
  9438. } else if (this.eatContextual(93)) {
  9439. const decl = node;
  9440. this.expectContextual(128);
  9441. decl.id = this.parseIdentifier();
  9442. this.semicolon();
  9443. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9444. } else {
  9445. return super.parseExport(node, decorators);
  9446. }
  9447. }
  9448. isAbstractClass() {
  9449. return this.isContextual(124) && this.isLookaheadContextual("class");
  9450. }
  9451. parseExportDefaultExpression() {
  9452. if (this.isAbstractClass()) {
  9453. const cls = this.startNode();
  9454. this.next();
  9455. cls.abstract = true;
  9456. return this.parseClass(cls, true, true);
  9457. }
  9458. if (this.match(129)) {
  9459. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9460. if (result) return result;
  9461. }
  9462. return super.parseExportDefaultExpression();
  9463. }
  9464. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9465. const {
  9466. isAmbientContext
  9467. } = this.state;
  9468. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9469. if (!isAmbientContext) return declaration;
  9470. if (!node.declare && (kind === "using" || kind === "await using")) {
  9471. this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
  9472. return declaration;
  9473. }
  9474. for (const {
  9475. id,
  9476. init
  9477. } of declaration.declarations) {
  9478. if (!init) continue;
  9479. if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
  9480. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9481. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9482. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9483. }
  9484. }
  9485. return declaration;
  9486. }
  9487. parseStatementContent(flags, decorators) {
  9488. if (!this.state.containsEsc) {
  9489. switch (this.state.type) {
  9490. case 75:
  9491. {
  9492. if (this.isLookaheadContextual("enum")) {
  9493. const node = this.startNode();
  9494. this.expect(75);
  9495. return this.tsParseEnumDeclaration(node, {
  9496. const: true
  9497. });
  9498. }
  9499. break;
  9500. }
  9501. case 124:
  9502. case 125:
  9503. {
  9504. if (this.nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine()) {
  9505. const token = this.state.type;
  9506. const node = this.startNode();
  9507. this.next();
  9508. const declaration = token === 125 ? this.tsTryParseDeclare(node) : this.tsParseAbstractDeclaration(node, decorators);
  9509. if (declaration) {
  9510. if (token === 125) {
  9511. declaration.declare = true;
  9512. }
  9513. return declaration;
  9514. } else {
  9515. node.expression = this.createIdentifier(this.startNodeAt(node.loc.start), token === 125 ? "declare" : "abstract");
  9516. this.semicolon(false);
  9517. return this.finishNode(node, "ExpressionStatement");
  9518. }
  9519. }
  9520. break;
  9521. }
  9522. case 126:
  9523. return this.tsParseEnumDeclaration(this.startNode());
  9524. case 112:
  9525. {
  9526. const nextCh = this.lookaheadCharCode();
  9527. if (nextCh === 123) {
  9528. const node = this.startNode();
  9529. return this.tsParseAmbientExternalModuleDeclaration(node);
  9530. }
  9531. break;
  9532. }
  9533. case 129:
  9534. {
  9535. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9536. if (result) return result;
  9537. break;
  9538. }
  9539. case 127:
  9540. {
  9541. if (this.nextTokenIsIdentifierOrStringLiteralOnSameLine()) {
  9542. const node = this.startNode();
  9543. this.next();
  9544. return this.tsParseDeclaration(node, 127, false, decorators);
  9545. }
  9546. break;
  9547. }
  9548. case 128:
  9549. {
  9550. if (this.nextTokenIsIdentifierOnSameLine()) {
  9551. const node = this.startNode();
  9552. this.next();
  9553. return this.tsParseDeclaration(node, 128, false, decorators);
  9554. }
  9555. break;
  9556. }
  9557. case 130:
  9558. {
  9559. if (this.nextTokenIsIdentifierOnSameLine()) {
  9560. const node = this.startNode();
  9561. this.next();
  9562. return this.tsParseTypeAliasDeclaration(node);
  9563. }
  9564. break;
  9565. }
  9566. }
  9567. }
  9568. return super.parseStatementContent(flags, decorators);
  9569. }
  9570. parseAccessModifier() {
  9571. return this.tsParseModifier(["public", "protected", "private"]);
  9572. }
  9573. tsHasSomeModifiers(member, modifiers) {
  9574. return modifiers.some(modifier => {
  9575. if (tsIsAccessModifier(modifier)) {
  9576. return member.accessibility === modifier;
  9577. }
  9578. return !!member[modifier];
  9579. });
  9580. }
  9581. tsIsStartOfStaticBlocks() {
  9582. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9583. }
  9584. parseClassMember(classBody, member, state) {
  9585. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9586. this.tsParseModifiers({
  9587. allowedModifiers: modifiers,
  9588. disallowedModifiers: ["in", "out"],
  9589. stopOnStartOfClassStaticBlock: true,
  9590. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9591. }, member);
  9592. const callParseClassMemberWithIsStatic = () => {
  9593. if (this.tsIsStartOfStaticBlocks()) {
  9594. this.next();
  9595. this.next();
  9596. if (this.tsHasSomeModifiers(member, modifiers)) {
  9597. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9598. }
  9599. super.parseClassStaticBlock(classBody, member);
  9600. } else {
  9601. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9602. }
  9603. };
  9604. if (member.declare) {
  9605. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9606. } else {
  9607. callParseClassMemberWithIsStatic();
  9608. }
  9609. }
  9610. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9611. const idx = this.tsTryParseIndexSignature(member);
  9612. if (idx) {
  9613. classBody.body.push(idx);
  9614. if (member.abstract) {
  9615. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9616. }
  9617. if (member.accessibility) {
  9618. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9619. modifier: member.accessibility
  9620. });
  9621. }
  9622. if (member.declare) {
  9623. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9624. }
  9625. if (member.override) {
  9626. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9627. }
  9628. return;
  9629. }
  9630. if (!this.state.inAbstractClass && member.abstract) {
  9631. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9632. }
  9633. if (member.override) {
  9634. if (!state.hadSuperClass) {
  9635. this.raise(TSErrors.OverrideNotInSubClass, member);
  9636. }
  9637. }
  9638. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9639. }
  9640. parsePostMemberNameModifiers(methodOrProp) {
  9641. const optional = this.eat(17);
  9642. if (optional) methodOrProp.optional = true;
  9643. if (methodOrProp.readonly && this.match(10)) {
  9644. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9645. }
  9646. if (methodOrProp.declare && this.match(10)) {
  9647. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9648. }
  9649. }
  9650. shouldParseExportDeclaration() {
  9651. if (this.tsIsDeclarationStart()) return true;
  9652. return super.shouldParseExportDeclaration();
  9653. }
  9654. parseConditional(expr, startLoc, refExpressionErrors) {
  9655. if (!this.match(17)) return expr;
  9656. if (this.state.maybeInArrowParameters) {
  9657. const nextCh = this.lookaheadCharCode();
  9658. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  9659. this.setOptionalParametersError(refExpressionErrors);
  9660. return expr;
  9661. }
  9662. }
  9663. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9664. }
  9665. parseParenItem(node, startLoc) {
  9666. const newNode = super.parseParenItem(node, startLoc);
  9667. if (this.eat(17)) {
  9668. newNode.optional = true;
  9669. this.resetEndLocation(node);
  9670. }
  9671. if (this.match(14)) {
  9672. const typeCastNode = this.startNodeAt(startLoc);
  9673. typeCastNode.expression = node;
  9674. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9675. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9676. }
  9677. return node;
  9678. }
  9679. parseExportDeclaration(node) {
  9680. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9681. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9682. }
  9683. const startLoc = this.state.startLoc;
  9684. const isDeclare = this.eatContextual(125);
  9685. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9686. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9687. }
  9688. const isIdentifier = tokenIsIdentifier(this.state.type);
  9689. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9690. if (!declaration) return null;
  9691. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9692. node.exportKind = "type";
  9693. }
  9694. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  9695. this.resetStartLocation(declaration, startLoc);
  9696. declaration.declare = true;
  9697. }
  9698. return declaration;
  9699. }
  9700. parseClassId(node, isStatement, optionalId, bindingType) {
  9701. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9702. return;
  9703. }
  9704. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9705. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9706. if (typeParameters) node.typeParameters = typeParameters;
  9707. }
  9708. parseClassPropertyAnnotation(node) {
  9709. if (!node.optional) {
  9710. if (this.eat(35)) {
  9711. node.definite = true;
  9712. } else if (this.eat(17)) {
  9713. node.optional = true;
  9714. }
  9715. }
  9716. const type = this.tsTryParseTypeAnnotation();
  9717. if (type) node.typeAnnotation = type;
  9718. }
  9719. parseClassProperty(node) {
  9720. this.parseClassPropertyAnnotation(node);
  9721. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9722. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9723. }
  9724. if (node.abstract && this.match(29)) {
  9725. const {
  9726. key
  9727. } = node;
  9728. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9729. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9730. });
  9731. }
  9732. return super.parseClassProperty(node);
  9733. }
  9734. parseClassPrivateProperty(node) {
  9735. if (node.abstract) {
  9736. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9737. }
  9738. if (node.accessibility) {
  9739. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9740. modifier: node.accessibility
  9741. });
  9742. }
  9743. this.parseClassPropertyAnnotation(node);
  9744. return super.parseClassPrivateProperty(node);
  9745. }
  9746. parseClassAccessorProperty(node) {
  9747. this.parseClassPropertyAnnotation(node);
  9748. if (node.optional) {
  9749. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9750. }
  9751. return super.parseClassAccessorProperty(node);
  9752. }
  9753. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9754. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9755. if (typeParameters && isConstructor) {
  9756. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9757. }
  9758. const {
  9759. declare = false,
  9760. kind
  9761. } = method;
  9762. if (declare && (kind === "get" || kind === "set")) {
  9763. this.raise(TSErrors.DeclareAccessor, method, {
  9764. kind
  9765. });
  9766. }
  9767. if (typeParameters) method.typeParameters = typeParameters;
  9768. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9769. }
  9770. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9771. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9772. if (typeParameters) method.typeParameters = typeParameters;
  9773. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9774. }
  9775. declareClassPrivateMethodInScope(node, kind) {
  9776. if (node.type === "TSDeclareMethod") return;
  9777. if (node.type === "MethodDefinition" && node.value.body == null) {
  9778. return;
  9779. }
  9780. super.declareClassPrivateMethodInScope(node, kind);
  9781. }
  9782. parseClassSuper(node) {
  9783. super.parseClassSuper(node);
  9784. if (node.superClass && (this.match(47) || this.match(51))) {
  9785. {
  9786. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9787. }
  9788. }
  9789. if (this.eatContextual(113)) {
  9790. node.implements = this.tsParseHeritageClause("implements");
  9791. }
  9792. }
  9793. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9794. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9795. if (typeParameters) prop.typeParameters = typeParameters;
  9796. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9797. }
  9798. parseFunctionParams(node, isConstructor) {
  9799. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9800. if (typeParameters) node.typeParameters = typeParameters;
  9801. super.parseFunctionParams(node, isConstructor);
  9802. }
  9803. parseVarId(decl, kind) {
  9804. super.parseVarId(decl, kind);
  9805. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9806. decl.definite = true;
  9807. }
  9808. const type = this.tsTryParseTypeAnnotation();
  9809. if (type) {
  9810. decl.id.typeAnnotation = type;
  9811. this.resetEndLocation(decl.id);
  9812. }
  9813. }
  9814. parseAsyncArrowFromCallExpression(node, call) {
  9815. if (this.match(14)) {
  9816. node.returnType = this.tsParseTypeAnnotation();
  9817. }
  9818. return super.parseAsyncArrowFromCallExpression(node, call);
  9819. }
  9820. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9821. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9822. let state;
  9823. let jsx;
  9824. let typeCast;
  9825. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  9826. state = this.state.clone();
  9827. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9828. if (!jsx.error) return jsx.node;
  9829. const {
  9830. context
  9831. } = this.state;
  9832. const currentContext = context[context.length - 1];
  9833. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9834. context.pop();
  9835. }
  9836. }
  9837. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9838. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9839. }
  9840. if (!state || state === this.state) state = this.state.clone();
  9841. let typeParameters;
  9842. const arrow = this.tryParse(abort => {
  9843. var _expr$extra, _typeParameters;
  9844. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9845. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9846. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9847. abort();
  9848. }
  9849. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9850. this.resetStartLocationFromNode(expr, typeParameters);
  9851. }
  9852. expr.typeParameters = typeParameters;
  9853. return expr;
  9854. }, state);
  9855. if (!arrow.error && !arrow.aborted) {
  9856. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9857. return arrow.node;
  9858. }
  9859. if (!jsx) {
  9860. assert(!this.hasPlugin("jsx"));
  9861. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9862. if (!typeCast.error) return typeCast.node;
  9863. }
  9864. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9865. this.state = jsx.failState;
  9866. return jsx.node;
  9867. }
  9868. if (arrow.node) {
  9869. this.state = arrow.failState;
  9870. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9871. return arrow.node;
  9872. }
  9873. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9874. this.state = typeCast.failState;
  9875. return typeCast.node;
  9876. }
  9877. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9878. }
  9879. reportReservedArrowTypeParam(node) {
  9880. var _node$extra2;
  9881. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9882. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9883. }
  9884. }
  9885. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9886. if (!this.hasPlugin("jsx") && this.match(47)) {
  9887. return this.tsParseTypeAssertion();
  9888. }
  9889. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9890. }
  9891. parseArrow(node) {
  9892. if (this.match(14)) {
  9893. const result = this.tryParse(abort => {
  9894. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9895. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9896. return returnType;
  9897. });
  9898. if (result.aborted) return;
  9899. if (!result.thrown) {
  9900. if (result.error) this.state = result.failState;
  9901. node.returnType = result.node;
  9902. }
  9903. }
  9904. return super.parseArrow(node);
  9905. }
  9906. parseFunctionParamType(param) {
  9907. if (this.eat(17)) {
  9908. param.optional = true;
  9909. }
  9910. const type = this.tsTryParseTypeAnnotation();
  9911. if (type) param.typeAnnotation = type;
  9912. this.resetEndLocation(param);
  9913. return param;
  9914. }
  9915. isAssignable(node, isBinding) {
  9916. switch (node.type) {
  9917. case "TSTypeCastExpression":
  9918. return this.isAssignable(node.expression, isBinding);
  9919. case "TSParameterProperty":
  9920. return true;
  9921. default:
  9922. return super.isAssignable(node, isBinding);
  9923. }
  9924. }
  9925. toAssignable(node, isLHS = false) {
  9926. switch (node.type) {
  9927. case "ParenthesizedExpression":
  9928. this.toAssignableParenthesizedExpression(node, isLHS);
  9929. break;
  9930. case "TSAsExpression":
  9931. case "TSSatisfiesExpression":
  9932. case "TSNonNullExpression":
  9933. case "TSTypeAssertion":
  9934. if (isLHS) {
  9935. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9936. } else {
  9937. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9938. }
  9939. this.toAssignable(node.expression, isLHS);
  9940. break;
  9941. case "AssignmentExpression":
  9942. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9943. node.left = this.typeCastToParameter(node.left);
  9944. }
  9945. default:
  9946. super.toAssignable(node, isLHS);
  9947. }
  9948. }
  9949. toAssignableParenthesizedExpression(node, isLHS) {
  9950. switch (node.expression.type) {
  9951. case "TSAsExpression":
  9952. case "TSSatisfiesExpression":
  9953. case "TSNonNullExpression":
  9954. case "TSTypeAssertion":
  9955. case "ParenthesizedExpression":
  9956. this.toAssignable(node.expression, isLHS);
  9957. break;
  9958. default:
  9959. super.toAssignable(node, isLHS);
  9960. }
  9961. }
  9962. checkToRestConversion(node, allowPattern) {
  9963. switch (node.type) {
  9964. case "TSAsExpression":
  9965. case "TSSatisfiesExpression":
  9966. case "TSTypeAssertion":
  9967. case "TSNonNullExpression":
  9968. this.checkToRestConversion(node.expression, false);
  9969. break;
  9970. default:
  9971. super.checkToRestConversion(node, allowPattern);
  9972. }
  9973. }
  9974. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  9975. switch (type) {
  9976. case "TSTypeCastExpression":
  9977. return true;
  9978. case "TSParameterProperty":
  9979. return "parameter";
  9980. case "TSNonNullExpression":
  9981. return "expression";
  9982. case "TSAsExpression":
  9983. case "TSSatisfiesExpression":
  9984. case "TSTypeAssertion":
  9985. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  9986. default:
  9987. return super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  9988. }
  9989. }
  9990. parseBindingAtom() {
  9991. if (this.state.type === 78) {
  9992. return this.parseIdentifier(true);
  9993. }
  9994. return super.parseBindingAtom();
  9995. }
  9996. parseMaybeDecoratorArguments(expr, startLoc) {
  9997. if (this.match(47) || this.match(51)) {
  9998. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9999. if (this.match(10)) {
  10000. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  10001. {
  10002. call.typeParameters = typeArguments;
  10003. }
  10004. return call;
  10005. }
  10006. this.unexpected(null, 10);
  10007. }
  10008. return super.parseMaybeDecoratorArguments(expr, startLoc);
  10009. }
  10010. checkCommaAfterRest(close) {
  10011. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  10012. this.next();
  10013. return false;
  10014. }
  10015. return super.checkCommaAfterRest(close);
  10016. }
  10017. isClassMethod() {
  10018. return this.match(47) || super.isClassMethod();
  10019. }
  10020. isClassProperty() {
  10021. return this.match(35) || this.match(14) || super.isClassProperty();
  10022. }
  10023. parseMaybeDefault(startLoc, left) {
  10024. const node = super.parseMaybeDefault(startLoc, left);
  10025. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  10026. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  10027. }
  10028. return node;
  10029. }
  10030. getTokenFromCode(code) {
  10031. if (this.state.inType) {
  10032. if (code === 62) {
  10033. this.finishOp(48, 1);
  10034. return;
  10035. }
  10036. if (code === 60) {
  10037. this.finishOp(47, 1);
  10038. return;
  10039. }
  10040. }
  10041. super.getTokenFromCode(code);
  10042. }
  10043. reScan_lt_gt() {
  10044. const {
  10045. type
  10046. } = this.state;
  10047. if (type === 47) {
  10048. this.state.pos -= 1;
  10049. this.readToken_lt();
  10050. } else if (type === 48) {
  10051. this.state.pos -= 1;
  10052. this.readToken_gt();
  10053. }
  10054. }
  10055. reScan_lt() {
  10056. const {
  10057. type
  10058. } = this.state;
  10059. if (type === 51) {
  10060. this.state.pos -= 2;
  10061. this.finishOp(47, 1);
  10062. return 47;
  10063. }
  10064. return type;
  10065. }
  10066. toAssignableListItem(exprList, index, isLHS) {
  10067. const node = exprList[index];
  10068. if (node.type === "TSTypeCastExpression") {
  10069. exprList[index] = this.typeCastToParameter(node);
  10070. }
  10071. super.toAssignableListItem(exprList, index, isLHS);
  10072. }
  10073. typeCastToParameter(node) {
  10074. node.expression.typeAnnotation = node.typeAnnotation;
  10075. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  10076. return node.expression;
  10077. }
  10078. shouldParseArrow(params) {
  10079. if (this.match(14)) {
  10080. return params.every(expr => this.isAssignable(expr, true));
  10081. }
  10082. return super.shouldParseArrow(params);
  10083. }
  10084. shouldParseAsyncArrow() {
  10085. return this.match(14) || super.shouldParseAsyncArrow();
  10086. }
  10087. canHaveLeadingDecorator() {
  10088. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  10089. }
  10090. jsxParseOpeningElementAfterName(node) {
  10091. if (this.match(47) || this.match(51)) {
  10092. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  10093. if (typeArguments) {
  10094. {
  10095. node.typeParameters = typeArguments;
  10096. }
  10097. }
  10098. }
  10099. return super.jsxParseOpeningElementAfterName(node);
  10100. }
  10101. getGetterSetterExpectedParamCount(method) {
  10102. const baseCount = super.getGetterSetterExpectedParamCount(method);
  10103. const params = this.getObjectOrClassMethodParams(method);
  10104. const firstParam = params[0];
  10105. const hasContextParam = firstParam && this.isThisParam(firstParam);
  10106. return hasContextParam ? baseCount + 1 : baseCount;
  10107. }
  10108. parseCatchClauseParam() {
  10109. const param = super.parseCatchClauseParam();
  10110. const type = this.tsTryParseTypeAnnotation();
  10111. if (type) {
  10112. param.typeAnnotation = type;
  10113. this.resetEndLocation(param);
  10114. }
  10115. return param;
  10116. }
  10117. tsInAmbientContext(cb) {
  10118. const {
  10119. isAmbientContext: oldIsAmbientContext,
  10120. strict: oldStrict
  10121. } = this.state;
  10122. this.state.isAmbientContext = true;
  10123. this.state.strict = false;
  10124. try {
  10125. return cb();
  10126. } finally {
  10127. this.state.isAmbientContext = oldIsAmbientContext;
  10128. this.state.strict = oldStrict;
  10129. }
  10130. }
  10131. parseClass(node, isStatement, optionalId) {
  10132. const oldInAbstractClass = this.state.inAbstractClass;
  10133. this.state.inAbstractClass = !!node.abstract;
  10134. try {
  10135. return super.parseClass(node, isStatement, optionalId);
  10136. } finally {
  10137. this.state.inAbstractClass = oldInAbstractClass;
  10138. }
  10139. }
  10140. tsParseAbstractDeclaration(node, decorators) {
  10141. if (this.match(80)) {
  10142. node.abstract = true;
  10143. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  10144. } else if (this.isContextual(129)) {
  10145. if (!this.hasFollowingLineBreak()) {
  10146. node.abstract = true;
  10147. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
  10148. return this.tsParseInterfaceDeclaration(node);
  10149. } else {
  10150. return null;
  10151. }
  10152. }
  10153. throw this.unexpected(null, 80);
  10154. }
  10155. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  10156. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  10157. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  10158. const hasEstreePlugin = this.hasPlugin("estree");
  10159. const methodFn = hasEstreePlugin ? method.value : method;
  10160. if (methodFn.body) {
  10161. const {
  10162. key
  10163. } = method;
  10164. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  10165. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  10166. });
  10167. }
  10168. }
  10169. return method;
  10170. }
  10171. tsParseTypeParameterName() {
  10172. const typeName = this.parseIdentifier();
  10173. return typeName.name;
  10174. }
  10175. shouldParseAsAmbientContext() {
  10176. return !!this.getPluginOption("typescript", "dts");
  10177. }
  10178. parse() {
  10179. if (this.shouldParseAsAmbientContext()) {
  10180. this.state.isAmbientContext = true;
  10181. }
  10182. return super.parse();
  10183. }
  10184. getExpression() {
  10185. if (this.shouldParseAsAmbientContext()) {
  10186. this.state.isAmbientContext = true;
  10187. }
  10188. return super.getExpression();
  10189. }
  10190. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10191. if (!isString && isMaybeTypeOnly) {
  10192. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10193. return this.finishNode(node, "ExportSpecifier");
  10194. }
  10195. node.exportKind = "value";
  10196. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10197. }
  10198. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10199. if (!importedIsString && isMaybeTypeOnly) {
  10200. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10201. return this.finishNode(specifier, "ImportSpecifier");
  10202. }
  10203. specifier.importKind = "value";
  10204. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  10205. }
  10206. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10207. const leftOfAsKey = isImport ? "imported" : "local";
  10208. const rightOfAsKey = isImport ? "local" : "exported";
  10209. let leftOfAs = node[leftOfAsKey];
  10210. let rightOfAs;
  10211. let hasTypeSpecifier = false;
  10212. let canParseAsKeyword = true;
  10213. const loc = leftOfAs.loc.start;
  10214. if (this.isContextual(93)) {
  10215. const firstAs = this.parseIdentifier();
  10216. if (this.isContextual(93)) {
  10217. const secondAs = this.parseIdentifier();
  10218. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10219. hasTypeSpecifier = true;
  10220. leftOfAs = firstAs;
  10221. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10222. canParseAsKeyword = false;
  10223. } else {
  10224. rightOfAs = secondAs;
  10225. canParseAsKeyword = false;
  10226. }
  10227. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10228. canParseAsKeyword = false;
  10229. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10230. } else {
  10231. hasTypeSpecifier = true;
  10232. leftOfAs = firstAs;
  10233. }
  10234. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10235. hasTypeSpecifier = true;
  10236. if (isImport) {
  10237. leftOfAs = this.parseIdentifier(true);
  10238. if (!this.isContextual(93)) {
  10239. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10240. }
  10241. } else {
  10242. leftOfAs = this.parseModuleExportName();
  10243. }
  10244. }
  10245. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10246. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  10247. }
  10248. node[leftOfAsKey] = leftOfAs;
  10249. node[rightOfAsKey] = rightOfAs;
  10250. const kindKey = isImport ? "importKind" : "exportKind";
  10251. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10252. if (canParseAsKeyword && this.eatContextual(93)) {
  10253. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10254. }
  10255. if (!node[rightOfAsKey]) {
  10256. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  10257. }
  10258. if (isImport) {
  10259. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10260. }
  10261. }
  10262. fillOptionalPropertiesForTSESLint(node) {
  10263. 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;
  10264. switch (node.type) {
  10265. case "ExpressionStatement":
  10266. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  10267. return;
  10268. case "RestElement":
  10269. node.value = undefined;
  10270. case "Identifier":
  10271. case "ArrayPattern":
  10272. case "AssignmentPattern":
  10273. case "ObjectPattern":
  10274. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  10275. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  10276. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  10277. return;
  10278. case "TSParameterProperty":
  10279. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  10280. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  10281. (_node$override = node.override) != null ? _node$override : node.override = false;
  10282. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  10283. (_node$static = node.static) != null ? _node$static : node.static = false;
  10284. return;
  10285. case "TSEmptyBodyFunctionExpression":
  10286. node.body = null;
  10287. case "TSDeclareFunction":
  10288. case "FunctionDeclaration":
  10289. case "FunctionExpression":
  10290. case "ClassMethod":
  10291. case "ClassPrivateMethod":
  10292. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  10293. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  10294. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  10295. return;
  10296. case "Property":
  10297. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  10298. return;
  10299. case "TSMethodSignature":
  10300. case "TSPropertySignature":
  10301. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  10302. case "TSIndexSignature":
  10303. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  10304. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  10305. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  10306. return;
  10307. case "TSAbstractPropertyDefinition":
  10308. case "PropertyDefinition":
  10309. case "TSAbstractAccessorProperty":
  10310. case "AccessorProperty":
  10311. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  10312. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  10313. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  10314. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  10315. case "TSAbstractMethodDefinition":
  10316. case "MethodDefinition":
  10317. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  10318. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  10319. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  10320. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  10321. return;
  10322. case "ClassExpression":
  10323. (_node$id = node.id) != null ? _node$id : node.id = null;
  10324. case "ClassDeclaration":
  10325. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  10326. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  10327. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  10328. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  10329. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  10330. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  10331. return;
  10332. case "TSTypeAliasDeclaration":
  10333. case "VariableDeclaration":
  10334. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  10335. return;
  10336. case "VariableDeclarator":
  10337. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  10338. return;
  10339. case "TSEnumDeclaration":
  10340. (_node$const = node.const) != null ? _node$const : node.const = false;
  10341. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  10342. return;
  10343. case "TSEnumMember":
  10344. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  10345. return;
  10346. case "TSImportType":
  10347. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  10348. (_node$options = node.options) != null ? _node$options : node.options = null;
  10349. return;
  10350. case "TSInterfaceDeclaration":
  10351. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  10352. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  10353. return;
  10354. case "TSMappedType":
  10355. (_node$optional5 = node.optional) != null ? _node$optional5 : node.optional = false;
  10356. (_node$readonly4 = node.readonly) != null ? _node$readonly4 : node.readonly = undefined;
  10357. return;
  10358. case "TSModuleDeclaration":
  10359. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  10360. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  10361. return;
  10362. case "TSTypeParameter":
  10363. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  10364. (_node$in = node.in) != null ? _node$in : node.in = false;
  10365. (_node$out = node.out) != null ? _node$out : node.out = false;
  10366. return;
  10367. }
  10368. }
  10369. chStartsBindingIdentifierAndNotRelationalOperator(ch, pos) {
  10370. if (isIdentifierStart(ch)) {
  10371. keywordAndTSRelationalOperator.lastIndex = pos;
  10372. if (keywordAndTSRelationalOperator.test(this.input)) {
  10373. const endCh = this.codePointAtPos(keywordAndTSRelationalOperator.lastIndex);
  10374. if (!isIdentifierChar(endCh) && endCh !== 92) {
  10375. return false;
  10376. }
  10377. }
  10378. return true;
  10379. } else if (ch === 92) {
  10380. return true;
  10381. } else {
  10382. return false;
  10383. }
  10384. }
  10385. nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine() {
  10386. const next = this.nextTokenInLineStart();
  10387. const nextCh = this.codePointAtPos(next);
  10388. return this.chStartsBindingIdentifierAndNotRelationalOperator(nextCh, next);
  10389. }
  10390. nextTokenIsIdentifierOrStringLiteralOnSameLine() {
  10391. const next = this.nextTokenInLineStart();
  10392. const nextCh = this.codePointAtPos(next);
  10393. return this.chStartsBindingIdentifier(nextCh, next) || nextCh === 34 || nextCh === 39;
  10394. }
  10395. };
  10396. function isPossiblyLiteralEnum(expression) {
  10397. if (expression.type !== "MemberExpression") return false;
  10398. const {
  10399. computed,
  10400. property
  10401. } = expression;
  10402. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10403. return false;
  10404. }
  10405. return isUncomputedMemberExpressionChain(expression.object);
  10406. }
  10407. function isValidAmbientConstInitializer(expression, estree) {
  10408. var _expression$extra;
  10409. const {
  10410. type
  10411. } = expression;
  10412. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10413. return false;
  10414. }
  10415. if (estree) {
  10416. if (type === "Literal") {
  10417. const {
  10418. value
  10419. } = expression;
  10420. if (typeof value === "string" || typeof value === "boolean") {
  10421. return true;
  10422. }
  10423. }
  10424. } else {
  10425. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10426. return true;
  10427. }
  10428. }
  10429. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10430. return true;
  10431. }
  10432. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10433. return true;
  10434. }
  10435. if (isPossiblyLiteralEnum(expression)) {
  10436. return true;
  10437. }
  10438. return false;
  10439. }
  10440. function isNumber(expression, estree) {
  10441. if (estree) {
  10442. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10443. }
  10444. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10445. }
  10446. function isNegativeNumber(expression, estree) {
  10447. if (expression.type === "UnaryExpression") {
  10448. const {
  10449. operator,
  10450. argument
  10451. } = expression;
  10452. if (operator === "-" && isNumber(argument, estree)) {
  10453. return true;
  10454. }
  10455. }
  10456. return false;
  10457. }
  10458. function isUncomputedMemberExpressionChain(expression) {
  10459. if (expression.type === "Identifier") return true;
  10460. if (expression.type !== "MemberExpression" || expression.computed) {
  10461. return false;
  10462. }
  10463. return isUncomputedMemberExpressionChain(expression.object);
  10464. }
  10465. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10466. ClassNameIsRequired: "A class name is required.",
  10467. UnexpectedSpace: "Unexpected space in placeholder."
  10468. });
  10469. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10470. parsePlaceholder(expectedNode) {
  10471. if (this.match(133)) {
  10472. const node = this.startNode();
  10473. this.next();
  10474. this.assertNoSpace();
  10475. node.name = super.parseIdentifier(true);
  10476. this.assertNoSpace();
  10477. this.expect(133);
  10478. return this.finishPlaceholder(node, expectedNode);
  10479. }
  10480. }
  10481. finishPlaceholder(node, expectedNode) {
  10482. let placeholder = node;
  10483. if (!placeholder.expectedNode || !placeholder.type) {
  10484. placeholder = this.finishNode(placeholder, "Placeholder");
  10485. }
  10486. placeholder.expectedNode = expectedNode;
  10487. return placeholder;
  10488. }
  10489. getTokenFromCode(code) {
  10490. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10491. this.finishOp(133, 2);
  10492. } else {
  10493. super.getTokenFromCode(code);
  10494. }
  10495. }
  10496. parseExprAtom(refExpressionErrors) {
  10497. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10498. }
  10499. parseIdentifier(liberal) {
  10500. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10501. }
  10502. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10503. if (word !== undefined) {
  10504. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10505. }
  10506. }
  10507. cloneIdentifier(node) {
  10508. const cloned = super.cloneIdentifier(node);
  10509. if (cloned.type === "Placeholder") {
  10510. cloned.expectedNode = node.expectedNode;
  10511. }
  10512. return cloned;
  10513. }
  10514. cloneStringLiteral(node) {
  10515. if (node.type === "Placeholder") {
  10516. return this.cloneIdentifier(node);
  10517. }
  10518. return super.cloneStringLiteral(node);
  10519. }
  10520. parseBindingAtom() {
  10521. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10522. }
  10523. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  10524. return type === "Placeholder" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  10525. }
  10526. toAssignable(node, isLHS) {
  10527. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10528. node.expectedNode = "Pattern";
  10529. } else {
  10530. super.toAssignable(node, isLHS);
  10531. }
  10532. }
  10533. chStartsBindingIdentifier(ch, pos) {
  10534. if (super.chStartsBindingIdentifier(ch, pos)) {
  10535. return true;
  10536. }
  10537. const next = this.nextTokenStart();
  10538. if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
  10539. return true;
  10540. }
  10541. return false;
  10542. }
  10543. verifyBreakContinue(node, isBreak) {
  10544. if (node.label && node.label.type === "Placeholder") return;
  10545. super.verifyBreakContinue(node, isBreak);
  10546. }
  10547. parseExpressionStatement(node, expr) {
  10548. var _expr$extra;
  10549. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10550. return super.parseExpressionStatement(node, expr);
  10551. }
  10552. if (this.match(14)) {
  10553. const stmt = node;
  10554. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10555. this.next();
  10556. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10557. return this.finishNode(stmt, "LabeledStatement");
  10558. }
  10559. this.semicolon();
  10560. const stmtPlaceholder = node;
  10561. stmtPlaceholder.name = expr.name;
  10562. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  10563. }
  10564. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10565. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10566. }
  10567. parseFunctionId(requireId) {
  10568. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10569. }
  10570. parseClass(node, isStatement, optionalId) {
  10571. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10572. this.next();
  10573. const oldStrict = this.state.strict;
  10574. const placeholder = this.parsePlaceholder("Identifier");
  10575. if (placeholder) {
  10576. if (this.match(81) || this.match(133) || this.match(5)) {
  10577. node.id = placeholder;
  10578. } else if (optionalId || !isStatement) {
  10579. node.id = null;
  10580. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10581. return this.finishNode(node, type);
  10582. } else {
  10583. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10584. }
  10585. } else {
  10586. this.parseClassId(node, isStatement, optionalId);
  10587. }
  10588. super.parseClassSuper(node);
  10589. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10590. return this.finishNode(node, type);
  10591. }
  10592. parseExport(node, decorators) {
  10593. const placeholder = this.parsePlaceholder("Identifier");
  10594. if (!placeholder) return super.parseExport(node, decorators);
  10595. const node2 = node;
  10596. if (!this.isContextual(98) && !this.match(12)) {
  10597. node2.specifiers = [];
  10598. node2.source = null;
  10599. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10600. return this.finishNode(node2, "ExportNamedDeclaration");
  10601. }
  10602. this.expectPlugin("exportDefaultFrom");
  10603. const specifier = this.startNode();
  10604. specifier.exported = placeholder;
  10605. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10606. return super.parseExport(node2, decorators);
  10607. }
  10608. isExportDefaultSpecifier() {
  10609. if (this.match(65)) {
  10610. const next = this.nextTokenStart();
  10611. if (this.isUnparsedContextual(next, "from")) {
  10612. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  10613. return true;
  10614. }
  10615. }
  10616. }
  10617. return super.isExportDefaultSpecifier();
  10618. }
  10619. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10620. var _specifiers;
  10621. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10622. return true;
  10623. }
  10624. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10625. }
  10626. checkExport(node) {
  10627. const {
  10628. specifiers
  10629. } = node;
  10630. if (specifiers != null && specifiers.length) {
  10631. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10632. }
  10633. super.checkExport(node);
  10634. node.specifiers = specifiers;
  10635. }
  10636. parseImport(node) {
  10637. const placeholder = this.parsePlaceholder("Identifier");
  10638. if (!placeholder) return super.parseImport(node);
  10639. node.specifiers = [];
  10640. if (!this.isContextual(98) && !this.match(12)) {
  10641. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10642. this.semicolon();
  10643. return this.finishNode(node, "ImportDeclaration");
  10644. }
  10645. const specifier = this.startNodeAtNode(placeholder);
  10646. specifier.local = placeholder;
  10647. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10648. if (this.eat(12)) {
  10649. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10650. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10651. }
  10652. this.expectContextual(98);
  10653. node.source = this.parseImportSource();
  10654. this.semicolon();
  10655. return this.finishNode(node, "ImportDeclaration");
  10656. }
  10657. parseImportSource() {
  10658. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10659. }
  10660. assertNoSpace() {
  10661. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  10662. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10663. }
  10664. }
  10665. };
  10666. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10667. parseV8Intrinsic() {
  10668. if (this.match(54)) {
  10669. const v8IntrinsicStartLoc = this.state.startLoc;
  10670. const node = this.startNode();
  10671. this.next();
  10672. if (tokenIsIdentifier(this.state.type)) {
  10673. const name = this.parseIdentifierName();
  10674. const identifier = this.createIdentifier(node, name);
  10675. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  10676. if (this.match(10)) {
  10677. return identifier;
  10678. }
  10679. }
  10680. this.unexpected(v8IntrinsicStartLoc);
  10681. }
  10682. }
  10683. parseExprAtom(refExpressionErrors) {
  10684. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10685. }
  10686. };
  10687. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10688. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10689. function validatePlugins(pluginsMap) {
  10690. if (pluginsMap.has("decorators")) {
  10691. if (pluginsMap.has("decorators-legacy")) {
  10692. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10693. }
  10694. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  10695. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10696. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10697. }
  10698. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  10699. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10700. throw new Error("'allowCallParenthesized' must be a boolean.");
  10701. }
  10702. }
  10703. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  10704. throw new Error("Cannot combine flow and typescript plugins.");
  10705. }
  10706. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  10707. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10708. }
  10709. if (pluginsMap.has("pipelineOperator")) {
  10710. var _pluginsMap$get2;
  10711. const proposal = pluginsMap.get("pipelineOperator").proposal;
  10712. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10713. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10714. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10715. }
  10716. if (proposal === "hack") {
  10717. if (pluginsMap.has("placeholders")) {
  10718. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10719. }
  10720. if (pluginsMap.has("v8intrinsic")) {
  10721. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10722. }
  10723. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  10724. if (!TOPIC_TOKENS.includes(topicToken)) {
  10725. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10726. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10727. }
  10728. {
  10729. var _pluginsMap$get;
  10730. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  10731. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10732. }
  10733. }
  10734. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  10735. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10736. }
  10737. }
  10738. if (pluginsMap.has("moduleAttributes")) {
  10739. {
  10740. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  10741. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  10742. }
  10743. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  10744. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10745. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10746. }
  10747. }
  10748. }
  10749. if (pluginsMap.has("importAssertions")) {
  10750. if (pluginsMap.has("deprecatedImportAssert")) {
  10751. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  10752. }
  10753. }
  10754. if (!pluginsMap.has("deprecatedImportAssert") && pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  10755. {
  10756. pluginsMap.set("deprecatedImportAssert", {});
  10757. }
  10758. }
  10759. if (pluginsMap.has("recordAndTuple")) {
  10760. {
  10761. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  10762. if (syntaxType != null) {
  10763. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10764. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  10765. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10766. }
  10767. }
  10768. }
  10769. }
  10770. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  10771. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10772. error.missingPlugins = "doExpressions";
  10773. throw error;
  10774. }
  10775. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  10776. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10777. }
  10778. if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
  10779. throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
  10780. }
  10781. }
  10782. const mixinPlugins = {
  10783. estree,
  10784. jsx,
  10785. flow,
  10786. typescript,
  10787. v8intrinsic,
  10788. placeholders
  10789. };
  10790. const mixinPluginNames = Object.keys(mixinPlugins);
  10791. class ExpressionParser extends LValParser {
  10792. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  10793. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10794. return sawProto;
  10795. }
  10796. const key = prop.key;
  10797. const name = key.type === "Identifier" ? key.name : key.value;
  10798. if (name === "__proto__") {
  10799. if (isRecord) {
  10800. this.raise(Errors.RecordNoProto, key);
  10801. return true;
  10802. }
  10803. if (sawProto) {
  10804. if (refExpressionErrors) {
  10805. if (refExpressionErrors.doubleProtoLoc === null) {
  10806. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10807. }
  10808. } else {
  10809. this.raise(Errors.DuplicateProto, key);
  10810. }
  10811. }
  10812. return true;
  10813. }
  10814. return sawProto;
  10815. }
  10816. shouldExitDescending(expr, potentialArrowAt) {
  10817. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  10818. }
  10819. getExpression() {
  10820. this.enterInitialScopes();
  10821. this.nextToken();
  10822. if (this.match(140)) {
  10823. throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
  10824. }
  10825. const expr = this.parseExpression();
  10826. if (!this.match(140)) {
  10827. throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
  10828. unexpected: this.input.codePointAt(this.state.start)
  10829. });
  10830. }
  10831. this.finalizeRemainingComments();
  10832. expr.comments = this.comments;
  10833. expr.errors = this.state.errors;
  10834. if (this.optionFlags & 256) {
  10835. expr.tokens = this.tokens;
  10836. }
  10837. return expr;
  10838. }
  10839. parseExpression(disallowIn, refExpressionErrors) {
  10840. if (disallowIn) {
  10841. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10842. }
  10843. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10844. }
  10845. parseExpressionBase(refExpressionErrors) {
  10846. const startLoc = this.state.startLoc;
  10847. const expr = this.parseMaybeAssign(refExpressionErrors);
  10848. if (this.match(12)) {
  10849. const node = this.startNodeAt(startLoc);
  10850. node.expressions = [expr];
  10851. while (this.eat(12)) {
  10852. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10853. }
  10854. this.toReferencedList(node.expressions);
  10855. return this.finishNode(node, "SequenceExpression");
  10856. }
  10857. return expr;
  10858. }
  10859. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10860. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10861. }
  10862. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10863. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10864. }
  10865. setOptionalParametersError(refExpressionErrors) {
  10866. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  10867. }
  10868. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10869. const startLoc = this.state.startLoc;
  10870. const isYield = this.isContextual(108);
  10871. if (isYield) {
  10872. if (this.prodParam.hasYield) {
  10873. this.next();
  10874. let left = this.parseYield(startLoc);
  10875. if (afterLeftParse) {
  10876. left = afterLeftParse.call(this, left, startLoc);
  10877. }
  10878. return left;
  10879. }
  10880. }
  10881. let ownExpressionErrors;
  10882. if (refExpressionErrors) {
  10883. ownExpressionErrors = false;
  10884. } else {
  10885. refExpressionErrors = new ExpressionErrors();
  10886. ownExpressionErrors = true;
  10887. }
  10888. const {
  10889. type
  10890. } = this.state;
  10891. if (type === 10 || tokenIsIdentifier(type)) {
  10892. this.state.potentialArrowAt = this.state.start;
  10893. }
  10894. let left = this.parseMaybeConditional(refExpressionErrors);
  10895. if (afterLeftParse) {
  10896. left = afterLeftParse.call(this, left, startLoc);
  10897. }
  10898. if (tokenIsAssignment(this.state.type)) {
  10899. const node = this.startNodeAt(startLoc);
  10900. const operator = this.state.value;
  10901. node.operator = operator;
  10902. if (this.match(29)) {
  10903. this.toAssignable(left, true);
  10904. node.left = left;
  10905. const startIndex = startLoc.index;
  10906. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10907. refExpressionErrors.doubleProtoLoc = null;
  10908. }
  10909. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10910. refExpressionErrors.shorthandAssignLoc = null;
  10911. }
  10912. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10913. this.checkDestructuringPrivate(refExpressionErrors);
  10914. refExpressionErrors.privateKeyLoc = null;
  10915. }
  10916. if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
  10917. refExpressionErrors.voidPatternLoc = null;
  10918. }
  10919. } else {
  10920. node.left = left;
  10921. }
  10922. this.next();
  10923. node.right = this.parseMaybeAssign();
  10924. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"), undefined, undefined, undefined, undefined, operator === "||=" || operator === "&&=" || operator === "??=");
  10925. return node;
  10926. } else if (ownExpressionErrors) {
  10927. this.checkExpressionErrors(refExpressionErrors, true);
  10928. }
  10929. if (isYield) {
  10930. const {
  10931. type
  10932. } = this.state;
  10933. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10934. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  10935. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  10936. return this.parseYield(startLoc);
  10937. }
  10938. }
  10939. return left;
  10940. }
  10941. parseMaybeConditional(refExpressionErrors) {
  10942. const startLoc = this.state.startLoc;
  10943. const potentialArrowAt = this.state.potentialArrowAt;
  10944. const expr = this.parseExprOps(refExpressionErrors);
  10945. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10946. return expr;
  10947. }
  10948. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10949. }
  10950. parseConditional(expr, startLoc, refExpressionErrors) {
  10951. if (this.eat(17)) {
  10952. const node = this.startNodeAt(startLoc);
  10953. node.test = expr;
  10954. node.consequent = this.parseMaybeAssignAllowIn();
  10955. this.expect(14);
  10956. node.alternate = this.parseMaybeAssign();
  10957. return this.finishNode(node, "ConditionalExpression");
  10958. }
  10959. return expr;
  10960. }
  10961. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10962. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10963. }
  10964. parseExprOps(refExpressionErrors) {
  10965. const startLoc = this.state.startLoc;
  10966. const potentialArrowAt = this.state.potentialArrowAt;
  10967. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10968. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10969. return expr;
  10970. }
  10971. return this.parseExprOp(expr, startLoc, -1);
  10972. }
  10973. parseExprOp(left, leftStartLoc, minPrec) {
  10974. if (this.isPrivateName(left)) {
  10975. const value = this.getPrivateNameSV(left);
  10976. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10977. this.raise(Errors.PrivateInExpectedIn, left, {
  10978. identifierName: value
  10979. });
  10980. }
  10981. this.classScope.usePrivateName(value, left.loc.start);
  10982. }
  10983. const op = this.state.type;
  10984. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10985. let prec = tokenOperatorPrecedence(op);
  10986. if (prec > minPrec) {
  10987. if (op === 39) {
  10988. this.expectPlugin("pipelineOperator");
  10989. if (this.state.inFSharpPipelineDirectBody) {
  10990. return left;
  10991. }
  10992. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10993. }
  10994. const node = this.startNodeAt(leftStartLoc);
  10995. node.left = left;
  10996. node.operator = this.state.value;
  10997. const logical = op === 41 || op === 42;
  10998. const coalesce = op === 40;
  10999. if (coalesce) {
  11000. prec = tokenOperatorPrecedence(42);
  11001. }
  11002. this.next();
  11003. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  11004. proposal: "minimal"
  11005. }])) {
  11006. if (this.state.type === 96 && this.prodParam.hasAwait) {
  11007. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  11008. }
  11009. }
  11010. node.right = this.parseExprOpRightExpr(op, prec);
  11011. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  11012. const nextOp = this.state.type;
  11013. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  11014. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  11015. }
  11016. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  11017. }
  11018. }
  11019. return left;
  11020. }
  11021. parseExprOpRightExpr(op, prec) {
  11022. const startLoc = this.state.startLoc;
  11023. switch (op) {
  11024. case 39:
  11025. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  11026. case "hack":
  11027. return this.withTopicBindingContext(() => {
  11028. return this.parseHackPipeBody();
  11029. });
  11030. case "fsharp":
  11031. return this.withSoloAwaitPermittingContext(() => {
  11032. return this.parseFSharpPipelineBody(prec);
  11033. });
  11034. }
  11035. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  11036. return this.withTopicBindingContext(() => {
  11037. if (this.prodParam.hasYield && this.isContextual(108)) {
  11038. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  11039. }
  11040. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  11041. });
  11042. }
  11043. default:
  11044. return this.parseExprOpBaseRightExpr(op, prec);
  11045. }
  11046. }
  11047. parseExprOpBaseRightExpr(op, prec) {
  11048. const startLoc = this.state.startLoc;
  11049. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  11050. }
  11051. parseHackPipeBody() {
  11052. var _body$extra;
  11053. const {
  11054. startLoc
  11055. } = this.state;
  11056. const body = this.parseMaybeAssign();
  11057. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  11058. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  11059. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  11060. type: body.type
  11061. });
  11062. }
  11063. if (!this.topicReferenceWasUsedInCurrentContext()) {
  11064. this.raise(Errors.PipeTopicUnused, startLoc);
  11065. }
  11066. return body;
  11067. }
  11068. checkExponentialAfterUnary(node) {
  11069. if (this.match(57)) {
  11070. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  11071. }
  11072. }
  11073. parseMaybeUnary(refExpressionErrors, sawUnary) {
  11074. const startLoc = this.state.startLoc;
  11075. const isAwait = this.isContextual(96);
  11076. if (isAwait && this.recordAwaitIfAllowed()) {
  11077. this.next();
  11078. const expr = this.parseAwait(startLoc);
  11079. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  11080. return expr;
  11081. }
  11082. const update = this.match(34);
  11083. const node = this.startNode();
  11084. if (tokenIsPrefix(this.state.type)) {
  11085. node.operator = this.state.value;
  11086. node.prefix = true;
  11087. if (this.match(72)) {
  11088. this.expectPlugin("throwExpressions");
  11089. }
  11090. const isDelete = this.match(89);
  11091. this.next();
  11092. node.argument = this.parseMaybeUnary(null, true);
  11093. this.checkExpressionErrors(refExpressionErrors, true);
  11094. if (this.state.strict && isDelete) {
  11095. const arg = node.argument;
  11096. if (arg.type === "Identifier") {
  11097. this.raise(Errors.StrictDelete, node);
  11098. } else if (this.hasPropertyAsPrivateName(arg)) {
  11099. this.raise(Errors.DeletePrivateField, node);
  11100. }
  11101. }
  11102. if (!update) {
  11103. if (!sawUnary) {
  11104. this.checkExponentialAfterUnary(node);
  11105. }
  11106. return this.finishNode(node, "UnaryExpression");
  11107. }
  11108. }
  11109. const expr = this.parseUpdate(node, update, refExpressionErrors);
  11110. if (isAwait) {
  11111. const {
  11112. type
  11113. } = this.state;
  11114. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  11115. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  11116. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  11117. return this.parseAwait(startLoc);
  11118. }
  11119. }
  11120. return expr;
  11121. }
  11122. parseUpdate(node, update, refExpressionErrors) {
  11123. if (update) {
  11124. const updateExpressionNode = node;
  11125. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  11126. return node;
  11127. }
  11128. const startLoc = this.state.startLoc;
  11129. let expr = this.parseExprSubscripts(refExpressionErrors);
  11130. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  11131. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  11132. const node = this.startNodeAt(startLoc);
  11133. node.operator = this.state.value;
  11134. node.prefix = false;
  11135. node.argument = expr;
  11136. this.next();
  11137. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  11138. }
  11139. return expr;
  11140. }
  11141. parseExprSubscripts(refExpressionErrors) {
  11142. const startLoc = this.state.startLoc;
  11143. const potentialArrowAt = this.state.potentialArrowAt;
  11144. const expr = this.parseExprAtom(refExpressionErrors);
  11145. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11146. return expr;
  11147. }
  11148. return this.parseSubscripts(expr, startLoc);
  11149. }
  11150. parseSubscripts(base, startLoc, noCalls) {
  11151. const state = {
  11152. optionalChainMember: false,
  11153. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  11154. stop: false
  11155. };
  11156. do {
  11157. base = this.parseSubscript(base, startLoc, noCalls, state);
  11158. state.maybeAsyncArrow = false;
  11159. } while (!state.stop);
  11160. return base;
  11161. }
  11162. parseSubscript(base, startLoc, noCalls, state) {
  11163. const {
  11164. type
  11165. } = this.state;
  11166. if (!noCalls && type === 15) {
  11167. return this.parseBind(base, startLoc, noCalls, state);
  11168. } else if (tokenIsTemplate(type)) {
  11169. return this.parseTaggedTemplateExpression(base, startLoc, state);
  11170. }
  11171. let optional = false;
  11172. if (type === 18) {
  11173. if (noCalls) {
  11174. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  11175. if (this.lookaheadCharCode() === 40) {
  11176. return this.stopParseSubscript(base, state);
  11177. }
  11178. }
  11179. state.optionalChainMember = optional = true;
  11180. this.next();
  11181. }
  11182. if (!noCalls && this.match(10)) {
  11183. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  11184. } else {
  11185. const computed = this.eat(0);
  11186. if (computed || optional || this.eat(16)) {
  11187. return this.parseMember(base, startLoc, state, computed, optional);
  11188. } else {
  11189. return this.stopParseSubscript(base, state);
  11190. }
  11191. }
  11192. }
  11193. stopParseSubscript(base, state) {
  11194. state.stop = true;
  11195. return base;
  11196. }
  11197. parseMember(base, startLoc, state, computed, optional) {
  11198. const node = this.startNodeAt(startLoc);
  11199. node.object = base;
  11200. node.computed = computed;
  11201. if (computed) {
  11202. node.property = this.parseExpression();
  11203. this.expect(3);
  11204. } else if (this.match(139)) {
  11205. if (base.type === "Super") {
  11206. this.raise(Errors.SuperPrivateField, startLoc);
  11207. }
  11208. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  11209. node.property = this.parsePrivateName();
  11210. } else {
  11211. node.property = this.parseIdentifier(true);
  11212. }
  11213. if (state.optionalChainMember) {
  11214. node.optional = optional;
  11215. return this.finishNode(node, "OptionalMemberExpression");
  11216. } else {
  11217. return this.finishNode(node, "MemberExpression");
  11218. }
  11219. }
  11220. parseBind(base, startLoc, noCalls, state) {
  11221. const node = this.startNodeAt(startLoc);
  11222. node.object = base;
  11223. this.next();
  11224. node.callee = this.parseNoCallExpr();
  11225. state.stop = true;
  11226. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  11227. }
  11228. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  11229. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11230. let refExpressionErrors = null;
  11231. this.state.maybeInArrowParameters = true;
  11232. this.next();
  11233. const node = this.startNodeAt(startLoc);
  11234. node.callee = base;
  11235. const {
  11236. maybeAsyncArrow,
  11237. optionalChainMember
  11238. } = state;
  11239. if (maybeAsyncArrow) {
  11240. this.expressionScope.enter(newAsyncArrowScope());
  11241. refExpressionErrors = new ExpressionErrors();
  11242. }
  11243. if (optionalChainMember) {
  11244. node.optional = optional;
  11245. }
  11246. if (optional) {
  11247. node.arguments = this.parseCallExpressionArguments();
  11248. } else {
  11249. node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
  11250. }
  11251. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  11252. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  11253. state.stop = true;
  11254. this.checkDestructuringPrivate(refExpressionErrors);
  11255. this.expressionScope.validateAsPattern();
  11256. this.expressionScope.exit();
  11257. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  11258. } else {
  11259. if (maybeAsyncArrow) {
  11260. this.checkExpressionErrors(refExpressionErrors, true);
  11261. this.expressionScope.exit();
  11262. }
  11263. this.toReferencedArguments(finishedNode);
  11264. }
  11265. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11266. return finishedNode;
  11267. }
  11268. toReferencedArguments(node, isParenthesizedExpr) {
  11269. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11270. }
  11271. parseTaggedTemplateExpression(base, startLoc, state) {
  11272. const node = this.startNodeAt(startLoc);
  11273. node.tag = base;
  11274. node.quasi = this.parseTemplate(true);
  11275. if (state.optionalChainMember) {
  11276. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  11277. }
  11278. return this.finishNode(node, "TaggedTemplateExpression");
  11279. }
  11280. atPossibleAsyncArrow(base) {
  11281. 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;
  11282. }
  11283. finishCallExpression(node, optional) {
  11284. if (node.callee.type === "Import") {
  11285. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11286. this.raise(Errors.ImportCallArity, node);
  11287. } else {
  11288. for (const arg of node.arguments) {
  11289. if (arg.type === "SpreadElement") {
  11290. this.raise(Errors.ImportCallSpreadArgument, arg);
  11291. }
  11292. }
  11293. }
  11294. }
  11295. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11296. }
  11297. parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11298. const elts = [];
  11299. let first = true;
  11300. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11301. this.state.inFSharpPipelineDirectBody = false;
  11302. while (!this.eat(11)) {
  11303. if (first) {
  11304. first = false;
  11305. } else {
  11306. this.expect(12);
  11307. if (this.match(11)) {
  11308. if (nodeForExtra) {
  11309. this.addTrailingCommaExtraToNode(nodeForExtra);
  11310. }
  11311. this.next();
  11312. break;
  11313. }
  11314. }
  11315. elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
  11316. }
  11317. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11318. return elts;
  11319. }
  11320. shouldParseAsyncArrow() {
  11321. return this.match(19) && !this.canInsertSemicolon();
  11322. }
  11323. parseAsyncArrowFromCallExpression(node, call) {
  11324. var _call$extra;
  11325. this.resetPreviousNodeTrailingComments(call);
  11326. this.expect(19);
  11327. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11328. if (call.innerComments) {
  11329. setInnerComments(node, call.innerComments);
  11330. }
  11331. if (call.callee.trailingComments) {
  11332. setInnerComments(node, call.callee.trailingComments);
  11333. }
  11334. return node;
  11335. }
  11336. parseNoCallExpr() {
  11337. const startLoc = this.state.startLoc;
  11338. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11339. }
  11340. parseExprAtom(refExpressionErrors) {
  11341. let node;
  11342. let decorators = null;
  11343. const {
  11344. type
  11345. } = this.state;
  11346. switch (type) {
  11347. case 79:
  11348. return this.parseSuper();
  11349. case 83:
  11350. node = this.startNode();
  11351. this.next();
  11352. if (this.match(16)) {
  11353. return this.parseImportMetaPropertyOrPhaseCall(node);
  11354. }
  11355. if (this.match(10)) {
  11356. if (this.optionFlags & 512) {
  11357. return this.parseImportCall(node);
  11358. } else {
  11359. return this.finishNode(node, "Import");
  11360. }
  11361. } else {
  11362. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  11363. return this.finishNode(node, "Import");
  11364. }
  11365. case 78:
  11366. node = this.startNode();
  11367. this.next();
  11368. return this.finishNode(node, "ThisExpression");
  11369. case 90:
  11370. {
  11371. return this.parseDo(this.startNode(), false);
  11372. }
  11373. case 56:
  11374. case 31:
  11375. {
  11376. this.readRegexp();
  11377. return this.parseRegExpLiteral(this.state.value);
  11378. }
  11379. case 135:
  11380. return this.parseNumericLiteral(this.state.value);
  11381. case 136:
  11382. return this.parseBigIntLiteral(this.state.value);
  11383. case 134:
  11384. return this.parseStringLiteral(this.state.value);
  11385. case 84:
  11386. return this.parseNullLiteral();
  11387. case 85:
  11388. return this.parseBooleanLiteral(true);
  11389. case 86:
  11390. return this.parseBooleanLiteral(false);
  11391. case 10:
  11392. {
  11393. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11394. return this.parseParenAndDistinguishExpression(canBeArrow);
  11395. }
  11396. case 0:
  11397. {
  11398. return this.parseArrayLike(3, false, refExpressionErrors);
  11399. }
  11400. case 5:
  11401. {
  11402. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11403. }
  11404. case 68:
  11405. return this.parseFunctionOrFunctionSent();
  11406. case 26:
  11407. decorators = this.parseDecorators();
  11408. case 80:
  11409. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11410. case 77:
  11411. return this.parseNewOrNewTarget();
  11412. case 25:
  11413. case 24:
  11414. return this.parseTemplate(false);
  11415. case 15:
  11416. {
  11417. node = this.startNode();
  11418. this.next();
  11419. node.object = null;
  11420. const callee = node.callee = this.parseNoCallExpr();
  11421. if (callee.type === "MemberExpression") {
  11422. return this.finishNode(node, "BindExpression");
  11423. } else {
  11424. throw this.raise(Errors.UnsupportedBind, callee);
  11425. }
  11426. }
  11427. case 139:
  11428. {
  11429. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  11430. identifierName: this.state.value
  11431. });
  11432. return this.parsePrivateName();
  11433. }
  11434. case 33:
  11435. {
  11436. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11437. }
  11438. case 32:
  11439. {
  11440. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11441. }
  11442. case 37:
  11443. case 38:
  11444. {
  11445. return this.parseTopicReference("hack");
  11446. }
  11447. case 44:
  11448. case 54:
  11449. case 27:
  11450. {
  11451. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11452. if (pipeProposal) {
  11453. return this.parseTopicReference(pipeProposal);
  11454. }
  11455. throw this.unexpected();
  11456. }
  11457. case 47:
  11458. {
  11459. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11460. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11461. throw this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11462. }
  11463. throw this.unexpected();
  11464. }
  11465. default:
  11466. {
  11467. if (type === 137) {
  11468. return this.parseDecimalLiteral(this.state.value);
  11469. } else if (type === 2 || type === 1) {
  11470. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, true);
  11471. } else if (type === 6 || type === 7) {
  11472. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11473. }
  11474. }
  11475. if (tokenIsIdentifier(type)) {
  11476. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11477. return this.parseModuleExpression();
  11478. }
  11479. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11480. const containsEsc = this.state.containsEsc;
  11481. const id = this.parseIdentifier();
  11482. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11483. const {
  11484. type
  11485. } = this.state;
  11486. if (type === 68) {
  11487. this.resetPreviousNodeTrailingComments(id);
  11488. this.next();
  11489. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11490. } else if (tokenIsIdentifier(type)) {
  11491. if (this.lookaheadCharCode() === 61) {
  11492. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11493. } else {
  11494. return id;
  11495. }
  11496. } else if (type === 90) {
  11497. this.resetPreviousNodeTrailingComments(id);
  11498. return this.parseDo(this.startNodeAtNode(id), true);
  11499. }
  11500. }
  11501. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11502. this.next();
  11503. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11504. }
  11505. return id;
  11506. } else {
  11507. throw this.unexpected();
  11508. }
  11509. }
  11510. }
  11511. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11512. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11513. if (pipeProposal) {
  11514. this.state.type = topicTokenType;
  11515. this.state.value = topicTokenValue;
  11516. this.state.pos--;
  11517. this.state.end--;
  11518. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11519. return this.parseTopicReference(pipeProposal);
  11520. }
  11521. throw this.unexpected();
  11522. }
  11523. parseTopicReference(pipeProposal) {
  11524. const node = this.startNode();
  11525. const startLoc = this.state.startLoc;
  11526. const tokenType = this.state.type;
  11527. this.next();
  11528. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11529. }
  11530. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11531. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11532. if (pipeProposal === "hack") {
  11533. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11534. this.raise(Errors.PipeTopicUnbound, startLoc);
  11535. }
  11536. this.registerTopicReference();
  11537. return this.finishNode(node, "TopicReference");
  11538. } else {
  11539. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11540. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  11541. }
  11542. this.registerTopicReference();
  11543. return this.finishNode(node, "PipelinePrimaryTopicReference");
  11544. }
  11545. } else {
  11546. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11547. token: tokenLabelName(tokenType)
  11548. });
  11549. }
  11550. }
  11551. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11552. switch (pipeProposal) {
  11553. case "hack":
  11554. {
  11555. return this.hasPlugin(["pipelineOperator", {
  11556. topicToken: tokenLabelName(tokenType)
  11557. }]);
  11558. }
  11559. case "smart":
  11560. return tokenType === 27;
  11561. default:
  11562. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11563. }
  11564. }
  11565. parseAsyncArrowUnaryFunction(node) {
  11566. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11567. const params = [this.parseIdentifier()];
  11568. this.prodParam.exit();
  11569. if (this.hasPrecedingLineBreak()) {
  11570. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11571. }
  11572. this.expect(19);
  11573. return this.parseArrowExpression(node, params, true);
  11574. }
  11575. parseDo(node, isAsync) {
  11576. this.expectPlugin("doExpressions");
  11577. if (isAsync) {
  11578. this.expectPlugin("asyncDoExpressions");
  11579. }
  11580. node.async = isAsync;
  11581. this.next();
  11582. const oldLabels = this.state.labels;
  11583. this.state.labels = [];
  11584. if (isAsync) {
  11585. this.prodParam.enter(2);
  11586. node.body = this.parseBlock();
  11587. this.prodParam.exit();
  11588. } else {
  11589. node.body = this.parseBlock();
  11590. }
  11591. this.state.labels = oldLabels;
  11592. return this.finishNode(node, "DoExpression");
  11593. }
  11594. parseSuper() {
  11595. const node = this.startNode();
  11596. this.next();
  11597. if (this.match(10) && !this.scope.allowDirectSuper) {
  11598. {
  11599. if (!(this.optionFlags & 16)) {
  11600. this.raise(Errors.SuperNotAllowed, node);
  11601. }
  11602. }
  11603. } else if (!this.scope.allowSuper) {
  11604. {
  11605. if (!(this.optionFlags & 16)) {
  11606. this.raise(Errors.UnexpectedSuper, node);
  11607. }
  11608. }
  11609. }
  11610. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11611. this.raise(Errors.UnsupportedSuper, node);
  11612. }
  11613. return this.finishNode(node, "Super");
  11614. }
  11615. parsePrivateName() {
  11616. const node = this.startNode();
  11617. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11618. const name = this.state.value;
  11619. this.next();
  11620. node.id = this.createIdentifier(id, name);
  11621. return this.finishNode(node, "PrivateName");
  11622. }
  11623. parseFunctionOrFunctionSent() {
  11624. const node = this.startNode();
  11625. this.next();
  11626. if (this.prodParam.hasYield && this.match(16)) {
  11627. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11628. this.next();
  11629. if (this.match(103)) {
  11630. this.expectPlugin("functionSent");
  11631. } else if (!this.hasPlugin("functionSent")) {
  11632. this.unexpected();
  11633. }
  11634. return this.parseMetaProperty(node, meta, "sent");
  11635. }
  11636. return this.parseFunction(node);
  11637. }
  11638. parseMetaProperty(node, meta, propertyName) {
  11639. node.meta = meta;
  11640. const containsEsc = this.state.containsEsc;
  11641. node.property = this.parseIdentifier(true);
  11642. if (node.property.name !== propertyName || containsEsc) {
  11643. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11644. target: meta.name,
  11645. onlyValidPropertyName: propertyName
  11646. });
  11647. }
  11648. return this.finishNode(node, "MetaProperty");
  11649. }
  11650. parseImportMetaPropertyOrPhaseCall(node) {
  11651. this.next();
  11652. if (this.isContextual(105) || this.isContextual(97)) {
  11653. const isSource = this.isContextual(105);
  11654. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11655. this.next();
  11656. node.phase = isSource ? "source" : "defer";
  11657. return this.parseImportCall(node);
  11658. } else {
  11659. const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
  11660. if (this.isContextual(101)) {
  11661. if (!this.inModule) {
  11662. this.raise(Errors.ImportMetaOutsideModule, id);
  11663. }
  11664. this.sawUnambiguousESM = true;
  11665. }
  11666. return this.parseMetaProperty(node, id, "meta");
  11667. }
  11668. }
  11669. parseLiteralAtNode(value, type, node) {
  11670. this.addExtra(node, "rawValue", value);
  11671. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11672. node.value = value;
  11673. this.next();
  11674. return this.finishNode(node, type);
  11675. }
  11676. parseLiteral(value, type) {
  11677. const node = this.startNode();
  11678. return this.parseLiteralAtNode(value, type, node);
  11679. }
  11680. parseStringLiteral(value) {
  11681. return this.parseLiteral(value, "StringLiteral");
  11682. }
  11683. parseNumericLiteral(value) {
  11684. return this.parseLiteral(value, "NumericLiteral");
  11685. }
  11686. parseBigIntLiteral(value) {
  11687. {
  11688. return this.parseLiteral(value, "BigIntLiteral");
  11689. }
  11690. }
  11691. parseDecimalLiteral(value) {
  11692. return this.parseLiteral(value, "DecimalLiteral");
  11693. }
  11694. parseRegExpLiteral(value) {
  11695. const node = this.startNode();
  11696. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11697. node.pattern = value.pattern;
  11698. node.flags = value.flags;
  11699. this.next();
  11700. return this.finishNode(node, "RegExpLiteral");
  11701. }
  11702. parseBooleanLiteral(value) {
  11703. const node = this.startNode();
  11704. node.value = value;
  11705. this.next();
  11706. return this.finishNode(node, "BooleanLiteral");
  11707. }
  11708. parseNullLiteral() {
  11709. const node = this.startNode();
  11710. this.next();
  11711. return this.finishNode(node, "NullLiteral");
  11712. }
  11713. parseParenAndDistinguishExpression(canBeArrow) {
  11714. const startLoc = this.state.startLoc;
  11715. let val;
  11716. this.next();
  11717. this.expressionScope.enter(newArrowHeadScope());
  11718. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11719. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11720. this.state.maybeInArrowParameters = true;
  11721. this.state.inFSharpPipelineDirectBody = false;
  11722. const innerStartLoc = this.state.startLoc;
  11723. const exprList = [];
  11724. const refExpressionErrors = new ExpressionErrors();
  11725. let first = true;
  11726. let spreadStartLoc;
  11727. let optionalCommaStartLoc;
  11728. while (!this.match(11)) {
  11729. if (first) {
  11730. first = false;
  11731. } else {
  11732. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11733. if (this.match(11)) {
  11734. optionalCommaStartLoc = this.state.startLoc;
  11735. break;
  11736. }
  11737. }
  11738. if (this.match(21)) {
  11739. const spreadNodeStartLoc = this.state.startLoc;
  11740. spreadStartLoc = this.state.startLoc;
  11741. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11742. if (!this.checkCommaAfterRest(41)) {
  11743. break;
  11744. }
  11745. } else {
  11746. exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
  11747. }
  11748. }
  11749. const innerEndLoc = this.state.lastTokEndLoc;
  11750. this.expect(11);
  11751. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11752. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11753. let arrowNode = this.startNodeAt(startLoc);
  11754. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11755. this.checkDestructuringPrivate(refExpressionErrors);
  11756. this.expressionScope.validateAsPattern();
  11757. this.expressionScope.exit();
  11758. this.parseArrowExpression(arrowNode, exprList, false);
  11759. return arrowNode;
  11760. }
  11761. this.expressionScope.exit();
  11762. if (!exprList.length) {
  11763. this.unexpected(this.state.lastTokStartLoc);
  11764. }
  11765. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11766. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11767. this.checkExpressionErrors(refExpressionErrors, true);
  11768. this.toReferencedListDeep(exprList, true);
  11769. if (exprList.length > 1) {
  11770. val = this.startNodeAt(innerStartLoc);
  11771. val.expressions = exprList;
  11772. this.finishNode(val, "SequenceExpression");
  11773. this.resetEndLocation(val, innerEndLoc);
  11774. } else {
  11775. val = exprList[0];
  11776. }
  11777. return this.wrapParenthesis(startLoc, val);
  11778. }
  11779. wrapParenthesis(startLoc, expression) {
  11780. if (!(this.optionFlags & 1024)) {
  11781. this.addExtra(expression, "parenthesized", true);
  11782. this.addExtra(expression, "parenStart", startLoc.index);
  11783. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11784. return expression;
  11785. }
  11786. const parenExpression = this.startNodeAt(startLoc);
  11787. parenExpression.expression = expression;
  11788. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11789. }
  11790. shouldParseArrow(params) {
  11791. return !this.canInsertSemicolon();
  11792. }
  11793. parseArrow(node) {
  11794. if (this.eat(19)) {
  11795. return node;
  11796. }
  11797. }
  11798. parseParenItem(node, startLoc) {
  11799. return node;
  11800. }
  11801. parseNewOrNewTarget() {
  11802. const node = this.startNode();
  11803. this.next();
  11804. if (this.match(16)) {
  11805. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11806. this.next();
  11807. const metaProp = this.parseMetaProperty(node, meta, "target");
  11808. if (!this.scope.allowNewTarget) {
  11809. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11810. }
  11811. return metaProp;
  11812. }
  11813. return this.parseNew(node);
  11814. }
  11815. parseNew(node) {
  11816. this.parseNewCallee(node);
  11817. if (this.eat(10)) {
  11818. const args = this.parseExprList(11);
  11819. this.toReferencedList(args);
  11820. node.arguments = args;
  11821. } else {
  11822. node.arguments = [];
  11823. }
  11824. return this.finishNode(node, "NewExpression");
  11825. }
  11826. parseNewCallee(node) {
  11827. const isImport = this.match(83);
  11828. const callee = this.parseNoCallExpr();
  11829. node.callee = callee;
  11830. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11831. this.raise(Errors.ImportCallNotNewExpression, callee);
  11832. }
  11833. }
  11834. parseTemplateElement(isTagged) {
  11835. const {
  11836. start,
  11837. startLoc,
  11838. end,
  11839. value
  11840. } = this.state;
  11841. const elemStart = start + 1;
  11842. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11843. if (value === null) {
  11844. if (!isTagged) {
  11845. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11846. }
  11847. }
  11848. const isTail = this.match(24);
  11849. const endOffset = isTail ? -1 : -2;
  11850. const elemEnd = end + endOffset;
  11851. elem.value = {
  11852. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11853. cooked: value === null ? null : value.slice(1, endOffset)
  11854. };
  11855. elem.tail = isTail;
  11856. this.next();
  11857. const finishedNode = this.finishNode(elem, "TemplateElement");
  11858. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11859. return finishedNode;
  11860. }
  11861. parseTemplate(isTagged) {
  11862. const node = this.startNode();
  11863. let curElt = this.parseTemplateElement(isTagged);
  11864. const quasis = [curElt];
  11865. const substitutions = [];
  11866. while (!curElt.tail) {
  11867. substitutions.push(this.parseTemplateSubstitution());
  11868. this.readTemplateContinuation();
  11869. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11870. }
  11871. node.expressions = substitutions;
  11872. node.quasis = quasis;
  11873. return this.finishNode(node, "TemplateLiteral");
  11874. }
  11875. parseTemplateSubstitution() {
  11876. return this.parseExpression();
  11877. }
  11878. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11879. if (isRecord) {
  11880. this.expectPlugin("recordAndTuple");
  11881. }
  11882. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11883. this.state.inFSharpPipelineDirectBody = false;
  11884. let sawProto = false;
  11885. let first = true;
  11886. const node = this.startNode();
  11887. node.properties = [];
  11888. this.next();
  11889. while (!this.match(close)) {
  11890. if (first) {
  11891. first = false;
  11892. } else {
  11893. this.expect(12);
  11894. if (this.match(close)) {
  11895. this.addTrailingCommaExtraToNode(node);
  11896. break;
  11897. }
  11898. }
  11899. let prop;
  11900. if (isPattern) {
  11901. prop = this.parseBindingProperty();
  11902. } else {
  11903. prop = this.parsePropertyDefinition(refExpressionErrors);
  11904. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  11905. }
  11906. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11907. this.raise(Errors.InvalidRecordProperty, prop);
  11908. }
  11909. {
  11910. if (prop.shorthand) {
  11911. this.addExtra(prop, "shorthand", true);
  11912. }
  11913. }
  11914. node.properties.push(prop);
  11915. }
  11916. this.next();
  11917. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11918. let type = "ObjectExpression";
  11919. if (isPattern) {
  11920. type = "ObjectPattern";
  11921. } else if (isRecord) {
  11922. type = "RecordExpression";
  11923. }
  11924. return this.finishNode(node, type);
  11925. }
  11926. addTrailingCommaExtraToNode(node) {
  11927. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11928. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11929. }
  11930. maybeAsyncOrAccessorProp(prop) {
  11931. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11932. }
  11933. parsePropertyDefinition(refExpressionErrors) {
  11934. let decorators = [];
  11935. if (this.match(26)) {
  11936. if (this.hasPlugin("decorators")) {
  11937. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11938. }
  11939. while (this.match(26)) {
  11940. decorators.push(this.parseDecorator());
  11941. }
  11942. }
  11943. const prop = this.startNode();
  11944. let isAsync = false;
  11945. let isAccessor = false;
  11946. let startLoc;
  11947. if (this.match(21)) {
  11948. if (decorators.length) this.unexpected();
  11949. return this.parseSpread();
  11950. }
  11951. if (decorators.length) {
  11952. prop.decorators = decorators;
  11953. decorators = [];
  11954. }
  11955. prop.method = false;
  11956. if (refExpressionErrors) {
  11957. startLoc = this.state.startLoc;
  11958. }
  11959. let isGenerator = this.eat(55);
  11960. this.parsePropertyNamePrefixOperator(prop);
  11961. const containsEsc = this.state.containsEsc;
  11962. this.parsePropertyName(prop, refExpressionErrors);
  11963. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11964. const {
  11965. key
  11966. } = prop;
  11967. const keyName = key.name;
  11968. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11969. isAsync = true;
  11970. this.resetPreviousNodeTrailingComments(key);
  11971. isGenerator = this.eat(55);
  11972. this.parsePropertyName(prop);
  11973. }
  11974. if (keyName === "get" || keyName === "set") {
  11975. isAccessor = true;
  11976. this.resetPreviousNodeTrailingComments(key);
  11977. prop.kind = keyName;
  11978. if (this.match(55)) {
  11979. isGenerator = true;
  11980. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11981. kind: keyName
  11982. });
  11983. this.next();
  11984. }
  11985. this.parsePropertyName(prop);
  11986. }
  11987. }
  11988. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11989. }
  11990. getGetterSetterExpectedParamCount(method) {
  11991. return method.kind === "get" ? 0 : 1;
  11992. }
  11993. getObjectOrClassMethodParams(method) {
  11994. return method.params;
  11995. }
  11996. checkGetterSetterParams(method) {
  11997. var _params;
  11998. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11999. const params = this.getObjectOrClassMethodParams(method);
  12000. if (params.length !== paramCount) {
  12001. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  12002. }
  12003. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  12004. this.raise(Errors.BadSetterRestParameter, method);
  12005. }
  12006. }
  12007. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  12008. if (isAccessor) {
  12009. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  12010. this.checkGetterSetterParams(finishedProp);
  12011. return finishedProp;
  12012. }
  12013. if (isAsync || isGenerator || this.match(10)) {
  12014. if (isPattern) this.unexpected();
  12015. prop.kind = "method";
  12016. prop.method = true;
  12017. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  12018. }
  12019. }
  12020. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  12021. prop.shorthand = false;
  12022. if (this.eat(14)) {
  12023. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
  12024. return this.finishObjectProperty(prop);
  12025. }
  12026. if (!prop.computed && prop.key.type === "Identifier") {
  12027. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  12028. if (isPattern) {
  12029. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  12030. } else if (this.match(29)) {
  12031. const shorthandAssignLoc = this.state.startLoc;
  12032. if (refExpressionErrors != null) {
  12033. if (refExpressionErrors.shorthandAssignLoc === null) {
  12034. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  12035. }
  12036. } else {
  12037. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  12038. }
  12039. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  12040. } else {
  12041. prop.value = this.cloneIdentifier(prop.key);
  12042. }
  12043. prop.shorthand = true;
  12044. return this.finishObjectProperty(prop);
  12045. }
  12046. }
  12047. finishObjectProperty(node) {
  12048. return this.finishNode(node, "ObjectProperty");
  12049. }
  12050. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  12051. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  12052. if (!node) this.unexpected();
  12053. return node;
  12054. }
  12055. parsePropertyName(prop, refExpressionErrors) {
  12056. if (this.eat(0)) {
  12057. prop.computed = true;
  12058. prop.key = this.parseMaybeAssignAllowIn();
  12059. this.expect(3);
  12060. } else {
  12061. const {
  12062. type,
  12063. value
  12064. } = this.state;
  12065. let key;
  12066. if (tokenIsKeywordOrIdentifier(type)) {
  12067. key = this.parseIdentifier(true);
  12068. } else {
  12069. switch (type) {
  12070. case 135:
  12071. key = this.parseNumericLiteral(value);
  12072. break;
  12073. case 134:
  12074. key = this.parseStringLiteral(value);
  12075. break;
  12076. case 136:
  12077. key = this.parseBigIntLiteral(value);
  12078. break;
  12079. case 139:
  12080. {
  12081. const privateKeyLoc = this.state.startLoc;
  12082. if (refExpressionErrors != null) {
  12083. if (refExpressionErrors.privateKeyLoc === null) {
  12084. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  12085. }
  12086. } else {
  12087. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  12088. }
  12089. key = this.parsePrivateName();
  12090. break;
  12091. }
  12092. default:
  12093. if (type === 137) {
  12094. key = this.parseDecimalLiteral(value);
  12095. break;
  12096. }
  12097. this.unexpected();
  12098. }
  12099. }
  12100. prop.key = key;
  12101. if (type !== 139) {
  12102. prop.computed = false;
  12103. }
  12104. }
  12105. }
  12106. initFunction(node, isAsync) {
  12107. node.id = null;
  12108. node.generator = false;
  12109. node.async = isAsync;
  12110. }
  12111. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  12112. this.initFunction(node, isAsync);
  12113. node.generator = isGenerator;
  12114. this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
  12115. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12116. this.parseFunctionParams(node, isConstructor);
  12117. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  12118. this.prodParam.exit();
  12119. this.scope.exit();
  12120. return finishedNode;
  12121. }
  12122. parseArrayLike(close, isTuple, refExpressionErrors) {
  12123. if (isTuple) {
  12124. this.expectPlugin("recordAndTuple");
  12125. }
  12126. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12127. this.state.inFSharpPipelineDirectBody = false;
  12128. const node = this.startNode();
  12129. this.next();
  12130. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  12131. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12132. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  12133. }
  12134. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  12135. this.scope.enter(514 | 4);
  12136. let flags = functionFlags(isAsync, false);
  12137. if (!this.match(5) && this.prodParam.hasIn) {
  12138. flags |= 8;
  12139. }
  12140. this.prodParam.enter(flags);
  12141. this.initFunction(node, isAsync);
  12142. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12143. if (params) {
  12144. this.state.maybeInArrowParameters = true;
  12145. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  12146. }
  12147. this.state.maybeInArrowParameters = false;
  12148. this.parseFunctionBody(node, true);
  12149. this.prodParam.exit();
  12150. this.scope.exit();
  12151. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12152. return this.finishNode(node, "ArrowFunctionExpression");
  12153. }
  12154. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  12155. this.toAssignableList(params, trailingCommaLoc, false);
  12156. node.params = params;
  12157. }
  12158. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  12159. this.parseFunctionBody(node, false, isMethod);
  12160. return this.finishNode(node, type);
  12161. }
  12162. parseFunctionBody(node, allowExpression, isMethod = false) {
  12163. const isExpression = allowExpression && !this.match(5);
  12164. this.expressionScope.enter(newExpressionScope());
  12165. if (isExpression) {
  12166. node.body = this.parseMaybeAssign();
  12167. this.checkParams(node, false, allowExpression, false);
  12168. } else {
  12169. const oldStrict = this.state.strict;
  12170. const oldLabels = this.state.labels;
  12171. this.state.labels = [];
  12172. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  12173. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  12174. const nonSimple = !this.isSimpleParamList(node.params);
  12175. if (hasStrictModeDirective && nonSimple) {
  12176. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  12177. }
  12178. const strictModeChanged = !oldStrict && this.state.strict;
  12179. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  12180. if (this.state.strict && node.id) {
  12181. this.checkIdentifier(node.id, 65, strictModeChanged);
  12182. }
  12183. });
  12184. this.prodParam.exit();
  12185. this.state.labels = oldLabels;
  12186. }
  12187. this.expressionScope.exit();
  12188. }
  12189. isSimpleParameter(node) {
  12190. return node.type === "Identifier";
  12191. }
  12192. isSimpleParamList(params) {
  12193. for (let i = 0, len = params.length; i < len; i++) {
  12194. if (!this.isSimpleParameter(params[i])) return false;
  12195. }
  12196. return true;
  12197. }
  12198. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  12199. const checkClashes = !allowDuplicates && new Set();
  12200. const formalParameters = {
  12201. type: "FormalParameters"
  12202. };
  12203. for (const param of node.params) {
  12204. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  12205. }
  12206. }
  12207. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  12208. const elts = [];
  12209. let first = true;
  12210. while (!this.eat(close)) {
  12211. if (first) {
  12212. first = false;
  12213. } else {
  12214. this.expect(12);
  12215. if (this.match(close)) {
  12216. if (nodeForExtra) {
  12217. this.addTrailingCommaExtraToNode(nodeForExtra);
  12218. }
  12219. this.next();
  12220. break;
  12221. }
  12222. }
  12223. elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
  12224. }
  12225. return elts;
  12226. }
  12227. parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
  12228. let elt;
  12229. if (this.match(12)) {
  12230. if (!allowEmpty) {
  12231. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  12232. unexpected: ","
  12233. });
  12234. }
  12235. elt = null;
  12236. } else if (this.match(21)) {
  12237. const spreadNodeStartLoc = this.state.startLoc;
  12238. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12239. } else if (this.match(17)) {
  12240. this.expectPlugin("partialApplication");
  12241. if (!allowPlaceholder) {
  12242. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  12243. }
  12244. const node = this.startNode();
  12245. this.next();
  12246. elt = this.finishNode(node, "ArgumentPlaceholder");
  12247. } else {
  12248. elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
  12249. }
  12250. return elt;
  12251. }
  12252. parseIdentifier(liberal) {
  12253. const node = this.startNode();
  12254. const name = this.parseIdentifierName(liberal);
  12255. return this.createIdentifier(node, name);
  12256. }
  12257. createIdentifier(node, name) {
  12258. node.name = name;
  12259. node.loc.identifierName = name;
  12260. return this.finishNode(node, "Identifier");
  12261. }
  12262. createIdentifierAt(node, name, endLoc) {
  12263. node.name = name;
  12264. node.loc.identifierName = name;
  12265. return this.finishNodeAt(node, "Identifier", endLoc);
  12266. }
  12267. parseIdentifierName(liberal) {
  12268. let name;
  12269. const {
  12270. startLoc,
  12271. type
  12272. } = this.state;
  12273. if (tokenIsKeywordOrIdentifier(type)) {
  12274. name = this.state.value;
  12275. } else {
  12276. this.unexpected();
  12277. }
  12278. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12279. if (liberal) {
  12280. if (tokenIsKeyword) {
  12281. this.replaceToken(132);
  12282. }
  12283. } else {
  12284. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12285. }
  12286. this.next();
  12287. return name;
  12288. }
  12289. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12290. if (word.length > 10) {
  12291. return;
  12292. }
  12293. if (!canBeReservedWord(word)) {
  12294. return;
  12295. }
  12296. if (checkKeywords && isKeyword(word)) {
  12297. this.raise(Errors.UnexpectedKeyword, startLoc, {
  12298. keyword: word
  12299. });
  12300. return;
  12301. }
  12302. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12303. if (reservedTest(word, this.inModule)) {
  12304. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  12305. reservedWord: word
  12306. });
  12307. return;
  12308. } else if (word === "yield") {
  12309. if (this.prodParam.hasYield) {
  12310. this.raise(Errors.YieldBindingIdentifier, startLoc);
  12311. return;
  12312. }
  12313. } else if (word === "await") {
  12314. if (this.prodParam.hasAwait) {
  12315. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  12316. return;
  12317. }
  12318. if (this.scope.inStaticBlock) {
  12319. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  12320. return;
  12321. }
  12322. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  12323. } else if (word === "arguments") {
  12324. if (this.scope.inClassAndNotInNonArrowFunction) {
  12325. this.raise(Errors.ArgumentsInClass, startLoc);
  12326. return;
  12327. }
  12328. }
  12329. }
  12330. recordAwaitIfAllowed() {
  12331. const isAwaitAllowed = this.prodParam.hasAwait;
  12332. if (isAwaitAllowed && !this.scope.inFunction) {
  12333. this.state.hasTopLevelAwait = true;
  12334. }
  12335. return isAwaitAllowed;
  12336. }
  12337. parseAwait(startLoc) {
  12338. const node = this.startNodeAt(startLoc);
  12339. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  12340. if (this.eat(55)) {
  12341. this.raise(Errors.ObsoleteAwaitStar, node);
  12342. }
  12343. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  12344. if (this.isAmbiguousPrefixOrIdentifier()) {
  12345. this.ambiguousScriptDifferentAst = true;
  12346. } else {
  12347. this.sawUnambiguousESM = true;
  12348. }
  12349. }
  12350. if (!this.state.soloAwait) {
  12351. node.argument = this.parseMaybeUnary(null, true);
  12352. }
  12353. return this.finishNode(node, "AwaitExpression");
  12354. }
  12355. isAmbiguousPrefixOrIdentifier() {
  12356. if (this.hasPrecedingLineBreak()) return true;
  12357. const {
  12358. type
  12359. } = this.state;
  12360. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12361. }
  12362. parseYield(startLoc) {
  12363. const node = this.startNodeAt(startLoc);
  12364. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  12365. let delegating = false;
  12366. let argument = null;
  12367. if (!this.hasPrecedingLineBreak()) {
  12368. delegating = this.eat(55);
  12369. switch (this.state.type) {
  12370. case 13:
  12371. case 140:
  12372. case 8:
  12373. case 11:
  12374. case 3:
  12375. case 9:
  12376. case 14:
  12377. case 12:
  12378. if (!delegating) break;
  12379. default:
  12380. argument = this.parseMaybeAssign();
  12381. }
  12382. }
  12383. node.delegate = delegating;
  12384. node.argument = argument;
  12385. return this.finishNode(node, "YieldExpression");
  12386. }
  12387. parseImportCall(node) {
  12388. this.next();
  12389. node.source = this.parseMaybeAssignAllowIn();
  12390. node.options = null;
  12391. if (this.eat(12)) {
  12392. if (!this.match(11)) {
  12393. node.options = this.parseMaybeAssignAllowIn();
  12394. if (this.eat(12)) {
  12395. this.addTrailingCommaExtraToNode(node.options);
  12396. if (!this.match(11)) {
  12397. do {
  12398. this.parseMaybeAssignAllowIn();
  12399. } while (this.eat(12) && !this.match(11));
  12400. this.raise(Errors.ImportCallArity, node);
  12401. }
  12402. }
  12403. } else {
  12404. this.addTrailingCommaExtraToNode(node.source);
  12405. }
  12406. }
  12407. this.expect(11);
  12408. return this.finishNode(node, "ImportExpression");
  12409. }
  12410. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12411. if (this.hasPlugin(["pipelineOperator", {
  12412. proposal: "smart"
  12413. }])) {
  12414. if (left.type === "SequenceExpression") {
  12415. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  12416. }
  12417. }
  12418. }
  12419. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12420. if (this.isSimpleReference(childExpr)) {
  12421. const bodyNode = this.startNodeAt(startLoc);
  12422. bodyNode.callee = childExpr;
  12423. return this.finishNode(bodyNode, "PipelineBareFunction");
  12424. } else {
  12425. const bodyNode = this.startNodeAt(startLoc);
  12426. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12427. bodyNode.expression = childExpr;
  12428. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12429. }
  12430. }
  12431. isSimpleReference(expression) {
  12432. switch (expression.type) {
  12433. case "MemberExpression":
  12434. return !expression.computed && this.isSimpleReference(expression.object);
  12435. case "Identifier":
  12436. return true;
  12437. default:
  12438. return false;
  12439. }
  12440. }
  12441. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12442. if (this.match(19)) {
  12443. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  12444. }
  12445. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12446. this.raise(Errors.PipelineTopicUnused, startLoc);
  12447. }
  12448. }
  12449. withTopicBindingContext(callback) {
  12450. const outerContextTopicState = this.state.topicContext;
  12451. this.state.topicContext = {
  12452. maxNumOfResolvableTopics: 1,
  12453. maxTopicIndex: null
  12454. };
  12455. try {
  12456. return callback();
  12457. } finally {
  12458. this.state.topicContext = outerContextTopicState;
  12459. }
  12460. }
  12461. withSmartMixTopicForbiddingContext(callback) {
  12462. if (this.hasPlugin(["pipelineOperator", {
  12463. proposal: "smart"
  12464. }])) {
  12465. const outerContextTopicState = this.state.topicContext;
  12466. this.state.topicContext = {
  12467. maxNumOfResolvableTopics: 0,
  12468. maxTopicIndex: null
  12469. };
  12470. try {
  12471. return callback();
  12472. } finally {
  12473. this.state.topicContext = outerContextTopicState;
  12474. }
  12475. } else {
  12476. return callback();
  12477. }
  12478. }
  12479. withSoloAwaitPermittingContext(callback) {
  12480. const outerContextSoloAwaitState = this.state.soloAwait;
  12481. this.state.soloAwait = true;
  12482. try {
  12483. return callback();
  12484. } finally {
  12485. this.state.soloAwait = outerContextSoloAwaitState;
  12486. }
  12487. }
  12488. allowInAnd(callback) {
  12489. const flags = this.prodParam.currentFlags();
  12490. const prodParamToSet = 8 & ~flags;
  12491. if (prodParamToSet) {
  12492. this.prodParam.enter(flags | 8);
  12493. try {
  12494. return callback();
  12495. } finally {
  12496. this.prodParam.exit();
  12497. }
  12498. }
  12499. return callback();
  12500. }
  12501. disallowInAnd(callback) {
  12502. const flags = this.prodParam.currentFlags();
  12503. const prodParamToClear = 8 & flags;
  12504. if (prodParamToClear) {
  12505. this.prodParam.enter(flags & ~8);
  12506. try {
  12507. return callback();
  12508. } finally {
  12509. this.prodParam.exit();
  12510. }
  12511. }
  12512. return callback();
  12513. }
  12514. registerTopicReference() {
  12515. this.state.topicContext.maxTopicIndex = 0;
  12516. }
  12517. topicReferenceIsAllowedInCurrentContext() {
  12518. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12519. }
  12520. topicReferenceWasUsedInCurrentContext() {
  12521. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12522. }
  12523. parseFSharpPipelineBody(prec) {
  12524. const startLoc = this.state.startLoc;
  12525. this.state.potentialArrowAt = this.state.start;
  12526. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12527. this.state.inFSharpPipelineDirectBody = true;
  12528. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12529. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12530. return ret;
  12531. }
  12532. parseModuleExpression() {
  12533. this.expectPlugin("moduleBlocks");
  12534. const node = this.startNode();
  12535. this.next();
  12536. if (!this.match(5)) {
  12537. this.unexpected(null, 5);
  12538. }
  12539. const program = this.startNodeAt(this.state.endLoc);
  12540. this.next();
  12541. const revertScopes = this.initializeScopes(true);
  12542. this.enterInitialScopes();
  12543. try {
  12544. node.body = this.parseProgram(program, 8, "module");
  12545. } finally {
  12546. revertScopes();
  12547. }
  12548. return this.finishNode(node, "ModuleExpression");
  12549. }
  12550. parseVoidPattern(refExpressionErrors) {
  12551. this.expectPlugin("discardBinding");
  12552. const node = this.startNode();
  12553. if (refExpressionErrors != null) {
  12554. refExpressionErrors.voidPatternLoc = this.state.startLoc;
  12555. }
  12556. this.next();
  12557. return this.finishNode(node, "VoidPattern");
  12558. }
  12559. parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
  12560. if (refExpressionErrors != null && this.match(88)) {
  12561. const nextCode = this.lookaheadCharCode();
  12562. if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
  12563. return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
  12564. }
  12565. }
  12566. return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
  12567. }
  12568. parsePropertyNamePrefixOperator(prop) {}
  12569. }
  12570. const loopLabel = {
  12571. kind: 1
  12572. },
  12573. switchLabel = {
  12574. kind: 2
  12575. };
  12576. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12577. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12578. function babel7CompatTokens(tokens, input, startIndex) {
  12579. for (let i = 0; i < tokens.length; i++) {
  12580. const token = tokens[i];
  12581. const {
  12582. type
  12583. } = token;
  12584. if (typeof type === "number") {
  12585. {
  12586. if (type === 139) {
  12587. const {
  12588. loc,
  12589. start,
  12590. value,
  12591. end
  12592. } = token;
  12593. const hashEndPos = start + 1;
  12594. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12595. tokens.splice(i, 1, new Token({
  12596. type: getExportedToken(27),
  12597. value: "#",
  12598. start: start,
  12599. end: hashEndPos,
  12600. startLoc: loc.start,
  12601. endLoc: hashEndLoc
  12602. }), new Token({
  12603. type: getExportedToken(132),
  12604. value: value,
  12605. start: hashEndPos,
  12606. end: end,
  12607. startLoc: hashEndLoc,
  12608. endLoc: loc.end
  12609. }));
  12610. i++;
  12611. continue;
  12612. }
  12613. if (tokenIsTemplate(type)) {
  12614. const {
  12615. loc,
  12616. start,
  12617. value,
  12618. end
  12619. } = token;
  12620. const backquoteEnd = start + 1;
  12621. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12622. let startToken;
  12623. if (input.charCodeAt(start - startIndex) === 96) {
  12624. startToken = new Token({
  12625. type: getExportedToken(22),
  12626. value: "`",
  12627. start: start,
  12628. end: backquoteEnd,
  12629. startLoc: loc.start,
  12630. endLoc: backquoteEndLoc
  12631. });
  12632. } else {
  12633. startToken = new Token({
  12634. type: getExportedToken(8),
  12635. value: "}",
  12636. start: start,
  12637. end: backquoteEnd,
  12638. startLoc: loc.start,
  12639. endLoc: backquoteEndLoc
  12640. });
  12641. }
  12642. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12643. if (type === 24) {
  12644. templateElementEnd = end - 1;
  12645. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12646. templateValue = value === null ? null : value.slice(1, -1);
  12647. endToken = new Token({
  12648. type: getExportedToken(22),
  12649. value: "`",
  12650. start: templateElementEnd,
  12651. end: end,
  12652. startLoc: templateElementEndLoc,
  12653. endLoc: loc.end
  12654. });
  12655. } else {
  12656. templateElementEnd = end - 2;
  12657. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12658. templateValue = value === null ? null : value.slice(1, -2);
  12659. endToken = new Token({
  12660. type: getExportedToken(23),
  12661. value: "${",
  12662. start: templateElementEnd,
  12663. end: end,
  12664. startLoc: templateElementEndLoc,
  12665. endLoc: loc.end
  12666. });
  12667. }
  12668. tokens.splice(i, 1, startToken, new Token({
  12669. type: getExportedToken(20),
  12670. value: templateValue,
  12671. start: backquoteEnd,
  12672. end: templateElementEnd,
  12673. startLoc: backquoteEndLoc,
  12674. endLoc: templateElementEndLoc
  12675. }), endToken);
  12676. i += 2;
  12677. continue;
  12678. }
  12679. }
  12680. token.type = getExportedToken(type);
  12681. }
  12682. }
  12683. return tokens;
  12684. }
  12685. class StatementParser extends ExpressionParser {
  12686. parseTopLevel(file, program) {
  12687. file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
  12688. file.comments = this.comments;
  12689. if (this.optionFlags & 256) {
  12690. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  12691. }
  12692. return this.finishNode(file, "File");
  12693. }
  12694. parseProgram(program, end, sourceType) {
  12695. program.sourceType = sourceType;
  12696. program.interpreter = this.parseInterpreterDirective();
  12697. this.parseBlockBody(program, true, true, end);
  12698. if (this.inModule) {
  12699. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  12700. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12701. this.raise(Errors.ModuleExportUndefined, at, {
  12702. localName
  12703. });
  12704. }
  12705. }
  12706. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  12707. }
  12708. let finishedProgram;
  12709. if (end === 140) {
  12710. finishedProgram = this.finishNode(program, "Program");
  12711. } else {
  12712. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12713. }
  12714. return finishedProgram;
  12715. }
  12716. stmtToDirective(stmt) {
  12717. const directive = this.castNodeTo(stmt, "Directive");
  12718. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  12719. const expressionValue = directiveLiteral.value;
  12720. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  12721. const val = directiveLiteral.value = raw.slice(1, -1);
  12722. this.addExtra(directiveLiteral, "raw", raw);
  12723. this.addExtra(directiveLiteral, "rawValue", val);
  12724. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12725. directive.value = directiveLiteral;
  12726. delete stmt.expression;
  12727. return directive;
  12728. }
  12729. parseInterpreterDirective() {
  12730. if (!this.match(28)) {
  12731. return null;
  12732. }
  12733. const node = this.startNode();
  12734. node.value = this.state.value;
  12735. this.next();
  12736. return this.finishNode(node, "InterpreterDirective");
  12737. }
  12738. isLet() {
  12739. if (!this.isContextual(100)) {
  12740. return false;
  12741. }
  12742. return this.hasFollowingBindingAtom();
  12743. }
  12744. isUsing() {
  12745. if (!this.isContextual(107)) {
  12746. return false;
  12747. }
  12748. return this.nextTokenIsIdentifierOnSameLine();
  12749. }
  12750. isForUsing() {
  12751. if (!this.isContextual(107)) {
  12752. return false;
  12753. }
  12754. const next = this.nextTokenInLineStart();
  12755. const nextCh = this.codePointAtPos(next);
  12756. if (this.isUnparsedContextual(next, "of")) {
  12757. const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
  12758. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  12759. return false;
  12760. }
  12761. }
  12762. if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
  12763. return true;
  12764. }
  12765. return false;
  12766. }
  12767. nextTokenIsIdentifierOnSameLine() {
  12768. const next = this.nextTokenInLineStart();
  12769. const nextCh = this.codePointAtPos(next);
  12770. return this.chStartsBindingIdentifier(nextCh, next);
  12771. }
  12772. isAwaitUsing() {
  12773. if (!this.isContextual(96)) {
  12774. return false;
  12775. }
  12776. let next = this.nextTokenInLineStart();
  12777. if (this.isUnparsedContextual(next, "using")) {
  12778. next = this.nextTokenInLineStartSince(next + 5);
  12779. const nextCh = this.codePointAtPos(next);
  12780. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12781. return true;
  12782. }
  12783. }
  12784. return false;
  12785. }
  12786. chStartsBindingIdentifier(ch, pos) {
  12787. if (isIdentifierStart(ch)) {
  12788. keywordRelationalOperator.lastIndex = pos;
  12789. if (keywordRelationalOperator.test(this.input)) {
  12790. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12791. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12792. return false;
  12793. }
  12794. }
  12795. return true;
  12796. } else if (ch === 92) {
  12797. return true;
  12798. } else {
  12799. return false;
  12800. }
  12801. }
  12802. chStartsBindingPattern(ch) {
  12803. return ch === 91 || ch === 123;
  12804. }
  12805. hasFollowingBindingAtom() {
  12806. const next = this.nextTokenStart();
  12807. const nextCh = this.codePointAtPos(next);
  12808. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12809. }
  12810. hasInLineFollowingBindingIdentifierOrBrace() {
  12811. const next = this.nextTokenInLineStart();
  12812. const nextCh = this.codePointAtPos(next);
  12813. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  12814. }
  12815. allowsUsing() {
  12816. return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
  12817. }
  12818. parseModuleItem() {
  12819. return this.parseStatementLike(1 | 2 | 4 | 8);
  12820. }
  12821. parseStatementListItem() {
  12822. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12823. }
  12824. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12825. let flags = 0;
  12826. if (this.options.annexB && !this.state.strict) {
  12827. flags |= 4;
  12828. if (allowLabeledFunction) {
  12829. flags |= 8;
  12830. }
  12831. }
  12832. return this.parseStatementLike(flags);
  12833. }
  12834. parseStatement() {
  12835. return this.parseStatementLike(0);
  12836. }
  12837. parseStatementLike(flags) {
  12838. let decorators = null;
  12839. if (this.match(26)) {
  12840. decorators = this.parseDecorators(true);
  12841. }
  12842. return this.parseStatementContent(flags, decorators);
  12843. }
  12844. parseStatementContent(flags, decorators) {
  12845. const startType = this.state.type;
  12846. const node = this.startNode();
  12847. const allowDeclaration = !!(flags & 2);
  12848. const allowFunctionDeclaration = !!(flags & 4);
  12849. const topLevel = flags & 1;
  12850. switch (startType) {
  12851. case 60:
  12852. return this.parseBreakContinueStatement(node, true);
  12853. case 63:
  12854. return this.parseBreakContinueStatement(node, false);
  12855. case 64:
  12856. return this.parseDebuggerStatement(node);
  12857. case 90:
  12858. return this.parseDoWhileStatement(node);
  12859. case 91:
  12860. return this.parseForStatement(node);
  12861. case 68:
  12862. if (this.lookaheadCharCode() === 46) break;
  12863. if (!allowFunctionDeclaration) {
  12864. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12865. }
  12866. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12867. case 80:
  12868. if (!allowDeclaration) this.unexpected();
  12869. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12870. case 69:
  12871. return this.parseIfStatement(node);
  12872. case 70:
  12873. return this.parseReturnStatement(node);
  12874. case 71:
  12875. return this.parseSwitchStatement(node);
  12876. case 72:
  12877. return this.parseThrowStatement(node);
  12878. case 73:
  12879. return this.parseTryStatement(node);
  12880. case 96:
  12881. if (this.isAwaitUsing()) {
  12882. if (!this.allowsUsing()) {
  12883. this.raise(Errors.UnexpectedUsingDeclaration, node);
  12884. } else if (!allowDeclaration) {
  12885. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12886. } else if (!this.recordAwaitIfAllowed()) {
  12887. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12888. }
  12889. this.next();
  12890. return this.parseVarStatement(node, "await using");
  12891. }
  12892. break;
  12893. case 107:
  12894. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  12895. break;
  12896. }
  12897. if (!this.allowsUsing()) {
  12898. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12899. } else if (!allowDeclaration) {
  12900. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12901. }
  12902. return this.parseVarStatement(node, "using");
  12903. case 100:
  12904. {
  12905. if (this.state.containsEsc) {
  12906. break;
  12907. }
  12908. const next = this.nextTokenStart();
  12909. const nextCh = this.codePointAtPos(next);
  12910. if (nextCh !== 91) {
  12911. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12912. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12913. break;
  12914. }
  12915. }
  12916. }
  12917. case 75:
  12918. {
  12919. if (!allowDeclaration) {
  12920. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12921. }
  12922. }
  12923. case 74:
  12924. {
  12925. const kind = this.state.value;
  12926. return this.parseVarStatement(node, kind);
  12927. }
  12928. case 92:
  12929. return this.parseWhileStatement(node);
  12930. case 76:
  12931. return this.parseWithStatement(node);
  12932. case 5:
  12933. return this.parseBlock();
  12934. case 13:
  12935. return this.parseEmptyStatement(node);
  12936. case 83:
  12937. {
  12938. const nextTokenCharCode = this.lookaheadCharCode();
  12939. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12940. break;
  12941. }
  12942. }
  12943. case 82:
  12944. {
  12945. if (!(this.optionFlags & 8) && !topLevel) {
  12946. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12947. }
  12948. this.next();
  12949. let result;
  12950. if (startType === 83) {
  12951. result = this.parseImport(node);
  12952. } else {
  12953. result = this.parseExport(node, decorators);
  12954. }
  12955. this.assertModuleNodeAllowed(result);
  12956. return result;
  12957. }
  12958. default:
  12959. {
  12960. if (this.isAsyncFunction()) {
  12961. if (!allowDeclaration) {
  12962. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12963. }
  12964. this.next();
  12965. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12966. }
  12967. }
  12968. }
  12969. const maybeName = this.state.value;
  12970. const expr = this.parseExpression();
  12971. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  12972. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12973. } else {
  12974. return this.parseExpressionStatement(node, expr, decorators);
  12975. }
  12976. }
  12977. assertModuleNodeAllowed(node) {
  12978. if (!(this.optionFlags & 8) && !this.inModule) {
  12979. this.raise(Errors.ImportOutsideModule, node);
  12980. }
  12981. }
  12982. decoratorsEnabledBeforeExport() {
  12983. if (this.hasPlugin("decorators-legacy")) return true;
  12984. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12985. }
  12986. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12987. if (maybeDecorators) {
  12988. var _classNode$decorators;
  12989. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  12990. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12991. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12992. }
  12993. classNode.decorators.unshift(...maybeDecorators);
  12994. } else {
  12995. classNode.decorators = maybeDecorators;
  12996. }
  12997. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12998. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12999. }
  13000. return classNode;
  13001. }
  13002. canHaveLeadingDecorator() {
  13003. return this.match(80);
  13004. }
  13005. parseDecorators(allowExport) {
  13006. const decorators = [];
  13007. do {
  13008. decorators.push(this.parseDecorator());
  13009. } while (this.match(26));
  13010. if (this.match(82)) {
  13011. if (!allowExport) {
  13012. this.unexpected();
  13013. }
  13014. if (!this.decoratorsEnabledBeforeExport()) {
  13015. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  13016. }
  13017. } else if (!this.canHaveLeadingDecorator()) {
  13018. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  13019. }
  13020. return decorators;
  13021. }
  13022. parseDecorator() {
  13023. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13024. const node = this.startNode();
  13025. this.next();
  13026. if (this.hasPlugin("decorators")) {
  13027. const startLoc = this.state.startLoc;
  13028. let expr;
  13029. if (this.match(10)) {
  13030. const startLoc = this.state.startLoc;
  13031. this.next();
  13032. expr = this.parseExpression();
  13033. this.expect(11);
  13034. expr = this.wrapParenthesis(startLoc, expr);
  13035. const paramsStartLoc = this.state.startLoc;
  13036. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  13037. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  13038. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  13039. }
  13040. } else {
  13041. expr = this.parseIdentifier(false);
  13042. while (this.eat(16)) {
  13043. const node = this.startNodeAt(startLoc);
  13044. node.object = expr;
  13045. if (this.match(139)) {
  13046. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  13047. node.property = this.parsePrivateName();
  13048. } else {
  13049. node.property = this.parseIdentifier(true);
  13050. }
  13051. node.computed = false;
  13052. expr = this.finishNode(node, "MemberExpression");
  13053. }
  13054. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  13055. }
  13056. } else {
  13057. node.expression = this.parseExprSubscripts();
  13058. }
  13059. return this.finishNode(node, "Decorator");
  13060. }
  13061. parseMaybeDecoratorArguments(expr, startLoc) {
  13062. if (this.eat(10)) {
  13063. const node = this.startNodeAt(startLoc);
  13064. node.callee = expr;
  13065. node.arguments = this.parseCallExpressionArguments();
  13066. this.toReferencedList(node.arguments);
  13067. return this.finishNode(node, "CallExpression");
  13068. }
  13069. return expr;
  13070. }
  13071. parseBreakContinueStatement(node, isBreak) {
  13072. this.next();
  13073. if (this.isLineTerminator()) {
  13074. node.label = null;
  13075. } else {
  13076. node.label = this.parseIdentifier();
  13077. this.semicolon();
  13078. }
  13079. this.verifyBreakContinue(node, isBreak);
  13080. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  13081. }
  13082. verifyBreakContinue(node, isBreak) {
  13083. let i;
  13084. for (i = 0; i < this.state.labels.length; ++i) {
  13085. const lab = this.state.labels[i];
  13086. if (node.label == null || lab.name === node.label.name) {
  13087. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  13088. break;
  13089. }
  13090. if (node.label && isBreak) break;
  13091. }
  13092. }
  13093. if (i === this.state.labels.length) {
  13094. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  13095. this.raise(Errors.IllegalBreakContinue, node, {
  13096. type
  13097. });
  13098. }
  13099. }
  13100. parseDebuggerStatement(node) {
  13101. this.next();
  13102. this.semicolon();
  13103. return this.finishNode(node, "DebuggerStatement");
  13104. }
  13105. parseHeaderExpression() {
  13106. this.expect(10);
  13107. const val = this.parseExpression();
  13108. this.expect(11);
  13109. return val;
  13110. }
  13111. parseDoWhileStatement(node) {
  13112. this.next();
  13113. this.state.labels.push(loopLabel);
  13114. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13115. this.state.labels.pop();
  13116. this.expect(92);
  13117. node.test = this.parseHeaderExpression();
  13118. this.eat(13);
  13119. return this.finishNode(node, "DoWhileStatement");
  13120. }
  13121. parseForStatement(node) {
  13122. this.next();
  13123. this.state.labels.push(loopLabel);
  13124. let awaitAt = null;
  13125. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  13126. awaitAt = this.state.startLoc;
  13127. this.next();
  13128. }
  13129. this.scope.enter(0);
  13130. this.expect(10);
  13131. if (this.match(13)) {
  13132. if (awaitAt !== null) {
  13133. this.unexpected(awaitAt);
  13134. }
  13135. return this.parseFor(node, null);
  13136. }
  13137. const startsWithLet = this.isContextual(100);
  13138. {
  13139. const startsWithAwaitUsing = this.isAwaitUsing();
  13140. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
  13141. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  13142. if (this.match(74) || this.match(75) || isLetOrUsing) {
  13143. const initNode = this.startNode();
  13144. let kind;
  13145. if (startsWithAwaitUsing) {
  13146. kind = "await using";
  13147. if (!this.recordAwaitIfAllowed()) {
  13148. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  13149. }
  13150. this.next();
  13151. } else {
  13152. kind = this.state.value;
  13153. }
  13154. this.next();
  13155. this.parseVar(initNode, true, kind);
  13156. const init = this.finishNode(initNode, "VariableDeclaration");
  13157. const isForIn = this.match(58);
  13158. if (isForIn && starsWithUsingDeclaration) {
  13159. this.raise(Errors.ForInUsing, init);
  13160. }
  13161. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  13162. return this.parseForIn(node, init, awaitAt);
  13163. }
  13164. if (awaitAt !== null) {
  13165. this.unexpected(awaitAt);
  13166. }
  13167. return this.parseFor(node, init);
  13168. }
  13169. }
  13170. const startsWithAsync = this.isContextual(95);
  13171. const refExpressionErrors = new ExpressionErrors();
  13172. const init = this.parseExpression(true, refExpressionErrors);
  13173. const isForOf = this.isContextual(102);
  13174. if (isForOf) {
  13175. if (startsWithLet) {
  13176. this.raise(Errors.ForOfLet, init);
  13177. }
  13178. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  13179. this.raise(Errors.ForOfAsync, init);
  13180. }
  13181. }
  13182. if (isForOf || this.match(58)) {
  13183. this.checkDestructuringPrivate(refExpressionErrors);
  13184. this.toAssignable(init, true);
  13185. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  13186. this.checkLVal(init, {
  13187. type
  13188. });
  13189. return this.parseForIn(node, init, awaitAt);
  13190. } else {
  13191. this.checkExpressionErrors(refExpressionErrors, true);
  13192. }
  13193. if (awaitAt !== null) {
  13194. this.unexpected(awaitAt);
  13195. }
  13196. return this.parseFor(node, init);
  13197. }
  13198. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  13199. this.next();
  13200. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  13201. }
  13202. parseIfStatement(node) {
  13203. this.next();
  13204. node.test = this.parseHeaderExpression();
  13205. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  13206. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  13207. return this.finishNode(node, "IfStatement");
  13208. }
  13209. parseReturnStatement(node) {
  13210. if (!this.prodParam.hasReturn) {
  13211. this.raise(Errors.IllegalReturn, this.state.startLoc);
  13212. }
  13213. this.next();
  13214. if (this.isLineTerminator()) {
  13215. node.argument = null;
  13216. } else {
  13217. node.argument = this.parseExpression();
  13218. this.semicolon();
  13219. }
  13220. return this.finishNode(node, "ReturnStatement");
  13221. }
  13222. parseSwitchStatement(node) {
  13223. this.next();
  13224. node.discriminant = this.parseHeaderExpression();
  13225. const cases = node.cases = [];
  13226. this.expect(5);
  13227. this.state.labels.push(switchLabel);
  13228. this.scope.enter(256);
  13229. let cur;
  13230. for (let sawDefault; !this.match(8);) {
  13231. if (this.match(61) || this.match(65)) {
  13232. const isCase = this.match(61);
  13233. if (cur) this.finishNode(cur, "SwitchCase");
  13234. cases.push(cur = this.startNode());
  13235. cur.consequent = [];
  13236. this.next();
  13237. if (isCase) {
  13238. cur.test = this.parseExpression();
  13239. } else {
  13240. if (sawDefault) {
  13241. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  13242. }
  13243. sawDefault = true;
  13244. cur.test = null;
  13245. }
  13246. this.expect(14);
  13247. } else {
  13248. if (cur) {
  13249. cur.consequent.push(this.parseStatementListItem());
  13250. } else {
  13251. this.unexpected();
  13252. }
  13253. }
  13254. }
  13255. this.scope.exit();
  13256. if (cur) this.finishNode(cur, "SwitchCase");
  13257. this.next();
  13258. this.state.labels.pop();
  13259. return this.finishNode(node, "SwitchStatement");
  13260. }
  13261. parseThrowStatement(node) {
  13262. this.next();
  13263. if (this.hasPrecedingLineBreak()) {
  13264. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  13265. }
  13266. node.argument = this.parseExpression();
  13267. this.semicolon();
  13268. return this.finishNode(node, "ThrowStatement");
  13269. }
  13270. parseCatchClauseParam() {
  13271. const param = this.parseBindingAtom();
  13272. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13273. this.checkLVal(param, {
  13274. type: "CatchClause"
  13275. }, 9);
  13276. return param;
  13277. }
  13278. parseTryStatement(node) {
  13279. this.next();
  13280. node.block = this.parseBlock();
  13281. node.handler = null;
  13282. if (this.match(62)) {
  13283. const clause = this.startNode();
  13284. this.next();
  13285. if (this.match(10)) {
  13286. this.expect(10);
  13287. clause.param = this.parseCatchClauseParam();
  13288. this.expect(11);
  13289. } else {
  13290. clause.param = null;
  13291. this.scope.enter(0);
  13292. }
  13293. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13294. this.scope.exit();
  13295. node.handler = this.finishNode(clause, "CatchClause");
  13296. }
  13297. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13298. if (!node.handler && !node.finalizer) {
  13299. this.raise(Errors.NoCatchOrFinally, node);
  13300. }
  13301. return this.finishNode(node, "TryStatement");
  13302. }
  13303. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13304. this.next();
  13305. this.parseVar(node, false, kind, allowMissingInitializer);
  13306. this.semicolon();
  13307. return this.finishNode(node, "VariableDeclaration");
  13308. }
  13309. parseWhileStatement(node) {
  13310. this.next();
  13311. node.test = this.parseHeaderExpression();
  13312. this.state.labels.push(loopLabel);
  13313. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13314. this.state.labels.pop();
  13315. return this.finishNode(node, "WhileStatement");
  13316. }
  13317. parseWithStatement(node) {
  13318. if (this.state.strict) {
  13319. this.raise(Errors.StrictWith, this.state.startLoc);
  13320. }
  13321. this.next();
  13322. node.object = this.parseHeaderExpression();
  13323. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13324. return this.finishNode(node, "WithStatement");
  13325. }
  13326. parseEmptyStatement(node) {
  13327. this.next();
  13328. return this.finishNode(node, "EmptyStatement");
  13329. }
  13330. parseLabeledStatement(node, maybeName, expr, flags) {
  13331. for (const label of this.state.labels) {
  13332. if (label.name === maybeName) {
  13333. this.raise(Errors.LabelRedeclaration, expr, {
  13334. labelName: maybeName
  13335. });
  13336. }
  13337. }
  13338. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  13339. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13340. const label = this.state.labels[i];
  13341. if (label.statementStart === node.start) {
  13342. label.statementStart = this.sourceToOffsetPos(this.state.start);
  13343. label.kind = kind;
  13344. } else {
  13345. break;
  13346. }
  13347. }
  13348. this.state.labels.push({
  13349. name: maybeName,
  13350. kind: kind,
  13351. statementStart: this.sourceToOffsetPos(this.state.start)
  13352. });
  13353. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13354. this.state.labels.pop();
  13355. node.label = expr;
  13356. return this.finishNode(node, "LabeledStatement");
  13357. }
  13358. parseExpressionStatement(node, expr, decorators) {
  13359. node.expression = expr;
  13360. this.semicolon();
  13361. return this.finishNode(node, "ExpressionStatement");
  13362. }
  13363. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13364. const node = this.startNode();
  13365. if (allowDirectives) {
  13366. this.state.strictErrors.clear();
  13367. }
  13368. this.expect(5);
  13369. if (createNewLexicalScope) {
  13370. this.scope.enter(0);
  13371. }
  13372. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13373. if (createNewLexicalScope) {
  13374. this.scope.exit();
  13375. }
  13376. return this.finishNode(node, "BlockStatement");
  13377. }
  13378. isValidDirective(stmt) {
  13379. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13380. }
  13381. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13382. const body = node.body = [];
  13383. const directives = node.directives = [];
  13384. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13385. }
  13386. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13387. const oldStrict = this.state.strict;
  13388. let hasStrictModeDirective = false;
  13389. let parsedNonDirective = false;
  13390. while (!this.match(end)) {
  13391. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13392. if (directives && !parsedNonDirective) {
  13393. if (this.isValidDirective(stmt)) {
  13394. const directive = this.stmtToDirective(stmt);
  13395. directives.push(directive);
  13396. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13397. hasStrictModeDirective = true;
  13398. this.setStrict(true);
  13399. }
  13400. continue;
  13401. }
  13402. parsedNonDirective = true;
  13403. this.state.strictErrors.clear();
  13404. }
  13405. body.push(stmt);
  13406. }
  13407. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  13408. if (!oldStrict) {
  13409. this.setStrict(false);
  13410. }
  13411. this.next();
  13412. }
  13413. parseFor(node, init) {
  13414. node.init = init;
  13415. this.semicolon(false);
  13416. node.test = this.match(13) ? null : this.parseExpression();
  13417. this.semicolon(false);
  13418. node.update = this.match(11) ? null : this.parseExpression();
  13419. this.expect(11);
  13420. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13421. this.scope.exit();
  13422. this.state.labels.pop();
  13423. return this.finishNode(node, "ForStatement");
  13424. }
  13425. parseForIn(node, init, awaitAt) {
  13426. const isForIn = this.match(58);
  13427. this.next();
  13428. if (isForIn) {
  13429. if (awaitAt !== null) this.unexpected(awaitAt);
  13430. } else {
  13431. node.await = awaitAt !== null;
  13432. }
  13433. 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")) {
  13434. this.raise(Errors.ForInOfLoopInitializer, init, {
  13435. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13436. });
  13437. }
  13438. if (init.type === "AssignmentPattern") {
  13439. this.raise(Errors.InvalidLhs, init, {
  13440. ancestor: {
  13441. type: "ForStatement"
  13442. }
  13443. });
  13444. }
  13445. node.left = init;
  13446. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13447. this.expect(11);
  13448. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13449. this.scope.exit();
  13450. this.state.labels.pop();
  13451. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13452. }
  13453. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13454. const declarations = node.declarations = [];
  13455. node.kind = kind;
  13456. for (;;) {
  13457. const decl = this.startNode();
  13458. this.parseVarId(decl, kind);
  13459. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13460. if (decl.init === null && !allowMissingInitializer) {
  13461. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13462. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13463. kind: "destructuring"
  13464. });
  13465. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  13466. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13467. kind
  13468. });
  13469. }
  13470. }
  13471. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13472. if (!this.eat(12)) break;
  13473. }
  13474. return node;
  13475. }
  13476. parseVarId(decl, kind) {
  13477. const id = this.parseBindingAtom();
  13478. if (kind === "using" || kind === "await using") {
  13479. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  13480. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  13481. }
  13482. } else {
  13483. if (id.type === "VoidPattern") {
  13484. this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
  13485. }
  13486. }
  13487. this.checkLVal(id, {
  13488. type: "VariableDeclarator"
  13489. }, kind === "var" ? 5 : 8201);
  13490. decl.id = id;
  13491. }
  13492. parseAsyncFunctionExpression(node) {
  13493. return this.parseFunction(node, 8);
  13494. }
  13495. parseFunction(node, flags = 0) {
  13496. const hangingDeclaration = flags & 2;
  13497. const isDeclaration = !!(flags & 1);
  13498. const requireId = isDeclaration && !(flags & 4);
  13499. const isAsync = !!(flags & 8);
  13500. this.initFunction(node, isAsync);
  13501. if (this.match(55)) {
  13502. if (hangingDeclaration) {
  13503. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  13504. }
  13505. this.next();
  13506. node.generator = true;
  13507. }
  13508. if (isDeclaration) {
  13509. node.id = this.parseFunctionId(requireId);
  13510. }
  13511. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13512. this.state.maybeInArrowParameters = false;
  13513. this.scope.enter(514);
  13514. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13515. if (!isDeclaration) {
  13516. node.id = this.parseFunctionId();
  13517. }
  13518. this.parseFunctionParams(node, false);
  13519. this.withSmartMixTopicForbiddingContext(() => {
  13520. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13521. });
  13522. this.prodParam.exit();
  13523. this.scope.exit();
  13524. if (isDeclaration && !hangingDeclaration) {
  13525. this.registerFunctionStatementId(node);
  13526. }
  13527. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13528. return node;
  13529. }
  13530. parseFunctionId(requireId) {
  13531. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13532. }
  13533. parseFunctionParams(node, isConstructor) {
  13534. this.expect(10);
  13535. this.expressionScope.enter(newParameterDeclarationScope());
  13536. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13537. this.expressionScope.exit();
  13538. }
  13539. registerFunctionStatementId(node) {
  13540. if (!node.id) return;
  13541. 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);
  13542. }
  13543. parseClass(node, isStatement, optionalId) {
  13544. this.next();
  13545. const oldStrict = this.state.strict;
  13546. this.state.strict = true;
  13547. this.parseClassId(node, isStatement, optionalId);
  13548. this.parseClassSuper(node);
  13549. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13550. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13551. }
  13552. isClassProperty() {
  13553. return this.match(29) || this.match(13) || this.match(8);
  13554. }
  13555. isClassMethod() {
  13556. return this.match(10);
  13557. }
  13558. nameIsConstructor(key) {
  13559. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  13560. }
  13561. isNonstaticConstructor(method) {
  13562. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  13563. }
  13564. parseClassBody(hadSuperClass, oldStrict) {
  13565. this.classScope.enter();
  13566. const state = {
  13567. hadConstructor: false,
  13568. hadSuperClass
  13569. };
  13570. let decorators = [];
  13571. const classBody = this.startNode();
  13572. classBody.body = [];
  13573. this.expect(5);
  13574. this.withSmartMixTopicForbiddingContext(() => {
  13575. while (!this.match(8)) {
  13576. if (this.eat(13)) {
  13577. if (decorators.length > 0) {
  13578. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  13579. }
  13580. continue;
  13581. }
  13582. if (this.match(26)) {
  13583. decorators.push(this.parseDecorator());
  13584. continue;
  13585. }
  13586. const member = this.startNode();
  13587. if (decorators.length) {
  13588. member.decorators = decorators;
  13589. this.resetStartLocationFromNode(member, decorators[0]);
  13590. decorators = [];
  13591. }
  13592. this.parseClassMember(classBody, member, state);
  13593. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13594. this.raise(Errors.DecoratorConstructor, member);
  13595. }
  13596. }
  13597. });
  13598. this.state.strict = oldStrict;
  13599. this.next();
  13600. if (decorators.length) {
  13601. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13602. }
  13603. this.classScope.exit();
  13604. return this.finishNode(classBody, "ClassBody");
  13605. }
  13606. parseClassMemberFromModifier(classBody, member) {
  13607. const key = this.parseIdentifier(true);
  13608. if (this.isClassMethod()) {
  13609. const method = member;
  13610. method.kind = "method";
  13611. method.computed = false;
  13612. method.key = key;
  13613. method.static = false;
  13614. this.pushClassMethod(classBody, method, false, false, false, false);
  13615. return true;
  13616. } else if (this.isClassProperty()) {
  13617. const prop = member;
  13618. prop.computed = false;
  13619. prop.key = key;
  13620. prop.static = false;
  13621. classBody.body.push(this.parseClassProperty(prop));
  13622. return true;
  13623. }
  13624. this.resetPreviousNodeTrailingComments(key);
  13625. return false;
  13626. }
  13627. parseClassMember(classBody, member, state) {
  13628. const isStatic = this.isContextual(106);
  13629. if (isStatic) {
  13630. if (this.parseClassMemberFromModifier(classBody, member)) {
  13631. return;
  13632. }
  13633. if (this.eat(5)) {
  13634. this.parseClassStaticBlock(classBody, member);
  13635. return;
  13636. }
  13637. }
  13638. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13639. }
  13640. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13641. const publicMethod = member;
  13642. const privateMethod = member;
  13643. const publicProp = member;
  13644. const privateProp = member;
  13645. const accessorProp = member;
  13646. const method = publicMethod;
  13647. const publicMember = publicMethod;
  13648. member.static = isStatic;
  13649. this.parsePropertyNamePrefixOperator(member);
  13650. if (this.eat(55)) {
  13651. method.kind = "method";
  13652. const isPrivateName = this.match(139);
  13653. this.parseClassElementName(method);
  13654. this.parsePostMemberNameModifiers(method);
  13655. if (isPrivateName) {
  13656. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13657. return;
  13658. }
  13659. if (this.isNonstaticConstructor(publicMethod)) {
  13660. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13661. }
  13662. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13663. return;
  13664. }
  13665. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13666. const key = this.parseClassElementName(member);
  13667. const maybeContextualKw = isContextual ? key.name : null;
  13668. const isPrivate = this.isPrivateName(key);
  13669. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13670. this.parsePostMemberNameModifiers(publicMember);
  13671. if (this.isClassMethod()) {
  13672. method.kind = "method";
  13673. if (isPrivate) {
  13674. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13675. return;
  13676. }
  13677. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13678. let allowsDirectSuper = false;
  13679. if (isConstructor) {
  13680. publicMethod.kind = "constructor";
  13681. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13682. this.raise(Errors.DuplicateConstructor, key);
  13683. }
  13684. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13685. this.raise(Errors.OverrideOnConstructor, key);
  13686. }
  13687. state.hadConstructor = true;
  13688. allowsDirectSuper = state.hadSuperClass;
  13689. }
  13690. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13691. } else if (this.isClassProperty()) {
  13692. if (isPrivate) {
  13693. this.pushClassPrivateProperty(classBody, privateProp);
  13694. } else {
  13695. this.pushClassProperty(classBody, publicProp);
  13696. }
  13697. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13698. this.resetPreviousNodeTrailingComments(key);
  13699. const isGenerator = this.eat(55);
  13700. if (publicMember.optional) {
  13701. this.unexpected(maybeQuestionTokenStartLoc);
  13702. }
  13703. method.kind = "method";
  13704. const isPrivate = this.match(139);
  13705. this.parseClassElementName(method);
  13706. this.parsePostMemberNameModifiers(publicMember);
  13707. if (isPrivate) {
  13708. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13709. } else {
  13710. if (this.isNonstaticConstructor(publicMethod)) {
  13711. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13712. }
  13713. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13714. }
  13715. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13716. this.resetPreviousNodeTrailingComments(key);
  13717. method.kind = maybeContextualKw;
  13718. const isPrivate = this.match(139);
  13719. this.parseClassElementName(publicMethod);
  13720. if (isPrivate) {
  13721. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13722. } else {
  13723. if (this.isNonstaticConstructor(publicMethod)) {
  13724. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13725. }
  13726. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13727. }
  13728. this.checkGetterSetterParams(publicMethod);
  13729. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13730. this.expectPlugin("decoratorAutoAccessors");
  13731. this.resetPreviousNodeTrailingComments(key);
  13732. const isPrivate = this.match(139);
  13733. this.parseClassElementName(publicProp);
  13734. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13735. } else if (this.isLineTerminator()) {
  13736. if (isPrivate) {
  13737. this.pushClassPrivateProperty(classBody, privateProp);
  13738. } else {
  13739. this.pushClassProperty(classBody, publicProp);
  13740. }
  13741. } else {
  13742. this.unexpected();
  13743. }
  13744. }
  13745. parseClassElementName(member) {
  13746. const {
  13747. type,
  13748. value
  13749. } = this.state;
  13750. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  13751. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13752. }
  13753. if (type === 139) {
  13754. if (value === "constructor") {
  13755. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13756. }
  13757. const key = this.parsePrivateName();
  13758. member.key = key;
  13759. return key;
  13760. }
  13761. this.parsePropertyName(member);
  13762. return member.key;
  13763. }
  13764. parseClassStaticBlock(classBody, member) {
  13765. var _member$decorators;
  13766. this.scope.enter(576 | 128 | 16);
  13767. const oldLabels = this.state.labels;
  13768. this.state.labels = [];
  13769. this.prodParam.enter(0);
  13770. const body = member.body = [];
  13771. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13772. this.prodParam.exit();
  13773. this.scope.exit();
  13774. this.state.labels = oldLabels;
  13775. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13776. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13777. this.raise(Errors.DecoratorStaticBlock, member);
  13778. }
  13779. }
  13780. pushClassProperty(classBody, prop) {
  13781. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13782. this.raise(Errors.ConstructorClassField, prop.key);
  13783. }
  13784. classBody.body.push(this.parseClassProperty(prop));
  13785. }
  13786. pushClassPrivateProperty(classBody, prop) {
  13787. const node = this.parseClassPrivateProperty(prop);
  13788. classBody.body.push(node);
  13789. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13790. }
  13791. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13792. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13793. this.raise(Errors.ConstructorClassField, prop.key);
  13794. }
  13795. const node = this.parseClassAccessorProperty(prop);
  13796. classBody.body.push(node);
  13797. if (isPrivate) {
  13798. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13799. }
  13800. }
  13801. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13802. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13803. }
  13804. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13805. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13806. classBody.body.push(node);
  13807. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13808. this.declareClassPrivateMethodInScope(node, kind);
  13809. }
  13810. declareClassPrivateMethodInScope(node, kind) {
  13811. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13812. }
  13813. parsePostMemberNameModifiers(methodOrProp) {}
  13814. parseClassPrivateProperty(node) {
  13815. this.parseInitializer(node);
  13816. this.semicolon();
  13817. return this.finishNode(node, "ClassPrivateProperty");
  13818. }
  13819. parseClassProperty(node) {
  13820. this.parseInitializer(node);
  13821. this.semicolon();
  13822. return this.finishNode(node, "ClassProperty");
  13823. }
  13824. parseClassAccessorProperty(node) {
  13825. this.parseInitializer(node);
  13826. this.semicolon();
  13827. return this.finishNode(node, "ClassAccessorProperty");
  13828. }
  13829. parseInitializer(node) {
  13830. this.scope.enter(576 | 16);
  13831. this.expressionScope.enter(newExpressionScope());
  13832. this.prodParam.enter(0);
  13833. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13834. this.expressionScope.exit();
  13835. this.prodParam.exit();
  13836. this.scope.exit();
  13837. }
  13838. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13839. if (tokenIsIdentifier(this.state.type)) {
  13840. node.id = this.parseIdentifier();
  13841. if (isStatement) {
  13842. this.declareNameFromIdentifier(node.id, bindingType);
  13843. }
  13844. } else {
  13845. if (optionalId || !isStatement) {
  13846. node.id = null;
  13847. } else {
  13848. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13849. }
  13850. }
  13851. }
  13852. parseClassSuper(node) {
  13853. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13854. }
  13855. parseExport(node, decorators) {
  13856. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13857. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13858. const parseAfterDefault = !hasDefault || this.eat(12);
  13859. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13860. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13861. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13862. const isFromRequired = hasDefault || hasStar;
  13863. if (hasStar && !hasNamespace) {
  13864. if (hasDefault) this.unexpected();
  13865. if (decorators) {
  13866. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13867. }
  13868. this.parseExportFrom(node, true);
  13869. this.sawUnambiguousESM = true;
  13870. return this.finishNode(node, "ExportAllDeclaration");
  13871. }
  13872. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13873. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13874. this.unexpected(null, 5);
  13875. }
  13876. if (hasNamespace && parseAfterNamespace) {
  13877. this.unexpected(null, 98);
  13878. }
  13879. let hasDeclaration;
  13880. if (isFromRequired || hasSpecifiers) {
  13881. hasDeclaration = false;
  13882. if (decorators) {
  13883. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13884. }
  13885. this.parseExportFrom(node, isFromRequired);
  13886. } else {
  13887. hasDeclaration = this.maybeParseExportDeclaration(node);
  13888. }
  13889. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13890. var _node2$declaration;
  13891. const node2 = node;
  13892. this.checkExport(node2, true, false, !!node2.source);
  13893. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13894. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13895. } else if (decorators) {
  13896. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13897. }
  13898. this.sawUnambiguousESM = true;
  13899. return this.finishNode(node2, "ExportNamedDeclaration");
  13900. }
  13901. if (this.eat(65)) {
  13902. const node2 = node;
  13903. const decl = this.parseExportDefaultExpression();
  13904. node2.declaration = decl;
  13905. if (decl.type === "ClassDeclaration") {
  13906. this.maybeTakeDecorators(decorators, decl, node2);
  13907. } else if (decorators) {
  13908. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13909. }
  13910. this.checkExport(node2, true, true);
  13911. this.sawUnambiguousESM = true;
  13912. return this.finishNode(node2, "ExportDefaultDeclaration");
  13913. }
  13914. throw this.unexpected(null, 5);
  13915. }
  13916. eatExportStar(node) {
  13917. return this.eat(55);
  13918. }
  13919. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13920. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13921. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13922. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13923. const specifier = this.startNodeAtNode(id);
  13924. specifier.exported = id;
  13925. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13926. return true;
  13927. }
  13928. return false;
  13929. }
  13930. maybeParseExportNamespaceSpecifier(node) {
  13931. if (this.isContextual(93)) {
  13932. var _ref, _ref$specifiers;
  13933. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13934. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13935. this.next();
  13936. specifier.exported = this.parseModuleExportName();
  13937. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13938. return true;
  13939. }
  13940. return false;
  13941. }
  13942. maybeParseExportNamedSpecifiers(node) {
  13943. if (this.match(5)) {
  13944. const node2 = node;
  13945. if (!node2.specifiers) node2.specifiers = [];
  13946. const isTypeExport = node2.exportKind === "type";
  13947. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13948. node2.source = null;
  13949. if (this.hasPlugin("importAssertions")) {
  13950. node2.assertions = [];
  13951. } else {
  13952. node2.attributes = [];
  13953. }
  13954. node2.declaration = null;
  13955. return true;
  13956. }
  13957. return false;
  13958. }
  13959. maybeParseExportDeclaration(node) {
  13960. if (this.shouldParseExportDeclaration()) {
  13961. node.specifiers = [];
  13962. node.source = null;
  13963. if (this.hasPlugin("importAssertions")) {
  13964. node.assertions = [];
  13965. } else {
  13966. node.attributes = [];
  13967. }
  13968. node.declaration = this.parseExportDeclaration(node);
  13969. return true;
  13970. }
  13971. return false;
  13972. }
  13973. isAsyncFunction() {
  13974. if (!this.isContextual(95)) return false;
  13975. const next = this.nextTokenInLineStart();
  13976. return this.isUnparsedContextual(next, "function");
  13977. }
  13978. parseExportDefaultExpression() {
  13979. const expr = this.startNode();
  13980. if (this.match(68)) {
  13981. this.next();
  13982. return this.parseFunction(expr, 1 | 4);
  13983. } else if (this.isAsyncFunction()) {
  13984. this.next();
  13985. this.next();
  13986. return this.parseFunction(expr, 1 | 4 | 8);
  13987. }
  13988. if (this.match(80)) {
  13989. return this.parseClass(expr, true, true);
  13990. }
  13991. if (this.match(26)) {
  13992. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13993. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13994. }
  13995. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13996. }
  13997. if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
  13998. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13999. }
  14000. const res = this.parseMaybeAssignAllowIn();
  14001. this.semicolon();
  14002. return res;
  14003. }
  14004. parseExportDeclaration(node) {
  14005. if (this.match(80)) {
  14006. const node = this.parseClass(this.startNode(), true, false);
  14007. return node;
  14008. }
  14009. return this.parseStatementListItem();
  14010. }
  14011. isExportDefaultSpecifier() {
  14012. const {
  14013. type
  14014. } = this.state;
  14015. if (tokenIsIdentifier(type)) {
  14016. if (type === 95 && !this.state.containsEsc || type === 100) {
  14017. return false;
  14018. }
  14019. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  14020. const next = this.nextTokenStart();
  14021. const nextChar = this.input.charCodeAt(next);
  14022. if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
  14023. this.expectOnePlugin(["flow", "typescript"]);
  14024. return false;
  14025. }
  14026. }
  14027. } else if (!this.match(65)) {
  14028. return false;
  14029. }
  14030. const next = this.nextTokenStart();
  14031. const hasFrom = this.isUnparsedContextual(next, "from");
  14032. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  14033. return true;
  14034. }
  14035. if (this.match(65) && hasFrom) {
  14036. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  14037. return nextAfterFrom === 34 || nextAfterFrom === 39;
  14038. }
  14039. return false;
  14040. }
  14041. parseExportFrom(node, expect) {
  14042. if (this.eatContextual(98)) {
  14043. node.source = this.parseImportSource();
  14044. this.checkExport(node);
  14045. this.maybeParseImportAttributes(node);
  14046. this.checkJSONModuleImport(node);
  14047. } else if (expect) {
  14048. this.unexpected();
  14049. }
  14050. this.semicolon();
  14051. }
  14052. shouldParseExportDeclaration() {
  14053. const {
  14054. type
  14055. } = this.state;
  14056. if (type === 26) {
  14057. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  14058. if (this.hasPlugin("decorators")) {
  14059. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  14060. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  14061. }
  14062. return true;
  14063. }
  14064. }
  14065. if (this.isUsing()) {
  14066. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  14067. return true;
  14068. }
  14069. if (this.isAwaitUsing()) {
  14070. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  14071. return true;
  14072. }
  14073. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  14074. }
  14075. checkExport(node, checkNames, isDefault, isFrom) {
  14076. if (checkNames) {
  14077. var _node$specifiers;
  14078. if (isDefault) {
  14079. this.checkDuplicateExports(node, "default");
  14080. if (this.hasPlugin("exportDefaultFrom")) {
  14081. var _declaration$extra;
  14082. const declaration = node.declaration;
  14083. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  14084. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  14085. }
  14086. }
  14087. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  14088. for (const specifier of node.specifiers) {
  14089. const {
  14090. exported
  14091. } = specifier;
  14092. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  14093. this.checkDuplicateExports(specifier, exportName);
  14094. if (!isFrom && specifier.local) {
  14095. const {
  14096. local
  14097. } = specifier;
  14098. if (local.type !== "Identifier") {
  14099. this.raise(Errors.ExportBindingIsString, specifier, {
  14100. localName: local.value,
  14101. exportName
  14102. });
  14103. } else {
  14104. this.checkReservedWord(local.name, local.loc.start, true, false);
  14105. this.scope.checkLocalExport(local);
  14106. }
  14107. }
  14108. }
  14109. } else if (node.declaration) {
  14110. const decl = node.declaration;
  14111. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  14112. const {
  14113. id
  14114. } = decl;
  14115. if (!id) throw new Error("Assertion failure");
  14116. this.checkDuplicateExports(node, id.name);
  14117. } else if (decl.type === "VariableDeclaration") {
  14118. for (const declaration of decl.declarations) {
  14119. this.checkDeclaration(declaration.id);
  14120. }
  14121. }
  14122. }
  14123. }
  14124. }
  14125. checkDeclaration(node) {
  14126. if (node.type === "Identifier") {
  14127. this.checkDuplicateExports(node, node.name);
  14128. } else if (node.type === "ObjectPattern") {
  14129. for (const prop of node.properties) {
  14130. this.checkDeclaration(prop);
  14131. }
  14132. } else if (node.type === "ArrayPattern") {
  14133. for (const elem of node.elements) {
  14134. if (elem) {
  14135. this.checkDeclaration(elem);
  14136. }
  14137. }
  14138. } else if (node.type === "ObjectProperty") {
  14139. this.checkDeclaration(node.value);
  14140. } else if (node.type === "RestElement") {
  14141. this.checkDeclaration(node.argument);
  14142. } else if (node.type === "AssignmentPattern") {
  14143. this.checkDeclaration(node.left);
  14144. }
  14145. }
  14146. checkDuplicateExports(node, exportName) {
  14147. if (this.exportedIdentifiers.has(exportName)) {
  14148. if (exportName === "default") {
  14149. this.raise(Errors.DuplicateDefaultExport, node);
  14150. } else {
  14151. this.raise(Errors.DuplicateExport, node, {
  14152. exportName
  14153. });
  14154. }
  14155. }
  14156. this.exportedIdentifiers.add(exportName);
  14157. }
  14158. parseExportSpecifiers(isInTypeExport) {
  14159. const nodes = [];
  14160. let first = true;
  14161. this.expect(5);
  14162. while (!this.eat(8)) {
  14163. if (first) {
  14164. first = false;
  14165. } else {
  14166. this.expect(12);
  14167. if (this.eat(8)) break;
  14168. }
  14169. const isMaybeTypeOnly = this.isContextual(130);
  14170. const isString = this.match(134);
  14171. const node = this.startNode();
  14172. node.local = this.parseModuleExportName();
  14173. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  14174. }
  14175. return nodes;
  14176. }
  14177. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14178. if (this.eatContextual(93)) {
  14179. node.exported = this.parseModuleExportName();
  14180. } else if (isString) {
  14181. node.exported = this.cloneStringLiteral(node.local);
  14182. } else if (!node.exported) {
  14183. node.exported = this.cloneIdentifier(node.local);
  14184. }
  14185. return this.finishNode(node, "ExportSpecifier");
  14186. }
  14187. parseModuleExportName() {
  14188. if (this.match(134)) {
  14189. const result = this.parseStringLiteral(this.state.value);
  14190. const surrogate = loneSurrogate.exec(result.value);
  14191. if (surrogate) {
  14192. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  14193. surrogateCharCode: surrogate[0].charCodeAt(0)
  14194. });
  14195. }
  14196. return result;
  14197. }
  14198. return this.parseIdentifier(true);
  14199. }
  14200. isJSONModuleImport(node) {
  14201. if (node.assertions != null) {
  14202. return node.assertions.some(({
  14203. key,
  14204. value
  14205. }) => {
  14206. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14207. });
  14208. }
  14209. return false;
  14210. }
  14211. checkImportReflection(node) {
  14212. const {
  14213. specifiers
  14214. } = node;
  14215. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  14216. if (node.phase === "source") {
  14217. if (singleBindingType !== "ImportDefaultSpecifier") {
  14218. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  14219. }
  14220. } else if (node.phase === "defer") {
  14221. if (singleBindingType !== "ImportNamespaceSpecifier") {
  14222. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  14223. }
  14224. } else if (node.module) {
  14225. var _node$assertions;
  14226. if (singleBindingType !== "ImportDefaultSpecifier") {
  14227. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  14228. }
  14229. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14230. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  14231. }
  14232. }
  14233. }
  14234. checkJSONModuleImport(node) {
  14235. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14236. const {
  14237. specifiers
  14238. } = node;
  14239. if (specifiers != null) {
  14240. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14241. let imported;
  14242. if (specifier.type === "ExportSpecifier") {
  14243. imported = specifier.local;
  14244. } else if (specifier.type === "ImportSpecifier") {
  14245. imported = specifier.imported;
  14246. }
  14247. if (imported !== undefined) {
  14248. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14249. }
  14250. });
  14251. if (nonDefaultNamedSpecifier !== undefined) {
  14252. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  14253. }
  14254. }
  14255. }
  14256. }
  14257. isPotentialImportPhase(isExport) {
  14258. if (isExport) return false;
  14259. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  14260. }
  14261. applyImportPhase(node, isExport, phase, loc) {
  14262. if (isExport) {
  14263. return;
  14264. }
  14265. if (phase === "module") {
  14266. this.expectPlugin("importReflection", loc);
  14267. node.module = true;
  14268. } else if (this.hasPlugin("importReflection")) {
  14269. node.module = false;
  14270. }
  14271. if (phase === "source") {
  14272. this.expectPlugin("sourcePhaseImports", loc);
  14273. node.phase = "source";
  14274. } else if (phase === "defer") {
  14275. this.expectPlugin("deferredImportEvaluation", loc);
  14276. node.phase = "defer";
  14277. } else if (this.hasPlugin("sourcePhaseImports")) {
  14278. node.phase = null;
  14279. }
  14280. }
  14281. parseMaybeImportPhase(node, isExport) {
  14282. if (!this.isPotentialImportPhase(isExport)) {
  14283. this.applyImportPhase(node, isExport, null);
  14284. return null;
  14285. }
  14286. const phaseIdentifier = this.startNode();
  14287. const phaseIdentifierName = this.parseIdentifierName(true);
  14288. const {
  14289. type
  14290. } = this.state;
  14291. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14292. if (isImportPhase) {
  14293. this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
  14294. return null;
  14295. } else {
  14296. this.applyImportPhase(node, isExport, null);
  14297. return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
  14298. }
  14299. }
  14300. isPrecedingIdImportPhase(phase) {
  14301. const {
  14302. type
  14303. } = this.state;
  14304. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14305. }
  14306. parseImport(node) {
  14307. if (this.match(134)) {
  14308. return this.parseImportSourceAndAttributes(node);
  14309. }
  14310. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14311. }
  14312. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14313. node.specifiers = [];
  14314. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14315. const parseNext = !hasDefault || this.eat(12);
  14316. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14317. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14318. this.expectContextual(98);
  14319. return this.parseImportSourceAndAttributes(node);
  14320. }
  14321. parseImportSourceAndAttributes(node) {
  14322. var _node$specifiers2;
  14323. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14324. node.source = this.parseImportSource();
  14325. this.maybeParseImportAttributes(node);
  14326. this.checkImportReflection(node);
  14327. this.checkJSONModuleImport(node);
  14328. this.semicolon();
  14329. this.sawUnambiguousESM = true;
  14330. return this.finishNode(node, "ImportDeclaration");
  14331. }
  14332. parseImportSource() {
  14333. if (!this.match(134)) this.unexpected();
  14334. return this.parseExprAtom();
  14335. }
  14336. parseImportSpecifierLocal(node, specifier, type) {
  14337. specifier.local = this.parseIdentifier();
  14338. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14339. }
  14340. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14341. this.checkLVal(specifier.local, {
  14342. type
  14343. }, bindingType);
  14344. return this.finishNode(specifier, type);
  14345. }
  14346. parseImportAttributes() {
  14347. this.expect(5);
  14348. const attrs = [];
  14349. const attrNames = new Set();
  14350. do {
  14351. if (this.match(8)) {
  14352. break;
  14353. }
  14354. const node = this.startNode();
  14355. const keyName = this.state.value;
  14356. if (attrNames.has(keyName)) {
  14357. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  14358. key: keyName
  14359. });
  14360. }
  14361. attrNames.add(keyName);
  14362. if (this.match(134)) {
  14363. node.key = this.parseStringLiteral(keyName);
  14364. } else {
  14365. node.key = this.parseIdentifier(true);
  14366. }
  14367. this.expect(14);
  14368. if (!this.match(134)) {
  14369. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14370. }
  14371. node.value = this.parseStringLiteral(this.state.value);
  14372. attrs.push(this.finishNode(node, "ImportAttribute"));
  14373. } while (this.eat(12));
  14374. this.expect(8);
  14375. return attrs;
  14376. }
  14377. parseModuleAttributes() {
  14378. const attrs = [];
  14379. const attributes = new Set();
  14380. do {
  14381. const node = this.startNode();
  14382. node.key = this.parseIdentifier(true);
  14383. if (node.key.name !== "type") {
  14384. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  14385. }
  14386. if (attributes.has(node.key.name)) {
  14387. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  14388. key: node.key.name
  14389. });
  14390. }
  14391. attributes.add(node.key.name);
  14392. this.expect(14);
  14393. if (!this.match(134)) {
  14394. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  14395. }
  14396. node.value = this.parseStringLiteral(this.state.value);
  14397. attrs.push(this.finishNode(node, "ImportAttribute"));
  14398. } while (this.eat(12));
  14399. return attrs;
  14400. }
  14401. maybeParseImportAttributes(node) {
  14402. let attributes;
  14403. {
  14404. var useWith = false;
  14405. }
  14406. if (this.match(76)) {
  14407. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14408. return;
  14409. }
  14410. this.next();
  14411. if (this.hasPlugin("moduleAttributes")) {
  14412. attributes = this.parseModuleAttributes();
  14413. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  14414. } else {
  14415. attributes = this.parseImportAttributes();
  14416. }
  14417. {
  14418. useWith = true;
  14419. }
  14420. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14421. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  14422. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  14423. }
  14424. if (!this.hasPlugin("importAssertions")) {
  14425. this.addExtra(node, "deprecatedAssertSyntax", true);
  14426. }
  14427. this.next();
  14428. attributes = this.parseImportAttributes();
  14429. } else {
  14430. attributes = [];
  14431. }
  14432. if (!useWith && this.hasPlugin("importAssertions")) {
  14433. node.assertions = attributes;
  14434. } else {
  14435. node.attributes = attributes;
  14436. }
  14437. }
  14438. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14439. if (maybeDefaultIdentifier) {
  14440. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14441. specifier.local = maybeDefaultIdentifier;
  14442. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14443. return true;
  14444. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14445. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14446. return true;
  14447. }
  14448. return false;
  14449. }
  14450. maybeParseStarImportSpecifier(node) {
  14451. if (this.match(55)) {
  14452. const specifier = this.startNode();
  14453. this.next();
  14454. this.expectContextual(93);
  14455. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14456. return true;
  14457. }
  14458. return false;
  14459. }
  14460. parseNamedImportSpecifiers(node) {
  14461. let first = true;
  14462. this.expect(5);
  14463. while (!this.eat(8)) {
  14464. if (first) {
  14465. first = false;
  14466. } else {
  14467. if (this.eat(14)) {
  14468. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  14469. }
  14470. this.expect(12);
  14471. if (this.eat(8)) break;
  14472. }
  14473. const specifier = this.startNode();
  14474. const importedIsString = this.match(134);
  14475. const isMaybeTypeOnly = this.isContextual(130);
  14476. specifier.imported = this.parseModuleExportName();
  14477. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14478. node.specifiers.push(importSpecifier);
  14479. }
  14480. }
  14481. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14482. if (this.eatContextual(93)) {
  14483. specifier.local = this.parseIdentifier();
  14484. } else {
  14485. const {
  14486. imported
  14487. } = specifier;
  14488. if (importedIsString) {
  14489. throw this.raise(Errors.ImportBindingIsString, specifier, {
  14490. importName: imported.value
  14491. });
  14492. }
  14493. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14494. if (!specifier.local) {
  14495. specifier.local = this.cloneIdentifier(imported);
  14496. }
  14497. }
  14498. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14499. }
  14500. isThisParam(param) {
  14501. return param.type === "Identifier" && param.name === "this";
  14502. }
  14503. }
  14504. class Parser extends StatementParser {
  14505. constructor(options, input, pluginsMap) {
  14506. const normalizedOptions = getOptions(options);
  14507. super(normalizedOptions, input);
  14508. this.options = normalizedOptions;
  14509. this.initializeScopes();
  14510. this.plugins = pluginsMap;
  14511. this.filename = normalizedOptions.sourceFilename;
  14512. this.startIndex = normalizedOptions.startIndex;
  14513. let optionFlags = 0;
  14514. if (normalizedOptions.allowAwaitOutsideFunction) {
  14515. optionFlags |= 1;
  14516. }
  14517. if (normalizedOptions.allowReturnOutsideFunction) {
  14518. optionFlags |= 2;
  14519. }
  14520. if (normalizedOptions.allowImportExportEverywhere) {
  14521. optionFlags |= 8;
  14522. }
  14523. if (normalizedOptions.allowSuperOutsideMethod) {
  14524. optionFlags |= 16;
  14525. }
  14526. if (normalizedOptions.allowUndeclaredExports) {
  14527. optionFlags |= 64;
  14528. }
  14529. if (normalizedOptions.allowNewTargetOutsideFunction) {
  14530. optionFlags |= 4;
  14531. }
  14532. if (normalizedOptions.allowYieldOutsideFunction) {
  14533. optionFlags |= 32;
  14534. }
  14535. if (normalizedOptions.ranges) {
  14536. optionFlags |= 128;
  14537. }
  14538. if (normalizedOptions.tokens) {
  14539. optionFlags |= 256;
  14540. }
  14541. if (normalizedOptions.createImportExpressions) {
  14542. optionFlags |= 512;
  14543. }
  14544. if (normalizedOptions.createParenthesizedExpressions) {
  14545. optionFlags |= 1024;
  14546. }
  14547. if (normalizedOptions.errorRecovery) {
  14548. optionFlags |= 2048;
  14549. }
  14550. if (normalizedOptions.attachComment) {
  14551. optionFlags |= 4096;
  14552. }
  14553. if (normalizedOptions.annexB) {
  14554. optionFlags |= 8192;
  14555. }
  14556. this.optionFlags = optionFlags;
  14557. }
  14558. getScopeHandler() {
  14559. return ScopeHandler;
  14560. }
  14561. parse() {
  14562. this.enterInitialScopes();
  14563. const file = this.startNode();
  14564. const program = this.startNode();
  14565. this.nextToken();
  14566. file.errors = null;
  14567. const result = this.parseTopLevel(file, program);
  14568. result.errors = this.state.errors;
  14569. result.comments.length = this.state.commentsLen;
  14570. return result;
  14571. }
  14572. }
  14573. function parse(input, options) {
  14574. var _options;
  14575. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14576. options = Object.assign({}, options);
  14577. try {
  14578. options.sourceType = "module";
  14579. const parser = getParser(options, input);
  14580. const ast = parser.parse();
  14581. if (parser.sawUnambiguousESM) {
  14582. return ast;
  14583. }
  14584. if (parser.ambiguousScriptDifferentAst) {
  14585. try {
  14586. options.sourceType = "script";
  14587. return getParser(options, input).parse();
  14588. } catch (_unused) {}
  14589. } else {
  14590. ast.program.sourceType = "script";
  14591. }
  14592. return ast;
  14593. } catch (moduleError) {
  14594. try {
  14595. options.sourceType = "script";
  14596. return getParser(options, input).parse();
  14597. } catch (_unused2) {}
  14598. throw moduleError;
  14599. }
  14600. } else {
  14601. return getParser(options, input).parse();
  14602. }
  14603. }
  14604. function parseExpression(input, options) {
  14605. const parser = getParser(options, input);
  14606. if (parser.options.strictMode) {
  14607. parser.state.strict = true;
  14608. }
  14609. return parser.getExpression();
  14610. }
  14611. function generateExportedTokenTypes(internalTokenTypes) {
  14612. const tokenTypes = {};
  14613. for (const typeName of Object.keys(internalTokenTypes)) {
  14614. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14615. }
  14616. return tokenTypes;
  14617. }
  14618. const tokTypes = generateExportedTokenTypes(tt);
  14619. function getParser(options, input) {
  14620. let cls = Parser;
  14621. const pluginsMap = new Map();
  14622. if (options != null && options.plugins) {
  14623. for (const plugin of options.plugins) {
  14624. let name, opts;
  14625. if (typeof plugin === "string") {
  14626. name = plugin;
  14627. } else {
  14628. [name, opts] = plugin;
  14629. }
  14630. if (!pluginsMap.has(name)) {
  14631. pluginsMap.set(name, opts || {});
  14632. }
  14633. }
  14634. validatePlugins(pluginsMap);
  14635. cls = getParserClass(pluginsMap);
  14636. }
  14637. return new cls(options, input, pluginsMap);
  14638. }
  14639. const parserClassCache = new Map();
  14640. function getParserClass(pluginsMap) {
  14641. const pluginList = [];
  14642. for (const name of mixinPluginNames) {
  14643. if (pluginsMap.has(name)) {
  14644. pluginList.push(name);
  14645. }
  14646. }
  14647. const key = pluginList.join("|");
  14648. let cls = parserClassCache.get(key);
  14649. if (!cls) {
  14650. cls = Parser;
  14651. for (const plugin of pluginList) {
  14652. cls = mixinPlugins[plugin](cls);
  14653. }
  14654. parserClassCache.set(key, cls);
  14655. }
  14656. return cls;
  14657. }
  14658. exports.parse = parse;
  14659. exports.parseExpression = parseExpression;
  14660. exports.tokTypes = tokTypes;
  14661. //# sourceMappingURL=index.js.map