index.js 471 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _objectWithoutPropertiesLoose(source, excluded) {
  4. if (source == null) return {};
  5. var target = {};
  6. var sourceKeys = Object.keys(source);
  7. var key, i;
  8. for (i = 0; i < sourceKeys.length; i++) {
  9. key = sourceKeys[i];
  10. if (excluded.indexOf(key) >= 0) continue;
  11. target[key] = source[key];
  12. }
  13. return target;
  14. }
  15. class Position {
  16. constructor(line, col, index) {
  17. this.line = void 0;
  18. this.column = void 0;
  19. this.index = void 0;
  20. this.line = line;
  21. this.column = col;
  22. this.index = index;
  23. }
  24. }
  25. class SourceLocation {
  26. constructor(start, end) {
  27. this.start = void 0;
  28. this.end = void 0;
  29. this.filename = void 0;
  30. this.identifierName = void 0;
  31. this.start = start;
  32. this.end = end;
  33. }
  34. }
  35. function createPositionWithColumnOffset(position, columnOffset) {
  36. const {
  37. line,
  38. column,
  39. index
  40. } = position;
  41. return new Position(line, column + columnOffset, index + columnOffset);
  42. }
  43. var ParseErrorCode = {
  44. SyntaxError: "BABEL_PARSER_SYNTAX_ERROR",
  45. SourceTypeModuleError: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"
  46. };
  47. const reflect = (keys, last = keys.length - 1) => ({
  48. get() {
  49. return keys.reduce((object, key) =>
  50. object[key], this);
  51. },
  52. set(value) {
  53. keys.reduce(
  54. (item, key, i) => i === last ? item[key] = value : item[key], this);
  55. }
  56. });
  57. const instantiate = (constructor, properties, descriptors) => Object.keys(descriptors).map(key => [key, descriptors[key]]).filter(([, descriptor]) => !!descriptor).map(([key, descriptor]) => [key, typeof descriptor === "function" ? {
  58. value: descriptor,
  59. enumerable: false
  60. } : typeof descriptor.reflect === "string" ? Object.assign({}, descriptor, reflect(descriptor.reflect.split("."))) : descriptor]).reduce((instance, [key, descriptor]) => Object.defineProperty(instance, key, Object.assign({
  61. configurable: true
  62. }, descriptor)), Object.assign(new constructor(), properties));
  63. var ModuleErrors = {
  64. ImportMetaOutsideModule: {
  65. message: `import.meta may appear only with 'sourceType: "module"'`,
  66. code: ParseErrorCode.SourceTypeModuleError
  67. },
  68. ImportOutsideModule: {
  69. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  70. code: ParseErrorCode.SourceTypeModuleError
  71. }
  72. };
  73. const NodeDescriptions = {
  74. ArrayPattern: "array destructuring pattern",
  75. AssignmentExpression: "assignment expression",
  76. AssignmentPattern: "assignment expression",
  77. ArrowFunctionExpression: "arrow function expression",
  78. ConditionalExpression: "conditional expression",
  79. CatchClause: "catch clause",
  80. ForOfStatement: "for-of statement",
  81. ForInStatement: "for-in statement",
  82. ForStatement: "for-loop",
  83. FormalParameters: "function parameter list",
  84. Identifier: "identifier",
  85. ImportSpecifier: "import specifier",
  86. ImportDefaultSpecifier: "import default specifier",
  87. ImportNamespaceSpecifier: "import namespace specifier",
  88. ObjectPattern: "object destructuring pattern",
  89. ParenthesizedExpression: "parenthesized expression",
  90. RestElement: "rest element",
  91. UpdateExpression: {
  92. true: "prefix operation",
  93. false: "postfix operation"
  94. },
  95. VariableDeclarator: "variable declaration",
  96. YieldExpression: "yield expression"
  97. };
  98. const toNodeDescription = ({
  99. type,
  100. prefix
  101. }) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
  102. var StandardErrors = {
  103. AccessorIsGenerator: ({
  104. kind
  105. }) => `A ${kind}ter cannot be a generator.`,
  106. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  107. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  108. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  109. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  110. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  111. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  112. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  113. BadGetterArity: "A 'get' accesor must not have any formal parameters.",
  114. BadSetterArity: "A 'set' accesor must have exactly one formal parameter.",
  115. BadSetterRestParameter: "A 'set' accesor function argument must not be a rest parameter.",
  116. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  117. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  118. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  119. ConstructorIsAsync: "Constructor can't be an async function.",
  120. ConstructorIsGenerator: "Constructor can't be a generator.",
  121. DeclarationMissingInitializer: ({
  122. kind
  123. }) => `Missing initializer in ${kind} declaration.`,
  124. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  125. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. You can set the 'decoratorsBeforeExport' option to false to use the 'export @decorator class {}' syntax.",
  126. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  127. DecoratorExportClass: "Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead.",
  128. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  129. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  130. DeletePrivateField: "Deleting a private field is not allowed.",
  131. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  132. DuplicateConstructor: "Duplicate constructor in the same class.",
  133. DuplicateDefaultExport: "Only one default export allowed per module.",
  134. DuplicateExport: ({
  135. exportName
  136. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  137. DuplicateProto: "Redefinition of __proto__ property.",
  138. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  139. ElementAfterRest: "Rest element must be last element.",
  140. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  141. ExportBindingIsString: ({
  142. localName,
  143. exportName
  144. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  145. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  146. ForInOfLoopInitializer: ({
  147. type
  148. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  149. ForInUsing: "For-in loop may not start with 'using' declaration.",
  150. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  151. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  152. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  153. IllegalBreakContinue: ({
  154. type
  155. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  156. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  157. IllegalReturn: "'return' outside of function.",
  158. ImportBindingIsString: ({
  159. importName
  160. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  161. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  162. ImportCallArity: ({
  163. maxArgumentCount
  164. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
  165. ImportCallNotNewExpression: "Cannot use new with import(...).",
  166. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  167. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  168. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  169. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  170. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  171. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  172. InvalidCodePoint: "Code point out of bounds.",
  173. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  174. InvalidDecimal: "Invalid decimal.",
  175. InvalidDigit: ({
  176. radix
  177. }) => `Expected number in radix ${radix}.`,
  178. InvalidEscapeSequence: "Bad character escape sequence.",
  179. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  180. InvalidEscapedReservedWord: ({
  181. reservedWord
  182. }) => `Escape sequence in keyword ${reservedWord}.`,
  183. InvalidIdentifier: ({
  184. identifierName
  185. }) => `Invalid identifier ${identifierName}.`,
  186. InvalidLhs: ({
  187. ancestor
  188. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  189. InvalidLhsBinding: ({
  190. ancestor
  191. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  192. InvalidNumber: "Invalid number.",
  193. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  194. InvalidOrUnexpectedToken: ({
  195. unexpected
  196. }) => `Unexpected character '${unexpected}'.`,
  197. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  198. InvalidPrivateFieldResolution: ({
  199. identifierName
  200. }) => `Private name #${identifierName} is not defined.`,
  201. InvalidPropertyBindingPattern: "Binding member expression.",
  202. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  203. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  204. LabelRedeclaration: ({
  205. labelName
  206. }) => `Label '${labelName}' is already declared.`,
  207. LetInLexicalBinding: "'let' is not allowed to be used as a name in 'let' or 'const' declarations.",
  208. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  209. MalformedRegExpFlags: "Invalid regular expression flag.",
  210. MissingClassName: "A class name is required.",
  211. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  212. MissingSemicolon: "Missing semicolon.",
  213. MissingPlugin: ({
  214. missingPlugin
  215. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  216. MissingOneOfPlugins: ({
  217. missingPlugin
  218. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  219. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  220. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  221. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  222. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  223. ModuleAttributesWithDuplicateKeys: ({
  224. key
  225. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  226. ModuleExportNameHasLoneSurrogate: ({
  227. surrogateCharCode
  228. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  229. ModuleExportUndefined: ({
  230. localName
  231. }) => `Export '${localName}' is not defined.`,
  232. MultipleDefaultsInSwitch: "Multiple default clauses.",
  233. NewlineAfterThrow: "Illegal newline after throw.",
  234. NoCatchOrFinally: "Missing catch or finally clause.",
  235. NumberIdentifier: "Identifier directly after number.",
  236. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  237. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  238. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  239. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  240. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  241. ParamDupe: "Argument name clash.",
  242. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  243. PatternHasMethod: "Object pattern can't contain methods.",
  244. PrivateInExpectedIn: ({
  245. identifierName
  246. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  247. PrivateNameRedeclaration: ({
  248. identifierName
  249. }) => `Duplicate private name #${identifierName}.`,
  250. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  251. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  252. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  253. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  254. RestTrailingComma: "Unexpected trailing comma after rest element.",
  255. SloppyFunction: "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement.",
  256. StaticPrototype: "Classes may not have static property named prototype.",
  257. 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?",
  258. SuperPrivateField: "Private fields can't be accessed on super.",
  259. TrailingDecorator: "Decorators must be attached to a class element.",
  260. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  261. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  262. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  263. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  264. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  265. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  266. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  267. UnexpectedKeyword: ({
  268. keyword
  269. }) => `Unexpected keyword '${keyword}'.`,
  270. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  271. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  272. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  273. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  274. UnexpectedPrivateField: "Unexpected private name.",
  275. UnexpectedReservedWord: ({
  276. reservedWord
  277. }) => `Unexpected reserved word '${reservedWord}'.`,
  278. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  279. UnexpectedToken: ({
  280. expected,
  281. unexpected
  282. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  283. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  284. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  285. UnsupportedBind: "Binding should be performed on object property.",
  286. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  287. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  288. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  289. UnsupportedMetaProperty: ({
  290. target,
  291. onlyValidPropertyName
  292. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  293. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  294. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  295. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  296. UnterminatedComment: "Unterminated comment.",
  297. UnterminatedRegExp: "Unterminated regular expression.",
  298. UnterminatedString: "Unterminated string constant.",
  299. UnterminatedTemplate: "Unterminated template.",
  300. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  301. VarRedeclaration: ({
  302. identifierName
  303. }) => `Identifier '${identifierName}' has already been declared.`,
  304. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  305. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  306. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  307. };
  308. var StrictModeErrors = {
  309. StrictDelete: "Deleting local variable in strict mode.",
  310. StrictEvalArguments: ({
  311. referenceName
  312. }) => `Assigning to '${referenceName}' in strict mode.`,
  313. StrictEvalArgumentsBinding: ({
  314. bindingName
  315. }) => `Binding '${bindingName}' in strict mode.`,
  316. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  317. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  318. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  319. StrictWith: "'with' in strict mode."
  320. };
  321. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  322. var PipelineOperatorErrors = {
  323. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  324. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  325. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  326. PipeTopicUnconfiguredToken: ({
  327. token
  328. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  329. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  330. PipeUnparenthesizedBody: ({
  331. type
  332. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  333. type
  334. })}; please wrap it in parentheses.`,
  335. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  336. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  337. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  338. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  339. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  340. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  341. };
  342. const _excluded$1 = ["toMessage"],
  343. _excluded2$1 = ["message"];
  344. function toParseErrorConstructor(_ref) {
  345. let {
  346. toMessage
  347. } = _ref,
  348. properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  349. return function constructor({
  350. loc,
  351. details
  352. }) {
  353. return instantiate(SyntaxError, Object.assign({}, properties, {
  354. loc
  355. }), {
  356. clone(overrides = {}) {
  357. const loc = overrides.loc || {};
  358. return constructor({
  359. loc: new Position("line" in loc ? loc.line : this.loc.line, "column" in loc ? loc.column : this.loc.column, "index" in loc ? loc.index : this.loc.index),
  360. details: Object.assign({}, this.details, overrides.details)
  361. });
  362. },
  363. details: {
  364. value: details,
  365. enumerable: false
  366. },
  367. message: {
  368. get() {
  369. return `${toMessage(this.details)} (${this.loc.line}:${this.loc.column})`;
  370. },
  371. set(value) {
  372. Object.defineProperty(this, "message", {
  373. value
  374. });
  375. }
  376. },
  377. pos: {
  378. reflect: "loc.index",
  379. enumerable: true
  380. },
  381. missingPlugin: "missingPlugin" in details && {
  382. reflect: "details.missingPlugin",
  383. enumerable: true
  384. }
  385. });
  386. };
  387. }
  388. function ParseErrorEnum(argument, syntaxPlugin) {
  389. if (Array.isArray(argument)) {
  390. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  391. }
  392. const ParseErrorConstructors = {};
  393. for (const reasonCode of Object.keys(argument)) {
  394. const template = argument[reasonCode];
  395. const _ref2 = typeof template === "string" ? {
  396. message: () => template
  397. } : typeof template === "function" ? {
  398. message: template
  399. } : template,
  400. {
  401. message
  402. } = _ref2,
  403. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
  404. const toMessage = typeof message === "string" ? () => message : message;
  405. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  406. code: ParseErrorCode.SyntaxError,
  407. reasonCode,
  408. toMessage
  409. }, syntaxPlugin ? {
  410. syntaxPlugin
  411. } : {}, rest));
  412. }
  413. return ParseErrorConstructors;
  414. }
  415. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  416. const {
  417. defineProperty
  418. } = Object;
  419. const toUnenumerable = (object, key) => defineProperty(object, key, {
  420. enumerable: false,
  421. value: object[key]
  422. });
  423. function toESTreeLocation(node) {
  424. node.loc.start && toUnenumerable(node.loc.start, "index");
  425. node.loc.end && toUnenumerable(node.loc.end, "index");
  426. return node;
  427. }
  428. var estree = (superClass => class ESTreeParserMixin extends superClass {
  429. parse() {
  430. const file = toESTreeLocation(super.parse());
  431. if (this.options.tokens) {
  432. file.tokens = file.tokens.map(toESTreeLocation);
  433. }
  434. return file;
  435. }
  436. parseRegExpLiteral({
  437. pattern,
  438. flags
  439. }) {
  440. let regex = null;
  441. try {
  442. regex = new RegExp(pattern, flags);
  443. } catch (e) {
  444. }
  445. const node = this.estreeParseLiteral(regex);
  446. node.regex = {
  447. pattern,
  448. flags
  449. };
  450. return node;
  451. }
  452. parseBigIntLiteral(value) {
  453. let bigInt;
  454. try {
  455. bigInt = BigInt(value);
  456. } catch (_unused) {
  457. bigInt = null;
  458. }
  459. const node = this.estreeParseLiteral(bigInt);
  460. node.bigint = String(node.value || value);
  461. return node;
  462. }
  463. parseDecimalLiteral(value) {
  464. const decimal = null;
  465. const node = this.estreeParseLiteral(decimal);
  466. node.decimal = String(node.value || value);
  467. return node;
  468. }
  469. estreeParseLiteral(value) {
  470. return this.parseLiteral(value, "Literal");
  471. }
  472. parseStringLiteral(value) {
  473. return this.estreeParseLiteral(value);
  474. }
  475. parseNumericLiteral(value) {
  476. return this.estreeParseLiteral(value);
  477. }
  478. parseNullLiteral() {
  479. return this.estreeParseLiteral(null);
  480. }
  481. parseBooleanLiteral(value) {
  482. return this.estreeParseLiteral(value);
  483. }
  484. directiveToStmt(directive) {
  485. const expression = directive.value;
  486. delete directive.value;
  487. expression.type = "Literal";
  488. expression.raw = expression.extra.raw;
  489. expression.value = expression.extra.expressionValue;
  490. const stmt = directive;
  491. stmt.type = "ExpressionStatement";
  492. stmt.expression = expression;
  493. stmt.directive = expression.extra.rawValue;
  494. delete expression.extra;
  495. return stmt;
  496. }
  497. initFunction(node, isAsync) {
  498. super.initFunction(node, isAsync);
  499. node.expression = false;
  500. }
  501. checkDeclaration(node) {
  502. if (node != null && this.isObjectProperty(node)) {
  503. this.checkDeclaration(node.value);
  504. } else {
  505. super.checkDeclaration(node);
  506. }
  507. }
  508. getObjectOrClassMethodParams(method) {
  509. return method.value.params;
  510. }
  511. isValidDirective(stmt) {
  512. var _stmt$expression$extr;
  513. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  514. }
  515. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  516. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  517. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  518. node.body = directiveStatements.concat(node.body);
  519. delete node.directives;
  520. }
  521. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  522. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  523. if (method.typeParameters) {
  524. method.value.typeParameters = method.typeParameters;
  525. delete method.typeParameters;
  526. }
  527. classBody.body.push(method);
  528. }
  529. parsePrivateName() {
  530. const node = super.parsePrivateName();
  531. {
  532. if (!this.getPluginOption("estree", "classFeatures")) {
  533. return node;
  534. }
  535. }
  536. return this.convertPrivateNameToPrivateIdentifier(node);
  537. }
  538. convertPrivateNameToPrivateIdentifier(node) {
  539. const name = super.getPrivateNameSV(node);
  540. node = node;
  541. delete node.id;
  542. node.name = name;
  543. node.type = "PrivateIdentifier";
  544. return node;
  545. }
  546. isPrivateName(node) {
  547. {
  548. if (!this.getPluginOption("estree", "classFeatures")) {
  549. return super.isPrivateName(node);
  550. }
  551. }
  552. return node.type === "PrivateIdentifier";
  553. }
  554. getPrivateNameSV(node) {
  555. {
  556. if (!this.getPluginOption("estree", "classFeatures")) {
  557. return super.getPrivateNameSV(node);
  558. }
  559. }
  560. return node.name;
  561. }
  562. parseLiteral(value, type) {
  563. const node = super.parseLiteral(value, type);
  564. node.raw = node.extra.raw;
  565. delete node.extra;
  566. return node;
  567. }
  568. parseFunctionBody(node, allowExpression, isMethod = false) {
  569. super.parseFunctionBody(node, allowExpression, isMethod);
  570. node.expression = node.body.type !== "BlockStatement";
  571. }
  572. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  573. let funcNode = this.startNode();
  574. funcNode.kind = node.kind;
  575. funcNode = super.parseMethod(
  576. funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  577. funcNode.type = "FunctionExpression";
  578. delete funcNode.kind;
  579. node.value = funcNode;
  580. if (type === "ClassPrivateMethod") {
  581. node.computed = false;
  582. }
  583. return this.finishNode(
  584. node, "MethodDefinition");
  585. }
  586. parseClassProperty(...args) {
  587. const propertyNode = super.parseClassProperty(...args);
  588. {
  589. if (!this.getPluginOption("estree", "classFeatures")) {
  590. return propertyNode;
  591. }
  592. }
  593. propertyNode.type = "PropertyDefinition";
  594. return propertyNode;
  595. }
  596. parseClassPrivateProperty(...args) {
  597. const propertyNode = super.parseClassPrivateProperty(...args);
  598. {
  599. if (!this.getPluginOption("estree", "classFeatures")) {
  600. return propertyNode;
  601. }
  602. }
  603. propertyNode.type = "PropertyDefinition";
  604. propertyNode.computed = false;
  605. return propertyNode;
  606. }
  607. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  608. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  609. if (node) {
  610. node.type = "Property";
  611. if (node.kind === "method") {
  612. node.kind = "init";
  613. }
  614. node.shorthand = false;
  615. }
  616. return node;
  617. }
  618. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  619. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  620. if (node) {
  621. node.kind = "init";
  622. node.type = "Property";
  623. }
  624. return node;
  625. }
  626. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  627. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  628. }
  629. isAssignable(node, isBinding) {
  630. if (node != null && this.isObjectProperty(node)) {
  631. return this.isAssignable(node.value, isBinding);
  632. }
  633. return super.isAssignable(node, isBinding);
  634. }
  635. toAssignable(node, isLHS = false) {
  636. if (node != null && this.isObjectProperty(node)) {
  637. const {
  638. key,
  639. value
  640. } = node;
  641. if (this.isPrivateName(key)) {
  642. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  643. }
  644. this.toAssignable(value, isLHS);
  645. } else {
  646. super.toAssignable(node, isLHS);
  647. }
  648. }
  649. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  650. if (prop.kind === "get" || prop.kind === "set") {
  651. this.raise(Errors.PatternHasAccessor, {
  652. at: prop.key
  653. });
  654. } else if (prop.method) {
  655. this.raise(Errors.PatternHasMethod, {
  656. at: prop.key
  657. });
  658. } else {
  659. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  660. }
  661. }
  662. finishCallExpression(unfinished, optional) {
  663. const node = super.finishCallExpression(unfinished, optional);
  664. if (node.callee.type === "Import") {
  665. node.type = "ImportExpression";
  666. node.source = node.arguments[0];
  667. if (this.hasPlugin("importAssertions")) {
  668. var _node$arguments$;
  669. node.attributes = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  670. }
  671. delete node.arguments;
  672. delete node.callee;
  673. }
  674. return node;
  675. }
  676. toReferencedArguments(node
  677. ) {
  678. if (node.type === "ImportExpression") {
  679. return;
  680. }
  681. super.toReferencedArguments(node);
  682. }
  683. parseExport(unfinished, decorators) {
  684. const exportStartLoc = this.state.lastTokStartLoc;
  685. const node = super.parseExport(unfinished, decorators);
  686. switch (node.type) {
  687. case "ExportAllDeclaration":
  688. node.exported = null;
  689. break;
  690. case "ExportNamedDeclaration":
  691. if (node.specifiers.length === 1 &&
  692. node.specifiers[0].type === "ExportNamespaceSpecifier") {
  693. node.type = "ExportAllDeclaration";
  694. node.exported = node.specifiers[0].exported;
  695. delete node.specifiers;
  696. }
  697. case "ExportDefaultDeclaration":
  698. {
  699. var _declaration$decorato;
  700. const {
  701. declaration
  702. } = node;
  703. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 &&
  704. declaration.start === node.start) {
  705. this.resetStartLocation(node,
  706. exportStartLoc);
  707. }
  708. }
  709. break;
  710. }
  711. return node;
  712. }
  713. parseSubscript(base, startLoc, noCalls, state) {
  714. const node = super.parseSubscript(base, startLoc, noCalls, state);
  715. if (state.optionalChainMember) {
  716. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  717. node.type = node.type.substring(8);
  718. }
  719. if (state.stop) {
  720. const chain = this.startNodeAtNode(node);
  721. chain.expression = node;
  722. return this.finishNode(chain, "ChainExpression");
  723. }
  724. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  725. node.optional = false;
  726. }
  727. return node;
  728. }
  729. hasPropertyAsPrivateName(node) {
  730. if (node.type === "ChainExpression") {
  731. node = node.expression;
  732. }
  733. return super.hasPropertyAsPrivateName(node);
  734. }
  735. isOptionalChain(node) {
  736. return node.type === "ChainExpression";
  737. }
  738. isObjectProperty(node) {
  739. return node.type === "Property" && node.kind === "init" && !node.method;
  740. }
  741. isObjectMethod(node) {
  742. return node.method || node.kind === "get" || node.kind === "set";
  743. }
  744. finishNodeAt(node, type, endLoc) {
  745. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  746. }
  747. resetStartLocation(node, startLoc) {
  748. super.resetStartLocation(node, startLoc);
  749. toESTreeLocation(node);
  750. }
  751. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  752. super.resetEndLocation(node, endLoc);
  753. toESTreeLocation(node);
  754. }
  755. });
  756. class TokContext {
  757. constructor(token, preserveSpace) {
  758. this.token = void 0;
  759. this.preserveSpace = void 0;
  760. this.token = token;
  761. this.preserveSpace = !!preserveSpace;
  762. }
  763. }
  764. const types = {
  765. brace: new TokContext("{"),
  766. j_oTag: new TokContext("<tag"),
  767. j_cTag: new TokContext("</tag"),
  768. j_expr: new TokContext("<tag>...</tag>", true)
  769. };
  770. {
  771. types.template = new TokContext("`", true);
  772. }
  773. const beforeExpr = true;
  774. const startsExpr = true;
  775. const isLoop = true;
  776. const isAssign = true;
  777. const prefix = true;
  778. const postfix = true;
  779. class ExportedTokenType {
  780. constructor(label, conf = {}) {
  781. this.label = void 0;
  782. this.keyword = void 0;
  783. this.beforeExpr = void 0;
  784. this.startsExpr = void 0;
  785. this.rightAssociative = void 0;
  786. this.isLoop = void 0;
  787. this.isAssign = void 0;
  788. this.prefix = void 0;
  789. this.postfix = void 0;
  790. this.binop = void 0;
  791. this.label = label;
  792. this.keyword = conf.keyword;
  793. this.beforeExpr = !!conf.beforeExpr;
  794. this.startsExpr = !!conf.startsExpr;
  795. this.rightAssociative = !!conf.rightAssociative;
  796. this.isLoop = !!conf.isLoop;
  797. this.isAssign = !!conf.isAssign;
  798. this.prefix = !!conf.prefix;
  799. this.postfix = !!conf.postfix;
  800. this.binop = conf.binop != null ? conf.binop : null;
  801. {
  802. this.updateContext = null;
  803. }
  804. }
  805. }
  806. const keywords$1 = new Map();
  807. function createKeyword(name, options = {}) {
  808. options.keyword = name;
  809. const token = createToken(name, options);
  810. keywords$1.set(name, token);
  811. return token;
  812. }
  813. function createBinop(name, binop) {
  814. return createToken(name, {
  815. beforeExpr,
  816. binop
  817. });
  818. }
  819. let tokenTypeCounter = -1;
  820. const tokenTypes = [];
  821. const tokenLabels = [];
  822. const tokenBinops = [];
  823. const tokenBeforeExprs = [];
  824. const tokenStartsExprs = [];
  825. const tokenPrefixes = [];
  826. function createToken(name, options = {}) {
  827. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  828. ++tokenTypeCounter;
  829. tokenLabels.push(name);
  830. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  831. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  832. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  833. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  834. tokenTypes.push(new ExportedTokenType(name, options));
  835. return tokenTypeCounter;
  836. }
  837. function createKeywordLike(name, options = {}) {
  838. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  839. ++tokenTypeCounter;
  840. keywords$1.set(name, tokenTypeCounter);
  841. tokenLabels.push(name);
  842. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  843. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  844. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  845. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  846. tokenTypes.push(new ExportedTokenType("name", options));
  847. return tokenTypeCounter;
  848. }
  849. const tt = {
  850. bracketL: createToken("[", {
  851. beforeExpr,
  852. startsExpr
  853. }),
  854. bracketHashL: createToken("#[", {
  855. beforeExpr,
  856. startsExpr
  857. }),
  858. bracketBarL: createToken("[|", {
  859. beforeExpr,
  860. startsExpr
  861. }),
  862. bracketR: createToken("]"),
  863. bracketBarR: createToken("|]"),
  864. braceL: createToken("{", {
  865. beforeExpr,
  866. startsExpr
  867. }),
  868. braceBarL: createToken("{|", {
  869. beforeExpr,
  870. startsExpr
  871. }),
  872. braceHashL: createToken("#{", {
  873. beforeExpr,
  874. startsExpr
  875. }),
  876. braceR: createToken("}"),
  877. braceBarR: createToken("|}"),
  878. parenL: createToken("(", {
  879. beforeExpr,
  880. startsExpr
  881. }),
  882. parenR: createToken(")"),
  883. comma: createToken(",", {
  884. beforeExpr
  885. }),
  886. semi: createToken(";", {
  887. beforeExpr
  888. }),
  889. colon: createToken(":", {
  890. beforeExpr
  891. }),
  892. doubleColon: createToken("::", {
  893. beforeExpr
  894. }),
  895. dot: createToken("."),
  896. question: createToken("?", {
  897. beforeExpr
  898. }),
  899. questionDot: createToken("?."),
  900. arrow: createToken("=>", {
  901. beforeExpr
  902. }),
  903. template: createToken("template"),
  904. ellipsis: createToken("...", {
  905. beforeExpr
  906. }),
  907. backQuote: createToken("`", {
  908. startsExpr
  909. }),
  910. dollarBraceL: createToken("${", {
  911. beforeExpr,
  912. startsExpr
  913. }),
  914. templateTail: createToken("...`", {
  915. startsExpr
  916. }),
  917. templateNonTail: createToken("...${", {
  918. beforeExpr,
  919. startsExpr
  920. }),
  921. at: createToken("@"),
  922. hash: createToken("#", {
  923. startsExpr
  924. }),
  925. interpreterDirective: createToken("#!..."),
  926. eq: createToken("=", {
  927. beforeExpr,
  928. isAssign
  929. }),
  930. assign: createToken("_=", {
  931. beforeExpr,
  932. isAssign
  933. }),
  934. slashAssign: createToken("_=", {
  935. beforeExpr,
  936. isAssign
  937. }),
  938. xorAssign: createToken("_=", {
  939. beforeExpr,
  940. isAssign
  941. }),
  942. moduloAssign: createToken("_=", {
  943. beforeExpr,
  944. isAssign
  945. }),
  946. incDec: createToken("++/--", {
  947. prefix,
  948. postfix,
  949. startsExpr
  950. }),
  951. bang: createToken("!", {
  952. beforeExpr,
  953. prefix,
  954. startsExpr
  955. }),
  956. tilde: createToken("~", {
  957. beforeExpr,
  958. prefix,
  959. startsExpr
  960. }),
  961. doubleCaret: createToken("^^", {
  962. startsExpr
  963. }),
  964. doubleAt: createToken("@@", {
  965. startsExpr
  966. }),
  967. pipeline: createBinop("|>", 0),
  968. nullishCoalescing: createBinop("??", 1),
  969. logicalOR: createBinop("||", 1),
  970. logicalAND: createBinop("&&", 2),
  971. bitwiseOR: createBinop("|", 3),
  972. bitwiseXOR: createBinop("^", 4),
  973. bitwiseAND: createBinop("&", 5),
  974. equality: createBinop("==/!=/===/!==", 6),
  975. lt: createBinop("</>/<=/>=", 7),
  976. gt: createBinop("</>/<=/>=", 7),
  977. relational: createBinop("</>/<=/>=", 7),
  978. bitShift: createBinop("<</>>/>>>", 8),
  979. bitShiftL: createBinop("<</>>/>>>", 8),
  980. bitShiftR: createBinop("<</>>/>>>", 8),
  981. plusMin: createToken("+/-", {
  982. beforeExpr,
  983. binop: 9,
  984. prefix,
  985. startsExpr
  986. }),
  987. modulo: createToken("%", {
  988. binop: 10,
  989. startsExpr
  990. }),
  991. star: createToken("*", {
  992. binop: 10
  993. }),
  994. slash: createBinop("/", 10),
  995. exponent: createToken("**", {
  996. beforeExpr,
  997. binop: 11,
  998. rightAssociative: true
  999. }),
  1000. _in: createKeyword("in", {
  1001. beforeExpr,
  1002. binop: 7
  1003. }),
  1004. _instanceof: createKeyword("instanceof", {
  1005. beforeExpr,
  1006. binop: 7
  1007. }),
  1008. _break: createKeyword("break"),
  1009. _case: createKeyword("case", {
  1010. beforeExpr
  1011. }),
  1012. _catch: createKeyword("catch"),
  1013. _continue: createKeyword("continue"),
  1014. _debugger: createKeyword("debugger"),
  1015. _default: createKeyword("default", {
  1016. beforeExpr
  1017. }),
  1018. _else: createKeyword("else", {
  1019. beforeExpr
  1020. }),
  1021. _finally: createKeyword("finally"),
  1022. _function: createKeyword("function", {
  1023. startsExpr
  1024. }),
  1025. _if: createKeyword("if"),
  1026. _return: createKeyword("return", {
  1027. beforeExpr
  1028. }),
  1029. _switch: createKeyword("switch"),
  1030. _throw: createKeyword("throw", {
  1031. beforeExpr,
  1032. prefix,
  1033. startsExpr
  1034. }),
  1035. _try: createKeyword("try"),
  1036. _var: createKeyword("var"),
  1037. _const: createKeyword("const"),
  1038. _with: createKeyword("with"),
  1039. _new: createKeyword("new", {
  1040. beforeExpr,
  1041. startsExpr
  1042. }),
  1043. _this: createKeyword("this", {
  1044. startsExpr
  1045. }),
  1046. _super: createKeyword("super", {
  1047. startsExpr
  1048. }),
  1049. _class: createKeyword("class", {
  1050. startsExpr
  1051. }),
  1052. _extends: createKeyword("extends", {
  1053. beforeExpr
  1054. }),
  1055. _export: createKeyword("export"),
  1056. _import: createKeyword("import", {
  1057. startsExpr
  1058. }),
  1059. _null: createKeyword("null", {
  1060. startsExpr
  1061. }),
  1062. _true: createKeyword("true", {
  1063. startsExpr
  1064. }),
  1065. _false: createKeyword("false", {
  1066. startsExpr
  1067. }),
  1068. _typeof: createKeyword("typeof", {
  1069. beforeExpr,
  1070. prefix,
  1071. startsExpr
  1072. }),
  1073. _void: createKeyword("void", {
  1074. beforeExpr,
  1075. prefix,
  1076. startsExpr
  1077. }),
  1078. _delete: createKeyword("delete", {
  1079. beforeExpr,
  1080. prefix,
  1081. startsExpr
  1082. }),
  1083. _do: createKeyword("do", {
  1084. isLoop,
  1085. beforeExpr
  1086. }),
  1087. _for: createKeyword("for", {
  1088. isLoop
  1089. }),
  1090. _while: createKeyword("while", {
  1091. isLoop
  1092. }),
  1093. _as: createKeywordLike("as", {
  1094. startsExpr
  1095. }),
  1096. _assert: createKeywordLike("assert", {
  1097. startsExpr
  1098. }),
  1099. _async: createKeywordLike("async", {
  1100. startsExpr
  1101. }),
  1102. _await: createKeywordLike("await", {
  1103. startsExpr
  1104. }),
  1105. _from: createKeywordLike("from", {
  1106. startsExpr
  1107. }),
  1108. _get: createKeywordLike("get", {
  1109. startsExpr
  1110. }),
  1111. _let: createKeywordLike("let", {
  1112. startsExpr
  1113. }),
  1114. _meta: createKeywordLike("meta", {
  1115. startsExpr
  1116. }),
  1117. _of: createKeywordLike("of", {
  1118. startsExpr
  1119. }),
  1120. _sent: createKeywordLike("sent", {
  1121. startsExpr
  1122. }),
  1123. _set: createKeywordLike("set", {
  1124. startsExpr
  1125. }),
  1126. _static: createKeywordLike("static", {
  1127. startsExpr
  1128. }),
  1129. _using: createKeywordLike("using", {
  1130. startsExpr
  1131. }),
  1132. _yield: createKeywordLike("yield", {
  1133. startsExpr
  1134. }),
  1135. _asserts: createKeywordLike("asserts", {
  1136. startsExpr
  1137. }),
  1138. _checks: createKeywordLike("checks", {
  1139. startsExpr
  1140. }),
  1141. _exports: createKeywordLike("exports", {
  1142. startsExpr
  1143. }),
  1144. _global: createKeywordLike("global", {
  1145. startsExpr
  1146. }),
  1147. _implements: createKeywordLike("implements", {
  1148. startsExpr
  1149. }),
  1150. _intrinsic: createKeywordLike("intrinsic", {
  1151. startsExpr
  1152. }),
  1153. _infer: createKeywordLike("infer", {
  1154. startsExpr
  1155. }),
  1156. _is: createKeywordLike("is", {
  1157. startsExpr
  1158. }),
  1159. _mixins: createKeywordLike("mixins", {
  1160. startsExpr
  1161. }),
  1162. _proto: createKeywordLike("proto", {
  1163. startsExpr
  1164. }),
  1165. _require: createKeywordLike("require", {
  1166. startsExpr
  1167. }),
  1168. _satisfies: createKeywordLike("satisfies", {
  1169. startsExpr
  1170. }),
  1171. _keyof: createKeywordLike("keyof", {
  1172. startsExpr
  1173. }),
  1174. _readonly: createKeywordLike("readonly", {
  1175. startsExpr
  1176. }),
  1177. _unique: createKeywordLike("unique", {
  1178. startsExpr
  1179. }),
  1180. _abstract: createKeywordLike("abstract", {
  1181. startsExpr
  1182. }),
  1183. _declare: createKeywordLike("declare", {
  1184. startsExpr
  1185. }),
  1186. _enum: createKeywordLike("enum", {
  1187. startsExpr
  1188. }),
  1189. _module: createKeywordLike("module", {
  1190. startsExpr
  1191. }),
  1192. _namespace: createKeywordLike("namespace", {
  1193. startsExpr
  1194. }),
  1195. _interface: createKeywordLike("interface", {
  1196. startsExpr
  1197. }),
  1198. _type: createKeywordLike("type", {
  1199. startsExpr
  1200. }),
  1201. _opaque: createKeywordLike("opaque", {
  1202. startsExpr
  1203. }),
  1204. name: createToken("name", {
  1205. startsExpr
  1206. }),
  1207. string: createToken("string", {
  1208. startsExpr
  1209. }),
  1210. num: createToken("num", {
  1211. startsExpr
  1212. }),
  1213. bigint: createToken("bigint", {
  1214. startsExpr
  1215. }),
  1216. decimal: createToken("decimal", {
  1217. startsExpr
  1218. }),
  1219. regexp: createToken("regexp", {
  1220. startsExpr
  1221. }),
  1222. privateName: createToken("#name", {
  1223. startsExpr
  1224. }),
  1225. eof: createToken("eof"),
  1226. jsxName: createToken("jsxName"),
  1227. jsxText: createToken("jsxText", {
  1228. beforeExpr: true
  1229. }),
  1230. jsxTagStart: createToken("jsxTagStart", {
  1231. startsExpr: true
  1232. }),
  1233. jsxTagEnd: createToken("jsxTagEnd"),
  1234. placeholder: createToken("%%", {
  1235. startsExpr: true
  1236. })
  1237. };
  1238. function tokenIsIdentifier(token) {
  1239. return token >= 93 && token <= 130;
  1240. }
  1241. function tokenKeywordOrIdentifierIsKeyword(token) {
  1242. return token <= 92;
  1243. }
  1244. function tokenIsKeywordOrIdentifier(token) {
  1245. return token >= 58 && token <= 130;
  1246. }
  1247. function tokenIsLiteralPropertyName(token) {
  1248. return token >= 58 && token <= 134;
  1249. }
  1250. function tokenComesBeforeExpression(token) {
  1251. return tokenBeforeExprs[token];
  1252. }
  1253. function tokenCanStartExpression(token) {
  1254. return tokenStartsExprs[token];
  1255. }
  1256. function tokenIsAssignment(token) {
  1257. return token >= 29 && token <= 33;
  1258. }
  1259. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1260. return token >= 127 && token <= 129;
  1261. }
  1262. function tokenIsLoop(token) {
  1263. return token >= 90 && token <= 92;
  1264. }
  1265. function tokenIsKeyword(token) {
  1266. return token >= 58 && token <= 92;
  1267. }
  1268. function tokenIsOperator(token) {
  1269. return token >= 39 && token <= 59;
  1270. }
  1271. function tokenIsPostfix(token) {
  1272. return token === 34;
  1273. }
  1274. function tokenIsPrefix(token) {
  1275. return tokenPrefixes[token];
  1276. }
  1277. function tokenIsTSTypeOperator(token) {
  1278. return token >= 119 && token <= 121;
  1279. }
  1280. function tokenIsTSDeclarationStart(token) {
  1281. return token >= 122 && token <= 128;
  1282. }
  1283. function tokenLabelName(token) {
  1284. return tokenLabels[token];
  1285. }
  1286. function tokenOperatorPrecedence(token) {
  1287. return tokenBinops[token];
  1288. }
  1289. function tokenIsRightAssociative(token) {
  1290. return token === 57;
  1291. }
  1292. function tokenIsTemplate(token) {
  1293. return token >= 24 && token <= 25;
  1294. }
  1295. function getExportedToken(token) {
  1296. return tokenTypes[token];
  1297. }
  1298. {
  1299. tokenTypes[8].updateContext = context => {
  1300. context.pop();
  1301. };
  1302. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1303. context.push(types.brace);
  1304. };
  1305. tokenTypes[22].updateContext = context => {
  1306. if (context[context.length - 1] === types.template) {
  1307. context.pop();
  1308. } else {
  1309. context.push(types.template);
  1310. }
  1311. };
  1312. tokenTypes[140].updateContext = context => {
  1313. context.push(types.j_expr, types.j_oTag);
  1314. };
  1315. }
  1316. let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\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-\ua7ca\ua7d0\ua7d1\ua7d3\ua7d5-\ua7d9\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  1317. let nonASCIIidentifierChars = "\u200c\u200d\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\u0898-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\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";
  1318. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1319. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1320. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1321. 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, 68, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 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, 159, 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, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 4026, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 757, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938, 6, 4191];
  1322. 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, 370, 1, 81, 2, 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, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 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, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 9, 5351, 0, 7, 14, 13835, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 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, 983, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1323. function isInAstralSet(code, set) {
  1324. let pos = 0x10000;
  1325. for (let i = 0, length = set.length; i < length; i += 2) {
  1326. pos += set[i];
  1327. if (pos > code) return false;
  1328. pos += set[i + 1];
  1329. if (pos >= code) return true;
  1330. }
  1331. return false;
  1332. }
  1333. function isIdentifierStart(code) {
  1334. if (code < 65) return code === 36;
  1335. if (code <= 90) return true;
  1336. if (code < 97) return code === 95;
  1337. if (code <= 122) return true;
  1338. if (code <= 0xffff) {
  1339. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1340. }
  1341. return isInAstralSet(code, astralIdentifierStartCodes);
  1342. }
  1343. function isIdentifierChar(code) {
  1344. if (code < 48) return code === 36;
  1345. if (code < 58) return true;
  1346. if (code < 65) return false;
  1347. if (code <= 90) return true;
  1348. if (code < 97) return code === 95;
  1349. if (code <= 122) return true;
  1350. if (code <= 0xffff) {
  1351. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1352. }
  1353. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1354. }
  1355. const reservedWords = {
  1356. 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"],
  1357. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1358. strictBind: ["eval", "arguments"]
  1359. };
  1360. const keywords = new Set(reservedWords.keyword);
  1361. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1362. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1363. function isReservedWord(word, inModule) {
  1364. return inModule && word === "await" || word === "enum";
  1365. }
  1366. function isStrictReservedWord(word, inModule) {
  1367. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1368. }
  1369. function isStrictBindOnlyReservedWord(word) {
  1370. return reservedWordsStrictBindSet.has(word);
  1371. }
  1372. function isStrictBindReservedWord(word, inModule) {
  1373. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1374. }
  1375. function isKeyword(word) {
  1376. return keywords.has(word);
  1377. }
  1378. function isIteratorStart(current, next, next2) {
  1379. return current === 64 && next === 64 && isIdentifierStart(next2);
  1380. }
  1381. 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",
  1382. "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield",
  1383. "eval", "arguments",
  1384. "enum", "await"]);
  1385. function canBeReservedWord(word) {
  1386. return reservedWordLikeSet.has(word);
  1387. }
  1388. const SCOPE_OTHER = 0b000000000,
  1389. SCOPE_PROGRAM = 0b000000001,
  1390. SCOPE_FUNCTION = 0b000000010,
  1391. SCOPE_ARROW = 0b000000100,
  1392. SCOPE_SIMPLE_CATCH = 0b000001000,
  1393. SCOPE_SUPER = 0b000010000,
  1394. SCOPE_DIRECT_SUPER = 0b000100000,
  1395. SCOPE_CLASS = 0b001000000,
  1396. SCOPE_STATIC_BLOCK = 0b010000000,
  1397. SCOPE_TS_MODULE = 0b100000000,
  1398. SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_STATIC_BLOCK | SCOPE_TS_MODULE;
  1399. const BIND_KIND_VALUE = 0b000000000001,
  1400. BIND_KIND_TYPE = 0b000000000010,
  1401. BIND_SCOPE_VAR = 0b000000000100,
  1402. BIND_SCOPE_LEXICAL = 0b000000001000,
  1403. BIND_SCOPE_FUNCTION = 0b000000010000,
  1404. BIND_FLAGS_NONE = 0b0000001000000,
  1405. BIND_FLAGS_CLASS = 0b0000010000000,
  1406. BIND_FLAGS_TS_ENUM = 0b0000100000000,
  1407. BIND_FLAGS_TS_CONST_ENUM = 0b0001000000000,
  1408. BIND_FLAGS_TS_EXPORT_ONLY = 0b0010000000000,
  1409. BIND_FLAGS_FLOW_DECLARE_FN = 0b0100000000000,
  1410. BIND_FLAGS_TS_IMPORT = 0b1000000000000;
  1411. const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS,
  1412. BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0,
  1413. BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0,
  1414. BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0,
  1415. BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS,
  1416. BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0,
  1417. BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM,
  1418. BIND_TS_AMBIENT = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1419. BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE,
  1420. BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE,
  1421. BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM,
  1422. BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1423. BIND_TS_TYPE_IMPORT = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_TS_IMPORT,
  1424. BIND_FLOW_DECLARE_FN = BIND_FLAGS_FLOW_DECLARE_FN;
  1425. const CLASS_ELEMENT_FLAG_STATIC = 0b100,
  1426. CLASS_ELEMENT_KIND_GETTER = 0b010,
  1427. CLASS_ELEMENT_KIND_SETTER = 0b001,
  1428. CLASS_ELEMENT_KIND_ACCESSOR = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_KIND_SETTER;
  1429. const CLASS_ELEMENT_STATIC_GETTER = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_FLAG_STATIC,
  1430. CLASS_ELEMENT_STATIC_SETTER = CLASS_ELEMENT_KIND_SETTER | CLASS_ELEMENT_FLAG_STATIC,
  1431. CLASS_ELEMENT_INSTANCE_GETTER = CLASS_ELEMENT_KIND_GETTER,
  1432. CLASS_ELEMENT_INSTANCE_SETTER = CLASS_ELEMENT_KIND_SETTER,
  1433. CLASS_ELEMENT_OTHER = 0;
  1434. class Scope {
  1435. constructor(flags) {
  1436. this.var = new Set();
  1437. this.lexical = new Set();
  1438. this.functions = new Set();
  1439. this.flags = flags;
  1440. }
  1441. }
  1442. class ScopeHandler {
  1443. constructor(parser, inModule) {
  1444. this.parser = void 0;
  1445. this.scopeStack = [];
  1446. this.inModule = void 0;
  1447. this.undefinedExports = new Map();
  1448. this.parser = parser;
  1449. this.inModule = inModule;
  1450. }
  1451. get inTopLevel() {
  1452. return (this.currentScope().flags & SCOPE_PROGRAM) > 0;
  1453. }
  1454. get inFunction() {
  1455. return (this.currentVarScopeFlags() & SCOPE_FUNCTION) > 0;
  1456. }
  1457. get allowSuper() {
  1458. return (this.currentThisScopeFlags() & SCOPE_SUPER) > 0;
  1459. }
  1460. get allowDirectSuper() {
  1461. return (this.currentThisScopeFlags() & SCOPE_DIRECT_SUPER) > 0;
  1462. }
  1463. get inClass() {
  1464. return (this.currentThisScopeFlags() & SCOPE_CLASS) > 0;
  1465. }
  1466. get inClassAndNotInNonArrowFunction() {
  1467. const flags = this.currentThisScopeFlags();
  1468. return (flags & SCOPE_CLASS) > 0 && (flags & SCOPE_FUNCTION) === 0;
  1469. }
  1470. get inStaticBlock() {
  1471. for (let i = this.scopeStack.length - 1;; i--) {
  1472. const {
  1473. flags
  1474. } = this.scopeStack[i];
  1475. if (flags & SCOPE_STATIC_BLOCK) {
  1476. return true;
  1477. }
  1478. if (flags & (SCOPE_VAR | SCOPE_CLASS)) {
  1479. return false;
  1480. }
  1481. }
  1482. }
  1483. get inNonArrowFunction() {
  1484. return (this.currentThisScopeFlags() & SCOPE_FUNCTION) > 0;
  1485. }
  1486. get treatFunctionsAsVar() {
  1487. return this.treatFunctionsAsVarInScope(this.currentScope());
  1488. }
  1489. createScope(flags) {
  1490. return new Scope(flags);
  1491. }
  1492. enter(flags) {
  1493. this.scopeStack.push(this.createScope(flags));
  1494. }
  1495. exit() {
  1496. const scope = this.scopeStack.pop();
  1497. return scope.flags;
  1498. }
  1499. treatFunctionsAsVarInScope(scope) {
  1500. return !!(scope.flags & (SCOPE_FUNCTION | SCOPE_STATIC_BLOCK) || !this.parser.inModule && scope.flags & SCOPE_PROGRAM);
  1501. }
  1502. declareName(name, bindingType, loc) {
  1503. let scope = this.currentScope();
  1504. if (bindingType & BIND_SCOPE_LEXICAL || bindingType & BIND_SCOPE_FUNCTION) {
  1505. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1506. if (bindingType & BIND_SCOPE_FUNCTION) {
  1507. scope.functions.add(name);
  1508. } else {
  1509. scope.lexical.add(name);
  1510. }
  1511. if (bindingType & BIND_SCOPE_LEXICAL) {
  1512. this.maybeExportDefined(scope, name);
  1513. }
  1514. } else if (bindingType & BIND_SCOPE_VAR) {
  1515. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1516. scope = this.scopeStack[i];
  1517. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1518. scope.var.add(name);
  1519. this.maybeExportDefined(scope, name);
  1520. if (scope.flags & SCOPE_VAR) break;
  1521. }
  1522. }
  1523. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  1524. this.undefinedExports.delete(name);
  1525. }
  1526. }
  1527. maybeExportDefined(scope, name) {
  1528. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  1529. this.undefinedExports.delete(name);
  1530. }
  1531. }
  1532. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1533. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1534. this.parser.raise(Errors.VarRedeclaration, {
  1535. at: loc,
  1536. identifierName: name
  1537. });
  1538. }
  1539. }
  1540. isRedeclaredInScope(scope, name, bindingType) {
  1541. if (!(bindingType & BIND_KIND_VALUE)) return false;
  1542. if (bindingType & BIND_SCOPE_LEXICAL) {
  1543. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  1544. }
  1545. if (bindingType & BIND_SCOPE_FUNCTION) {
  1546. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  1547. }
  1548. return scope.lexical.has(name) && !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  1549. }
  1550. checkLocalExport(id) {
  1551. const {
  1552. name
  1553. } = id;
  1554. const topLevelScope = this.scopeStack[0];
  1555. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) &&
  1556. !topLevelScope.functions.has(name)) {
  1557. this.undefinedExports.set(name, id.loc.start);
  1558. }
  1559. }
  1560. currentScope() {
  1561. return this.scopeStack[this.scopeStack.length - 1];
  1562. }
  1563. currentVarScopeFlags() {
  1564. for (let i = this.scopeStack.length - 1;; i--) {
  1565. const {
  1566. flags
  1567. } = this.scopeStack[i];
  1568. if (flags & SCOPE_VAR) {
  1569. return flags;
  1570. }
  1571. }
  1572. }
  1573. currentThisScopeFlags() {
  1574. for (let i = this.scopeStack.length - 1;; i--) {
  1575. const {
  1576. flags
  1577. } = this.scopeStack[i];
  1578. if (flags & (SCOPE_VAR | SCOPE_CLASS) && !(flags & SCOPE_ARROW)) {
  1579. return flags;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. class FlowScope extends Scope {
  1585. constructor(...args) {
  1586. super(...args);
  1587. this.declareFunctions = new Set();
  1588. }
  1589. }
  1590. class FlowScopeHandler extends ScopeHandler {
  1591. createScope(flags) {
  1592. return new FlowScope(flags);
  1593. }
  1594. declareName(name, bindingType, loc) {
  1595. const scope = this.currentScope();
  1596. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  1597. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1598. this.maybeExportDefined(scope, name);
  1599. scope.declareFunctions.add(name);
  1600. return;
  1601. }
  1602. super.declareName(name, bindingType, loc);
  1603. }
  1604. isRedeclaredInScope(scope, name, bindingType) {
  1605. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1606. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  1607. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  1608. }
  1609. return false;
  1610. }
  1611. checkLocalExport(id) {
  1612. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1613. super.checkLocalExport(id);
  1614. }
  1615. }
  1616. }
  1617. class BaseParser {
  1618. constructor() {
  1619. this.sawUnambiguousESM = false;
  1620. this.ambiguousScriptDifferentAst = false;
  1621. }
  1622. hasPlugin(pluginConfig) {
  1623. if (typeof pluginConfig === "string") {
  1624. return this.plugins.has(pluginConfig);
  1625. } else {
  1626. const [pluginName, pluginOptions] = pluginConfig;
  1627. if (!this.hasPlugin(pluginName)) {
  1628. return false;
  1629. }
  1630. const actualOptions = this.plugins.get(pluginName);
  1631. for (const key of Object.keys(pluginOptions)) {
  1632. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1633. return false;
  1634. }
  1635. }
  1636. return true;
  1637. }
  1638. }
  1639. getPluginOption(plugin, name) {
  1640. var _this$plugins$get;
  1641. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1642. }
  1643. }
  1644. function setTrailingComments(node, comments) {
  1645. if (node.trailingComments === undefined) {
  1646. node.trailingComments = comments;
  1647. } else {
  1648. node.trailingComments.unshift(...comments);
  1649. }
  1650. }
  1651. function setLeadingComments(node, comments) {
  1652. if (node.leadingComments === undefined) {
  1653. node.leadingComments = comments;
  1654. } else {
  1655. node.leadingComments.unshift(...comments);
  1656. }
  1657. }
  1658. function setInnerComments(node, comments) {
  1659. if (node.innerComments === undefined) {
  1660. node.innerComments = comments;
  1661. } else {
  1662. node.innerComments.unshift(...comments);
  1663. }
  1664. }
  1665. function adjustInnerComments(node, elements, commentWS) {
  1666. let lastElement = null;
  1667. let i = elements.length;
  1668. while (lastElement === null && i > 0) {
  1669. lastElement = elements[--i];
  1670. }
  1671. if (lastElement === null || lastElement.start > commentWS.start) {
  1672. setInnerComments(node, commentWS.comments);
  1673. } else {
  1674. setTrailingComments(lastElement, commentWS.comments);
  1675. }
  1676. }
  1677. class CommentsParser extends BaseParser {
  1678. addComment(comment) {
  1679. if (this.filename) comment.loc.filename = this.filename;
  1680. this.state.comments.push(comment);
  1681. }
  1682. processComment(node) {
  1683. const {
  1684. commentStack
  1685. } = this.state;
  1686. const commentStackLength = commentStack.length;
  1687. if (commentStackLength === 0) return;
  1688. let i = commentStackLength - 1;
  1689. const lastCommentWS = commentStack[i];
  1690. if (lastCommentWS.start === node.end) {
  1691. lastCommentWS.leadingNode = node;
  1692. i--;
  1693. }
  1694. const {
  1695. start: nodeStart
  1696. } = node;
  1697. for (; i >= 0; i--) {
  1698. const commentWS = commentStack[i];
  1699. const commentEnd = commentWS.end;
  1700. if (commentEnd > nodeStart) {
  1701. commentWS.containingNode = node;
  1702. this.finalizeComment(commentWS);
  1703. commentStack.splice(i, 1);
  1704. } else {
  1705. if (commentEnd === nodeStart) {
  1706. commentWS.trailingNode = node;
  1707. }
  1708. break;
  1709. }
  1710. }
  1711. }
  1712. finalizeComment(commentWS) {
  1713. const {
  1714. comments
  1715. } = commentWS;
  1716. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1717. if (commentWS.leadingNode !== null) {
  1718. setTrailingComments(commentWS.leadingNode, comments);
  1719. }
  1720. if (commentWS.trailingNode !== null) {
  1721. setLeadingComments(commentWS.trailingNode, comments);
  1722. }
  1723. } else {
  1724. const {
  1725. containingNode: node,
  1726. start: commentStart
  1727. } = commentWS;
  1728. if (this.input.charCodeAt(commentStart - 1) === 44) {
  1729. switch (node.type) {
  1730. case "ObjectExpression":
  1731. case "ObjectPattern":
  1732. case "RecordExpression":
  1733. adjustInnerComments(node, node.properties, commentWS);
  1734. break;
  1735. case "CallExpression":
  1736. case "OptionalCallExpression":
  1737. adjustInnerComments(node, node.arguments, commentWS);
  1738. break;
  1739. case "FunctionDeclaration":
  1740. case "FunctionExpression":
  1741. case "ArrowFunctionExpression":
  1742. case "ObjectMethod":
  1743. case "ClassMethod":
  1744. case "ClassPrivateMethod":
  1745. adjustInnerComments(node, node.params, commentWS);
  1746. break;
  1747. case "ArrayExpression":
  1748. case "ArrayPattern":
  1749. case "TupleExpression":
  1750. adjustInnerComments(node, node.elements, commentWS);
  1751. break;
  1752. case "ExportNamedDeclaration":
  1753. case "ImportDeclaration":
  1754. adjustInnerComments(node, node.specifiers, commentWS);
  1755. break;
  1756. default:
  1757. {
  1758. setInnerComments(node, comments);
  1759. }
  1760. }
  1761. } else {
  1762. setInnerComments(node, comments);
  1763. }
  1764. }
  1765. }
  1766. finalizeRemainingComments() {
  1767. const {
  1768. commentStack
  1769. } = this.state;
  1770. for (let i = commentStack.length - 1; i >= 0; i--) {
  1771. this.finalizeComment(commentStack[i]);
  1772. }
  1773. this.state.commentStack = [];
  1774. }
  1775. resetPreviousNodeTrailingComments(node) {
  1776. const {
  1777. commentStack
  1778. } = this.state;
  1779. const {
  1780. length
  1781. } = commentStack;
  1782. if (length === 0) return;
  1783. const commentWS = commentStack[length - 1];
  1784. if (commentWS.leadingNode === node) {
  1785. commentWS.leadingNode = null;
  1786. }
  1787. }
  1788. takeSurroundingComments(node, start, end) {
  1789. const {
  1790. commentStack
  1791. } = this.state;
  1792. const commentStackLength = commentStack.length;
  1793. if (commentStackLength === 0) return;
  1794. let i = commentStackLength - 1;
  1795. for (; i >= 0; i--) {
  1796. const commentWS = commentStack[i];
  1797. const commentEnd = commentWS.end;
  1798. const commentStart = commentWS.start;
  1799. if (commentStart === end) {
  1800. commentWS.leadingNode = node;
  1801. } else if (commentEnd === start) {
  1802. commentWS.trailingNode = node;
  1803. } else if (commentEnd < start) {
  1804. break;
  1805. }
  1806. }
  1807. }
  1808. }
  1809. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  1810. const lineBreakG = new RegExp(lineBreak.source, "g");
  1811. function isNewLine(code) {
  1812. switch (code) {
  1813. case 10:
  1814. case 13:
  1815. case 8232:
  1816. case 8233:
  1817. return true;
  1818. default:
  1819. return false;
  1820. }
  1821. }
  1822. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1823. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/y;
  1824. const skipWhiteSpaceToLineBreak = new RegExp(
  1825. "(?=(" +
  1826. skipWhiteSpaceInLine.source + "))\\1" +
  1827. /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  1828. function isWhitespace(code) {
  1829. switch (code) {
  1830. case 0x0009:
  1831. case 0x000b:
  1832. case 0x000c:
  1833. case 32:
  1834. case 160:
  1835. case 5760:
  1836. case 0x2000:
  1837. case 0x2001:
  1838. case 0x2002:
  1839. case 0x2003:
  1840. case 0x2004:
  1841. case 0x2005:
  1842. case 0x2006:
  1843. case 0x2007:
  1844. case 0x2008:
  1845. case 0x2009:
  1846. case 0x200a:
  1847. case 0x202f:
  1848. case 0x205f:
  1849. case 0x3000:
  1850. case 0xfeff:
  1851. return true;
  1852. default:
  1853. return false;
  1854. }
  1855. }
  1856. class State {
  1857. constructor() {
  1858. this.strict = void 0;
  1859. this.curLine = void 0;
  1860. this.lineStart = void 0;
  1861. this.startLoc = void 0;
  1862. this.endLoc = void 0;
  1863. this.errors = [];
  1864. this.potentialArrowAt = -1;
  1865. this.noArrowAt = [];
  1866. this.noArrowParamsConversionAt = [];
  1867. this.maybeInArrowParameters = false;
  1868. this.inType = false;
  1869. this.noAnonFunctionType = false;
  1870. this.hasFlowComment = false;
  1871. this.isAmbientContext = false;
  1872. this.inAbstractClass = false;
  1873. this.inDisallowConditionalTypesContext = false;
  1874. this.topicContext = {
  1875. maxNumOfResolvableTopics: 0,
  1876. maxTopicIndex: null
  1877. };
  1878. this.soloAwait = false;
  1879. this.inFSharpPipelineDirectBody = false;
  1880. this.labels = [];
  1881. this.comments = [];
  1882. this.commentStack = [];
  1883. this.pos = 0;
  1884. this.type = 137;
  1885. this.value = null;
  1886. this.start = 0;
  1887. this.end = 0;
  1888. this.lastTokEndLoc = null;
  1889. this.lastTokStartLoc = null;
  1890. this.lastTokStart = 0;
  1891. this.context = [types.brace];
  1892. this.canStartJSXElement = true;
  1893. this.containsEsc = false;
  1894. this.firstInvalidTemplateEscapePos = null;
  1895. this.strictErrors = new Map();
  1896. this.tokensLength = 0;
  1897. }
  1898. init({
  1899. strictMode,
  1900. sourceType,
  1901. startLine,
  1902. startColumn
  1903. }) {
  1904. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1905. this.curLine = startLine;
  1906. this.lineStart = -startColumn;
  1907. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  1908. }
  1909. curPosition() {
  1910. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  1911. }
  1912. clone(skipArrays) {
  1913. const state = new State();
  1914. const keys = Object.keys(this);
  1915. for (let i = 0, length = keys.length; i < length; i++) {
  1916. const key = keys[i];
  1917. let val = this[key];
  1918. if (!skipArrays && Array.isArray(val)) {
  1919. val = val.slice();
  1920. }
  1921. state[key] = val;
  1922. }
  1923. return state;
  1924. }
  1925. }
  1926. var _isDigit = function isDigit(code) {
  1927. return code >= 48 && code <= 57;
  1928. };
  1929. const forbiddenNumericSeparatorSiblings = {
  1930. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  1931. hex: new Set([46, 88, 95, 120])
  1932. };
  1933. const isAllowedNumericSeparatorSibling = {
  1934. bin: ch => ch === 48 || ch === 49,
  1935. oct: ch => ch >= 48 && ch <= 55,
  1936. dec: ch => ch >= 48 && ch <= 57,
  1937. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  1938. };
  1939. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  1940. const initialPos = pos;
  1941. const initialLineStart = lineStart;
  1942. const initialCurLine = curLine;
  1943. let out = "";
  1944. let firstInvalidLoc = null;
  1945. let chunkStart = pos;
  1946. const {
  1947. length
  1948. } = input;
  1949. for (;;) {
  1950. if (pos >= length) {
  1951. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1952. out += input.slice(chunkStart, pos);
  1953. break;
  1954. }
  1955. const ch = input.charCodeAt(pos);
  1956. if (isStringEnd(type, ch, input, pos)) {
  1957. out += input.slice(chunkStart, pos);
  1958. break;
  1959. }
  1960. if (ch === 92) {
  1961. out += input.slice(chunkStart, pos);
  1962. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  1963. if (res.ch === null && !firstInvalidLoc) {
  1964. firstInvalidLoc = {
  1965. pos,
  1966. lineStart,
  1967. curLine
  1968. };
  1969. } else {
  1970. out += res.ch;
  1971. }
  1972. ({
  1973. pos,
  1974. lineStart,
  1975. curLine
  1976. } = res);
  1977. chunkStart = pos;
  1978. } else if (ch === 8232 || ch === 8233) {
  1979. ++pos;
  1980. ++curLine;
  1981. lineStart = pos;
  1982. } else if (ch === 10 || ch === 13) {
  1983. if (type === "template") {
  1984. out += input.slice(chunkStart, pos) + "\n";
  1985. ++pos;
  1986. if (ch === 13 && input.charCodeAt(pos) === 10) {
  1987. ++pos;
  1988. }
  1989. ++curLine;
  1990. chunkStart = lineStart = pos;
  1991. } else {
  1992. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1993. }
  1994. } else {
  1995. ++pos;
  1996. }
  1997. }
  1998. return {
  1999. pos,
  2000. str: out,
  2001. firstInvalidLoc,
  2002. lineStart,
  2003. curLine,
  2004. containsInvalid: !!firstInvalidLoc
  2005. };
  2006. }
  2007. function isStringEnd(type, ch, input, pos) {
  2008. if (type === "template") {
  2009. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2010. }
  2011. return ch === (type === "double" ? 34 : 39);
  2012. }
  2013. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2014. const throwOnInvalid = !inTemplate;
  2015. pos++;
  2016. const res = ch => ({
  2017. pos,
  2018. ch,
  2019. lineStart,
  2020. curLine
  2021. });
  2022. const ch = input.charCodeAt(pos++);
  2023. switch (ch) {
  2024. case 110:
  2025. return res("\n");
  2026. case 114:
  2027. return res("\r");
  2028. case 120:
  2029. {
  2030. let code;
  2031. ({
  2032. code,
  2033. pos
  2034. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2035. return res(code === null ? null : String.fromCharCode(code));
  2036. }
  2037. case 117:
  2038. {
  2039. let code;
  2040. ({
  2041. code,
  2042. pos
  2043. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2044. return res(code === null ? null : String.fromCodePoint(code));
  2045. }
  2046. case 116:
  2047. return res("\t");
  2048. case 98:
  2049. return res("\b");
  2050. case 118:
  2051. return res("\u000b");
  2052. case 102:
  2053. return res("\f");
  2054. case 13:
  2055. if (input.charCodeAt(pos) === 10) {
  2056. ++pos;
  2057. }
  2058. case 10:
  2059. lineStart = pos;
  2060. ++curLine;
  2061. case 8232:
  2062. case 8233:
  2063. return res("");
  2064. case 56:
  2065. case 57:
  2066. if (inTemplate) {
  2067. return res(null);
  2068. } else {
  2069. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2070. }
  2071. default:
  2072. if (ch >= 48 && ch <= 55) {
  2073. const startPos = pos - 1;
  2074. const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
  2075. let octalStr = match[0];
  2076. let octal = parseInt(octalStr, 8);
  2077. if (octal > 255) {
  2078. octalStr = octalStr.slice(0, -1);
  2079. octal = parseInt(octalStr, 8);
  2080. }
  2081. pos += octalStr.length - 1;
  2082. const next = input.charCodeAt(pos);
  2083. if (octalStr !== "0" || next === 56 || next === 57) {
  2084. if (inTemplate) {
  2085. return res(null);
  2086. } else {
  2087. errors.strictNumericEscape(startPos, lineStart, curLine);
  2088. }
  2089. }
  2090. return res(String.fromCharCode(octal));
  2091. }
  2092. return res(String.fromCharCode(ch));
  2093. }
  2094. }
  2095. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2096. const initialPos = pos;
  2097. let n;
  2098. ({
  2099. n,
  2100. pos
  2101. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2102. if (n === null) {
  2103. if (throwOnInvalid) {
  2104. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2105. } else {
  2106. pos = initialPos - 1;
  2107. }
  2108. }
  2109. return {
  2110. code: n,
  2111. pos
  2112. };
  2113. }
  2114. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2115. const start = pos;
  2116. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2117. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2118. let invalid = false;
  2119. let total = 0;
  2120. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2121. const code = input.charCodeAt(pos);
  2122. let val;
  2123. if (code === 95 && allowNumSeparator !== "bail") {
  2124. const prev = input.charCodeAt(pos - 1);
  2125. const next = input.charCodeAt(pos + 1);
  2126. if (!allowNumSeparator) {
  2127. if (bailOnError) return {
  2128. n: null,
  2129. pos
  2130. };
  2131. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2132. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2133. if (bailOnError) return {
  2134. n: null,
  2135. pos
  2136. };
  2137. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2138. }
  2139. ++pos;
  2140. continue;
  2141. }
  2142. if (code >= 97) {
  2143. val = code - 97 + 10;
  2144. } else if (code >= 65) {
  2145. val = code - 65 + 10;
  2146. } else if (_isDigit(code)) {
  2147. val = code - 48;
  2148. } else {
  2149. val = Infinity;
  2150. }
  2151. if (val >= radix) {
  2152. if (val <= 9 && bailOnError) {
  2153. return {
  2154. n: null,
  2155. pos
  2156. };
  2157. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2158. val = 0;
  2159. } else if (forceLen) {
  2160. val = 0;
  2161. invalid = true;
  2162. } else {
  2163. break;
  2164. }
  2165. }
  2166. ++pos;
  2167. total = total * radix + val;
  2168. }
  2169. if (pos === start || len != null && pos - start !== len || invalid) {
  2170. return {
  2171. n: null,
  2172. pos
  2173. };
  2174. }
  2175. return {
  2176. n: total,
  2177. pos
  2178. };
  2179. }
  2180. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2181. const ch = input.charCodeAt(pos);
  2182. let code;
  2183. if (ch === 123) {
  2184. ++pos;
  2185. ({
  2186. code,
  2187. pos
  2188. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2189. ++pos;
  2190. if (code !== null && code > 0x10ffff) {
  2191. if (throwOnInvalid) {
  2192. errors.invalidCodePoint(pos, lineStart, curLine);
  2193. } else {
  2194. return {
  2195. code: null,
  2196. pos
  2197. };
  2198. }
  2199. }
  2200. } else {
  2201. ({
  2202. code,
  2203. pos
  2204. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2205. }
  2206. return {
  2207. code,
  2208. pos
  2209. };
  2210. }
  2211. const _excluded = ["at"],
  2212. _excluded2 = ["at"];
  2213. function buildPosition(pos, lineStart, curLine) {
  2214. return new Position(curLine, pos - lineStart, pos);
  2215. }
  2216. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2217. class Token {
  2218. constructor(state) {
  2219. this.type = state.type;
  2220. this.value = state.value;
  2221. this.start = state.start;
  2222. this.end = state.end;
  2223. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2224. }
  2225. }
  2226. class Tokenizer extends CommentsParser {
  2227. constructor(options, input) {
  2228. super();
  2229. this.isLookahead = void 0;
  2230. this.tokens = [];
  2231. this.errorHandlers_readInt = {
  2232. invalidDigit: (pos, lineStart, curLine, radix) => {
  2233. if (!this.options.errorRecovery) return false;
  2234. this.raise(Errors.InvalidDigit, {
  2235. at: buildPosition(pos, lineStart, curLine),
  2236. radix
  2237. });
  2238. return true;
  2239. },
  2240. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2241. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2242. };
  2243. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2244. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2245. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2246. });
  2247. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2248. strictNumericEscape: (pos, lineStart, curLine) => {
  2249. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2250. at: buildPosition(pos, lineStart, curLine)
  2251. });
  2252. },
  2253. unterminated: (pos, lineStart, curLine) => {
  2254. throw this.raise(Errors.UnterminatedString, {
  2255. at: buildPosition(pos - 1, lineStart, curLine)
  2256. });
  2257. }
  2258. });
  2259. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2260. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2261. unterminated: (pos, lineStart, curLine) => {
  2262. throw this.raise(Errors.UnterminatedTemplate, {
  2263. at: buildPosition(pos, lineStart, curLine)
  2264. });
  2265. }
  2266. });
  2267. this.state = new State();
  2268. this.state.init(options);
  2269. this.input = input;
  2270. this.length = input.length;
  2271. this.isLookahead = false;
  2272. }
  2273. pushToken(token) {
  2274. this.tokens.length = this.state.tokensLength;
  2275. this.tokens.push(token);
  2276. ++this.state.tokensLength;
  2277. }
  2278. next() {
  2279. this.checkKeywordEscapes();
  2280. if (this.options.tokens) {
  2281. this.pushToken(new Token(this.state));
  2282. }
  2283. this.state.lastTokStart = this.state.start;
  2284. this.state.lastTokEndLoc = this.state.endLoc;
  2285. this.state.lastTokStartLoc = this.state.startLoc;
  2286. this.nextToken();
  2287. }
  2288. eat(type) {
  2289. if (this.match(type)) {
  2290. this.next();
  2291. return true;
  2292. } else {
  2293. return false;
  2294. }
  2295. }
  2296. match(type) {
  2297. return this.state.type === type;
  2298. }
  2299. createLookaheadState(state) {
  2300. return {
  2301. pos: state.pos,
  2302. value: null,
  2303. type: state.type,
  2304. start: state.start,
  2305. end: state.end,
  2306. context: [this.curContext()],
  2307. inType: state.inType,
  2308. startLoc: state.startLoc,
  2309. lastTokEndLoc: state.lastTokEndLoc,
  2310. curLine: state.curLine,
  2311. lineStart: state.lineStart,
  2312. curPosition: state.curPosition
  2313. };
  2314. }
  2315. lookahead() {
  2316. const old = this.state;
  2317. this.state = this.createLookaheadState(old);
  2318. this.isLookahead = true;
  2319. this.nextToken();
  2320. this.isLookahead = false;
  2321. const curr = this.state;
  2322. this.state = old;
  2323. return curr;
  2324. }
  2325. nextTokenStart() {
  2326. return this.nextTokenStartSince(this.state.pos);
  2327. }
  2328. nextTokenStartSince(pos) {
  2329. skipWhiteSpace.lastIndex = pos;
  2330. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2331. }
  2332. lookaheadCharCode() {
  2333. return this.input.charCodeAt(this.nextTokenStart());
  2334. }
  2335. codePointAtPos(pos) {
  2336. let cp = this.input.charCodeAt(pos);
  2337. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2338. const trail = this.input.charCodeAt(pos);
  2339. if ((trail & 0xfc00) === 0xdc00) {
  2340. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2341. }
  2342. }
  2343. return cp;
  2344. }
  2345. setStrict(strict) {
  2346. this.state.strict = strict;
  2347. if (strict) {
  2348. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
  2349. at
  2350. }));
  2351. this.state.strictErrors.clear();
  2352. }
  2353. }
  2354. curContext() {
  2355. return this.state.context[this.state.context.length - 1];
  2356. }
  2357. nextToken() {
  2358. this.skipSpace();
  2359. this.state.start = this.state.pos;
  2360. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2361. if (this.state.pos >= this.length) {
  2362. this.finishToken(137);
  2363. return;
  2364. }
  2365. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2366. }
  2367. skipBlockComment(commentEnd) {
  2368. let startLoc;
  2369. if (!this.isLookahead) startLoc = this.state.curPosition();
  2370. const start = this.state.pos;
  2371. const end = this.input.indexOf(commentEnd, start + 2);
  2372. if (end === -1) {
  2373. throw this.raise(Errors.UnterminatedComment, {
  2374. at: this.state.curPosition()
  2375. });
  2376. }
  2377. this.state.pos = end + commentEnd.length;
  2378. lineBreakG.lastIndex = start + 2;
  2379. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2380. ++this.state.curLine;
  2381. this.state.lineStart = lineBreakG.lastIndex;
  2382. }
  2383. if (this.isLookahead) return;
  2384. const comment = {
  2385. type: "CommentBlock",
  2386. value: this.input.slice(start + 2, end),
  2387. start,
  2388. end: end + commentEnd.length,
  2389. loc: new SourceLocation(startLoc, this.state.curPosition())
  2390. };
  2391. if (this.options.tokens) this.pushToken(comment);
  2392. return comment;
  2393. }
  2394. skipLineComment(startSkip) {
  2395. const start = this.state.pos;
  2396. let startLoc;
  2397. if (!this.isLookahead) startLoc = this.state.curPosition();
  2398. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2399. if (this.state.pos < this.length) {
  2400. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2401. ch = this.input.charCodeAt(this.state.pos);
  2402. }
  2403. }
  2404. if (this.isLookahead) return;
  2405. const end = this.state.pos;
  2406. const value = this.input.slice(start + startSkip, end);
  2407. const comment = {
  2408. type: "CommentLine",
  2409. value,
  2410. start,
  2411. end,
  2412. loc: new SourceLocation(startLoc, this.state.curPosition())
  2413. };
  2414. if (this.options.tokens) this.pushToken(comment);
  2415. return comment;
  2416. }
  2417. skipSpace() {
  2418. const spaceStart = this.state.pos;
  2419. const comments = [];
  2420. loop: while (this.state.pos < this.length) {
  2421. const ch = this.input.charCodeAt(this.state.pos);
  2422. switch (ch) {
  2423. case 32:
  2424. case 160:
  2425. case 9:
  2426. ++this.state.pos;
  2427. break;
  2428. case 13:
  2429. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2430. ++this.state.pos;
  2431. }
  2432. case 10:
  2433. case 8232:
  2434. case 8233:
  2435. ++this.state.pos;
  2436. ++this.state.curLine;
  2437. this.state.lineStart = this.state.pos;
  2438. break;
  2439. case 47:
  2440. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2441. case 42:
  2442. {
  2443. const comment = this.skipBlockComment("*/");
  2444. if (comment !== undefined) {
  2445. this.addComment(comment);
  2446. if (this.options.attachComment) comments.push(comment);
  2447. }
  2448. break;
  2449. }
  2450. case 47:
  2451. {
  2452. const comment = this.skipLineComment(2);
  2453. if (comment !== undefined) {
  2454. this.addComment(comment);
  2455. if (this.options.attachComment) comments.push(comment);
  2456. }
  2457. break;
  2458. }
  2459. default:
  2460. break loop;
  2461. }
  2462. break;
  2463. default:
  2464. if (isWhitespace(ch)) {
  2465. ++this.state.pos;
  2466. } else if (ch === 45 && !this.inModule) {
  2467. const pos = this.state.pos;
  2468. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2469. const comment = this.skipLineComment(3);
  2470. if (comment !== undefined) {
  2471. this.addComment(comment);
  2472. if (this.options.attachComment) comments.push(comment);
  2473. }
  2474. } else {
  2475. break loop;
  2476. }
  2477. } else if (ch === 60 && !this.inModule) {
  2478. const pos = this.state.pos;
  2479. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2480. const comment = this.skipLineComment(4);
  2481. if (comment !== undefined) {
  2482. this.addComment(comment);
  2483. if (this.options.attachComment) comments.push(comment);
  2484. }
  2485. } else {
  2486. break loop;
  2487. }
  2488. } else {
  2489. break loop;
  2490. }
  2491. }
  2492. }
  2493. if (comments.length > 0) {
  2494. const end = this.state.pos;
  2495. const commentWhitespace = {
  2496. start: spaceStart,
  2497. end,
  2498. comments,
  2499. leadingNode: null,
  2500. trailingNode: null,
  2501. containingNode: null
  2502. };
  2503. this.state.commentStack.push(commentWhitespace);
  2504. }
  2505. }
  2506. finishToken(type, val) {
  2507. this.state.end = this.state.pos;
  2508. this.state.endLoc = this.state.curPosition();
  2509. const prevType = this.state.type;
  2510. this.state.type = type;
  2511. this.state.value = val;
  2512. if (!this.isLookahead) {
  2513. this.updateContext(prevType);
  2514. }
  2515. }
  2516. replaceToken(type) {
  2517. this.state.type = type;
  2518. this.updateContext();
  2519. }
  2520. readToken_numberSign() {
  2521. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2522. return;
  2523. }
  2524. const nextPos = this.state.pos + 1;
  2525. const next = this.codePointAtPos(nextPos);
  2526. if (next >= 48 && next <= 57) {
  2527. throw this.raise(Errors.UnexpectedDigitAfterHash, {
  2528. at: this.state.curPosition()
  2529. });
  2530. }
  2531. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2532. this.expectPlugin("recordAndTuple");
  2533. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2534. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
  2535. at: this.state.curPosition()
  2536. });
  2537. }
  2538. this.state.pos += 2;
  2539. if (next === 123) {
  2540. this.finishToken(7);
  2541. } else {
  2542. this.finishToken(1);
  2543. }
  2544. } else if (isIdentifierStart(next)) {
  2545. ++this.state.pos;
  2546. this.finishToken(136, this.readWord1(next));
  2547. } else if (next === 92) {
  2548. ++this.state.pos;
  2549. this.finishToken(136, this.readWord1());
  2550. } else {
  2551. this.finishOp(27, 1);
  2552. }
  2553. }
  2554. readToken_dot() {
  2555. const next = this.input.charCodeAt(this.state.pos + 1);
  2556. if (next >= 48 && next <= 57) {
  2557. this.readNumber(true);
  2558. return;
  2559. }
  2560. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2561. this.state.pos += 3;
  2562. this.finishToken(21);
  2563. } else {
  2564. ++this.state.pos;
  2565. this.finishToken(16);
  2566. }
  2567. }
  2568. readToken_slash() {
  2569. const next = this.input.charCodeAt(this.state.pos + 1);
  2570. if (next === 61) {
  2571. this.finishOp(31, 2);
  2572. } else {
  2573. this.finishOp(56, 1);
  2574. }
  2575. }
  2576. readToken_interpreter() {
  2577. if (this.state.pos !== 0 || this.length < 2) return false;
  2578. let ch = this.input.charCodeAt(this.state.pos + 1);
  2579. if (ch !== 33) return false;
  2580. const start = this.state.pos;
  2581. this.state.pos += 1;
  2582. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2583. ch = this.input.charCodeAt(this.state.pos);
  2584. }
  2585. const value = this.input.slice(start + 2, this.state.pos);
  2586. this.finishToken(28, value);
  2587. return true;
  2588. }
  2589. readToken_mult_modulo(code) {
  2590. let type = code === 42 ? 55 : 54;
  2591. let width = 1;
  2592. let next = this.input.charCodeAt(this.state.pos + 1);
  2593. if (code === 42 && next === 42) {
  2594. width++;
  2595. next = this.input.charCodeAt(this.state.pos + 2);
  2596. type = 57;
  2597. }
  2598. if (next === 61 && !this.state.inType) {
  2599. width++;
  2600. type = code === 37 ? 33 : 30;
  2601. }
  2602. this.finishOp(type, width);
  2603. }
  2604. readToken_pipe_amp(code) {
  2605. const next = this.input.charCodeAt(this.state.pos + 1);
  2606. if (next === code) {
  2607. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2608. this.finishOp(30, 3);
  2609. } else {
  2610. this.finishOp(code === 124 ? 41 : 42, 2);
  2611. }
  2612. return;
  2613. }
  2614. if (code === 124) {
  2615. if (next === 62) {
  2616. this.finishOp(39, 2);
  2617. return;
  2618. }
  2619. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2620. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2621. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
  2622. at: this.state.curPosition()
  2623. });
  2624. }
  2625. this.state.pos += 2;
  2626. this.finishToken(9);
  2627. return;
  2628. }
  2629. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2630. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2631. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
  2632. at: this.state.curPosition()
  2633. });
  2634. }
  2635. this.state.pos += 2;
  2636. this.finishToken(4);
  2637. return;
  2638. }
  2639. }
  2640. if (next === 61) {
  2641. this.finishOp(30, 2);
  2642. return;
  2643. }
  2644. this.finishOp(code === 124 ? 43 : 45, 1);
  2645. }
  2646. readToken_caret() {
  2647. const next = this.input.charCodeAt(this.state.pos + 1);
  2648. if (next === 61 && !this.state.inType) {
  2649. this.finishOp(32, 2);
  2650. }
  2651. else if (next === 94 &&
  2652. this.hasPlugin(["pipelineOperator", {
  2653. proposal: "hack",
  2654. topicToken: "^^"
  2655. }])) {
  2656. this.finishOp(37, 2);
  2657. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2658. if (lookaheadCh === 94) {
  2659. throw this.unexpected();
  2660. }
  2661. }
  2662. else {
  2663. this.finishOp(44, 1);
  2664. }
  2665. }
  2666. readToken_atSign() {
  2667. const next = this.input.charCodeAt(this.state.pos + 1);
  2668. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2669. proposal: "hack",
  2670. topicToken: "@@"
  2671. }])) {
  2672. this.finishOp(38, 2);
  2673. }
  2674. else {
  2675. this.finishOp(26, 1);
  2676. }
  2677. }
  2678. readToken_plus_min(code) {
  2679. const next = this.input.charCodeAt(this.state.pos + 1);
  2680. if (next === code) {
  2681. this.finishOp(34, 2);
  2682. return;
  2683. }
  2684. if (next === 61) {
  2685. this.finishOp(30, 2);
  2686. } else {
  2687. this.finishOp(53, 1);
  2688. }
  2689. }
  2690. readToken_lt() {
  2691. const {
  2692. pos
  2693. } = this.state;
  2694. const next = this.input.charCodeAt(pos + 1);
  2695. if (next === 60) {
  2696. if (this.input.charCodeAt(pos + 2) === 61) {
  2697. this.finishOp(30, 3);
  2698. return;
  2699. }
  2700. this.finishOp(51, 2);
  2701. return;
  2702. }
  2703. if (next === 61) {
  2704. this.finishOp(49, 2);
  2705. return;
  2706. }
  2707. this.finishOp(47, 1);
  2708. }
  2709. readToken_gt() {
  2710. const {
  2711. pos
  2712. } = this.state;
  2713. const next = this.input.charCodeAt(pos + 1);
  2714. if (next === 62) {
  2715. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2716. if (this.input.charCodeAt(pos + size) === 61) {
  2717. this.finishOp(30, size + 1);
  2718. return;
  2719. }
  2720. this.finishOp(52, size);
  2721. return;
  2722. }
  2723. if (next === 61) {
  2724. this.finishOp(49, 2);
  2725. return;
  2726. }
  2727. this.finishOp(48, 1);
  2728. }
  2729. readToken_eq_excl(code) {
  2730. const next = this.input.charCodeAt(this.state.pos + 1);
  2731. if (next === 61) {
  2732. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2733. return;
  2734. }
  2735. if (code === 61 && next === 62) {
  2736. this.state.pos += 2;
  2737. this.finishToken(19);
  2738. return;
  2739. }
  2740. this.finishOp(code === 61 ? 29 : 35, 1);
  2741. }
  2742. readToken_question() {
  2743. const next = this.input.charCodeAt(this.state.pos + 1);
  2744. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2745. if (next === 63) {
  2746. if (next2 === 61) {
  2747. this.finishOp(30, 3);
  2748. } else {
  2749. this.finishOp(40, 2);
  2750. }
  2751. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2752. this.state.pos += 2;
  2753. this.finishToken(18);
  2754. } else {
  2755. ++this.state.pos;
  2756. this.finishToken(17);
  2757. }
  2758. }
  2759. getTokenFromCode(code) {
  2760. switch (code) {
  2761. case 46:
  2762. this.readToken_dot();
  2763. return;
  2764. case 40:
  2765. ++this.state.pos;
  2766. this.finishToken(10);
  2767. return;
  2768. case 41:
  2769. ++this.state.pos;
  2770. this.finishToken(11);
  2771. return;
  2772. case 59:
  2773. ++this.state.pos;
  2774. this.finishToken(13);
  2775. return;
  2776. case 44:
  2777. ++this.state.pos;
  2778. this.finishToken(12);
  2779. return;
  2780. case 91:
  2781. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2782. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2783. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
  2784. at: this.state.curPosition()
  2785. });
  2786. }
  2787. this.state.pos += 2;
  2788. this.finishToken(2);
  2789. } else {
  2790. ++this.state.pos;
  2791. this.finishToken(0);
  2792. }
  2793. return;
  2794. case 93:
  2795. ++this.state.pos;
  2796. this.finishToken(3);
  2797. return;
  2798. case 123:
  2799. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2800. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2801. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
  2802. at: this.state.curPosition()
  2803. });
  2804. }
  2805. this.state.pos += 2;
  2806. this.finishToken(6);
  2807. } else {
  2808. ++this.state.pos;
  2809. this.finishToken(5);
  2810. }
  2811. return;
  2812. case 125:
  2813. ++this.state.pos;
  2814. this.finishToken(8);
  2815. return;
  2816. case 58:
  2817. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2818. this.finishOp(15, 2);
  2819. } else {
  2820. ++this.state.pos;
  2821. this.finishToken(14);
  2822. }
  2823. return;
  2824. case 63:
  2825. this.readToken_question();
  2826. return;
  2827. case 96:
  2828. this.readTemplateToken();
  2829. return;
  2830. case 48:
  2831. {
  2832. const next = this.input.charCodeAt(this.state.pos + 1);
  2833. if (next === 120 || next === 88) {
  2834. this.readRadixNumber(16);
  2835. return;
  2836. }
  2837. if (next === 111 || next === 79) {
  2838. this.readRadixNumber(8);
  2839. return;
  2840. }
  2841. if (next === 98 || next === 66) {
  2842. this.readRadixNumber(2);
  2843. return;
  2844. }
  2845. }
  2846. case 49:
  2847. case 50:
  2848. case 51:
  2849. case 52:
  2850. case 53:
  2851. case 54:
  2852. case 55:
  2853. case 56:
  2854. case 57:
  2855. this.readNumber(false);
  2856. return;
  2857. case 34:
  2858. case 39:
  2859. this.readString(code);
  2860. return;
  2861. case 47:
  2862. this.readToken_slash();
  2863. return;
  2864. case 37:
  2865. case 42:
  2866. this.readToken_mult_modulo(code);
  2867. return;
  2868. case 124:
  2869. case 38:
  2870. this.readToken_pipe_amp(code);
  2871. return;
  2872. case 94:
  2873. this.readToken_caret();
  2874. return;
  2875. case 43:
  2876. case 45:
  2877. this.readToken_plus_min(code);
  2878. return;
  2879. case 60:
  2880. this.readToken_lt();
  2881. return;
  2882. case 62:
  2883. this.readToken_gt();
  2884. return;
  2885. case 61:
  2886. case 33:
  2887. this.readToken_eq_excl(code);
  2888. return;
  2889. case 126:
  2890. this.finishOp(36, 1);
  2891. return;
  2892. case 64:
  2893. this.readToken_atSign();
  2894. return;
  2895. case 35:
  2896. this.readToken_numberSign();
  2897. return;
  2898. case 92:
  2899. this.readWord();
  2900. return;
  2901. default:
  2902. if (isIdentifierStart(code)) {
  2903. this.readWord(code);
  2904. return;
  2905. }
  2906. }
  2907. throw this.raise(Errors.InvalidOrUnexpectedToken, {
  2908. at: this.state.curPosition(),
  2909. unexpected: String.fromCodePoint(code)
  2910. });
  2911. }
  2912. finishOp(type, size) {
  2913. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2914. this.state.pos += size;
  2915. this.finishToken(type, str);
  2916. }
  2917. readRegexp() {
  2918. const startLoc = this.state.startLoc;
  2919. const start = this.state.start + 1;
  2920. let escaped, inClass;
  2921. let {
  2922. pos
  2923. } = this.state;
  2924. for (;; ++pos) {
  2925. if (pos >= this.length) {
  2926. throw this.raise(Errors.UnterminatedRegExp, {
  2927. at: createPositionWithColumnOffset(startLoc, 1)
  2928. });
  2929. }
  2930. const ch = this.input.charCodeAt(pos);
  2931. if (isNewLine(ch)) {
  2932. throw this.raise(Errors.UnterminatedRegExp, {
  2933. at: createPositionWithColumnOffset(startLoc, 1)
  2934. });
  2935. }
  2936. if (escaped) {
  2937. escaped = false;
  2938. } else {
  2939. if (ch === 91) {
  2940. inClass = true;
  2941. } else if (ch === 93 && inClass) {
  2942. inClass = false;
  2943. } else if (ch === 47 && !inClass) {
  2944. break;
  2945. }
  2946. escaped = ch === 92;
  2947. }
  2948. }
  2949. const content = this.input.slice(start, pos);
  2950. ++pos;
  2951. let mods = "";
  2952. const nextPos = () =>
  2953. createPositionWithColumnOffset(startLoc, pos + 2 - start);
  2954. while (pos < this.length) {
  2955. const cp = this.codePointAtPos(pos);
  2956. const char = String.fromCharCode(cp);
  2957. if (VALID_REGEX_FLAGS.has(cp)) {
  2958. if (cp === 118) {
  2959. this.expectPlugin("regexpUnicodeSets", nextPos());
  2960. if (mods.includes("u")) {
  2961. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2962. at: nextPos()
  2963. });
  2964. }
  2965. } else if (cp === 117) {
  2966. if (mods.includes("v")) {
  2967. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2968. at: nextPos()
  2969. });
  2970. }
  2971. }
  2972. if (mods.includes(char)) {
  2973. this.raise(Errors.DuplicateRegExpFlags, {
  2974. at: nextPos()
  2975. });
  2976. }
  2977. } else if (isIdentifierChar(cp) || cp === 92) {
  2978. this.raise(Errors.MalformedRegExpFlags, {
  2979. at: nextPos()
  2980. });
  2981. } else {
  2982. break;
  2983. }
  2984. ++pos;
  2985. mods += char;
  2986. }
  2987. this.state.pos = pos;
  2988. this.finishToken(135, {
  2989. pattern: content,
  2990. flags: mods
  2991. });
  2992. }
  2993. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  2994. const {
  2995. n,
  2996. pos
  2997. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  2998. this.state.pos = pos;
  2999. return n;
  3000. }
  3001. readRadixNumber(radix) {
  3002. const startLoc = this.state.curPosition();
  3003. let isBigInt = false;
  3004. this.state.pos += 2;
  3005. const val = this.readInt(radix);
  3006. if (val == null) {
  3007. this.raise(Errors.InvalidDigit, {
  3008. at: createPositionWithColumnOffset(startLoc, 2),
  3009. radix
  3010. });
  3011. }
  3012. const next = this.input.charCodeAt(this.state.pos);
  3013. if (next === 110) {
  3014. ++this.state.pos;
  3015. isBigInt = true;
  3016. } else if (next === 109) {
  3017. throw this.raise(Errors.InvalidDecimal, {
  3018. at: startLoc
  3019. });
  3020. }
  3021. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3022. throw this.raise(Errors.NumberIdentifier, {
  3023. at: this.state.curPosition()
  3024. });
  3025. }
  3026. if (isBigInt) {
  3027. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  3028. this.finishToken(133, str);
  3029. return;
  3030. }
  3031. this.finishToken(132, val);
  3032. }
  3033. readNumber(startsWithDot) {
  3034. const start = this.state.pos;
  3035. const startLoc = this.state.curPosition();
  3036. let isFloat = false;
  3037. let isBigInt = false;
  3038. let isDecimal = false;
  3039. let hasExponent = false;
  3040. let isOctal = false;
  3041. if (!startsWithDot && this.readInt(10) === null) {
  3042. this.raise(Errors.InvalidNumber, {
  3043. at: this.state.curPosition()
  3044. });
  3045. }
  3046. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3047. if (hasLeadingZero) {
  3048. const integer = this.input.slice(start, this.state.pos);
  3049. this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
  3050. at: startLoc
  3051. });
  3052. if (!this.state.strict) {
  3053. const underscorePos = integer.indexOf("_");
  3054. if (underscorePos > 0) {
  3055. this.raise(Errors.ZeroDigitNumericSeparator, {
  3056. at: createPositionWithColumnOffset(startLoc, underscorePos)
  3057. });
  3058. }
  3059. }
  3060. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3061. }
  3062. let next = this.input.charCodeAt(this.state.pos);
  3063. if (next === 46 && !isOctal) {
  3064. ++this.state.pos;
  3065. this.readInt(10);
  3066. isFloat = true;
  3067. next = this.input.charCodeAt(this.state.pos);
  3068. }
  3069. if ((next === 69 || next === 101) && !isOctal) {
  3070. next = this.input.charCodeAt(++this.state.pos);
  3071. if (next === 43 || next === 45) {
  3072. ++this.state.pos;
  3073. }
  3074. if (this.readInt(10) === null) {
  3075. this.raise(Errors.InvalidOrMissingExponent, {
  3076. at: startLoc
  3077. });
  3078. }
  3079. isFloat = true;
  3080. hasExponent = true;
  3081. next = this.input.charCodeAt(this.state.pos);
  3082. }
  3083. if (next === 110) {
  3084. if (isFloat || hasLeadingZero) {
  3085. this.raise(Errors.InvalidBigIntLiteral, {
  3086. at: startLoc
  3087. });
  3088. }
  3089. ++this.state.pos;
  3090. isBigInt = true;
  3091. }
  3092. if (next === 109) {
  3093. this.expectPlugin("decimal", this.state.curPosition());
  3094. if (hasExponent || hasLeadingZero) {
  3095. this.raise(Errors.InvalidDecimal, {
  3096. at: startLoc
  3097. });
  3098. }
  3099. ++this.state.pos;
  3100. isDecimal = true;
  3101. }
  3102. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3103. throw this.raise(Errors.NumberIdentifier, {
  3104. at: this.state.curPosition()
  3105. });
  3106. }
  3107. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3108. if (isBigInt) {
  3109. this.finishToken(133, str);
  3110. return;
  3111. }
  3112. if (isDecimal) {
  3113. this.finishToken(134, str);
  3114. return;
  3115. }
  3116. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3117. this.finishToken(132, val);
  3118. }
  3119. readCodePoint(throwOnInvalid) {
  3120. const {
  3121. code,
  3122. pos
  3123. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3124. this.state.pos = pos;
  3125. return code;
  3126. }
  3127. readString(quote) {
  3128. const {
  3129. str,
  3130. pos,
  3131. curLine,
  3132. lineStart
  3133. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1,
  3134. this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3135. this.state.pos = pos + 1;
  3136. this.state.lineStart = lineStart;
  3137. this.state.curLine = curLine;
  3138. this.finishToken(131, str);
  3139. }
  3140. readTemplateContinuation() {
  3141. if (!this.match(8)) {
  3142. this.unexpected(null, 8);
  3143. }
  3144. this.state.pos--;
  3145. this.readTemplateToken();
  3146. }
  3147. readTemplateToken() {
  3148. const opening = this.input[this.state.pos];
  3149. const {
  3150. str,
  3151. firstInvalidLoc,
  3152. pos,
  3153. curLine,
  3154. lineStart
  3155. } = readStringContents("template", this.input, this.state.pos + 1,
  3156. this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3157. this.state.pos = pos + 1;
  3158. this.state.lineStart = lineStart;
  3159. this.state.curLine = curLine;
  3160. if (firstInvalidLoc) {
  3161. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3162. }
  3163. if (this.input.codePointAt(pos) === 96) {
  3164. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3165. } else {
  3166. this.state.pos++;
  3167. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3168. }
  3169. }
  3170. recordStrictModeErrors(toParseError, {
  3171. at
  3172. }) {
  3173. const index = at.index;
  3174. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3175. this.raise(toParseError, {
  3176. at
  3177. });
  3178. } else {
  3179. this.state.strictErrors.set(index, [toParseError, at]);
  3180. }
  3181. }
  3182. readWord1(firstCode) {
  3183. this.state.containsEsc = false;
  3184. let word = "";
  3185. const start = this.state.pos;
  3186. let chunkStart = this.state.pos;
  3187. if (firstCode !== undefined) {
  3188. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3189. }
  3190. while (this.state.pos < this.length) {
  3191. const ch = this.codePointAtPos(this.state.pos);
  3192. if (isIdentifierChar(ch)) {
  3193. this.state.pos += ch <= 0xffff ? 1 : 2;
  3194. } else if (ch === 92) {
  3195. this.state.containsEsc = true;
  3196. word += this.input.slice(chunkStart, this.state.pos);
  3197. const escStart = this.state.curPosition();
  3198. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3199. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3200. this.raise(Errors.MissingUnicodeEscape, {
  3201. at: this.state.curPosition()
  3202. });
  3203. chunkStart = this.state.pos - 1;
  3204. continue;
  3205. }
  3206. ++this.state.pos;
  3207. const esc = this.readCodePoint(true);
  3208. if (esc !== null) {
  3209. if (!identifierCheck(esc)) {
  3210. this.raise(Errors.EscapedCharNotAnIdentifier, {
  3211. at: escStart
  3212. });
  3213. }
  3214. word += String.fromCodePoint(esc);
  3215. }
  3216. chunkStart = this.state.pos;
  3217. } else {
  3218. break;
  3219. }
  3220. }
  3221. return word + this.input.slice(chunkStart, this.state.pos);
  3222. }
  3223. readWord(firstCode) {
  3224. const word = this.readWord1(firstCode);
  3225. const type = keywords$1.get(word);
  3226. if (type !== undefined) {
  3227. this.finishToken(type, tokenLabelName(type));
  3228. } else {
  3229. this.finishToken(130, word);
  3230. }
  3231. }
  3232. checkKeywordEscapes() {
  3233. const {
  3234. type
  3235. } = this.state;
  3236. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3237. this.raise(Errors.InvalidEscapedReservedWord, {
  3238. at: this.state.startLoc,
  3239. reservedWord: tokenLabelName(type)
  3240. });
  3241. }
  3242. }
  3243. raise(toParseError, raiseProperties) {
  3244. const {
  3245. at
  3246. } = raiseProperties,
  3247. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
  3248. const loc = at instanceof Position ? at : at.loc.start;
  3249. const error = toParseError({
  3250. loc,
  3251. details
  3252. });
  3253. if (!this.options.errorRecovery) throw error;
  3254. if (!this.isLookahead) this.state.errors.push(error);
  3255. return error;
  3256. }
  3257. raiseOverwrite(toParseError, raiseProperties) {
  3258. const {
  3259. at
  3260. } = raiseProperties,
  3261. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
  3262. const loc = at instanceof Position ? at : at.loc.start;
  3263. const pos = loc.index;
  3264. const errors = this.state.errors;
  3265. for (let i = errors.length - 1; i >= 0; i--) {
  3266. const error = errors[i];
  3267. if (error.loc.index === pos) {
  3268. return errors[i] = toParseError({
  3269. loc,
  3270. details
  3271. });
  3272. }
  3273. if (error.loc.index < pos) break;
  3274. }
  3275. return this.raise(toParseError, raiseProperties);
  3276. }
  3277. updateContext(prevType) {}
  3278. unexpected(loc, type) {
  3279. throw this.raise(Errors.UnexpectedToken, {
  3280. expected: type ? tokenLabelName(type) : null,
  3281. at: loc != null ? loc : this.state.startLoc
  3282. });
  3283. }
  3284. expectPlugin(pluginName, loc) {
  3285. if (this.hasPlugin(pluginName)) {
  3286. return true;
  3287. }
  3288. throw this.raise(Errors.MissingPlugin, {
  3289. at: loc != null ? loc : this.state.startLoc,
  3290. missingPlugin: [pluginName]
  3291. });
  3292. }
  3293. expectOnePlugin(pluginNames) {
  3294. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3295. throw this.raise(Errors.MissingOneOfPlugins, {
  3296. at: this.state.startLoc,
  3297. missingPlugin: pluginNames
  3298. });
  3299. }
  3300. }
  3301. errorBuilder(error) {
  3302. return (pos, lineStart, curLine) => {
  3303. this.raise(error, {
  3304. at: buildPosition(pos, lineStart, curLine)
  3305. });
  3306. };
  3307. }
  3308. }
  3309. class ClassScope {
  3310. constructor() {
  3311. this.privateNames = new Set();
  3312. this.loneAccessors = new Map();
  3313. this.undefinedPrivateNames = new Map();
  3314. }
  3315. }
  3316. class ClassScopeHandler {
  3317. constructor(parser) {
  3318. this.parser = void 0;
  3319. this.stack = [];
  3320. this.undefinedPrivateNames = new Map();
  3321. this.parser = parser;
  3322. }
  3323. current() {
  3324. return this.stack[this.stack.length - 1];
  3325. }
  3326. enter() {
  3327. this.stack.push(new ClassScope());
  3328. }
  3329. exit() {
  3330. const oldClassScope = this.stack.pop();
  3331. const current = this.current();
  3332. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3333. if (current) {
  3334. if (!current.undefinedPrivateNames.has(name)) {
  3335. current.undefinedPrivateNames.set(name, loc);
  3336. }
  3337. } else {
  3338. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3339. at: loc,
  3340. identifierName: name
  3341. });
  3342. }
  3343. }
  3344. }
  3345. declarePrivateName(name, elementType, loc) {
  3346. const {
  3347. privateNames,
  3348. loneAccessors,
  3349. undefinedPrivateNames
  3350. } = this.current();
  3351. let redefined = privateNames.has(name);
  3352. if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) {
  3353. const accessor = redefined && loneAccessors.get(name);
  3354. if (accessor) {
  3355. const oldStatic = accessor & CLASS_ELEMENT_FLAG_STATIC;
  3356. const newStatic = elementType & CLASS_ELEMENT_FLAG_STATIC;
  3357. const oldKind = accessor & CLASS_ELEMENT_KIND_ACCESSOR;
  3358. const newKind = elementType & CLASS_ELEMENT_KIND_ACCESSOR;
  3359. redefined = oldKind === newKind || oldStatic !== newStatic;
  3360. if (!redefined) loneAccessors.delete(name);
  3361. } else if (!redefined) {
  3362. loneAccessors.set(name, elementType);
  3363. }
  3364. }
  3365. if (redefined) {
  3366. this.parser.raise(Errors.PrivateNameRedeclaration, {
  3367. at: loc,
  3368. identifierName: name
  3369. });
  3370. }
  3371. privateNames.add(name);
  3372. undefinedPrivateNames.delete(name);
  3373. }
  3374. usePrivateName(name, loc) {
  3375. let classScope;
  3376. for (classScope of this.stack) {
  3377. if (classScope.privateNames.has(name)) return;
  3378. }
  3379. if (classScope) {
  3380. classScope.undefinedPrivateNames.set(name, loc);
  3381. } else {
  3382. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3383. at: loc,
  3384. identifierName: name
  3385. });
  3386. }
  3387. }
  3388. }
  3389. const kExpression = 0,
  3390. kMaybeArrowParameterDeclaration = 1,
  3391. kMaybeAsyncArrowParameterDeclaration = 2,
  3392. kParameterDeclaration = 3;
  3393. class ExpressionScope {
  3394. constructor(type = kExpression) {
  3395. this.type = void 0;
  3396. this.type = type;
  3397. }
  3398. canBeArrowParameterDeclaration() {
  3399. return this.type === kMaybeAsyncArrowParameterDeclaration || this.type === kMaybeArrowParameterDeclaration;
  3400. }
  3401. isCertainlyParameterDeclaration() {
  3402. return this.type === kParameterDeclaration;
  3403. }
  3404. }
  3405. class ArrowHeadParsingScope extends ExpressionScope {
  3406. constructor(type) {
  3407. super(type);
  3408. this.declarationErrors = new Map();
  3409. }
  3410. recordDeclarationError(ParsingErrorClass, {
  3411. at
  3412. }) {
  3413. const index = at.index;
  3414. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3415. }
  3416. clearDeclarationError(index) {
  3417. this.declarationErrors.delete(index);
  3418. }
  3419. iterateErrors(iterator) {
  3420. this.declarationErrors.forEach(iterator);
  3421. }
  3422. }
  3423. class ExpressionScopeHandler {
  3424. constructor(parser) {
  3425. this.parser = void 0;
  3426. this.stack = [new ExpressionScope()];
  3427. this.parser = parser;
  3428. }
  3429. enter(scope) {
  3430. this.stack.push(scope);
  3431. }
  3432. exit() {
  3433. this.stack.pop();
  3434. }
  3435. recordParameterInitializerError(toParseError, {
  3436. at: node
  3437. }) {
  3438. const origin = {
  3439. at: node.loc.start
  3440. };
  3441. const {
  3442. stack
  3443. } = this;
  3444. let i = stack.length - 1;
  3445. let scope = stack[i];
  3446. while (!scope.isCertainlyParameterDeclaration()) {
  3447. if (scope.canBeArrowParameterDeclaration()) {
  3448. scope.recordDeclarationError(toParseError, origin);
  3449. } else {
  3450. return;
  3451. }
  3452. scope = stack[--i];
  3453. }
  3454. this.parser.raise(toParseError, origin);
  3455. }
  3456. recordArrowParemeterBindingError(error, {
  3457. at: node
  3458. }) {
  3459. const {
  3460. stack
  3461. } = this;
  3462. const scope = stack[stack.length - 1];
  3463. const origin = {
  3464. at: node.loc.start
  3465. };
  3466. if (scope.isCertainlyParameterDeclaration()) {
  3467. this.parser.raise(error, origin);
  3468. } else if (scope.canBeArrowParameterDeclaration()) {
  3469. scope.recordDeclarationError(error, origin);
  3470. } else {
  3471. return;
  3472. }
  3473. }
  3474. recordAsyncArrowParametersError({
  3475. at
  3476. }) {
  3477. const {
  3478. stack
  3479. } = this;
  3480. let i = stack.length - 1;
  3481. let scope = stack[i];
  3482. while (scope.canBeArrowParameterDeclaration()) {
  3483. if (scope.type === kMaybeAsyncArrowParameterDeclaration) {
  3484. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
  3485. at
  3486. });
  3487. }
  3488. scope = stack[--i];
  3489. }
  3490. }
  3491. validateAsPattern() {
  3492. const {
  3493. stack
  3494. } = this;
  3495. const currentScope = stack[stack.length - 1];
  3496. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3497. currentScope.iterateErrors(([toParseError, loc]) => {
  3498. this.parser.raise(toParseError, {
  3499. at: loc
  3500. });
  3501. let i = stack.length - 2;
  3502. let scope = stack[i];
  3503. while (scope.canBeArrowParameterDeclaration()) {
  3504. scope.clearDeclarationError(loc.index);
  3505. scope = stack[--i];
  3506. }
  3507. });
  3508. }
  3509. }
  3510. function newParameterDeclarationScope() {
  3511. return new ExpressionScope(kParameterDeclaration);
  3512. }
  3513. function newArrowHeadScope() {
  3514. return new ArrowHeadParsingScope(kMaybeArrowParameterDeclaration);
  3515. }
  3516. function newAsyncArrowScope() {
  3517. return new ArrowHeadParsingScope(kMaybeAsyncArrowParameterDeclaration);
  3518. }
  3519. function newExpressionScope() {
  3520. return new ExpressionScope();
  3521. }
  3522. const
  3523. PARAM = 0b0000,
  3524. PARAM_YIELD = 0b0001,
  3525. PARAM_AWAIT = 0b0010,
  3526. PARAM_RETURN = 0b0100,
  3527. PARAM_IN = 0b1000;
  3528. class ProductionParameterHandler {
  3529. constructor() {
  3530. this.stacks = [];
  3531. }
  3532. enter(flags) {
  3533. this.stacks.push(flags);
  3534. }
  3535. exit() {
  3536. this.stacks.pop();
  3537. }
  3538. currentFlags() {
  3539. return this.stacks[this.stacks.length - 1];
  3540. }
  3541. get hasAwait() {
  3542. return (this.currentFlags() & PARAM_AWAIT) > 0;
  3543. }
  3544. get hasYield() {
  3545. return (this.currentFlags() & PARAM_YIELD) > 0;
  3546. }
  3547. get hasReturn() {
  3548. return (this.currentFlags() & PARAM_RETURN) > 0;
  3549. }
  3550. get hasIn() {
  3551. return (this.currentFlags() & PARAM_IN) > 0;
  3552. }
  3553. }
  3554. function functionFlags(isAsync, isGenerator) {
  3555. return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
  3556. }
  3557. class UtilParser extends Tokenizer {
  3558. addExtra(node, key, value, enumerable = true) {
  3559. if (!node) return;
  3560. const extra = node.extra = node.extra || {};
  3561. if (enumerable) {
  3562. extra[key] = value;
  3563. } else {
  3564. Object.defineProperty(extra, key, {
  3565. enumerable,
  3566. value
  3567. });
  3568. }
  3569. }
  3570. isContextual(token) {
  3571. return this.state.type === token && !this.state.containsEsc;
  3572. }
  3573. isUnparsedContextual(nameStart, name) {
  3574. const nameEnd = nameStart + name.length;
  3575. if (this.input.slice(nameStart, nameEnd) === name) {
  3576. const nextCh = this.input.charCodeAt(nameEnd);
  3577. return !(isIdentifierChar(nextCh) ||
  3578. (nextCh & 0xfc00) === 0xd800);
  3579. }
  3580. return false;
  3581. }
  3582. isLookaheadContextual(name) {
  3583. const next = this.nextTokenStart();
  3584. return this.isUnparsedContextual(next, name);
  3585. }
  3586. eatContextual(token) {
  3587. if (this.isContextual(token)) {
  3588. this.next();
  3589. return true;
  3590. }
  3591. return false;
  3592. }
  3593. expectContextual(token, toParseError) {
  3594. if (!this.eatContextual(token)) {
  3595. if (toParseError != null) {
  3596. throw this.raise(toParseError, {
  3597. at: this.state.startLoc
  3598. });
  3599. }
  3600. throw this.unexpected(null, token);
  3601. }
  3602. }
  3603. canInsertSemicolon() {
  3604. return this.match(137) || this.match(8) || this.hasPrecedingLineBreak();
  3605. }
  3606. hasPrecedingLineBreak() {
  3607. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  3608. }
  3609. hasFollowingLineBreak() {
  3610. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  3611. return skipWhiteSpaceToLineBreak.test(this.input);
  3612. }
  3613. isLineTerminator() {
  3614. return this.eat(13) || this.canInsertSemicolon();
  3615. }
  3616. semicolon(allowAsi = true) {
  3617. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3618. this.raise(Errors.MissingSemicolon, {
  3619. at: this.state.lastTokEndLoc
  3620. });
  3621. }
  3622. expect(type, loc) {
  3623. this.eat(type) || this.unexpected(loc, type);
  3624. }
  3625. tryParse(fn, oldState = this.state.clone()) {
  3626. const abortSignal = {
  3627. node: null
  3628. };
  3629. try {
  3630. const node = fn((node = null) => {
  3631. abortSignal.node = node;
  3632. throw abortSignal;
  3633. });
  3634. if (this.state.errors.length > oldState.errors.length) {
  3635. const failState = this.state;
  3636. this.state = oldState;
  3637. this.state.tokensLength = failState.tokensLength;
  3638. return {
  3639. node,
  3640. error: failState.errors[oldState.errors.length],
  3641. thrown: false,
  3642. aborted: false,
  3643. failState
  3644. };
  3645. }
  3646. return {
  3647. node,
  3648. error: null,
  3649. thrown: false,
  3650. aborted: false,
  3651. failState: null
  3652. };
  3653. } catch (error) {
  3654. const failState = this.state;
  3655. this.state = oldState;
  3656. if (error instanceof SyntaxError) {
  3657. return {
  3658. node: null,
  3659. error,
  3660. thrown: true,
  3661. aborted: false,
  3662. failState
  3663. };
  3664. }
  3665. if (error === abortSignal) {
  3666. return {
  3667. node: abortSignal.node,
  3668. error: null,
  3669. thrown: false,
  3670. aborted: true,
  3671. failState
  3672. };
  3673. }
  3674. throw error;
  3675. }
  3676. }
  3677. checkExpressionErrors(refExpressionErrors, andThrow) {
  3678. if (!refExpressionErrors) return false;
  3679. const {
  3680. shorthandAssignLoc,
  3681. doubleProtoLoc,
  3682. privateKeyLoc,
  3683. optionalParametersLoc
  3684. } = refExpressionErrors;
  3685. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3686. if (!andThrow) {
  3687. return hasErrors;
  3688. }
  3689. if (shorthandAssignLoc != null) {
  3690. this.raise(Errors.InvalidCoverInitializedName, {
  3691. at: shorthandAssignLoc
  3692. });
  3693. }
  3694. if (doubleProtoLoc != null) {
  3695. this.raise(Errors.DuplicateProto, {
  3696. at: doubleProtoLoc
  3697. });
  3698. }
  3699. if (privateKeyLoc != null) {
  3700. this.raise(Errors.UnexpectedPrivateField, {
  3701. at: privateKeyLoc
  3702. });
  3703. }
  3704. if (optionalParametersLoc != null) {
  3705. this.unexpected(optionalParametersLoc);
  3706. }
  3707. }
  3708. isLiteralPropertyName() {
  3709. return tokenIsLiteralPropertyName(this.state.type);
  3710. }
  3711. isPrivateName(node) {
  3712. return node.type === "PrivateName";
  3713. }
  3714. getPrivateNameSV(node) {
  3715. return node.id.name;
  3716. }
  3717. hasPropertyAsPrivateName(node) {
  3718. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3719. }
  3720. isOptionalChain(node) {
  3721. return node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression";
  3722. }
  3723. isObjectProperty(node) {
  3724. return node.type === "ObjectProperty";
  3725. }
  3726. isObjectMethod(node) {
  3727. return node.type === "ObjectMethod";
  3728. }
  3729. initializeScopes(inModule = this.options.sourceType === "module") {
  3730. const oldLabels = this.state.labels;
  3731. this.state.labels = [];
  3732. const oldExportedIdentifiers = this.exportedIdentifiers;
  3733. this.exportedIdentifiers = new Set();
  3734. const oldInModule = this.inModule;
  3735. this.inModule = inModule;
  3736. const oldScope = this.scope;
  3737. const ScopeHandler = this.getScopeHandler();
  3738. this.scope = new ScopeHandler(this, inModule);
  3739. const oldProdParam = this.prodParam;
  3740. this.prodParam = new ProductionParameterHandler();
  3741. const oldClassScope = this.classScope;
  3742. this.classScope = new ClassScopeHandler(this);
  3743. const oldExpressionScope = this.expressionScope;
  3744. this.expressionScope = new ExpressionScopeHandler(this);
  3745. return () => {
  3746. this.state.labels = oldLabels;
  3747. this.exportedIdentifiers = oldExportedIdentifiers;
  3748. this.inModule = oldInModule;
  3749. this.scope = oldScope;
  3750. this.prodParam = oldProdParam;
  3751. this.classScope = oldClassScope;
  3752. this.expressionScope = oldExpressionScope;
  3753. };
  3754. }
  3755. enterInitialScopes() {
  3756. let paramFlags = PARAM;
  3757. if (this.inModule) {
  3758. paramFlags |= PARAM_AWAIT;
  3759. }
  3760. this.scope.enter(SCOPE_PROGRAM);
  3761. this.prodParam.enter(paramFlags);
  3762. }
  3763. checkDestructuringPrivate(refExpressionErrors) {
  3764. const {
  3765. privateKeyLoc
  3766. } = refExpressionErrors;
  3767. if (privateKeyLoc !== null) {
  3768. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3769. }
  3770. }
  3771. }
  3772. class ExpressionErrors {
  3773. constructor() {
  3774. this.shorthandAssignLoc = null;
  3775. this.doubleProtoLoc = null;
  3776. this.privateKeyLoc = null;
  3777. this.optionalParametersLoc = null;
  3778. }
  3779. }
  3780. class Node {
  3781. constructor(parser, pos, loc) {
  3782. this.type = "";
  3783. this.start = pos;
  3784. this.end = 0;
  3785. this.loc = new SourceLocation(loc);
  3786. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3787. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3788. }
  3789. }
  3790. const NodePrototype = Node.prototype;
  3791. {
  3792. NodePrototype.__clone = function () {
  3793. const newNode = new Node(undefined, this.start, this.loc.start);
  3794. const keys = Object.keys(this);
  3795. for (let i = 0, length = keys.length; i < length; i++) {
  3796. const key = keys[i];
  3797. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3798. newNode[key] = this[key];
  3799. }
  3800. }
  3801. return newNode;
  3802. };
  3803. }
  3804. function clonePlaceholder(node) {
  3805. return cloneIdentifier(node);
  3806. }
  3807. function cloneIdentifier(node) {
  3808. const {
  3809. type,
  3810. start,
  3811. end,
  3812. loc,
  3813. range,
  3814. extra,
  3815. name
  3816. } = node;
  3817. const cloned = Object.create(NodePrototype);
  3818. cloned.type = type;
  3819. cloned.start = start;
  3820. cloned.end = end;
  3821. cloned.loc = loc;
  3822. cloned.range = range;
  3823. cloned.extra = extra;
  3824. cloned.name = name;
  3825. if (type === "Placeholder") {
  3826. cloned.expectedNode = node.expectedNode;
  3827. }
  3828. return cloned;
  3829. }
  3830. function cloneStringLiteral(node) {
  3831. const {
  3832. type,
  3833. start,
  3834. end,
  3835. loc,
  3836. range,
  3837. extra
  3838. } = node;
  3839. if (type === "Placeholder") {
  3840. return clonePlaceholder(node);
  3841. }
  3842. const cloned = Object.create(NodePrototype);
  3843. cloned.type = type;
  3844. cloned.start = start;
  3845. cloned.end = end;
  3846. cloned.loc = loc;
  3847. cloned.range = range;
  3848. if (node.raw !== undefined) {
  3849. cloned.raw = node.raw;
  3850. } else {
  3851. cloned.extra = extra;
  3852. }
  3853. cloned.value = node.value;
  3854. return cloned;
  3855. }
  3856. class NodeUtils extends UtilParser {
  3857. startNode() {
  3858. return new Node(this, this.state.start, this.state.startLoc);
  3859. }
  3860. startNodeAt(loc) {
  3861. return new Node(this, loc.index, loc);
  3862. }
  3863. startNodeAtNode(type) {
  3864. return this.startNodeAt(type.loc.start);
  3865. }
  3866. finishNode(node, type) {
  3867. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3868. }
  3869. finishNodeAt(node, type, endLoc) {
  3870. node.type = type;
  3871. node.end = endLoc.index;
  3872. node.loc.end = endLoc;
  3873. if (this.options.ranges) node.range[1] = endLoc.index;
  3874. if (this.options.attachComment) this.processComment(node);
  3875. return node;
  3876. }
  3877. resetStartLocation(node, startLoc) {
  3878. node.start = startLoc.index;
  3879. node.loc.start = startLoc;
  3880. if (this.options.ranges) node.range[0] = startLoc.index;
  3881. }
  3882. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3883. node.end = endLoc.index;
  3884. node.loc.end = endLoc;
  3885. if (this.options.ranges) node.range[1] = endLoc.index;
  3886. }
  3887. resetStartLocationFromNode(node, locationNode) {
  3888. this.resetStartLocation(node, locationNode.loc.start);
  3889. }
  3890. }
  3891. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3892. const FlowErrors = ParseErrorEnum`flow`({
  3893. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3894. 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.",
  3895. AssignReservedType: ({
  3896. reservedType
  3897. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3898. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3899. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3900. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3901. EnumBooleanMemberNotInitialized: ({
  3902. memberName,
  3903. enumName
  3904. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3905. EnumDuplicateMemberName: ({
  3906. memberName,
  3907. enumName
  3908. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3909. EnumInconsistentMemberValues: ({
  3910. enumName
  3911. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3912. EnumInvalidExplicitType: ({
  3913. invalidEnumType,
  3914. enumName
  3915. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3916. EnumInvalidExplicitTypeUnknownSupplied: ({
  3917. enumName
  3918. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3919. EnumInvalidMemberInitializerPrimaryType: ({
  3920. enumName,
  3921. memberName,
  3922. explicitType
  3923. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3924. EnumInvalidMemberInitializerSymbolType: ({
  3925. enumName,
  3926. memberName
  3927. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3928. EnumInvalidMemberInitializerUnknownType: ({
  3929. enumName,
  3930. memberName
  3931. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3932. EnumInvalidMemberName: ({
  3933. enumName,
  3934. memberName,
  3935. suggestion
  3936. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3937. EnumNumberMemberNotInitialized: ({
  3938. enumName,
  3939. memberName
  3940. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3941. EnumStringMemberInconsistentlyInitailized: ({
  3942. enumName
  3943. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3944. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3945. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3946. 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.",
  3947. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3948. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3949. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3950. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3951. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3952. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3953. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3954. PatternIsOptional: Object.assign({
  3955. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3956. }, {
  3957. reasonCode: "OptionalBindingPattern"
  3958. }),
  3959. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3960. SpreadVariance: "Spread properties cannot have variance.",
  3961. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3962. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3963. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3964. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3965. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3966. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3967. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3968. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3969. UnexpectedReservedType: ({
  3970. reservedType
  3971. }) => `Unexpected reserved type ${reservedType}.`,
  3972. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3973. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3974. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3975. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3976. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3977. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3978. UnsupportedDeclareExportKind: ({
  3979. unsupportedExportKind,
  3980. suggestion
  3981. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  3982. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3983. UnterminatedFlowComment: "Unterminated flow-comment."
  3984. });
  3985. function isEsModuleType(bodyElement) {
  3986. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3987. }
  3988. function hasTypeImportKind(node) {
  3989. return node.importKind === "type" || node.importKind === "typeof";
  3990. }
  3991. function isMaybeDefaultImport(type) {
  3992. return tokenIsKeywordOrIdentifier(type) && type !== 97;
  3993. }
  3994. const exportSuggestions = {
  3995. const: "declare export var",
  3996. let: "declare export var",
  3997. type: "export type",
  3998. interface: "export interface"
  3999. };
  4000. function partition(list, test) {
  4001. const list1 = [];
  4002. const list2 = [];
  4003. for (let i = 0; i < list.length; i++) {
  4004. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  4005. }
  4006. return [list1, list2];
  4007. }
  4008. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  4009. var flow = (superClass => class FlowParserMixin extends superClass {
  4010. constructor(...args) {
  4011. super(...args);
  4012. this.flowPragma = undefined;
  4013. }
  4014. getScopeHandler() {
  4015. return FlowScopeHandler;
  4016. }
  4017. shouldParseTypes() {
  4018. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  4019. }
  4020. shouldParseEnums() {
  4021. return !!this.getPluginOption("flow", "enums");
  4022. }
  4023. finishToken(type, val) {
  4024. if (type !== 131 && type !== 13 && type !== 28) {
  4025. if (this.flowPragma === undefined) {
  4026. this.flowPragma = null;
  4027. }
  4028. }
  4029. return super.finishToken(type, val);
  4030. }
  4031. addComment(comment) {
  4032. if (this.flowPragma === undefined) {
  4033. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4034. if (!matches) ; else if (matches[1] === "flow") {
  4035. this.flowPragma = "flow";
  4036. } else if (matches[1] === "noflow") {
  4037. this.flowPragma = "noflow";
  4038. } else {
  4039. throw new Error("Unexpected flow pragma");
  4040. }
  4041. }
  4042. return super.addComment(comment);
  4043. }
  4044. flowParseTypeInitialiser(tok) {
  4045. const oldInType = this.state.inType;
  4046. this.state.inType = true;
  4047. this.expect(tok || 14);
  4048. const type = this.flowParseType();
  4049. this.state.inType = oldInType;
  4050. return type;
  4051. }
  4052. flowParsePredicate() {
  4053. const node = this.startNode();
  4054. const moduloLoc = this.state.startLoc;
  4055. this.next();
  4056. this.expectContextual(108);
  4057. if (this.state.lastTokStart > moduloLoc.index + 1) {
  4058. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
  4059. at: moduloLoc
  4060. });
  4061. }
  4062. if (this.eat(10)) {
  4063. node.value = super.parseExpression();
  4064. this.expect(11);
  4065. return this.finishNode(node, "DeclaredPredicate");
  4066. } else {
  4067. return this.finishNode(node, "InferredPredicate");
  4068. }
  4069. }
  4070. flowParseTypeAndPredicateInitialiser() {
  4071. const oldInType = this.state.inType;
  4072. this.state.inType = true;
  4073. this.expect(14);
  4074. let type = null;
  4075. let predicate = null;
  4076. if (this.match(54)) {
  4077. this.state.inType = oldInType;
  4078. predicate = this.flowParsePredicate();
  4079. } else {
  4080. type = this.flowParseType();
  4081. this.state.inType = oldInType;
  4082. if (this.match(54)) {
  4083. predicate = this.flowParsePredicate();
  4084. }
  4085. }
  4086. return [type, predicate];
  4087. }
  4088. flowParseDeclareClass(node) {
  4089. this.next();
  4090. this.flowParseInterfaceish(node, true);
  4091. return this.finishNode(node, "DeclareClass");
  4092. }
  4093. flowParseDeclareFunction(node) {
  4094. this.next();
  4095. const id = node.id = this.parseIdentifier();
  4096. const typeNode = this.startNode();
  4097. const typeContainer = this.startNode();
  4098. if (this.match(47)) {
  4099. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4100. } else {
  4101. typeNode.typeParameters = null;
  4102. }
  4103. this.expect(10);
  4104. const tmp = this.flowParseFunctionTypeParams();
  4105. typeNode.params = tmp.params;
  4106. typeNode.rest = tmp.rest;
  4107. typeNode.this = tmp._this;
  4108. this.expect(11);
  4109. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4110. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4111. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4112. this.resetEndLocation(id);
  4113. this.semicolon();
  4114. this.scope.declareName(node.id.name, BIND_FLOW_DECLARE_FN, node.id.loc.start);
  4115. return this.finishNode(node, "DeclareFunction");
  4116. }
  4117. flowParseDeclare(node, insideModule) {
  4118. if (this.match(80)) {
  4119. return this.flowParseDeclareClass(node);
  4120. } else if (this.match(68)) {
  4121. return this.flowParseDeclareFunction(node);
  4122. } else if (this.match(74)) {
  4123. return this.flowParseDeclareVariable(node);
  4124. } else if (this.eatContextual(125)) {
  4125. if (this.match(16)) {
  4126. return this.flowParseDeclareModuleExports(node);
  4127. } else {
  4128. if (insideModule) {
  4129. this.raise(FlowErrors.NestedDeclareModule, {
  4130. at: this.state.lastTokStartLoc
  4131. });
  4132. }
  4133. return this.flowParseDeclareModule(node);
  4134. }
  4135. } else if (this.isContextual(128)) {
  4136. return this.flowParseDeclareTypeAlias(node);
  4137. } else if (this.isContextual(129)) {
  4138. return this.flowParseDeclareOpaqueType(node);
  4139. } else if (this.isContextual(127)) {
  4140. return this.flowParseDeclareInterface(node);
  4141. } else if (this.match(82)) {
  4142. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4143. } else {
  4144. throw this.unexpected();
  4145. }
  4146. }
  4147. flowParseDeclareVariable(node) {
  4148. this.next();
  4149. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4150. this.scope.declareName(node.id.name, BIND_VAR, node.id.loc.start);
  4151. this.semicolon();
  4152. return this.finishNode(node, "DeclareVariable");
  4153. }
  4154. flowParseDeclareModule(node) {
  4155. this.scope.enter(SCOPE_OTHER);
  4156. if (this.match(131)) {
  4157. node.id = super.parseExprAtom();
  4158. } else {
  4159. node.id = this.parseIdentifier();
  4160. }
  4161. const bodyNode = node.body = this.startNode();
  4162. const body = bodyNode.body = [];
  4163. this.expect(5);
  4164. while (!this.match(8)) {
  4165. let bodyNode = this.startNode();
  4166. if (this.match(83)) {
  4167. this.next();
  4168. if (!this.isContextual(128) && !this.match(87)) {
  4169. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
  4170. at: this.state.lastTokStartLoc
  4171. });
  4172. }
  4173. super.parseImport(bodyNode);
  4174. } else {
  4175. this.expectContextual(123, FlowErrors.UnsupportedStatementInDeclareModule);
  4176. bodyNode = this.flowParseDeclare(bodyNode, true);
  4177. }
  4178. body.push(bodyNode);
  4179. }
  4180. this.scope.exit();
  4181. this.expect(8);
  4182. this.finishNode(bodyNode, "BlockStatement");
  4183. let kind = null;
  4184. let hasModuleExport = false;
  4185. body.forEach(bodyElement => {
  4186. if (isEsModuleType(bodyElement)) {
  4187. if (kind === "CommonJS") {
  4188. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4189. at: bodyElement
  4190. });
  4191. }
  4192. kind = "ES";
  4193. } else if (bodyElement.type === "DeclareModuleExports") {
  4194. if (hasModuleExport) {
  4195. this.raise(FlowErrors.DuplicateDeclareModuleExports, {
  4196. at: bodyElement
  4197. });
  4198. }
  4199. if (kind === "ES") {
  4200. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4201. at: bodyElement
  4202. });
  4203. }
  4204. kind = "CommonJS";
  4205. hasModuleExport = true;
  4206. }
  4207. });
  4208. node.kind = kind || "CommonJS";
  4209. return this.finishNode(node, "DeclareModule");
  4210. }
  4211. flowParseDeclareExportDeclaration(node, insideModule) {
  4212. this.expect(82);
  4213. if (this.eat(65)) {
  4214. if (this.match(68) || this.match(80)) {
  4215. node.declaration = this.flowParseDeclare(this.startNode());
  4216. } else {
  4217. node.declaration = this.flowParseType();
  4218. this.semicolon();
  4219. }
  4220. node.default = true;
  4221. return this.finishNode(node, "DeclareExportDeclaration");
  4222. } else {
  4223. if (this.match(75) || this.isLet() || (this.isContextual(128) || this.isContextual(127)) && !insideModule) {
  4224. const label = this.state.value;
  4225. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
  4226. at: this.state.startLoc,
  4227. unsupportedExportKind: label,
  4228. suggestion: exportSuggestions[label]
  4229. });
  4230. }
  4231. if (this.match(74) ||
  4232. this.match(68) ||
  4233. this.match(80) ||
  4234. this.isContextual(129)) {
  4235. node.declaration = this.flowParseDeclare(this.startNode());
  4236. node.default = false;
  4237. return this.finishNode(node, "DeclareExportDeclaration");
  4238. } else if (this.match(55) ||
  4239. this.match(5) ||
  4240. this.isContextual(127) ||
  4241. this.isContextual(128) ||
  4242. this.isContextual(129)) {
  4243. node = this.parseExport(node, null);
  4244. if (node.type === "ExportNamedDeclaration") {
  4245. node.type = "ExportDeclaration";
  4246. node.default = false;
  4247. delete node.exportKind;
  4248. }
  4249. node.type = "Declare" + node.type;
  4250. return node;
  4251. }
  4252. }
  4253. throw this.unexpected();
  4254. }
  4255. flowParseDeclareModuleExports(node) {
  4256. this.next();
  4257. this.expectContextual(109);
  4258. node.typeAnnotation = this.flowParseTypeAnnotation();
  4259. this.semicolon();
  4260. return this.finishNode(node, "DeclareModuleExports");
  4261. }
  4262. flowParseDeclareTypeAlias(node) {
  4263. this.next();
  4264. const finished = this.flowParseTypeAlias(node);
  4265. finished.type = "DeclareTypeAlias";
  4266. return finished;
  4267. }
  4268. flowParseDeclareOpaqueType(node) {
  4269. this.next();
  4270. const finished = this.flowParseOpaqueType(node, true);
  4271. finished.type = "DeclareOpaqueType";
  4272. return finished;
  4273. }
  4274. flowParseDeclareInterface(node) {
  4275. this.next();
  4276. this.flowParseInterfaceish(node);
  4277. return this.finishNode(node, "DeclareInterface");
  4278. }
  4279. flowParseInterfaceish(node, isClass = false) {
  4280. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4281. this.scope.declareName(node.id.name, isClass ? BIND_FUNCTION : BIND_LEXICAL, node.id.loc.start);
  4282. if (this.match(47)) {
  4283. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4284. } else {
  4285. node.typeParameters = null;
  4286. }
  4287. node.extends = [];
  4288. node.implements = [];
  4289. node.mixins = [];
  4290. if (this.eat(81)) {
  4291. do {
  4292. node.extends.push(this.flowParseInterfaceExtends());
  4293. } while (!isClass && this.eat(12));
  4294. }
  4295. if (this.isContextual(115)) {
  4296. this.next();
  4297. do {
  4298. node.mixins.push(this.flowParseInterfaceExtends());
  4299. } while (this.eat(12));
  4300. }
  4301. if (this.isContextual(111)) {
  4302. this.next();
  4303. do {
  4304. node.implements.push(this.flowParseInterfaceExtends());
  4305. } while (this.eat(12));
  4306. }
  4307. node.body = this.flowParseObjectType({
  4308. allowStatic: isClass,
  4309. allowExact: false,
  4310. allowSpread: false,
  4311. allowProto: isClass,
  4312. allowInexact: false
  4313. });
  4314. }
  4315. flowParseInterfaceExtends() {
  4316. const node = this.startNode();
  4317. node.id = this.flowParseQualifiedTypeIdentifier();
  4318. if (this.match(47)) {
  4319. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4320. } else {
  4321. node.typeParameters = null;
  4322. }
  4323. return this.finishNode(node, "InterfaceExtends");
  4324. }
  4325. flowParseInterface(node) {
  4326. this.flowParseInterfaceish(node);
  4327. return this.finishNode(node, "InterfaceDeclaration");
  4328. }
  4329. checkNotUnderscore(word) {
  4330. if (word === "_") {
  4331. this.raise(FlowErrors.UnexpectedReservedUnderscore, {
  4332. at: this.state.startLoc
  4333. });
  4334. }
  4335. }
  4336. checkReservedType(word, startLoc, declaration) {
  4337. if (!reservedTypes.has(word)) return;
  4338. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
  4339. at: startLoc,
  4340. reservedType: word
  4341. });
  4342. }
  4343. flowParseRestrictedIdentifier(liberal, declaration) {
  4344. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4345. return this.parseIdentifier(liberal);
  4346. }
  4347. flowParseTypeAlias(node) {
  4348. node.id = this.flowParseRestrictedIdentifier(false, true);
  4349. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  4350. if (this.match(47)) {
  4351. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4352. } else {
  4353. node.typeParameters = null;
  4354. }
  4355. node.right = this.flowParseTypeInitialiser(29);
  4356. this.semicolon();
  4357. return this.finishNode(node, "TypeAlias");
  4358. }
  4359. flowParseOpaqueType(node, declare) {
  4360. this.expectContextual(128);
  4361. node.id = this.flowParseRestrictedIdentifier(true, true);
  4362. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  4363. if (this.match(47)) {
  4364. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4365. } else {
  4366. node.typeParameters = null;
  4367. }
  4368. node.supertype = null;
  4369. if (this.match(14)) {
  4370. node.supertype = this.flowParseTypeInitialiser(14);
  4371. }
  4372. node.impltype = null;
  4373. if (!declare) {
  4374. node.impltype = this.flowParseTypeInitialiser(29);
  4375. }
  4376. this.semicolon();
  4377. return this.finishNode(node, "OpaqueType");
  4378. }
  4379. flowParseTypeParameter(requireDefault = false) {
  4380. const nodeStartLoc = this.state.startLoc;
  4381. const node = this.startNode();
  4382. const variance = this.flowParseVariance();
  4383. const ident = this.flowParseTypeAnnotatableIdentifier();
  4384. node.name = ident.name;
  4385. node.variance = variance;
  4386. node.bound = ident.typeAnnotation;
  4387. if (this.match(29)) {
  4388. this.eat(29);
  4389. node.default = this.flowParseType();
  4390. } else {
  4391. if (requireDefault) {
  4392. this.raise(FlowErrors.MissingTypeParamDefault, {
  4393. at: nodeStartLoc
  4394. });
  4395. }
  4396. }
  4397. return this.finishNode(node, "TypeParameter");
  4398. }
  4399. flowParseTypeParameterDeclaration() {
  4400. const oldInType = this.state.inType;
  4401. const node = this.startNode();
  4402. node.params = [];
  4403. this.state.inType = true;
  4404. if (this.match(47) || this.match(140)) {
  4405. this.next();
  4406. } else {
  4407. this.unexpected();
  4408. }
  4409. let defaultRequired = false;
  4410. do {
  4411. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4412. node.params.push(typeParameter);
  4413. if (typeParameter.default) {
  4414. defaultRequired = true;
  4415. }
  4416. if (!this.match(48)) {
  4417. this.expect(12);
  4418. }
  4419. } while (!this.match(48));
  4420. this.expect(48);
  4421. this.state.inType = oldInType;
  4422. return this.finishNode(node, "TypeParameterDeclaration");
  4423. }
  4424. flowParseTypeParameterInstantiation() {
  4425. const node = this.startNode();
  4426. const oldInType = this.state.inType;
  4427. node.params = [];
  4428. this.state.inType = true;
  4429. this.expect(47);
  4430. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4431. this.state.noAnonFunctionType = false;
  4432. while (!this.match(48)) {
  4433. node.params.push(this.flowParseType());
  4434. if (!this.match(48)) {
  4435. this.expect(12);
  4436. }
  4437. }
  4438. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4439. this.expect(48);
  4440. this.state.inType = oldInType;
  4441. return this.finishNode(node, "TypeParameterInstantiation");
  4442. }
  4443. flowParseTypeParameterInstantiationCallOrNew() {
  4444. const node = this.startNode();
  4445. const oldInType = this.state.inType;
  4446. node.params = [];
  4447. this.state.inType = true;
  4448. this.expect(47);
  4449. while (!this.match(48)) {
  4450. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4451. if (!this.match(48)) {
  4452. this.expect(12);
  4453. }
  4454. }
  4455. this.expect(48);
  4456. this.state.inType = oldInType;
  4457. return this.finishNode(node, "TypeParameterInstantiation");
  4458. }
  4459. flowParseInterfaceType() {
  4460. const node = this.startNode();
  4461. this.expectContextual(127);
  4462. node.extends = [];
  4463. if (this.eat(81)) {
  4464. do {
  4465. node.extends.push(this.flowParseInterfaceExtends());
  4466. } while (this.eat(12));
  4467. }
  4468. node.body = this.flowParseObjectType({
  4469. allowStatic: false,
  4470. allowExact: false,
  4471. allowSpread: false,
  4472. allowProto: false,
  4473. allowInexact: false
  4474. });
  4475. return this.finishNode(node, "InterfaceTypeAnnotation");
  4476. }
  4477. flowParseObjectPropertyKey() {
  4478. return this.match(132) || this.match(131) ? super.parseExprAtom() : this.parseIdentifier(true);
  4479. }
  4480. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4481. node.static = isStatic;
  4482. if (this.lookahead().type === 14) {
  4483. node.id = this.flowParseObjectPropertyKey();
  4484. node.key = this.flowParseTypeInitialiser();
  4485. } else {
  4486. node.id = null;
  4487. node.key = this.flowParseType();
  4488. }
  4489. this.expect(3);
  4490. node.value = this.flowParseTypeInitialiser();
  4491. node.variance = variance;
  4492. return this.finishNode(node, "ObjectTypeIndexer");
  4493. }
  4494. flowParseObjectTypeInternalSlot(node, isStatic) {
  4495. node.static = isStatic;
  4496. node.id = this.flowParseObjectPropertyKey();
  4497. this.expect(3);
  4498. this.expect(3);
  4499. if (this.match(47) || this.match(10)) {
  4500. node.method = true;
  4501. node.optional = false;
  4502. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4503. } else {
  4504. node.method = false;
  4505. if (this.eat(17)) {
  4506. node.optional = true;
  4507. }
  4508. node.value = this.flowParseTypeInitialiser();
  4509. }
  4510. return this.finishNode(node, "ObjectTypeInternalSlot");
  4511. }
  4512. flowParseObjectTypeMethodish(node) {
  4513. node.params = [];
  4514. node.rest = null;
  4515. node.typeParameters = null;
  4516. node.this = null;
  4517. if (this.match(47)) {
  4518. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4519. }
  4520. this.expect(10);
  4521. if (this.match(78)) {
  4522. node.this = this.flowParseFunctionTypeParam(true);
  4523. node.this.name = null;
  4524. if (!this.match(11)) {
  4525. this.expect(12);
  4526. }
  4527. }
  4528. while (!this.match(11) && !this.match(21)) {
  4529. node.params.push(this.flowParseFunctionTypeParam(false));
  4530. if (!this.match(11)) {
  4531. this.expect(12);
  4532. }
  4533. }
  4534. if (this.eat(21)) {
  4535. node.rest = this.flowParseFunctionTypeParam(false);
  4536. }
  4537. this.expect(11);
  4538. node.returnType = this.flowParseTypeInitialiser();
  4539. return this.finishNode(node, "FunctionTypeAnnotation");
  4540. }
  4541. flowParseObjectTypeCallProperty(node, isStatic) {
  4542. const valueNode = this.startNode();
  4543. node.static = isStatic;
  4544. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4545. return this.finishNode(node, "ObjectTypeCallProperty");
  4546. }
  4547. flowParseObjectType({
  4548. allowStatic,
  4549. allowExact,
  4550. allowSpread,
  4551. allowProto,
  4552. allowInexact
  4553. }) {
  4554. const oldInType = this.state.inType;
  4555. this.state.inType = true;
  4556. const nodeStart = this.startNode();
  4557. nodeStart.callProperties = [];
  4558. nodeStart.properties = [];
  4559. nodeStart.indexers = [];
  4560. nodeStart.internalSlots = [];
  4561. let endDelim;
  4562. let exact;
  4563. let inexact = false;
  4564. if (allowExact && this.match(6)) {
  4565. this.expect(6);
  4566. endDelim = 9;
  4567. exact = true;
  4568. } else {
  4569. this.expect(5);
  4570. endDelim = 8;
  4571. exact = false;
  4572. }
  4573. nodeStart.exact = exact;
  4574. while (!this.match(endDelim)) {
  4575. let isStatic = false;
  4576. let protoStartLoc = null;
  4577. let inexactStartLoc = null;
  4578. const node = this.startNode();
  4579. if (allowProto && this.isContextual(116)) {
  4580. const lookahead = this.lookahead();
  4581. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4582. this.next();
  4583. protoStartLoc = this.state.startLoc;
  4584. allowStatic = false;
  4585. }
  4586. }
  4587. if (allowStatic && this.isContextual(104)) {
  4588. const lookahead = this.lookahead();
  4589. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4590. this.next();
  4591. isStatic = true;
  4592. }
  4593. }
  4594. const variance = this.flowParseVariance();
  4595. if (this.eat(0)) {
  4596. if (protoStartLoc != null) {
  4597. this.unexpected(protoStartLoc);
  4598. }
  4599. if (this.eat(0)) {
  4600. if (variance) {
  4601. this.unexpected(variance.loc.start);
  4602. }
  4603. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4604. } else {
  4605. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4606. }
  4607. } else if (this.match(10) || this.match(47)) {
  4608. if (protoStartLoc != null) {
  4609. this.unexpected(protoStartLoc);
  4610. }
  4611. if (variance) {
  4612. this.unexpected(variance.loc.start);
  4613. }
  4614. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4615. } else {
  4616. let kind = "init";
  4617. if (this.isContextual(98) || this.isContextual(103)) {
  4618. const lookahead = this.lookahead();
  4619. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4620. kind = this.state.value;
  4621. this.next();
  4622. }
  4623. }
  4624. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4625. if (propOrInexact === null) {
  4626. inexact = true;
  4627. inexactStartLoc = this.state.lastTokStartLoc;
  4628. } else {
  4629. nodeStart.properties.push(propOrInexact);
  4630. }
  4631. }
  4632. this.flowObjectTypeSemicolon();
  4633. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4634. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
  4635. at: inexactStartLoc
  4636. });
  4637. }
  4638. }
  4639. this.expect(endDelim);
  4640. if (allowSpread) {
  4641. nodeStart.inexact = inexact;
  4642. }
  4643. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4644. this.state.inType = oldInType;
  4645. return out;
  4646. }
  4647. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4648. if (this.eat(21)) {
  4649. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4650. if (isInexactToken) {
  4651. if (!allowSpread) {
  4652. this.raise(FlowErrors.InexactInsideNonObject, {
  4653. at: this.state.lastTokStartLoc
  4654. });
  4655. } else if (!allowInexact) {
  4656. this.raise(FlowErrors.InexactInsideExact, {
  4657. at: this.state.lastTokStartLoc
  4658. });
  4659. }
  4660. if (variance) {
  4661. this.raise(FlowErrors.InexactVariance, {
  4662. at: variance
  4663. });
  4664. }
  4665. return null;
  4666. }
  4667. if (!allowSpread) {
  4668. this.raise(FlowErrors.UnexpectedSpreadType, {
  4669. at: this.state.lastTokStartLoc
  4670. });
  4671. }
  4672. if (protoStartLoc != null) {
  4673. this.unexpected(protoStartLoc);
  4674. }
  4675. if (variance) {
  4676. this.raise(FlowErrors.SpreadVariance, {
  4677. at: variance
  4678. });
  4679. }
  4680. node.argument = this.flowParseType();
  4681. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4682. } else {
  4683. node.key = this.flowParseObjectPropertyKey();
  4684. node.static = isStatic;
  4685. node.proto = protoStartLoc != null;
  4686. node.kind = kind;
  4687. let optional = false;
  4688. if (this.match(47) || this.match(10)) {
  4689. node.method = true;
  4690. if (protoStartLoc != null) {
  4691. this.unexpected(protoStartLoc);
  4692. }
  4693. if (variance) {
  4694. this.unexpected(variance.loc.start);
  4695. }
  4696. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4697. if (kind === "get" || kind === "set") {
  4698. this.flowCheckGetterSetterParams(node);
  4699. }
  4700. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4701. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  4702. at: node.value.this
  4703. });
  4704. }
  4705. } else {
  4706. if (kind !== "init") this.unexpected();
  4707. node.method = false;
  4708. if (this.eat(17)) {
  4709. optional = true;
  4710. }
  4711. node.value = this.flowParseTypeInitialiser();
  4712. node.variance = variance;
  4713. }
  4714. node.optional = optional;
  4715. return this.finishNode(node, "ObjectTypeProperty");
  4716. }
  4717. }
  4718. flowCheckGetterSetterParams(property) {
  4719. const paramCount = property.kind === "get" ? 0 : 1;
  4720. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4721. if (property.value.this) {
  4722. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
  4723. at: property.value.this
  4724. });
  4725. }
  4726. if (length !== paramCount) {
  4727. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  4728. at: property
  4729. });
  4730. }
  4731. if (property.kind === "set" && property.value.rest) {
  4732. this.raise(Errors.BadSetterRestParameter, {
  4733. at: property
  4734. });
  4735. }
  4736. }
  4737. flowObjectTypeSemicolon() {
  4738. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4739. this.unexpected();
  4740. }
  4741. }
  4742. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4743. var _startLoc;
  4744. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4745. let node = id || this.flowParseRestrictedIdentifier(true);
  4746. while (this.eat(16)) {
  4747. const node2 = this.startNodeAt(startLoc);
  4748. node2.qualification = node;
  4749. node2.id = this.flowParseRestrictedIdentifier(true);
  4750. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4751. }
  4752. return node;
  4753. }
  4754. flowParseGenericType(startLoc, id) {
  4755. const node = this.startNodeAt(startLoc);
  4756. node.typeParameters = null;
  4757. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4758. if (this.match(47)) {
  4759. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4760. }
  4761. return this.finishNode(node, "GenericTypeAnnotation");
  4762. }
  4763. flowParseTypeofType() {
  4764. const node = this.startNode();
  4765. this.expect(87);
  4766. node.argument = this.flowParsePrimaryType();
  4767. return this.finishNode(node, "TypeofTypeAnnotation");
  4768. }
  4769. flowParseTupleType() {
  4770. const node = this.startNode();
  4771. node.types = [];
  4772. this.expect(0);
  4773. while (this.state.pos < this.length && !this.match(3)) {
  4774. node.types.push(this.flowParseType());
  4775. if (this.match(3)) break;
  4776. this.expect(12);
  4777. }
  4778. this.expect(3);
  4779. return this.finishNode(node, "TupleTypeAnnotation");
  4780. }
  4781. flowParseFunctionTypeParam(first) {
  4782. let name = null;
  4783. let optional = false;
  4784. let typeAnnotation = null;
  4785. const node = this.startNode();
  4786. const lh = this.lookahead();
  4787. const isThis = this.state.type === 78;
  4788. if (lh.type === 14 || lh.type === 17) {
  4789. if (isThis && !first) {
  4790. this.raise(FlowErrors.ThisParamMustBeFirst, {
  4791. at: node
  4792. });
  4793. }
  4794. name = this.parseIdentifier(isThis);
  4795. if (this.eat(17)) {
  4796. optional = true;
  4797. if (isThis) {
  4798. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  4799. at: node
  4800. });
  4801. }
  4802. }
  4803. typeAnnotation = this.flowParseTypeInitialiser();
  4804. } else {
  4805. typeAnnotation = this.flowParseType();
  4806. }
  4807. node.name = name;
  4808. node.optional = optional;
  4809. node.typeAnnotation = typeAnnotation;
  4810. return this.finishNode(node, "FunctionTypeParam");
  4811. }
  4812. reinterpretTypeAsFunctionTypeParam(type) {
  4813. const node = this.startNodeAt(type.loc.start);
  4814. node.name = null;
  4815. node.optional = false;
  4816. node.typeAnnotation = type;
  4817. return this.finishNode(node, "FunctionTypeParam");
  4818. }
  4819. flowParseFunctionTypeParams(params = []) {
  4820. let rest = null;
  4821. let _this = null;
  4822. if (this.match(78)) {
  4823. _this = this.flowParseFunctionTypeParam(true);
  4824. _this.name = null;
  4825. if (!this.match(11)) {
  4826. this.expect(12);
  4827. }
  4828. }
  4829. while (!this.match(11) && !this.match(21)) {
  4830. params.push(this.flowParseFunctionTypeParam(false));
  4831. if (!this.match(11)) {
  4832. this.expect(12);
  4833. }
  4834. }
  4835. if (this.eat(21)) {
  4836. rest = this.flowParseFunctionTypeParam(false);
  4837. }
  4838. return {
  4839. params,
  4840. rest,
  4841. _this
  4842. };
  4843. }
  4844. flowIdentToTypeAnnotation(startLoc, node, id) {
  4845. switch (id.name) {
  4846. case "any":
  4847. return this.finishNode(node, "AnyTypeAnnotation");
  4848. case "bool":
  4849. case "boolean":
  4850. return this.finishNode(node, "BooleanTypeAnnotation");
  4851. case "mixed":
  4852. return this.finishNode(node, "MixedTypeAnnotation");
  4853. case "empty":
  4854. return this.finishNode(node, "EmptyTypeAnnotation");
  4855. case "number":
  4856. return this.finishNode(node, "NumberTypeAnnotation");
  4857. case "string":
  4858. return this.finishNode(node, "StringTypeAnnotation");
  4859. case "symbol":
  4860. return this.finishNode(node, "SymbolTypeAnnotation");
  4861. default:
  4862. this.checkNotUnderscore(id.name);
  4863. return this.flowParseGenericType(startLoc, id);
  4864. }
  4865. }
  4866. flowParsePrimaryType() {
  4867. const startLoc = this.state.startLoc;
  4868. const node = this.startNode();
  4869. let tmp;
  4870. let type;
  4871. let isGroupedType = false;
  4872. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4873. switch (this.state.type) {
  4874. case 5:
  4875. return this.flowParseObjectType({
  4876. allowStatic: false,
  4877. allowExact: false,
  4878. allowSpread: true,
  4879. allowProto: false,
  4880. allowInexact: true
  4881. });
  4882. case 6:
  4883. return this.flowParseObjectType({
  4884. allowStatic: false,
  4885. allowExact: true,
  4886. allowSpread: true,
  4887. allowProto: false,
  4888. allowInexact: false
  4889. });
  4890. case 0:
  4891. this.state.noAnonFunctionType = false;
  4892. type = this.flowParseTupleType();
  4893. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4894. return type;
  4895. case 47:
  4896. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4897. this.expect(10);
  4898. tmp = this.flowParseFunctionTypeParams();
  4899. node.params = tmp.params;
  4900. node.rest = tmp.rest;
  4901. node.this = tmp._this;
  4902. this.expect(11);
  4903. this.expect(19);
  4904. node.returnType = this.flowParseType();
  4905. return this.finishNode(node, "FunctionTypeAnnotation");
  4906. case 10:
  4907. this.next();
  4908. if (!this.match(11) && !this.match(21)) {
  4909. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4910. const token = this.lookahead().type;
  4911. isGroupedType = token !== 17 && token !== 14;
  4912. } else {
  4913. isGroupedType = true;
  4914. }
  4915. }
  4916. if (isGroupedType) {
  4917. this.state.noAnonFunctionType = false;
  4918. type = this.flowParseType();
  4919. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4920. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4921. this.expect(11);
  4922. return type;
  4923. } else {
  4924. this.eat(12);
  4925. }
  4926. }
  4927. if (type) {
  4928. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4929. } else {
  4930. tmp = this.flowParseFunctionTypeParams();
  4931. }
  4932. node.params = tmp.params;
  4933. node.rest = tmp.rest;
  4934. node.this = tmp._this;
  4935. this.expect(11);
  4936. this.expect(19);
  4937. node.returnType = this.flowParseType();
  4938. node.typeParameters = null;
  4939. return this.finishNode(node, "FunctionTypeAnnotation");
  4940. case 131:
  4941. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4942. case 85:
  4943. case 86:
  4944. node.value = this.match(85);
  4945. this.next();
  4946. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4947. case 53:
  4948. if (this.state.value === "-") {
  4949. this.next();
  4950. if (this.match(132)) {
  4951. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4952. }
  4953. if (this.match(133)) {
  4954. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4955. }
  4956. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
  4957. at: this.state.startLoc
  4958. });
  4959. }
  4960. throw this.unexpected();
  4961. case 132:
  4962. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4963. case 133:
  4964. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4965. case 88:
  4966. this.next();
  4967. return this.finishNode(node, "VoidTypeAnnotation");
  4968. case 84:
  4969. this.next();
  4970. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4971. case 78:
  4972. this.next();
  4973. return this.finishNode(node, "ThisTypeAnnotation");
  4974. case 55:
  4975. this.next();
  4976. return this.finishNode(node, "ExistsTypeAnnotation");
  4977. case 87:
  4978. return this.flowParseTypeofType();
  4979. default:
  4980. if (tokenIsKeyword(this.state.type)) {
  4981. const label = tokenLabelName(this.state.type);
  4982. this.next();
  4983. return super.createIdentifier(node, label);
  4984. } else if (tokenIsIdentifier(this.state.type)) {
  4985. if (this.isContextual(127)) {
  4986. return this.flowParseInterfaceType();
  4987. }
  4988. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4989. }
  4990. }
  4991. throw this.unexpected();
  4992. }
  4993. flowParsePostfixType() {
  4994. const startLoc = this.state.startLoc;
  4995. let type = this.flowParsePrimaryType();
  4996. let seenOptionalIndexedAccess = false;
  4997. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4998. const node = this.startNodeAt(startLoc);
  4999. const optional = this.eat(18);
  5000. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  5001. this.expect(0);
  5002. if (!optional && this.match(3)) {
  5003. node.elementType = type;
  5004. this.next();
  5005. type = this.finishNode(node, "ArrayTypeAnnotation");
  5006. } else {
  5007. node.objectType = type;
  5008. node.indexType = this.flowParseType();
  5009. this.expect(3);
  5010. if (seenOptionalIndexedAccess) {
  5011. node.optional = optional;
  5012. type = this.finishNode(
  5013. node, "OptionalIndexedAccessType");
  5014. } else {
  5015. type = this.finishNode(
  5016. node, "IndexedAccessType");
  5017. }
  5018. }
  5019. }
  5020. return type;
  5021. }
  5022. flowParsePrefixType() {
  5023. const node = this.startNode();
  5024. if (this.eat(17)) {
  5025. node.typeAnnotation = this.flowParsePrefixType();
  5026. return this.finishNode(node, "NullableTypeAnnotation");
  5027. } else {
  5028. return this.flowParsePostfixType();
  5029. }
  5030. }
  5031. flowParseAnonFunctionWithoutParens() {
  5032. const param = this.flowParsePrefixType();
  5033. if (!this.state.noAnonFunctionType && this.eat(19)) {
  5034. const node = this.startNodeAt(param.loc.start);
  5035. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  5036. node.rest = null;
  5037. node.this = null;
  5038. node.returnType = this.flowParseType();
  5039. node.typeParameters = null;
  5040. return this.finishNode(node, "FunctionTypeAnnotation");
  5041. }
  5042. return param;
  5043. }
  5044. flowParseIntersectionType() {
  5045. const node = this.startNode();
  5046. this.eat(45);
  5047. const type = this.flowParseAnonFunctionWithoutParens();
  5048. node.types = [type];
  5049. while (this.eat(45)) {
  5050. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5051. }
  5052. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5053. }
  5054. flowParseUnionType() {
  5055. const node = this.startNode();
  5056. this.eat(43);
  5057. const type = this.flowParseIntersectionType();
  5058. node.types = [type];
  5059. while (this.eat(43)) {
  5060. node.types.push(this.flowParseIntersectionType());
  5061. }
  5062. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5063. }
  5064. flowParseType() {
  5065. const oldInType = this.state.inType;
  5066. this.state.inType = true;
  5067. const type = this.flowParseUnionType();
  5068. this.state.inType = oldInType;
  5069. return type;
  5070. }
  5071. flowParseTypeOrImplicitInstantiation() {
  5072. if (this.state.type === 130 && this.state.value === "_") {
  5073. const startLoc = this.state.startLoc;
  5074. const node = this.parseIdentifier();
  5075. return this.flowParseGenericType(startLoc, node);
  5076. } else {
  5077. return this.flowParseType();
  5078. }
  5079. }
  5080. flowParseTypeAnnotation() {
  5081. const node = this.startNode();
  5082. node.typeAnnotation = this.flowParseTypeInitialiser();
  5083. return this.finishNode(node, "TypeAnnotation");
  5084. }
  5085. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5086. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5087. if (this.match(14)) {
  5088. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5089. this.resetEndLocation(ident);
  5090. }
  5091. return ident;
  5092. }
  5093. typeCastToParameter(node) {
  5094. node.expression.typeAnnotation = node.typeAnnotation;
  5095. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5096. return node.expression;
  5097. }
  5098. flowParseVariance() {
  5099. let variance = null;
  5100. if (this.match(53)) {
  5101. variance = this.startNode();
  5102. if (this.state.value === "+") {
  5103. variance.kind = "plus";
  5104. } else {
  5105. variance.kind = "minus";
  5106. }
  5107. this.next();
  5108. return this.finishNode(variance, "Variance");
  5109. }
  5110. return variance;
  5111. }
  5112. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5113. if (allowExpressionBody) {
  5114. return this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5115. }
  5116. return super.parseFunctionBody(node, false, isMethod);
  5117. }
  5118. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5119. if (this.match(14)) {
  5120. const typeNode = this.startNode();
  5121. [typeNode.typeAnnotation,
  5122. node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5123. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5124. }
  5125. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5126. }
  5127. parseStatement(context, topLevel) {
  5128. if (this.state.strict && this.isContextual(127)) {
  5129. const lookahead = this.lookahead();
  5130. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5131. const node = this.startNode();
  5132. this.next();
  5133. return this.flowParseInterface(node);
  5134. }
  5135. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  5136. const node = this.startNode();
  5137. this.next();
  5138. return this.flowParseEnumDeclaration(node);
  5139. }
  5140. const stmt = super.parseStatement(context, topLevel);
  5141. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5142. this.flowPragma = null;
  5143. }
  5144. return stmt;
  5145. }
  5146. parseExpressionStatement(node, expr, decorators) {
  5147. if (expr.type === "Identifier") {
  5148. if (expr.name === "declare") {
  5149. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5150. return this.flowParseDeclare(node);
  5151. }
  5152. } else if (tokenIsIdentifier(this.state.type)) {
  5153. if (expr.name === "interface") {
  5154. return this.flowParseInterface(node);
  5155. } else if (expr.name === "type") {
  5156. return this.flowParseTypeAlias(node);
  5157. } else if (expr.name === "opaque") {
  5158. return this.flowParseOpaqueType(node, false);
  5159. }
  5160. }
  5161. }
  5162. return super.parseExpressionStatement(node, expr, decorators);
  5163. }
  5164. shouldParseExportDeclaration() {
  5165. const {
  5166. type
  5167. } = this.state;
  5168. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5169. return !this.state.containsEsc;
  5170. }
  5171. return super.shouldParseExportDeclaration();
  5172. }
  5173. isExportDefaultSpecifier() {
  5174. const {
  5175. type
  5176. } = this.state;
  5177. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5178. return this.state.containsEsc;
  5179. }
  5180. return super.isExportDefaultSpecifier();
  5181. }
  5182. parseExportDefaultExpression() {
  5183. if (this.shouldParseEnums() && this.isContextual(124)) {
  5184. const node = this.startNode();
  5185. this.next();
  5186. return this.flowParseEnumDeclaration(node);
  5187. }
  5188. return super.parseExportDefaultExpression();
  5189. }
  5190. parseConditional(expr, startLoc, refExpressionErrors) {
  5191. if (!this.match(17)) return expr;
  5192. if (this.state.maybeInArrowParameters) {
  5193. const nextCh = this.lookaheadCharCode();
  5194. if (nextCh === 44 ||
  5195. nextCh === 61 ||
  5196. nextCh === 58 ||
  5197. nextCh === 41) {
  5198. this.setOptionalParametersError(refExpressionErrors);
  5199. return expr;
  5200. }
  5201. }
  5202. this.expect(17);
  5203. const state = this.state.clone();
  5204. const originalNoArrowAt = this.state.noArrowAt;
  5205. const node = this.startNodeAt(startLoc);
  5206. let {
  5207. consequent,
  5208. failed
  5209. } = this.tryParseConditionalConsequent();
  5210. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5211. if (failed || invalid.length > 0) {
  5212. const noArrowAt = [...originalNoArrowAt];
  5213. if (invalid.length > 0) {
  5214. this.state = state;
  5215. this.state.noArrowAt = noArrowAt;
  5216. for (let i = 0; i < invalid.length; i++) {
  5217. noArrowAt.push(invalid[i].start);
  5218. }
  5219. ({
  5220. consequent,
  5221. failed
  5222. } = this.tryParseConditionalConsequent());
  5223. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5224. }
  5225. if (failed && valid.length > 1) {
  5226. this.raise(FlowErrors.AmbiguousConditionalArrow, {
  5227. at: state.startLoc
  5228. });
  5229. }
  5230. if (failed && valid.length === 1) {
  5231. this.state = state;
  5232. noArrowAt.push(valid[0].start);
  5233. this.state.noArrowAt = noArrowAt;
  5234. ({
  5235. consequent,
  5236. failed
  5237. } = this.tryParseConditionalConsequent());
  5238. }
  5239. }
  5240. this.getArrowLikeExpressions(consequent, true);
  5241. this.state.noArrowAt = originalNoArrowAt;
  5242. this.expect(14);
  5243. node.test = expr;
  5244. node.consequent = consequent;
  5245. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5246. return this.finishNode(node, "ConditionalExpression");
  5247. }
  5248. tryParseConditionalConsequent() {
  5249. this.state.noArrowParamsConversionAt.push(this.state.start);
  5250. const consequent = this.parseMaybeAssignAllowIn();
  5251. const failed = !this.match(14);
  5252. this.state.noArrowParamsConversionAt.pop();
  5253. return {
  5254. consequent,
  5255. failed
  5256. };
  5257. }
  5258. getArrowLikeExpressions(node, disallowInvalid) {
  5259. const stack = [node];
  5260. const arrows = [];
  5261. while (stack.length !== 0) {
  5262. const node = stack.pop();
  5263. if (node.type === "ArrowFunctionExpression") {
  5264. if (node.typeParameters || !node.returnType) {
  5265. this.finishArrowValidation(node);
  5266. } else {
  5267. arrows.push(node);
  5268. }
  5269. stack.push(node.body);
  5270. } else if (node.type === "ConditionalExpression") {
  5271. stack.push(node.consequent);
  5272. stack.push(node.alternate);
  5273. }
  5274. }
  5275. if (disallowInvalid) {
  5276. arrows.forEach(node => this.finishArrowValidation(node));
  5277. return [arrows, []];
  5278. }
  5279. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5280. }
  5281. finishArrowValidation(node) {
  5282. var _node$extra;
  5283. this.toAssignableList(
  5284. node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5285. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  5286. super.checkParams(node, false, true);
  5287. this.scope.exit();
  5288. }
  5289. forwardNoArrowParamsConversionAt(node, parse) {
  5290. let result;
  5291. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5292. this.state.noArrowParamsConversionAt.push(this.state.start);
  5293. result = parse();
  5294. this.state.noArrowParamsConversionAt.pop();
  5295. } else {
  5296. result = parse();
  5297. }
  5298. return result;
  5299. }
  5300. parseParenItem(node, startLoc) {
  5301. node = super.parseParenItem(node, startLoc);
  5302. if (this.eat(17)) {
  5303. node.optional = true;
  5304. this.resetEndLocation(node);
  5305. }
  5306. if (this.match(14)) {
  5307. const typeCastNode = this.startNodeAt(startLoc);
  5308. typeCastNode.expression = node;
  5309. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5310. return this.finishNode(typeCastNode, "TypeCastExpression");
  5311. }
  5312. return node;
  5313. }
  5314. assertModuleNodeAllowed(node) {
  5315. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5316. return;
  5317. }
  5318. super.assertModuleNodeAllowed(node);
  5319. }
  5320. parseExport(node, decorators) {
  5321. const decl = super.parseExport(node, decorators);
  5322. if (decl.type === "ExportNamedDeclaration" || decl.type === "ExportAllDeclaration") {
  5323. decl.exportKind = decl.exportKind || "value";
  5324. }
  5325. return decl;
  5326. }
  5327. parseExportDeclaration(node) {
  5328. if (this.isContextual(128)) {
  5329. node.exportKind = "type";
  5330. const declarationNode = this.startNode();
  5331. this.next();
  5332. if (this.match(5)) {
  5333. node.specifiers = this.parseExportSpecifiers(true);
  5334. super.parseExportFrom(node);
  5335. return null;
  5336. } else {
  5337. return this.flowParseTypeAlias(declarationNode);
  5338. }
  5339. } else if (this.isContextual(129)) {
  5340. node.exportKind = "type";
  5341. const declarationNode = this.startNode();
  5342. this.next();
  5343. return this.flowParseOpaqueType(declarationNode, false);
  5344. } else if (this.isContextual(127)) {
  5345. node.exportKind = "type";
  5346. const declarationNode = this.startNode();
  5347. this.next();
  5348. return this.flowParseInterface(declarationNode);
  5349. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  5350. node.exportKind = "value";
  5351. const declarationNode = this.startNode();
  5352. this.next();
  5353. return this.flowParseEnumDeclaration(declarationNode);
  5354. } else {
  5355. return super.parseExportDeclaration(node);
  5356. }
  5357. }
  5358. eatExportStar(node) {
  5359. if (super.eatExportStar(node)) return true;
  5360. if (this.isContextual(128) && this.lookahead().type === 55) {
  5361. node.exportKind = "type";
  5362. this.next();
  5363. this.next();
  5364. return true;
  5365. }
  5366. return false;
  5367. }
  5368. maybeParseExportNamespaceSpecifier(node) {
  5369. const {
  5370. startLoc
  5371. } = this.state;
  5372. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5373. if (hasNamespace && node.exportKind === "type") {
  5374. this.unexpected(startLoc);
  5375. }
  5376. return hasNamespace;
  5377. }
  5378. parseClassId(node, isStatement, optionalId) {
  5379. super.parseClassId(node, isStatement, optionalId);
  5380. if (this.match(47)) {
  5381. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5382. }
  5383. }
  5384. parseClassMember(classBody, member, state) {
  5385. const {
  5386. startLoc
  5387. } = this.state;
  5388. if (this.isContextual(123)) {
  5389. if (super.parseClassMemberFromModifier(classBody, member)) {
  5390. return;
  5391. }
  5392. member.declare = true;
  5393. }
  5394. super.parseClassMember(classBody, member, state);
  5395. if (member.declare) {
  5396. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5397. this.raise(FlowErrors.DeclareClassElement, {
  5398. at: startLoc
  5399. });
  5400. } else if (member.value) {
  5401. this.raise(FlowErrors.DeclareClassFieldInitializer, {
  5402. at: member.value
  5403. });
  5404. }
  5405. }
  5406. }
  5407. isIterator(word) {
  5408. return word === "iterator" || word === "asyncIterator";
  5409. }
  5410. readIterator() {
  5411. const word = super.readWord1();
  5412. const fullWord = "@@" + word;
  5413. if (!this.isIterator(word) || !this.state.inType) {
  5414. this.raise(Errors.InvalidIdentifier, {
  5415. at: this.state.curPosition(),
  5416. identifierName: fullWord
  5417. });
  5418. }
  5419. this.finishToken(130, fullWord);
  5420. }
  5421. getTokenFromCode(code) {
  5422. const next = this.input.charCodeAt(this.state.pos + 1);
  5423. if (code === 123 && next === 124) {
  5424. return this.finishOp(6, 2);
  5425. } else if (this.state.inType && (code === 62 || code === 60)) {
  5426. return this.finishOp(code === 62 ? 48 : 47, 1);
  5427. } else if (this.state.inType && code === 63) {
  5428. if (next === 46) {
  5429. return this.finishOp(18, 2);
  5430. }
  5431. return this.finishOp(17, 1);
  5432. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5433. this.state.pos += 2;
  5434. return this.readIterator();
  5435. } else {
  5436. return super.getTokenFromCode(code);
  5437. }
  5438. }
  5439. isAssignable(node, isBinding) {
  5440. if (node.type === "TypeCastExpression") {
  5441. return this.isAssignable(node.expression, isBinding);
  5442. } else {
  5443. return super.isAssignable(node, isBinding);
  5444. }
  5445. }
  5446. toAssignable(node, isLHS = false) {
  5447. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5448. node.left = this.typeCastToParameter(node.left);
  5449. }
  5450. super.toAssignable(node, isLHS);
  5451. }
  5452. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5453. for (let i = 0; i < exprList.length; i++) {
  5454. const expr = exprList[i];
  5455. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5456. exprList[i] = this.typeCastToParameter(expr);
  5457. }
  5458. }
  5459. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5460. }
  5461. toReferencedList(exprList, isParenthesizedExpr) {
  5462. for (let i = 0; i < exprList.length; i++) {
  5463. var _expr$extra;
  5464. const expr = exprList[i];
  5465. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5466. this.raise(FlowErrors.TypeCastInPattern, {
  5467. at: expr.typeAnnotation
  5468. });
  5469. }
  5470. }
  5471. return exprList;
  5472. }
  5473. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5474. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5475. if (canBePattern && !this.state.maybeInArrowParameters) {
  5476. this.toReferencedList(node.elements);
  5477. }
  5478. return node;
  5479. }
  5480. isValidLVal(type, isParenthesized, binding) {
  5481. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5482. }
  5483. parseClassProperty(node) {
  5484. if (this.match(14)) {
  5485. node.typeAnnotation = this.flowParseTypeAnnotation();
  5486. }
  5487. return super.parseClassProperty(node);
  5488. }
  5489. parseClassPrivateProperty(node) {
  5490. if (this.match(14)) {
  5491. node.typeAnnotation = this.flowParseTypeAnnotation();
  5492. }
  5493. return super.parseClassPrivateProperty(node);
  5494. }
  5495. isClassMethod() {
  5496. return this.match(47) || super.isClassMethod();
  5497. }
  5498. isClassProperty() {
  5499. return this.match(14) || super.isClassProperty();
  5500. }
  5501. isNonstaticConstructor(method) {
  5502. return !this.match(14) && super.isNonstaticConstructor(method);
  5503. }
  5504. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5505. if (method.variance) {
  5506. this.unexpected(method.variance.loc.start);
  5507. }
  5508. delete method.variance;
  5509. if (this.match(47)) {
  5510. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5511. }
  5512. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5513. if (method.params && isConstructor) {
  5514. const params = method.params;
  5515. if (params.length > 0 && this.isThisParam(params[0])) {
  5516. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5517. at: method
  5518. });
  5519. }
  5520. } else if (
  5521. method.type === "MethodDefinition" && isConstructor &&
  5522. method.value.params) {
  5523. const params = method.value.params;
  5524. if (params.length > 0 && this.isThisParam(params[0])) {
  5525. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5526. at: method
  5527. });
  5528. }
  5529. }
  5530. }
  5531. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5532. if (method.variance) {
  5533. this.unexpected(method.variance.loc.start);
  5534. }
  5535. delete method.variance;
  5536. if (this.match(47)) {
  5537. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5538. }
  5539. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5540. }
  5541. parseClassSuper(node) {
  5542. super.parseClassSuper(node);
  5543. if (node.superClass && this.match(47)) {
  5544. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  5545. }
  5546. if (this.isContextual(111)) {
  5547. this.next();
  5548. const implemented = node.implements = [];
  5549. do {
  5550. const node = this.startNode();
  5551. node.id = this.flowParseRestrictedIdentifier(true);
  5552. if (this.match(47)) {
  5553. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5554. } else {
  5555. node.typeParameters = null;
  5556. }
  5557. implemented.push(this.finishNode(node, "ClassImplements"));
  5558. } while (this.eat(12));
  5559. }
  5560. }
  5561. checkGetterSetterParams(method) {
  5562. super.checkGetterSetterParams(method);
  5563. const params = this.getObjectOrClassMethodParams(method);
  5564. if (params.length > 0) {
  5565. const param = params[0];
  5566. if (this.isThisParam(param) && method.kind === "get") {
  5567. this.raise(FlowErrors.GetterMayNotHaveThisParam, {
  5568. at: param
  5569. });
  5570. } else if (this.isThisParam(param)) {
  5571. this.raise(FlowErrors.SetterMayNotHaveThisParam, {
  5572. at: param
  5573. });
  5574. }
  5575. }
  5576. }
  5577. parsePropertyNamePrefixOperator(node) {
  5578. node.variance = this.flowParseVariance();
  5579. }
  5580. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5581. if (prop.variance) {
  5582. this.unexpected(prop.variance.loc.start);
  5583. }
  5584. delete prop.variance;
  5585. let typeParameters;
  5586. if (this.match(47) && !isAccessor) {
  5587. typeParameters = this.flowParseTypeParameterDeclaration();
  5588. if (!this.match(10)) this.unexpected();
  5589. }
  5590. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5591. if (typeParameters) {
  5592. (result.value || result).typeParameters = typeParameters;
  5593. }
  5594. return result;
  5595. }
  5596. parseAssignableListItemTypes(param) {
  5597. if (this.eat(17)) {
  5598. if (param.type !== "Identifier") {
  5599. this.raise(FlowErrors.PatternIsOptional, {
  5600. at: param
  5601. });
  5602. }
  5603. if (this.isThisParam(param)) {
  5604. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  5605. at: param
  5606. });
  5607. }
  5608. param.optional = true;
  5609. }
  5610. if (this.match(14)) {
  5611. param.typeAnnotation = this.flowParseTypeAnnotation();
  5612. } else if (this.isThisParam(param)) {
  5613. this.raise(FlowErrors.ThisParamAnnotationRequired, {
  5614. at: param
  5615. });
  5616. }
  5617. if (this.match(29) && this.isThisParam(param)) {
  5618. this.raise(FlowErrors.ThisParamNoDefault, {
  5619. at: param
  5620. });
  5621. }
  5622. this.resetEndLocation(param);
  5623. return param;
  5624. }
  5625. parseMaybeDefault(startLoc, left) {
  5626. const node = super.parseMaybeDefault(startLoc, left);
  5627. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5628. this.raise(FlowErrors.TypeBeforeInitializer, {
  5629. at: node.typeAnnotation
  5630. });
  5631. }
  5632. return node;
  5633. }
  5634. shouldParseDefaultImport(node) {
  5635. if (!hasTypeImportKind(node)) {
  5636. return super.shouldParseDefaultImport(node);
  5637. }
  5638. return isMaybeDefaultImport(this.state.type);
  5639. }
  5640. checkImportReflection(node) {
  5641. super.checkImportReflection(node);
  5642. if (node.module && node.importKind !== "value") {
  5643. this.raise(FlowErrors.ImportReflectionHasImportType, {
  5644. at: node.specifiers[0].loc.start
  5645. });
  5646. }
  5647. }
  5648. parseImportSpecifierLocal(node, specifier, type) {
  5649. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5650. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5651. }
  5652. maybeParseDefaultImportSpecifier(node) {
  5653. node.importKind = "value";
  5654. let kind = null;
  5655. if (this.match(87)) {
  5656. kind = "typeof";
  5657. } else if (this.isContextual(128)) {
  5658. kind = "type";
  5659. }
  5660. if (kind) {
  5661. const lh = this.lookahead();
  5662. const {
  5663. type
  5664. } = lh;
  5665. if (kind === "type" && type === 55) {
  5666. this.unexpected(null, lh.type);
  5667. }
  5668. if (isMaybeDefaultImport(type) || type === 5 || type === 55) {
  5669. this.next();
  5670. node.importKind = kind;
  5671. }
  5672. }
  5673. return super.maybeParseDefaultImportSpecifier(node);
  5674. }
  5675. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport,
  5676. isMaybeTypeOnly,
  5677. bindingType) {
  5678. const firstIdent = specifier.imported;
  5679. let specifierTypeKind = null;
  5680. if (firstIdent.type === "Identifier") {
  5681. if (firstIdent.name === "type") {
  5682. specifierTypeKind = "type";
  5683. } else if (firstIdent.name === "typeof") {
  5684. specifierTypeKind = "typeof";
  5685. }
  5686. }
  5687. let isBinding = false;
  5688. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5689. const as_ident = this.parseIdentifier(true);
  5690. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5691. specifier.imported = as_ident;
  5692. specifier.importKind = specifierTypeKind;
  5693. specifier.local = cloneIdentifier(as_ident);
  5694. } else {
  5695. specifier.imported = firstIdent;
  5696. specifier.importKind = null;
  5697. specifier.local = this.parseIdentifier();
  5698. }
  5699. } else {
  5700. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5701. specifier.imported = this.parseIdentifier(true);
  5702. specifier.importKind = specifierTypeKind;
  5703. } else {
  5704. if (importedIsString) {
  5705. throw this.raise(Errors.ImportBindingIsString, {
  5706. at: specifier,
  5707. importName: firstIdent.value
  5708. });
  5709. }
  5710. specifier.imported = firstIdent;
  5711. specifier.importKind = null;
  5712. }
  5713. if (this.eatContextual(93)) {
  5714. specifier.local = this.parseIdentifier();
  5715. } else {
  5716. isBinding = true;
  5717. specifier.local = cloneIdentifier(specifier.imported);
  5718. }
  5719. }
  5720. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5721. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5722. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
  5723. at: specifier
  5724. });
  5725. }
  5726. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5727. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5728. }
  5729. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5730. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5731. }
  5732. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5733. }
  5734. parseBindingAtom() {
  5735. switch (this.state.type) {
  5736. case 78:
  5737. return this.parseIdentifier(true);
  5738. default:
  5739. return super.parseBindingAtom();
  5740. }
  5741. }
  5742. parseFunctionParams(node, allowModifiers) {
  5743. const kind = node.kind;
  5744. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5745. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5746. }
  5747. super.parseFunctionParams(node, allowModifiers);
  5748. }
  5749. parseVarId(decl, kind) {
  5750. super.parseVarId(decl, kind);
  5751. if (this.match(14)) {
  5752. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5753. this.resetEndLocation(decl.id);
  5754. }
  5755. }
  5756. parseAsyncArrowFromCallExpression(node, call) {
  5757. if (this.match(14)) {
  5758. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5759. this.state.noAnonFunctionType = true;
  5760. node.returnType = this.flowParseTypeAnnotation();
  5761. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5762. }
  5763. return super.parseAsyncArrowFromCallExpression(node, call);
  5764. }
  5765. shouldParseAsyncArrow() {
  5766. return this.match(14) || super.shouldParseAsyncArrow();
  5767. }
  5768. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5769. var _jsx;
  5770. let state = null;
  5771. let jsx;
  5772. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  5773. state = this.state.clone();
  5774. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5775. if (!jsx.error) return jsx.node;
  5776. const {
  5777. context
  5778. } = this.state;
  5779. const currentContext = context[context.length - 1];
  5780. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5781. context.pop();
  5782. }
  5783. }
  5784. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5785. var _jsx2, _jsx3;
  5786. state = state || this.state.clone();
  5787. let typeParameters;
  5788. const arrow = this.tryParse(abort => {
  5789. var _arrowExpression$extr;
  5790. typeParameters = this.flowParseTypeParameterDeclaration();
  5791. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5792. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5793. this.resetStartLocationFromNode(result, typeParameters);
  5794. return result;
  5795. });
  5796. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5797. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5798. if (expr.type !== "ArrowFunctionExpression") abort();
  5799. expr.typeParameters = typeParameters;
  5800. this.resetStartLocationFromNode(expr, typeParameters);
  5801. return arrowExpression;
  5802. }, state);
  5803. let arrowExpression = null;
  5804. if (arrow.node &&
  5805. this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5806. if (!arrow.error && !arrow.aborted) {
  5807. if (arrow.node.async) {
  5808. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
  5809. at: typeParameters
  5810. });
  5811. }
  5812. return arrow.node;
  5813. }
  5814. arrowExpression = arrow.node;
  5815. }
  5816. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5817. this.state = jsx.failState;
  5818. return jsx.node;
  5819. }
  5820. if (arrowExpression) {
  5821. this.state = arrow.failState;
  5822. return arrowExpression;
  5823. }
  5824. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5825. if (arrow.thrown) throw arrow.error;
  5826. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
  5827. at: typeParameters
  5828. });
  5829. }
  5830. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5831. }
  5832. parseArrow(node) {
  5833. if (this.match(14)) {
  5834. const result = this.tryParse(() => {
  5835. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5836. this.state.noAnonFunctionType = true;
  5837. const typeNode = this.startNode();
  5838. [typeNode.typeAnnotation,
  5839. node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5840. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5841. if (this.canInsertSemicolon()) this.unexpected();
  5842. if (!this.match(19)) this.unexpected();
  5843. return typeNode;
  5844. });
  5845. if (result.thrown) return null;
  5846. if (result.error) this.state = result.failState;
  5847. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5848. }
  5849. return super.parseArrow(node);
  5850. }
  5851. shouldParseArrow(params) {
  5852. return this.match(14) || super.shouldParseArrow(params);
  5853. }
  5854. setArrowFunctionParameters(node, params) {
  5855. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5856. node.params = params;
  5857. } else {
  5858. super.setArrowFunctionParameters(node, params);
  5859. }
  5860. }
  5861. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5862. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5863. return;
  5864. }
  5865. for (let i = 0; i < node.params.length; i++) {
  5866. if (this.isThisParam(node.params[i]) && i > 0) {
  5867. this.raise(FlowErrors.ThisParamMustBeFirst, {
  5868. at: node.params[i]
  5869. });
  5870. }
  5871. }
  5872. return super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5873. }
  5874. parseParenAndDistinguishExpression(canBeArrow) {
  5875. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  5876. }
  5877. parseSubscripts(base, startLoc, noCalls) {
  5878. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
  5879. this.next();
  5880. const node = this.startNodeAt(startLoc);
  5881. node.callee = base;
  5882. node.arguments = super.parseCallExpressionArguments(11, false);
  5883. base = this.finishNode(node, "CallExpression");
  5884. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5885. const state = this.state.clone();
  5886. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5887. if (!arrow.error && !arrow.aborted) return arrow.node;
  5888. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5889. if (result.node && !result.error) return result.node;
  5890. if (arrow.node) {
  5891. this.state = arrow.failState;
  5892. return arrow.node;
  5893. }
  5894. if (result.node) {
  5895. this.state = result.failState;
  5896. return result.node;
  5897. }
  5898. throw arrow.error || result.error;
  5899. }
  5900. return super.parseSubscripts(base, startLoc, noCalls);
  5901. }
  5902. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5903. if (this.match(18) && this.isLookaheadToken_lt()) {
  5904. subscriptState.optionalChainMember = true;
  5905. if (noCalls) {
  5906. subscriptState.stop = true;
  5907. return base;
  5908. }
  5909. this.next();
  5910. const node = this.startNodeAt(startLoc);
  5911. node.callee = base;
  5912. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5913. this.expect(10);
  5914. node.arguments = this.parseCallExpressionArguments(11, false);
  5915. node.optional = true;
  5916. return this.finishCallExpression(node, true);
  5917. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  5918. const node = this.startNodeAt(startLoc);
  5919. node.callee = base;
  5920. const result = this.tryParse(() => {
  5921. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5922. this.expect(10);
  5923. node.arguments = super.parseCallExpressionArguments(11, false);
  5924. if (subscriptState.optionalChainMember) {
  5925. node.optional = false;
  5926. }
  5927. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5928. });
  5929. if (result.node) {
  5930. if (result.error) this.state = result.failState;
  5931. return result.node;
  5932. }
  5933. }
  5934. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5935. }
  5936. parseNewCallee(node) {
  5937. super.parseNewCallee(node);
  5938. let targs = null;
  5939. if (this.shouldParseTypes() && this.match(47)) {
  5940. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5941. }
  5942. node.typeArguments = targs;
  5943. }
  5944. parseAsyncArrowWithTypeParameters(startLoc) {
  5945. const node = this.startNodeAt(startLoc);
  5946. this.parseFunctionParams(node);
  5947. if (!this.parseArrow(node)) return;
  5948. return super.parseArrowExpression(node, undefined, true);
  5949. }
  5950. readToken_mult_modulo(code) {
  5951. const next = this.input.charCodeAt(this.state.pos + 1);
  5952. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5953. this.state.hasFlowComment = false;
  5954. this.state.pos += 2;
  5955. this.nextToken();
  5956. return;
  5957. }
  5958. super.readToken_mult_modulo(code);
  5959. }
  5960. readToken_pipe_amp(code) {
  5961. const next = this.input.charCodeAt(this.state.pos + 1);
  5962. if (code === 124 && next === 125) {
  5963. this.finishOp(9, 2);
  5964. return;
  5965. }
  5966. super.readToken_pipe_amp(code);
  5967. }
  5968. parseTopLevel(file, program) {
  5969. const fileNode = super.parseTopLevel(file, program);
  5970. if (this.state.hasFlowComment) {
  5971. this.raise(FlowErrors.UnterminatedFlowComment, {
  5972. at: this.state.curPosition()
  5973. });
  5974. }
  5975. return fileNode;
  5976. }
  5977. skipBlockComment() {
  5978. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5979. if (this.state.hasFlowComment) {
  5980. throw this.raise(FlowErrors.NestedFlowComment, {
  5981. at: this.state.startLoc
  5982. });
  5983. }
  5984. this.hasFlowCommentCompletion();
  5985. const commentSkip = this.skipFlowComment();
  5986. if (commentSkip) {
  5987. this.state.pos += commentSkip;
  5988. this.state.hasFlowComment = true;
  5989. }
  5990. return;
  5991. }
  5992. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5993. }
  5994. skipFlowComment() {
  5995. const {
  5996. pos
  5997. } = this.state;
  5998. let shiftToFirstNonWhiteSpace = 2;
  5999. while ([32, 9].includes(
  6000. this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  6001. shiftToFirstNonWhiteSpace++;
  6002. }
  6003. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  6004. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  6005. if (ch2 === 58 && ch3 === 58) {
  6006. return shiftToFirstNonWhiteSpace + 2;
  6007. }
  6008. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  6009. return shiftToFirstNonWhiteSpace + 12;
  6010. }
  6011. if (ch2 === 58 && ch3 !== 58) {
  6012. return shiftToFirstNonWhiteSpace;
  6013. }
  6014. return false;
  6015. }
  6016. hasFlowCommentCompletion() {
  6017. const end = this.input.indexOf("*/", this.state.pos);
  6018. if (end === -1) {
  6019. throw this.raise(Errors.UnterminatedComment, {
  6020. at: this.state.curPosition()
  6021. });
  6022. }
  6023. }
  6024. flowEnumErrorBooleanMemberNotInitialized(loc, {
  6025. enumName,
  6026. memberName
  6027. }) {
  6028. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
  6029. at: loc,
  6030. memberName,
  6031. enumName
  6032. });
  6033. }
  6034. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  6035. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
  6036. at: loc
  6037. }, enumContext));
  6038. }
  6039. flowEnumErrorNumberMemberNotInitialized(loc, {
  6040. enumName,
  6041. memberName
  6042. }) {
  6043. this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
  6044. at: loc,
  6045. enumName,
  6046. memberName
  6047. });
  6048. }
  6049. flowEnumErrorStringMemberInconsistentlyInitailized(node, {
  6050. enumName
  6051. }) {
  6052. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitailized, {
  6053. at: node,
  6054. enumName
  6055. });
  6056. }
  6057. flowEnumMemberInit() {
  6058. const startLoc = this.state.startLoc;
  6059. const endOfInit = () => this.match(12) || this.match(8);
  6060. switch (this.state.type) {
  6061. case 132:
  6062. {
  6063. const literal = this.parseNumericLiteral(this.state.value);
  6064. if (endOfInit()) {
  6065. return {
  6066. type: "number",
  6067. loc: literal.loc.start,
  6068. value: literal
  6069. };
  6070. }
  6071. return {
  6072. type: "invalid",
  6073. loc: startLoc
  6074. };
  6075. }
  6076. case 131:
  6077. {
  6078. const literal = this.parseStringLiteral(this.state.value);
  6079. if (endOfInit()) {
  6080. return {
  6081. type: "string",
  6082. loc: literal.loc.start,
  6083. value: literal
  6084. };
  6085. }
  6086. return {
  6087. type: "invalid",
  6088. loc: startLoc
  6089. };
  6090. }
  6091. case 85:
  6092. case 86:
  6093. {
  6094. const literal = this.parseBooleanLiteral(this.match(85));
  6095. if (endOfInit()) {
  6096. return {
  6097. type: "boolean",
  6098. loc: literal.loc.start,
  6099. value: literal
  6100. };
  6101. }
  6102. return {
  6103. type: "invalid",
  6104. loc: startLoc
  6105. };
  6106. }
  6107. default:
  6108. return {
  6109. type: "invalid",
  6110. loc: startLoc
  6111. };
  6112. }
  6113. }
  6114. flowEnumMemberRaw() {
  6115. const loc = this.state.startLoc;
  6116. const id = this.parseIdentifier(true);
  6117. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6118. type: "none",
  6119. loc
  6120. };
  6121. return {
  6122. id,
  6123. init
  6124. };
  6125. }
  6126. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6127. const {
  6128. explicitType
  6129. } = context;
  6130. if (explicitType === null) {
  6131. return;
  6132. }
  6133. if (explicitType !== expectedType) {
  6134. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6135. }
  6136. }
  6137. flowEnumMembers({
  6138. enumName,
  6139. explicitType
  6140. }) {
  6141. const seenNames = new Set();
  6142. const members = {
  6143. booleanMembers: [],
  6144. numberMembers: [],
  6145. stringMembers: [],
  6146. defaultedMembers: []
  6147. };
  6148. let hasUnknownMembers = false;
  6149. while (!this.match(8)) {
  6150. if (this.eat(21)) {
  6151. hasUnknownMembers = true;
  6152. break;
  6153. }
  6154. const memberNode = this.startNode();
  6155. const {
  6156. id,
  6157. init
  6158. } = this.flowEnumMemberRaw();
  6159. const memberName = id.name;
  6160. if (memberName === "") {
  6161. continue;
  6162. }
  6163. if (/^[a-z]/.test(memberName)) {
  6164. this.raise(FlowErrors.EnumInvalidMemberName, {
  6165. at: id,
  6166. memberName,
  6167. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6168. enumName
  6169. });
  6170. }
  6171. if (seenNames.has(memberName)) {
  6172. this.raise(FlowErrors.EnumDuplicateMemberName, {
  6173. at: id,
  6174. memberName,
  6175. enumName
  6176. });
  6177. }
  6178. seenNames.add(memberName);
  6179. const context = {
  6180. enumName,
  6181. explicitType,
  6182. memberName
  6183. };
  6184. memberNode.id = id;
  6185. switch (init.type) {
  6186. case "boolean":
  6187. {
  6188. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6189. memberNode.init = init.value;
  6190. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6191. break;
  6192. }
  6193. case "number":
  6194. {
  6195. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6196. memberNode.init = init.value;
  6197. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6198. break;
  6199. }
  6200. case "string":
  6201. {
  6202. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6203. memberNode.init = init.value;
  6204. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6205. break;
  6206. }
  6207. case "invalid":
  6208. {
  6209. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6210. }
  6211. case "none":
  6212. {
  6213. switch (explicitType) {
  6214. case "boolean":
  6215. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6216. break;
  6217. case "number":
  6218. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6219. break;
  6220. default:
  6221. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6222. }
  6223. }
  6224. }
  6225. if (!this.match(8)) {
  6226. this.expect(12);
  6227. }
  6228. }
  6229. return {
  6230. members,
  6231. hasUnknownMembers
  6232. };
  6233. }
  6234. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6235. enumName
  6236. }) {
  6237. if (initializedMembers.length === 0) {
  6238. return defaultedMembers;
  6239. } else if (defaultedMembers.length === 0) {
  6240. return initializedMembers;
  6241. } else if (defaultedMembers.length > initializedMembers.length) {
  6242. for (const member of initializedMembers) {
  6243. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6244. enumName
  6245. });
  6246. }
  6247. return defaultedMembers;
  6248. } else {
  6249. for (const member of defaultedMembers) {
  6250. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6251. enumName
  6252. });
  6253. }
  6254. return initializedMembers;
  6255. }
  6256. }
  6257. flowEnumParseExplicitType({
  6258. enumName
  6259. }) {
  6260. if (!this.eatContextual(101)) return null;
  6261. if (!tokenIsIdentifier(this.state.type)) {
  6262. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
  6263. at: this.state.startLoc,
  6264. enumName
  6265. });
  6266. }
  6267. const {
  6268. value
  6269. } = this.state;
  6270. this.next();
  6271. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6272. this.raise(FlowErrors.EnumInvalidExplicitType, {
  6273. at: this.state.startLoc,
  6274. enumName,
  6275. invalidEnumType: value
  6276. });
  6277. }
  6278. return value;
  6279. }
  6280. flowEnumBody(node, id) {
  6281. const enumName = id.name;
  6282. const nameLoc = id.loc.start;
  6283. const explicitType = this.flowEnumParseExplicitType({
  6284. enumName
  6285. });
  6286. this.expect(5);
  6287. const {
  6288. members,
  6289. hasUnknownMembers
  6290. } = this.flowEnumMembers({
  6291. enumName,
  6292. explicitType
  6293. });
  6294. node.hasUnknownMembers = hasUnknownMembers;
  6295. switch (explicitType) {
  6296. case "boolean":
  6297. node.explicitType = true;
  6298. node.members = members.booleanMembers;
  6299. this.expect(8);
  6300. return this.finishNode(node, "EnumBooleanBody");
  6301. case "number":
  6302. node.explicitType = true;
  6303. node.members = members.numberMembers;
  6304. this.expect(8);
  6305. return this.finishNode(node, "EnumNumberBody");
  6306. case "string":
  6307. node.explicitType = true;
  6308. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6309. enumName
  6310. });
  6311. this.expect(8);
  6312. return this.finishNode(node, "EnumStringBody");
  6313. case "symbol":
  6314. node.members = members.defaultedMembers;
  6315. this.expect(8);
  6316. return this.finishNode(node, "EnumSymbolBody");
  6317. default:
  6318. {
  6319. const empty = () => {
  6320. node.members = [];
  6321. this.expect(8);
  6322. return this.finishNode(node, "EnumStringBody");
  6323. };
  6324. node.explicitType = false;
  6325. const boolsLen = members.booleanMembers.length;
  6326. const numsLen = members.numberMembers.length;
  6327. const strsLen = members.stringMembers.length;
  6328. const defaultedLen = members.defaultedMembers.length;
  6329. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6330. return empty();
  6331. } else if (!boolsLen && !numsLen) {
  6332. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6333. enumName
  6334. });
  6335. this.expect(8);
  6336. return this.finishNode(node, "EnumStringBody");
  6337. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6338. for (const member of members.defaultedMembers) {
  6339. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6340. enumName,
  6341. memberName: member.id.name
  6342. });
  6343. }
  6344. node.members = members.booleanMembers;
  6345. this.expect(8);
  6346. return this.finishNode(node, "EnumBooleanBody");
  6347. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6348. for (const member of members.defaultedMembers) {
  6349. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6350. enumName,
  6351. memberName: member.id.name
  6352. });
  6353. }
  6354. node.members = members.numberMembers;
  6355. this.expect(8);
  6356. return this.finishNode(node, "EnumNumberBody");
  6357. } else {
  6358. this.raise(FlowErrors.EnumInconsistentMemberValues, {
  6359. at: nameLoc,
  6360. enumName
  6361. });
  6362. return empty();
  6363. }
  6364. }
  6365. }
  6366. }
  6367. flowParseEnumDeclaration(node) {
  6368. const id = this.parseIdentifier();
  6369. node.id = id;
  6370. node.body = this.flowEnumBody(this.startNode(), id);
  6371. return this.finishNode(node, "EnumDeclaration");
  6372. }
  6373. isLookaheadToken_lt() {
  6374. const next = this.nextTokenStart();
  6375. if (this.input.charCodeAt(next) === 60) {
  6376. const afterNext = this.input.charCodeAt(next + 1);
  6377. return afterNext !== 60 && afterNext !== 61;
  6378. }
  6379. return false;
  6380. }
  6381. maybeUnwrapTypeCastExpression(node) {
  6382. return node.type === "TypeCastExpression" ? node.expression : node;
  6383. }
  6384. });
  6385. const entities = {
  6386. __proto__: null,
  6387. quot: "\u0022",
  6388. amp: "&",
  6389. apos: "\u0027",
  6390. lt: "<",
  6391. gt: ">",
  6392. nbsp: "\u00A0",
  6393. iexcl: "\u00A1",
  6394. cent: "\u00A2",
  6395. pound: "\u00A3",
  6396. curren: "\u00A4",
  6397. yen: "\u00A5",
  6398. brvbar: "\u00A6",
  6399. sect: "\u00A7",
  6400. uml: "\u00A8",
  6401. copy: "\u00A9",
  6402. ordf: "\u00AA",
  6403. laquo: "\u00AB",
  6404. not: "\u00AC",
  6405. shy: "\u00AD",
  6406. reg: "\u00AE",
  6407. macr: "\u00AF",
  6408. deg: "\u00B0",
  6409. plusmn: "\u00B1",
  6410. sup2: "\u00B2",
  6411. sup3: "\u00B3",
  6412. acute: "\u00B4",
  6413. micro: "\u00B5",
  6414. para: "\u00B6",
  6415. middot: "\u00B7",
  6416. cedil: "\u00B8",
  6417. sup1: "\u00B9",
  6418. ordm: "\u00BA",
  6419. raquo: "\u00BB",
  6420. frac14: "\u00BC",
  6421. frac12: "\u00BD",
  6422. frac34: "\u00BE",
  6423. iquest: "\u00BF",
  6424. Agrave: "\u00C0",
  6425. Aacute: "\u00C1",
  6426. Acirc: "\u00C2",
  6427. Atilde: "\u00C3",
  6428. Auml: "\u00C4",
  6429. Aring: "\u00C5",
  6430. AElig: "\u00C6",
  6431. Ccedil: "\u00C7",
  6432. Egrave: "\u00C8",
  6433. Eacute: "\u00C9",
  6434. Ecirc: "\u00CA",
  6435. Euml: "\u00CB",
  6436. Igrave: "\u00CC",
  6437. Iacute: "\u00CD",
  6438. Icirc: "\u00CE",
  6439. Iuml: "\u00CF",
  6440. ETH: "\u00D0",
  6441. Ntilde: "\u00D1",
  6442. Ograve: "\u00D2",
  6443. Oacute: "\u00D3",
  6444. Ocirc: "\u00D4",
  6445. Otilde: "\u00D5",
  6446. Ouml: "\u00D6",
  6447. times: "\u00D7",
  6448. Oslash: "\u00D8",
  6449. Ugrave: "\u00D9",
  6450. Uacute: "\u00DA",
  6451. Ucirc: "\u00DB",
  6452. Uuml: "\u00DC",
  6453. Yacute: "\u00DD",
  6454. THORN: "\u00DE",
  6455. szlig: "\u00DF",
  6456. agrave: "\u00E0",
  6457. aacute: "\u00E1",
  6458. acirc: "\u00E2",
  6459. atilde: "\u00E3",
  6460. auml: "\u00E4",
  6461. aring: "\u00E5",
  6462. aelig: "\u00E6",
  6463. ccedil: "\u00E7",
  6464. egrave: "\u00E8",
  6465. eacute: "\u00E9",
  6466. ecirc: "\u00EA",
  6467. euml: "\u00EB",
  6468. igrave: "\u00EC",
  6469. iacute: "\u00ED",
  6470. icirc: "\u00EE",
  6471. iuml: "\u00EF",
  6472. eth: "\u00F0",
  6473. ntilde: "\u00F1",
  6474. ograve: "\u00F2",
  6475. oacute: "\u00F3",
  6476. ocirc: "\u00F4",
  6477. otilde: "\u00F5",
  6478. ouml: "\u00F6",
  6479. divide: "\u00F7",
  6480. oslash: "\u00F8",
  6481. ugrave: "\u00F9",
  6482. uacute: "\u00FA",
  6483. ucirc: "\u00FB",
  6484. uuml: "\u00FC",
  6485. yacute: "\u00FD",
  6486. thorn: "\u00FE",
  6487. yuml: "\u00FF",
  6488. OElig: "\u0152",
  6489. oelig: "\u0153",
  6490. Scaron: "\u0160",
  6491. scaron: "\u0161",
  6492. Yuml: "\u0178",
  6493. fnof: "\u0192",
  6494. circ: "\u02C6",
  6495. tilde: "\u02DC",
  6496. Alpha: "\u0391",
  6497. Beta: "\u0392",
  6498. Gamma: "\u0393",
  6499. Delta: "\u0394",
  6500. Epsilon: "\u0395",
  6501. Zeta: "\u0396",
  6502. Eta: "\u0397",
  6503. Theta: "\u0398",
  6504. Iota: "\u0399",
  6505. Kappa: "\u039A",
  6506. Lambda: "\u039B",
  6507. Mu: "\u039C",
  6508. Nu: "\u039D",
  6509. Xi: "\u039E",
  6510. Omicron: "\u039F",
  6511. Pi: "\u03A0",
  6512. Rho: "\u03A1",
  6513. Sigma: "\u03A3",
  6514. Tau: "\u03A4",
  6515. Upsilon: "\u03A5",
  6516. Phi: "\u03A6",
  6517. Chi: "\u03A7",
  6518. Psi: "\u03A8",
  6519. Omega: "\u03A9",
  6520. alpha: "\u03B1",
  6521. beta: "\u03B2",
  6522. gamma: "\u03B3",
  6523. delta: "\u03B4",
  6524. epsilon: "\u03B5",
  6525. zeta: "\u03B6",
  6526. eta: "\u03B7",
  6527. theta: "\u03B8",
  6528. iota: "\u03B9",
  6529. kappa: "\u03BA",
  6530. lambda: "\u03BB",
  6531. mu: "\u03BC",
  6532. nu: "\u03BD",
  6533. xi: "\u03BE",
  6534. omicron: "\u03BF",
  6535. pi: "\u03C0",
  6536. rho: "\u03C1",
  6537. sigmaf: "\u03C2",
  6538. sigma: "\u03C3",
  6539. tau: "\u03C4",
  6540. upsilon: "\u03C5",
  6541. phi: "\u03C6",
  6542. chi: "\u03C7",
  6543. psi: "\u03C8",
  6544. omega: "\u03C9",
  6545. thetasym: "\u03D1",
  6546. upsih: "\u03D2",
  6547. piv: "\u03D6",
  6548. ensp: "\u2002",
  6549. emsp: "\u2003",
  6550. thinsp: "\u2009",
  6551. zwnj: "\u200C",
  6552. zwj: "\u200D",
  6553. lrm: "\u200E",
  6554. rlm: "\u200F",
  6555. ndash: "\u2013",
  6556. mdash: "\u2014",
  6557. lsquo: "\u2018",
  6558. rsquo: "\u2019",
  6559. sbquo: "\u201A",
  6560. ldquo: "\u201C",
  6561. rdquo: "\u201D",
  6562. bdquo: "\u201E",
  6563. dagger: "\u2020",
  6564. Dagger: "\u2021",
  6565. bull: "\u2022",
  6566. hellip: "\u2026",
  6567. permil: "\u2030",
  6568. prime: "\u2032",
  6569. Prime: "\u2033",
  6570. lsaquo: "\u2039",
  6571. rsaquo: "\u203A",
  6572. oline: "\u203E",
  6573. frasl: "\u2044",
  6574. euro: "\u20AC",
  6575. image: "\u2111",
  6576. weierp: "\u2118",
  6577. real: "\u211C",
  6578. trade: "\u2122",
  6579. alefsym: "\u2135",
  6580. larr: "\u2190",
  6581. uarr: "\u2191",
  6582. rarr: "\u2192",
  6583. darr: "\u2193",
  6584. harr: "\u2194",
  6585. crarr: "\u21B5",
  6586. lArr: "\u21D0",
  6587. uArr: "\u21D1",
  6588. rArr: "\u21D2",
  6589. dArr: "\u21D3",
  6590. hArr: "\u21D4",
  6591. forall: "\u2200",
  6592. part: "\u2202",
  6593. exist: "\u2203",
  6594. empty: "\u2205",
  6595. nabla: "\u2207",
  6596. isin: "\u2208",
  6597. notin: "\u2209",
  6598. ni: "\u220B",
  6599. prod: "\u220F",
  6600. sum: "\u2211",
  6601. minus: "\u2212",
  6602. lowast: "\u2217",
  6603. radic: "\u221A",
  6604. prop: "\u221D",
  6605. infin: "\u221E",
  6606. ang: "\u2220",
  6607. and: "\u2227",
  6608. or: "\u2228",
  6609. cap: "\u2229",
  6610. cup: "\u222A",
  6611. int: "\u222B",
  6612. there4: "\u2234",
  6613. sim: "\u223C",
  6614. cong: "\u2245",
  6615. asymp: "\u2248",
  6616. ne: "\u2260",
  6617. equiv: "\u2261",
  6618. le: "\u2264",
  6619. ge: "\u2265",
  6620. sub: "\u2282",
  6621. sup: "\u2283",
  6622. nsub: "\u2284",
  6623. sube: "\u2286",
  6624. supe: "\u2287",
  6625. oplus: "\u2295",
  6626. otimes: "\u2297",
  6627. perp: "\u22A5",
  6628. sdot: "\u22C5",
  6629. lceil: "\u2308",
  6630. rceil: "\u2309",
  6631. lfloor: "\u230A",
  6632. rfloor: "\u230B",
  6633. lang: "\u2329",
  6634. rang: "\u232A",
  6635. loz: "\u25CA",
  6636. spades: "\u2660",
  6637. clubs: "\u2663",
  6638. hearts: "\u2665",
  6639. diams: "\u2666"
  6640. };
  6641. const JsxErrors = ParseErrorEnum`jsx`({
  6642. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6643. MissingClosingTagElement: ({
  6644. openingTagName
  6645. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6646. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6647. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6648. UnexpectedToken: ({
  6649. unexpected,
  6650. HTMLEntity
  6651. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6652. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6653. UnterminatedJsxContent: "Unterminated JSX contents.",
  6654. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6655. });
  6656. function isFragment(object) {
  6657. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6658. }
  6659. function getQualifiedJSXName(object) {
  6660. if (object.type === "JSXIdentifier") {
  6661. return object.name;
  6662. }
  6663. if (object.type === "JSXNamespacedName") {
  6664. return object.namespace.name + ":" + object.name.name;
  6665. }
  6666. if (object.type === "JSXMemberExpression") {
  6667. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6668. }
  6669. throw new Error("Node had unexpected type: " + object.type);
  6670. }
  6671. var jsx = (superClass => class JSXParserMixin extends superClass {
  6672. jsxReadToken() {
  6673. let out = "";
  6674. let chunkStart = this.state.pos;
  6675. for (;;) {
  6676. if (this.state.pos >= this.length) {
  6677. throw this.raise(JsxErrors.UnterminatedJsxContent, {
  6678. at: this.state.startLoc
  6679. });
  6680. }
  6681. const ch = this.input.charCodeAt(this.state.pos);
  6682. switch (ch) {
  6683. case 60:
  6684. case 123:
  6685. if (this.state.pos === this.state.start) {
  6686. if (ch === 60 && this.state.canStartJSXElement) {
  6687. ++this.state.pos;
  6688. return this.finishToken(140);
  6689. }
  6690. return super.getTokenFromCode(ch);
  6691. }
  6692. out += this.input.slice(chunkStart, this.state.pos);
  6693. return this.finishToken(139, out);
  6694. case 38:
  6695. out += this.input.slice(chunkStart, this.state.pos);
  6696. out += this.jsxReadEntity();
  6697. chunkStart = this.state.pos;
  6698. break;
  6699. case 62:
  6700. case 125:
  6701. default:
  6702. if (isNewLine(ch)) {
  6703. out += this.input.slice(chunkStart, this.state.pos);
  6704. out += this.jsxReadNewLine(true);
  6705. chunkStart = this.state.pos;
  6706. } else {
  6707. ++this.state.pos;
  6708. }
  6709. }
  6710. }
  6711. }
  6712. jsxReadNewLine(normalizeCRLF) {
  6713. const ch = this.input.charCodeAt(this.state.pos);
  6714. let out;
  6715. ++this.state.pos;
  6716. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6717. ++this.state.pos;
  6718. out = normalizeCRLF ? "\n" : "\r\n";
  6719. } else {
  6720. out = String.fromCharCode(ch);
  6721. }
  6722. ++this.state.curLine;
  6723. this.state.lineStart = this.state.pos;
  6724. return out;
  6725. }
  6726. jsxReadString(quote) {
  6727. let out = "";
  6728. let chunkStart = ++this.state.pos;
  6729. for (;;) {
  6730. if (this.state.pos >= this.length) {
  6731. throw this.raise(Errors.UnterminatedString, {
  6732. at: this.state.startLoc
  6733. });
  6734. }
  6735. const ch = this.input.charCodeAt(this.state.pos);
  6736. if (ch === quote) break;
  6737. if (ch === 38) {
  6738. out += this.input.slice(chunkStart, this.state.pos);
  6739. out += this.jsxReadEntity();
  6740. chunkStart = this.state.pos;
  6741. } else if (isNewLine(ch)) {
  6742. out += this.input.slice(chunkStart, this.state.pos);
  6743. out += this.jsxReadNewLine(false);
  6744. chunkStart = this.state.pos;
  6745. } else {
  6746. ++this.state.pos;
  6747. }
  6748. }
  6749. out += this.input.slice(chunkStart, this.state.pos++);
  6750. return this.finishToken(131, out);
  6751. }
  6752. jsxReadEntity() {
  6753. const startPos = ++this.state.pos;
  6754. if (this.codePointAtPos(this.state.pos) === 35) {
  6755. ++this.state.pos;
  6756. let radix = 10;
  6757. if (this.codePointAtPos(this.state.pos) === 120) {
  6758. radix = 16;
  6759. ++this.state.pos;
  6760. }
  6761. const codePoint = this.readInt(radix, undefined, false, "bail");
  6762. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6763. ++this.state.pos;
  6764. return String.fromCodePoint(codePoint);
  6765. }
  6766. } else {
  6767. let count = 0;
  6768. let semi = false;
  6769. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
  6770. ++this.state.pos;
  6771. }
  6772. if (semi) {
  6773. const desc = this.input.slice(startPos, this.state.pos);
  6774. const entity = entities[desc];
  6775. ++this.state.pos;
  6776. if (entity) {
  6777. return entity;
  6778. }
  6779. }
  6780. }
  6781. this.state.pos = startPos;
  6782. return "&";
  6783. }
  6784. jsxReadWord() {
  6785. let ch;
  6786. const start = this.state.pos;
  6787. do {
  6788. ch = this.input.charCodeAt(++this.state.pos);
  6789. } while (isIdentifierChar(ch) || ch === 45);
  6790. return this.finishToken(138, this.input.slice(start, this.state.pos));
  6791. }
  6792. jsxParseIdentifier() {
  6793. const node = this.startNode();
  6794. if (this.match(138)) {
  6795. node.name = this.state.value;
  6796. } else if (tokenIsKeyword(this.state.type)) {
  6797. node.name = tokenLabelName(this.state.type);
  6798. } else {
  6799. this.unexpected();
  6800. }
  6801. this.next();
  6802. return this.finishNode(node, "JSXIdentifier");
  6803. }
  6804. jsxParseNamespacedName() {
  6805. const startLoc = this.state.startLoc;
  6806. const name = this.jsxParseIdentifier();
  6807. if (!this.eat(14)) return name;
  6808. const node = this.startNodeAt(startLoc);
  6809. node.namespace = name;
  6810. node.name = this.jsxParseIdentifier();
  6811. return this.finishNode(node, "JSXNamespacedName");
  6812. }
  6813. jsxParseElementName() {
  6814. const startLoc = this.state.startLoc;
  6815. let node = this.jsxParseNamespacedName();
  6816. if (node.type === "JSXNamespacedName") {
  6817. return node;
  6818. }
  6819. while (this.eat(16)) {
  6820. const newNode = this.startNodeAt(startLoc);
  6821. newNode.object = node;
  6822. newNode.property = this.jsxParseIdentifier();
  6823. node = this.finishNode(newNode, "JSXMemberExpression");
  6824. }
  6825. return node;
  6826. }
  6827. jsxParseAttributeValue() {
  6828. let node;
  6829. switch (this.state.type) {
  6830. case 5:
  6831. node = this.startNode();
  6832. this.setContext(types.brace);
  6833. this.next();
  6834. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6835. if (node.expression.type === "JSXEmptyExpression") {
  6836. this.raise(JsxErrors.AttributeIsEmpty, {
  6837. at: node
  6838. });
  6839. }
  6840. return node;
  6841. case 140:
  6842. case 131:
  6843. return this.parseExprAtom();
  6844. default:
  6845. throw this.raise(JsxErrors.UnsupportedJsxValue, {
  6846. at: this.state.startLoc
  6847. });
  6848. }
  6849. }
  6850. jsxParseEmptyExpression() {
  6851. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6852. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6853. }
  6854. jsxParseSpreadChild(node) {
  6855. this.next();
  6856. node.expression = this.parseExpression();
  6857. this.setContext(types.j_expr);
  6858. this.state.canStartJSXElement = true;
  6859. this.expect(8);
  6860. return this.finishNode(node, "JSXSpreadChild");
  6861. }
  6862. jsxParseExpressionContainer(node, previousContext) {
  6863. if (this.match(8)) {
  6864. node.expression = this.jsxParseEmptyExpression();
  6865. } else {
  6866. const expression = this.parseExpression();
  6867. node.expression = expression;
  6868. }
  6869. this.setContext(previousContext);
  6870. this.state.canStartJSXElement = true;
  6871. this.expect(8);
  6872. return this.finishNode(node, "JSXExpressionContainer");
  6873. }
  6874. jsxParseAttribute() {
  6875. const node = this.startNode();
  6876. if (this.match(5)) {
  6877. this.setContext(types.brace);
  6878. this.next();
  6879. this.expect(21);
  6880. node.argument = this.parseMaybeAssignAllowIn();
  6881. this.setContext(types.j_oTag);
  6882. this.state.canStartJSXElement = true;
  6883. this.expect(8);
  6884. return this.finishNode(node, "JSXSpreadAttribute");
  6885. }
  6886. node.name = this.jsxParseNamespacedName();
  6887. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6888. return this.finishNode(node, "JSXAttribute");
  6889. }
  6890. jsxParseOpeningElementAt(startLoc) {
  6891. const node = this.startNodeAt(startLoc);
  6892. if (this.eat(141)) {
  6893. return this.finishNode(node, "JSXOpeningFragment");
  6894. }
  6895. node.name = this.jsxParseElementName();
  6896. return this.jsxParseOpeningElementAfterName(node);
  6897. }
  6898. jsxParseOpeningElementAfterName(node) {
  6899. const attributes = [];
  6900. while (!this.match(56) && !this.match(141)) {
  6901. attributes.push(this.jsxParseAttribute());
  6902. }
  6903. node.attributes = attributes;
  6904. node.selfClosing = this.eat(56);
  6905. this.expect(141);
  6906. return this.finishNode(node, "JSXOpeningElement");
  6907. }
  6908. jsxParseClosingElementAt(startLoc) {
  6909. const node = this.startNodeAt(startLoc);
  6910. if (this.eat(141)) {
  6911. return this.finishNode(node, "JSXClosingFragment");
  6912. }
  6913. node.name = this.jsxParseElementName();
  6914. this.expect(141);
  6915. return this.finishNode(node, "JSXClosingElement");
  6916. }
  6917. jsxParseElementAt(startLoc) {
  6918. const node = this.startNodeAt(startLoc);
  6919. const children = [];
  6920. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6921. let closingElement = null;
  6922. if (!openingElement.selfClosing) {
  6923. contents: for (;;) {
  6924. switch (this.state.type) {
  6925. case 140:
  6926. startLoc = this.state.startLoc;
  6927. this.next();
  6928. if (this.eat(56)) {
  6929. closingElement = this.jsxParseClosingElementAt(startLoc);
  6930. break contents;
  6931. }
  6932. children.push(this.jsxParseElementAt(startLoc));
  6933. break;
  6934. case 139:
  6935. children.push(this.parseExprAtom());
  6936. break;
  6937. case 5:
  6938. {
  6939. const node = this.startNode();
  6940. this.setContext(types.brace);
  6941. this.next();
  6942. if (this.match(21)) {
  6943. children.push(this.jsxParseSpreadChild(node));
  6944. } else {
  6945. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6946. }
  6947. break;
  6948. }
  6949. default:
  6950. throw this.unexpected();
  6951. }
  6952. }
  6953. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6954. this.raise(JsxErrors.MissingClosingTagFragment, {
  6955. at: closingElement
  6956. });
  6957. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6958. this.raise(JsxErrors.MissingClosingTagElement, {
  6959. at: closingElement,
  6960. openingTagName: getQualifiedJSXName(openingElement.name)
  6961. });
  6962. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6963. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6964. this.raise(JsxErrors.MissingClosingTagElement, {
  6965. at: closingElement,
  6966. openingTagName: getQualifiedJSXName(openingElement.name)
  6967. });
  6968. }
  6969. }
  6970. }
  6971. if (isFragment(openingElement)) {
  6972. node.openingFragment = openingElement;
  6973. node.closingFragment = closingElement;
  6974. } else {
  6975. node.openingElement = openingElement;
  6976. node.closingElement = closingElement;
  6977. }
  6978. node.children = children;
  6979. if (this.match(47)) {
  6980. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
  6981. at: this.state.startLoc
  6982. });
  6983. }
  6984. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6985. }
  6986. jsxParseElement() {
  6987. const startLoc = this.state.startLoc;
  6988. this.next();
  6989. return this.jsxParseElementAt(startLoc);
  6990. }
  6991. setContext(newContext) {
  6992. const {
  6993. context
  6994. } = this.state;
  6995. context[context.length - 1] = newContext;
  6996. }
  6997. parseExprAtom(refExpressionErrors) {
  6998. if (this.match(139)) {
  6999. return this.parseLiteral(this.state.value, "JSXText");
  7000. } else if (this.match(140)) {
  7001. return this.jsxParseElement();
  7002. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  7003. this.replaceToken(140);
  7004. return this.jsxParseElement();
  7005. } else {
  7006. return super.parseExprAtom(refExpressionErrors);
  7007. }
  7008. }
  7009. skipSpace() {
  7010. const curContext = this.curContext();
  7011. if (!curContext.preserveSpace) super.skipSpace();
  7012. }
  7013. getTokenFromCode(code) {
  7014. const context = this.curContext();
  7015. if (context === types.j_expr) {
  7016. return this.jsxReadToken();
  7017. }
  7018. if (context === types.j_oTag || context === types.j_cTag) {
  7019. if (isIdentifierStart(code)) {
  7020. return this.jsxReadWord();
  7021. }
  7022. if (code === 62) {
  7023. ++this.state.pos;
  7024. return this.finishToken(141);
  7025. }
  7026. if ((code === 34 || code === 39) && context === types.j_oTag) {
  7027. return this.jsxReadString(code);
  7028. }
  7029. }
  7030. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  7031. ++this.state.pos;
  7032. return this.finishToken(140);
  7033. }
  7034. return super.getTokenFromCode(code);
  7035. }
  7036. updateContext(prevType) {
  7037. const {
  7038. context,
  7039. type
  7040. } = this.state;
  7041. if (type === 56 && prevType === 140) {
  7042. context.splice(-2, 2, types.j_cTag);
  7043. this.state.canStartJSXElement = false;
  7044. } else if (type === 140) {
  7045. context.push(types.j_oTag);
  7046. } else if (type === 141) {
  7047. const out = context[context.length - 1];
  7048. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  7049. context.pop();
  7050. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  7051. } else {
  7052. this.setContext(types.j_expr);
  7053. this.state.canStartJSXElement = true;
  7054. }
  7055. } else {
  7056. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  7057. }
  7058. }
  7059. });
  7060. class TypeScriptScope extends Scope {
  7061. constructor(...args) {
  7062. super(...args);
  7063. this.types = new Set();
  7064. this.enums = new Set();
  7065. this.constEnums = new Set();
  7066. this.classes = new Set();
  7067. this.exportOnlyBindings = new Set();
  7068. }
  7069. }
  7070. class TypeScriptScopeHandler extends ScopeHandler {
  7071. constructor(...args) {
  7072. super(...args);
  7073. this.importsStack = [];
  7074. }
  7075. createScope(flags) {
  7076. this.importsStack.push(new Set());
  7077. return new TypeScriptScope(flags);
  7078. }
  7079. enter(flags) {
  7080. if (flags == SCOPE_TS_MODULE) {
  7081. this.importsStack.push(new Set());
  7082. }
  7083. super.enter(flags);
  7084. }
  7085. exit() {
  7086. const flags = super.exit();
  7087. if (flags == SCOPE_TS_MODULE) {
  7088. this.importsStack.pop();
  7089. }
  7090. return flags;
  7091. }
  7092. hasImport(name, allowShadow) {
  7093. const len = this.importsStack.length;
  7094. if (this.importsStack[len - 1].has(name)) {
  7095. return true;
  7096. }
  7097. if (!allowShadow && len > 1) {
  7098. for (let i = 0; i < len - 1; i++) {
  7099. if (this.importsStack[i].has(name)) return true;
  7100. }
  7101. }
  7102. return false;
  7103. }
  7104. declareName(name, bindingType, loc) {
  7105. if (bindingType & BIND_FLAGS_TS_IMPORT) {
  7106. if (this.hasImport(name, true)) {
  7107. this.parser.raise(Errors.VarRedeclaration, {
  7108. at: loc,
  7109. identifierName: name
  7110. });
  7111. }
  7112. this.importsStack[this.importsStack.length - 1].add(name);
  7113. return;
  7114. }
  7115. const scope = this.currentScope();
  7116. if (bindingType & BIND_FLAGS_TS_EXPORT_ONLY) {
  7117. this.maybeExportDefined(scope, name);
  7118. scope.exportOnlyBindings.add(name);
  7119. return;
  7120. }
  7121. super.declareName(name, bindingType, loc);
  7122. if (bindingType & BIND_KIND_TYPE) {
  7123. if (!(bindingType & BIND_KIND_VALUE)) {
  7124. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7125. this.maybeExportDefined(scope, name);
  7126. }
  7127. scope.types.add(name);
  7128. }
  7129. if (bindingType & BIND_FLAGS_TS_ENUM) scope.enums.add(name);
  7130. if (bindingType & BIND_FLAGS_TS_CONST_ENUM) scope.constEnums.add(name);
  7131. if (bindingType & BIND_FLAGS_CLASS) scope.classes.add(name);
  7132. }
  7133. isRedeclaredInScope(scope, name, bindingType) {
  7134. if (scope.enums.has(name)) {
  7135. if (bindingType & BIND_FLAGS_TS_ENUM) {
  7136. const isConst = !!(bindingType & BIND_FLAGS_TS_CONST_ENUM);
  7137. const wasConst = scope.constEnums.has(name);
  7138. return isConst !== wasConst;
  7139. }
  7140. return true;
  7141. }
  7142. if (bindingType & BIND_FLAGS_CLASS && scope.classes.has(name)) {
  7143. if (scope.lexical.has(name)) {
  7144. return !!(bindingType & BIND_KIND_VALUE);
  7145. } else {
  7146. return false;
  7147. }
  7148. }
  7149. if (bindingType & BIND_KIND_TYPE && scope.types.has(name)) {
  7150. return true;
  7151. }
  7152. return super.isRedeclaredInScope(scope, name, bindingType);
  7153. }
  7154. checkLocalExport(id) {
  7155. const {
  7156. name
  7157. } = id;
  7158. if (this.hasImport(name)) return;
  7159. const len = this.scopeStack.length;
  7160. for (let i = len - 1; i >= 0; i--) {
  7161. const scope = this.scopeStack[i];
  7162. if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return;
  7163. }
  7164. super.checkLocalExport(id);
  7165. }
  7166. }
  7167. const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7168. function nonNull(x) {
  7169. if (x == null) {
  7170. throw new Error(`Unexpected ${x} value.`);
  7171. }
  7172. return x;
  7173. }
  7174. function assert(x) {
  7175. if (!x) {
  7176. throw new Error("Assert fail");
  7177. }
  7178. }
  7179. const TSErrors = ParseErrorEnum`typescript`({
  7180. AbstractMethodHasImplementation: ({
  7181. methodName
  7182. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7183. AbstractPropertyHasInitializer: ({
  7184. propertyName
  7185. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7186. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7187. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7188. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7189. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7190. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7191. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7192. DeclareAccessor: ({
  7193. kind
  7194. }) => `'declare' is not allowed in ${kind}ters.`,
  7195. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7196. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7197. DuplicateAccessibilityModifier:
  7198. ({
  7199. modifier
  7200. }) => `Accessibility modifier already seen.`,
  7201. DuplicateModifier: ({
  7202. modifier
  7203. }) => `Duplicate modifier: '${modifier}'.`,
  7204. EmptyHeritageClauseType: ({
  7205. token
  7206. }) => `'${token}' list cannot be empty.`,
  7207. EmptyTypeArguments: "Type argument list cannot be empty.",
  7208. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7209. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7210. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7211. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7212. IncompatibleModifiers: ({
  7213. modifiers
  7214. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7215. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7216. IndexSignatureHasAccessibility: ({
  7217. modifier
  7218. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7219. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7220. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7221. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7222. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7223. InvalidModifierOnTypeMember: ({
  7224. modifier
  7225. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7226. InvalidModifierOnTypeParameter: ({
  7227. modifier
  7228. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7229. InvalidModifierOnTypeParameterPositions: ({
  7230. modifier
  7231. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7232. InvalidModifiersOrder: ({
  7233. orderedModifiers
  7234. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7235. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7236. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7237. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7238. MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
  7239. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7240. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7241. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7242. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7243. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7244. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7245. PrivateElementHasAccessibility: ({
  7246. modifier
  7247. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7248. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7249. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7250. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7251. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7252. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7253. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7254. SingleTypeParameterWithoutTrailingComma: ({
  7255. typeParameterName
  7256. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7257. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7258. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7259. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7260. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7261. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7262. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7263. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7264. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7265. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7266. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7267. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7268. UnsupportedSignatureParameterKind: ({
  7269. type
  7270. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7271. });
  7272. function keywordTypeFromName(value) {
  7273. switch (value) {
  7274. case "any":
  7275. return "TSAnyKeyword";
  7276. case "boolean":
  7277. return "TSBooleanKeyword";
  7278. case "bigint":
  7279. return "TSBigIntKeyword";
  7280. case "never":
  7281. return "TSNeverKeyword";
  7282. case "number":
  7283. return "TSNumberKeyword";
  7284. case "object":
  7285. return "TSObjectKeyword";
  7286. case "string":
  7287. return "TSStringKeyword";
  7288. case "symbol":
  7289. return "TSSymbolKeyword";
  7290. case "undefined":
  7291. return "TSUndefinedKeyword";
  7292. case "unknown":
  7293. return "TSUnknownKeyword";
  7294. default:
  7295. return undefined;
  7296. }
  7297. }
  7298. function tsIsAccessModifier(modifier) {
  7299. return modifier === "private" || modifier === "public" || modifier === "protected";
  7300. }
  7301. function tsIsVarianceAnnotations(modifier) {
  7302. return modifier === "in" || modifier === "out";
  7303. }
  7304. var typescript = (superClass => class TypeScriptParserMixin extends superClass {
  7305. getScopeHandler() {
  7306. return TypeScriptScopeHandler;
  7307. }
  7308. tsIsIdentifier() {
  7309. return tokenIsIdentifier(this.state.type);
  7310. }
  7311. tsTokenCanFollowModifier() {
  7312. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(136) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  7313. }
  7314. tsNextTokenCanFollowModifier() {
  7315. this.next();
  7316. return this.tsTokenCanFollowModifier();
  7317. }
  7318. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7319. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58) {
  7320. return undefined;
  7321. }
  7322. const modifier = this.state.value;
  7323. if (allowedModifiers.indexOf(modifier) !== -1) {
  7324. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7325. return undefined;
  7326. }
  7327. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7328. return modifier;
  7329. }
  7330. }
  7331. return undefined;
  7332. }
  7333. tsParseModifiers({
  7334. modified,
  7335. allowedModifiers,
  7336. disallowedModifiers,
  7337. stopOnStartOfClassStaticBlock,
  7338. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7339. }) {
  7340. const enforceOrder = (loc, modifier, before, after) => {
  7341. if (modifier === before && modified[after]) {
  7342. this.raise(TSErrors.InvalidModifiersOrder, {
  7343. at: loc,
  7344. orderedModifiers: [before, after]
  7345. });
  7346. }
  7347. };
  7348. const incompatible = (loc, modifier, mod1, mod2) => {
  7349. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7350. this.raise(TSErrors.IncompatibleModifiers, {
  7351. at: loc,
  7352. modifiers: [mod1, mod2]
  7353. });
  7354. }
  7355. };
  7356. for (;;) {
  7357. const {
  7358. startLoc
  7359. } = this.state;
  7360. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7361. if (!modifier) break;
  7362. if (tsIsAccessModifier(modifier)) {
  7363. if (modified.accessibility) {
  7364. this.raise(TSErrors.DuplicateAccessibilityModifier, {
  7365. at: startLoc,
  7366. modifier
  7367. });
  7368. } else {
  7369. enforceOrder(startLoc, modifier, modifier, "override");
  7370. enforceOrder(startLoc, modifier, modifier, "static");
  7371. enforceOrder(startLoc, modifier, modifier, "readonly");
  7372. modified.accessibility = modifier;
  7373. }
  7374. } else if (tsIsVarianceAnnotations(modifier)) {
  7375. if (modified[modifier]) {
  7376. this.raise(TSErrors.DuplicateModifier, {
  7377. at: startLoc,
  7378. modifier
  7379. });
  7380. }
  7381. modified[modifier] = true;
  7382. enforceOrder(startLoc, modifier, "in", "out");
  7383. } else {
  7384. if (Object.hasOwnProperty.call(modified, modifier)) {
  7385. this.raise(TSErrors.DuplicateModifier, {
  7386. at: startLoc,
  7387. modifier
  7388. });
  7389. } else {
  7390. enforceOrder(startLoc, modifier, "static", "readonly");
  7391. enforceOrder(startLoc, modifier, "static", "override");
  7392. enforceOrder(startLoc, modifier, "override", "readonly");
  7393. enforceOrder(startLoc, modifier, "abstract", "override");
  7394. incompatible(startLoc, modifier, "declare", "override");
  7395. incompatible(startLoc, modifier, "static", "abstract");
  7396. }
  7397. modified[modifier] = true;
  7398. }
  7399. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7400. this.raise(errorTemplate, {
  7401. at: startLoc,
  7402. modifier
  7403. });
  7404. }
  7405. }
  7406. }
  7407. tsIsListTerminator(kind) {
  7408. switch (kind) {
  7409. case "EnumMembers":
  7410. case "TypeMembers":
  7411. return this.match(8);
  7412. case "HeritageClauseElement":
  7413. return this.match(5);
  7414. case "TupleElementTypes":
  7415. return this.match(3);
  7416. case "TypeParametersOrArguments":
  7417. return this.match(48);
  7418. }
  7419. throw new Error("Unreachable");
  7420. }
  7421. tsParseList(kind, parseElement) {
  7422. const result = [];
  7423. while (!this.tsIsListTerminator(kind)) {
  7424. result.push(parseElement());
  7425. }
  7426. return result;
  7427. }
  7428. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7429. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7430. }
  7431. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7432. const result = [];
  7433. let trailingCommaPos = -1;
  7434. for (;;) {
  7435. if (this.tsIsListTerminator(kind)) {
  7436. break;
  7437. }
  7438. trailingCommaPos = -1;
  7439. const element = parseElement();
  7440. if (element == null) {
  7441. return undefined;
  7442. }
  7443. result.push(element);
  7444. if (this.eat(12)) {
  7445. trailingCommaPos = this.state.lastTokStart;
  7446. continue;
  7447. }
  7448. if (this.tsIsListTerminator(kind)) {
  7449. break;
  7450. }
  7451. if (expectSuccess) {
  7452. this.expect(12);
  7453. }
  7454. return undefined;
  7455. }
  7456. if (refTrailingCommaPos) {
  7457. refTrailingCommaPos.value = trailingCommaPos;
  7458. }
  7459. return result;
  7460. }
  7461. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7462. if (!skipFirstToken) {
  7463. if (bracket) {
  7464. this.expect(0);
  7465. } else {
  7466. this.expect(47);
  7467. }
  7468. }
  7469. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7470. if (bracket) {
  7471. this.expect(3);
  7472. } else {
  7473. this.expect(48);
  7474. }
  7475. return result;
  7476. }
  7477. tsParseImportType() {
  7478. const node = this.startNode();
  7479. this.expect(83);
  7480. this.expect(10);
  7481. if (!this.match(131)) {
  7482. this.raise(TSErrors.UnsupportedImportTypeArgument, {
  7483. at: this.state.startLoc
  7484. });
  7485. }
  7486. node.argument = super.parseExprAtom();
  7487. this.expect(11);
  7488. if (this.eat(16)) {
  7489. node.qualifier = this.tsParseEntityName();
  7490. }
  7491. if (this.match(47)) {
  7492. node.typeParameters = this.tsParseTypeArguments();
  7493. }
  7494. return this.finishNode(node, "TSImportType");
  7495. }
  7496. tsParseEntityName(allowReservedWords = true) {
  7497. let entity = this.parseIdentifier(allowReservedWords);
  7498. while (this.eat(16)) {
  7499. const node = this.startNodeAtNode(entity);
  7500. node.left = entity;
  7501. node.right = this.parseIdentifier(allowReservedWords);
  7502. entity = this.finishNode(node, "TSQualifiedName");
  7503. }
  7504. return entity;
  7505. }
  7506. tsParseTypeReference() {
  7507. const node = this.startNode();
  7508. node.typeName = this.tsParseEntityName();
  7509. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7510. node.typeParameters = this.tsParseTypeArguments();
  7511. }
  7512. return this.finishNode(node, "TSTypeReference");
  7513. }
  7514. tsParseThisTypePredicate(lhs) {
  7515. this.next();
  7516. const node = this.startNodeAtNode(lhs);
  7517. node.parameterName = lhs;
  7518. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7519. node.asserts = false;
  7520. return this.finishNode(node, "TSTypePredicate");
  7521. }
  7522. tsParseThisTypeNode() {
  7523. const node = this.startNode();
  7524. this.next();
  7525. return this.finishNode(node, "TSThisType");
  7526. }
  7527. tsParseTypeQuery() {
  7528. const node = this.startNode();
  7529. this.expect(87);
  7530. if (this.match(83)) {
  7531. node.exprName = this.tsParseImportType();
  7532. } else {
  7533. node.exprName = this.tsParseEntityName();
  7534. }
  7535. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7536. node.typeParameters = this.tsParseTypeArguments();
  7537. }
  7538. return this.finishNode(node, "TSTypeQuery");
  7539. }
  7540. tsParseInOutModifiers(node) {
  7541. this.tsParseModifiers({
  7542. modified: node,
  7543. allowedModifiers: ["in", "out"],
  7544. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7545. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7546. });
  7547. }
  7548. tsParseNoneModifiers(node) {
  7549. this.tsParseModifiers({
  7550. modified: node,
  7551. allowedModifiers: [],
  7552. disallowedModifiers: ["in", "out"],
  7553. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7554. });
  7555. }
  7556. tsParseTypeParameter(parseModifiers = this.tsParseNoneModifiers.bind(this)) {
  7557. const node = this.startNode();
  7558. parseModifiers(node);
  7559. node.name = this.tsParseTypeParameterName();
  7560. node.constraint = this.tsEatThenParseType(81);
  7561. node.default = this.tsEatThenParseType(29);
  7562. return this.finishNode(node, "TSTypeParameter");
  7563. }
  7564. tsTryParseTypeParameters(parseModifiers) {
  7565. if (this.match(47)) {
  7566. return this.tsParseTypeParameters(parseModifiers);
  7567. }
  7568. }
  7569. tsParseTypeParameters(parseModifiers) {
  7570. const node = this.startNode();
  7571. if (this.match(47) || this.match(140)) {
  7572. this.next();
  7573. } else {
  7574. this.unexpected();
  7575. }
  7576. const refTrailingCommaPos = {
  7577. value: -1
  7578. };
  7579. node.params = this.tsParseBracketedList("TypeParametersOrArguments",
  7580. this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7581. if (node.params.length === 0) {
  7582. this.raise(TSErrors.EmptyTypeParameters, {
  7583. at: node
  7584. });
  7585. }
  7586. if (refTrailingCommaPos.value !== -1) {
  7587. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7588. }
  7589. return this.finishNode(node, "TSTypeParameterDeclaration");
  7590. }
  7591. tsFillSignature(returnToken, signature) {
  7592. const returnTokenRequired = returnToken === 19;
  7593. const paramsKey = "parameters";
  7594. const returnTypeKey = "typeAnnotation";
  7595. signature.typeParameters = this.tsTryParseTypeParameters();
  7596. this.expect(10);
  7597. signature[paramsKey] = this.tsParseBindingListForSignature();
  7598. if (returnTokenRequired) {
  7599. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7600. } else if (this.match(returnToken)) {
  7601. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7602. }
  7603. }
  7604. tsParseBindingListForSignature() {
  7605. return super.parseBindingList(11, 41).map(pattern => {
  7606. if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") {
  7607. this.raise(TSErrors.UnsupportedSignatureParameterKind, {
  7608. at: pattern,
  7609. type: pattern.type
  7610. });
  7611. }
  7612. return pattern;
  7613. });
  7614. }
  7615. tsParseTypeMemberSemicolon() {
  7616. if (!this.eat(12) && !this.isLineTerminator()) {
  7617. this.expect(13);
  7618. }
  7619. }
  7620. tsParseSignatureMember(kind, node) {
  7621. this.tsFillSignature(14, node);
  7622. this.tsParseTypeMemberSemicolon();
  7623. return this.finishNode(node, kind);
  7624. }
  7625. tsIsUnambiguouslyIndexSignature() {
  7626. this.next();
  7627. if (tokenIsIdentifier(this.state.type)) {
  7628. this.next();
  7629. return this.match(14);
  7630. }
  7631. return false;
  7632. }
  7633. tsTryParseIndexSignature(node) {
  7634. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  7635. return undefined;
  7636. }
  7637. this.expect(0);
  7638. const id = this.parseIdentifier();
  7639. id.typeAnnotation = this.tsParseTypeAnnotation();
  7640. this.resetEndLocation(id);
  7641. this.expect(3);
  7642. node.parameters = [id];
  7643. const type = this.tsTryParseTypeAnnotation();
  7644. if (type) node.typeAnnotation = type;
  7645. this.tsParseTypeMemberSemicolon();
  7646. return this.finishNode(node, "TSIndexSignature");
  7647. }
  7648. tsParsePropertyOrMethodSignature(node, readonly) {
  7649. if (this.eat(17)) node.optional = true;
  7650. const nodeAny = node;
  7651. if (this.match(10) || this.match(47)) {
  7652. if (readonly) {
  7653. this.raise(TSErrors.ReadonlyForMethodSignature, {
  7654. at: node
  7655. });
  7656. }
  7657. const method = nodeAny;
  7658. if (method.kind && this.match(47)) {
  7659. this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
  7660. at: this.state.curPosition()
  7661. });
  7662. }
  7663. this.tsFillSignature(14, method);
  7664. this.tsParseTypeMemberSemicolon();
  7665. const paramsKey = "parameters";
  7666. const returnTypeKey = "typeAnnotation";
  7667. if (method.kind === "get") {
  7668. if (method[paramsKey].length > 0) {
  7669. this.raise(Errors.BadGetterArity, {
  7670. at: this.state.curPosition()
  7671. });
  7672. if (this.isThisParam(method[paramsKey][0])) {
  7673. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  7674. at: this.state.curPosition()
  7675. });
  7676. }
  7677. }
  7678. } else if (method.kind === "set") {
  7679. if (method[paramsKey].length !== 1) {
  7680. this.raise(Errors.BadSetterArity, {
  7681. at: this.state.curPosition()
  7682. });
  7683. } else {
  7684. const firstParameter = method[paramsKey][0];
  7685. if (this.isThisParam(firstParameter)) {
  7686. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  7687. at: this.state.curPosition()
  7688. });
  7689. }
  7690. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  7691. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
  7692. at: this.state.curPosition()
  7693. });
  7694. }
  7695. if (firstParameter.type === "RestElement") {
  7696. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
  7697. at: this.state.curPosition()
  7698. });
  7699. }
  7700. }
  7701. if (method[returnTypeKey]) {
  7702. this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
  7703. at: method[returnTypeKey]
  7704. });
  7705. }
  7706. } else {
  7707. method.kind = "method";
  7708. }
  7709. return this.finishNode(method, "TSMethodSignature");
  7710. } else {
  7711. const property = nodeAny;
  7712. if (readonly) property.readonly = true;
  7713. const type = this.tsTryParseTypeAnnotation();
  7714. if (type) property.typeAnnotation = type;
  7715. this.tsParseTypeMemberSemicolon();
  7716. return this.finishNode(property, "TSPropertySignature");
  7717. }
  7718. }
  7719. tsParseTypeMember() {
  7720. const node = this.startNode();
  7721. if (this.match(10) || this.match(47)) {
  7722. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  7723. }
  7724. if (this.match(77)) {
  7725. const id = this.startNode();
  7726. this.next();
  7727. if (this.match(10) || this.match(47)) {
  7728. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  7729. } else {
  7730. node.key = this.createIdentifier(id, "new");
  7731. return this.tsParsePropertyOrMethodSignature(node, false);
  7732. }
  7733. }
  7734. this.tsParseModifiers({
  7735. modified: node,
  7736. allowedModifiers: ["readonly"],
  7737. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  7738. });
  7739. const idx = this.tsTryParseIndexSignature(node);
  7740. if (idx) {
  7741. return idx;
  7742. }
  7743. super.parsePropertyName(node);
  7744. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  7745. node.kind = node.key.name;
  7746. super.parsePropertyName(node);
  7747. }
  7748. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  7749. }
  7750. tsParseTypeLiteral() {
  7751. const node = this.startNode();
  7752. node.members = this.tsParseObjectTypeMembers();
  7753. return this.finishNode(node, "TSTypeLiteral");
  7754. }
  7755. tsParseObjectTypeMembers() {
  7756. this.expect(5);
  7757. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  7758. this.expect(8);
  7759. return members;
  7760. }
  7761. tsIsStartOfMappedType() {
  7762. this.next();
  7763. if (this.eat(53)) {
  7764. return this.isContextual(120);
  7765. }
  7766. if (this.isContextual(120)) {
  7767. this.next();
  7768. }
  7769. if (!this.match(0)) {
  7770. return false;
  7771. }
  7772. this.next();
  7773. if (!this.tsIsIdentifier()) {
  7774. return false;
  7775. }
  7776. this.next();
  7777. return this.match(58);
  7778. }
  7779. tsParseMappedTypeParameter() {
  7780. const node = this.startNode();
  7781. node.name = this.tsParseTypeParameterName();
  7782. node.constraint = this.tsExpectThenParseType(58);
  7783. return this.finishNode(node, "TSTypeParameter");
  7784. }
  7785. tsParseMappedType() {
  7786. const node = this.startNode();
  7787. this.expect(5);
  7788. if (this.match(53)) {
  7789. node.readonly = this.state.value;
  7790. this.next();
  7791. this.expectContextual(120);
  7792. } else if (this.eatContextual(120)) {
  7793. node.readonly = true;
  7794. }
  7795. this.expect(0);
  7796. node.typeParameter = this.tsParseMappedTypeParameter();
  7797. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  7798. this.expect(3);
  7799. if (this.match(53)) {
  7800. node.optional = this.state.value;
  7801. this.next();
  7802. this.expect(17);
  7803. } else if (this.eat(17)) {
  7804. node.optional = true;
  7805. }
  7806. node.typeAnnotation = this.tsTryParseType();
  7807. this.semicolon();
  7808. this.expect(8);
  7809. return this.finishNode(node, "TSMappedType");
  7810. }
  7811. tsParseTupleType() {
  7812. const node = this.startNode();
  7813. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  7814. let seenOptionalElement = false;
  7815. let labeledElements = null;
  7816. node.elementTypes.forEach(elementNode => {
  7817. var _labeledElements;
  7818. const {
  7819. type
  7820. } = elementNode;
  7821. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  7822. this.raise(TSErrors.OptionalTypeBeforeRequired, {
  7823. at: elementNode
  7824. });
  7825. }
  7826. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  7827. let checkType = type;
  7828. if (type === "TSRestType") {
  7829. elementNode = elementNode.typeAnnotation;
  7830. checkType = elementNode.type;
  7831. }
  7832. const isLabeled = checkType === "TSNamedTupleMember";
  7833. (_labeledElements = labeledElements) != null ? _labeledElements : labeledElements = isLabeled;
  7834. if (labeledElements !== isLabeled) {
  7835. this.raise(TSErrors.MixedLabeledAndUnlabeledElements, {
  7836. at: elementNode
  7837. });
  7838. }
  7839. });
  7840. return this.finishNode(node, "TSTupleType");
  7841. }
  7842. tsParseTupleElementType() {
  7843. const {
  7844. startLoc
  7845. } = this.state;
  7846. const rest = this.eat(21);
  7847. let type = this.tsParseType();
  7848. const optional = this.eat(17);
  7849. const labeled = this.eat(14);
  7850. if (labeled) {
  7851. const labeledNode = this.startNodeAtNode(type);
  7852. labeledNode.optional = optional;
  7853. if (type.type === "TSTypeReference" && !type.typeParameters && type.typeName.type === "Identifier") {
  7854. labeledNode.label = type.typeName;
  7855. } else {
  7856. this.raise(TSErrors.InvalidTupleMemberLabel, {
  7857. at: type
  7858. });
  7859. labeledNode.label = type;
  7860. }
  7861. labeledNode.elementType = this.tsParseType();
  7862. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  7863. } else if (optional) {
  7864. const optionalTypeNode = this.startNodeAtNode(type);
  7865. optionalTypeNode.typeAnnotation = type;
  7866. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  7867. }
  7868. if (rest) {
  7869. const restNode = this.startNodeAt(startLoc);
  7870. restNode.typeAnnotation = type;
  7871. type = this.finishNode(restNode, "TSRestType");
  7872. }
  7873. return type;
  7874. }
  7875. tsParseParenthesizedType() {
  7876. const node = this.startNode();
  7877. this.expect(10);
  7878. node.typeAnnotation = this.tsParseType();
  7879. this.expect(11);
  7880. return this.finishNode(node, "TSParenthesizedType");
  7881. }
  7882. tsParseFunctionOrConstructorType(type, abstract) {
  7883. const node = this.startNode();
  7884. if (type === "TSConstructorType") {
  7885. node.abstract = !!abstract;
  7886. if (abstract) this.next();
  7887. this.next();
  7888. }
  7889. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  7890. return this.finishNode(node, type);
  7891. }
  7892. tsParseLiteralTypeNode() {
  7893. const node = this.startNode();
  7894. node.literal = (() => {
  7895. switch (this.state.type) {
  7896. case 132:
  7897. case 133:
  7898. case 131:
  7899. case 85:
  7900. case 86:
  7901. return super.parseExprAtom();
  7902. default:
  7903. throw this.unexpected();
  7904. }
  7905. })();
  7906. return this.finishNode(node, "TSLiteralType");
  7907. }
  7908. tsParseTemplateLiteralType() {
  7909. const node = this.startNode();
  7910. node.literal = super.parseTemplate(false);
  7911. return this.finishNode(node, "TSLiteralType");
  7912. }
  7913. parseTemplateSubstitution() {
  7914. if (this.state.inType) return this.tsParseType();
  7915. return super.parseTemplateSubstitution();
  7916. }
  7917. tsParseThisTypeOrThisTypePredicate() {
  7918. const thisKeyword = this.tsParseThisTypeNode();
  7919. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  7920. return this.tsParseThisTypePredicate(thisKeyword);
  7921. } else {
  7922. return thisKeyword;
  7923. }
  7924. }
  7925. tsParseNonArrayType() {
  7926. switch (this.state.type) {
  7927. case 131:
  7928. case 132:
  7929. case 133:
  7930. case 85:
  7931. case 86:
  7932. return this.tsParseLiteralTypeNode();
  7933. case 53:
  7934. if (this.state.value === "-") {
  7935. const node = this.startNode();
  7936. const nextToken = this.lookahead();
  7937. if (nextToken.type !== 132 && nextToken.type !== 133) {
  7938. throw this.unexpected();
  7939. }
  7940. node.literal = this.parseMaybeUnary();
  7941. return this.finishNode(node, "TSLiteralType");
  7942. }
  7943. break;
  7944. case 78:
  7945. return this.tsParseThisTypeOrThisTypePredicate();
  7946. case 87:
  7947. return this.tsParseTypeQuery();
  7948. case 83:
  7949. return this.tsParseImportType();
  7950. case 5:
  7951. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  7952. case 0:
  7953. return this.tsParseTupleType();
  7954. case 10:
  7955. return this.tsParseParenthesizedType();
  7956. case 25:
  7957. case 24:
  7958. return this.tsParseTemplateLiteralType();
  7959. default:
  7960. {
  7961. const {
  7962. type
  7963. } = this.state;
  7964. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  7965. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  7966. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  7967. const node = this.startNode();
  7968. this.next();
  7969. return this.finishNode(node, nodeType);
  7970. }
  7971. return this.tsParseTypeReference();
  7972. }
  7973. }
  7974. }
  7975. throw this.unexpected();
  7976. }
  7977. tsParseArrayTypeOrHigher() {
  7978. let type = this.tsParseNonArrayType();
  7979. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  7980. if (this.match(3)) {
  7981. const node = this.startNodeAtNode(type);
  7982. node.elementType = type;
  7983. this.expect(3);
  7984. type = this.finishNode(node, "TSArrayType");
  7985. } else {
  7986. const node = this.startNodeAtNode(type);
  7987. node.objectType = type;
  7988. node.indexType = this.tsParseType();
  7989. this.expect(3);
  7990. type = this.finishNode(node, "TSIndexedAccessType");
  7991. }
  7992. }
  7993. return type;
  7994. }
  7995. tsParseTypeOperator() {
  7996. const node = this.startNode();
  7997. const operator = this.state.value;
  7998. this.next();
  7999. node.operator = operator;
  8000. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8001. if (operator === "readonly") {
  8002. this.tsCheckTypeAnnotationForReadOnly(
  8003. node);
  8004. }
  8005. return this.finishNode(node, "TSTypeOperator");
  8006. }
  8007. tsCheckTypeAnnotationForReadOnly(node) {
  8008. switch (node.typeAnnotation.type) {
  8009. case "TSTupleType":
  8010. case "TSArrayType":
  8011. return;
  8012. default:
  8013. this.raise(TSErrors.UnexpectedReadonly, {
  8014. at: node
  8015. });
  8016. }
  8017. }
  8018. tsParseInferType() {
  8019. const node = this.startNode();
  8020. this.expectContextual(113);
  8021. const typeParameter = this.startNode();
  8022. typeParameter.name = this.tsParseTypeParameterName();
  8023. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8024. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8025. return this.finishNode(node, "TSInferType");
  8026. }
  8027. tsParseConstraintForInferType() {
  8028. if (this.eat(81)) {
  8029. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8030. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8031. return constraint;
  8032. }
  8033. }
  8034. }
  8035. tsParseTypeOperatorOrHigher() {
  8036. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8037. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(113) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8038. }
  8039. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8040. const node = this.startNode();
  8041. const hasLeadingOperator = this.eat(operator);
  8042. const types = [];
  8043. do {
  8044. types.push(parseConstituentType());
  8045. } while (this.eat(operator));
  8046. if (types.length === 1 && !hasLeadingOperator) {
  8047. return types[0];
  8048. }
  8049. node.types = types;
  8050. return this.finishNode(node, kind);
  8051. }
  8052. tsParseIntersectionTypeOrHigher() {
  8053. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8054. }
  8055. tsParseUnionTypeOrHigher() {
  8056. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8057. }
  8058. tsIsStartOfFunctionType() {
  8059. if (this.match(47)) {
  8060. return true;
  8061. }
  8062. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8063. }
  8064. tsSkipParameterStart() {
  8065. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8066. this.next();
  8067. return true;
  8068. }
  8069. if (this.match(5)) {
  8070. const {
  8071. errors
  8072. } = this.state;
  8073. const previousErrorCount = errors.length;
  8074. try {
  8075. this.parseObjectLike(8, true);
  8076. return errors.length === previousErrorCount;
  8077. } catch (_unused) {
  8078. return false;
  8079. }
  8080. }
  8081. if (this.match(0)) {
  8082. this.next();
  8083. const {
  8084. errors
  8085. } = this.state;
  8086. const previousErrorCount = errors.length;
  8087. try {
  8088. super.parseBindingList(3, 93, true);
  8089. return errors.length === previousErrorCount;
  8090. } catch (_unused2) {
  8091. return false;
  8092. }
  8093. }
  8094. return false;
  8095. }
  8096. tsIsUnambiguouslyStartOfFunctionType() {
  8097. this.next();
  8098. if (this.match(11) || this.match(21)) {
  8099. return true;
  8100. }
  8101. if (this.tsSkipParameterStart()) {
  8102. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8103. return true;
  8104. }
  8105. if (this.match(11)) {
  8106. this.next();
  8107. if (this.match(19)) {
  8108. return true;
  8109. }
  8110. }
  8111. }
  8112. return false;
  8113. }
  8114. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8115. return this.tsInType(() => {
  8116. const t = this.startNode();
  8117. this.expect(returnToken);
  8118. const node = this.startNode();
  8119. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8120. if (asserts && this.match(78)) {
  8121. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8122. if (thisTypePredicate.type === "TSThisType") {
  8123. node.parameterName = thisTypePredicate;
  8124. node.asserts = true;
  8125. node.typeAnnotation = null;
  8126. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8127. } else {
  8128. this.resetStartLocationFromNode(thisTypePredicate, node);
  8129. thisTypePredicate.asserts = true;
  8130. }
  8131. t.typeAnnotation = thisTypePredicate;
  8132. return this.finishNode(t, "TSTypeAnnotation");
  8133. }
  8134. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8135. if (!typePredicateVariable) {
  8136. if (!asserts) {
  8137. return this.tsParseTypeAnnotation(false, t);
  8138. }
  8139. node.parameterName = this.parseIdentifier();
  8140. node.asserts = asserts;
  8141. node.typeAnnotation = null;
  8142. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8143. return this.finishNode(t, "TSTypeAnnotation");
  8144. }
  8145. const type = this.tsParseTypeAnnotation(false);
  8146. node.parameterName = typePredicateVariable;
  8147. node.typeAnnotation = type;
  8148. node.asserts = asserts;
  8149. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8150. return this.finishNode(t, "TSTypeAnnotation");
  8151. });
  8152. }
  8153. tsTryParseTypeOrTypePredicateAnnotation() {
  8154. return this.match(14) ? this.tsParseTypeOrTypePredicateAnnotation(14) : undefined;
  8155. }
  8156. tsTryParseTypeAnnotation() {
  8157. return this.match(14) ? this.tsParseTypeAnnotation() : undefined;
  8158. }
  8159. tsTryParseType() {
  8160. return this.tsEatThenParseType(14);
  8161. }
  8162. tsParseTypePredicatePrefix() {
  8163. const id = this.parseIdentifier();
  8164. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  8165. this.next();
  8166. return id;
  8167. }
  8168. }
  8169. tsParseTypePredicateAsserts() {
  8170. if (this.state.type !== 107) {
  8171. return false;
  8172. }
  8173. const containsEsc = this.state.containsEsc;
  8174. this.next();
  8175. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8176. return false;
  8177. }
  8178. if (containsEsc) {
  8179. this.raise(Errors.InvalidEscapedReservedWord, {
  8180. at: this.state.lastTokStartLoc,
  8181. reservedWord: "asserts"
  8182. });
  8183. }
  8184. return true;
  8185. }
  8186. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8187. this.tsInType(() => {
  8188. if (eatColon) this.expect(14);
  8189. t.typeAnnotation = this.tsParseType();
  8190. });
  8191. return this.finishNode(t, "TSTypeAnnotation");
  8192. }
  8193. tsParseType() {
  8194. assert(this.state.inType);
  8195. const type = this.tsParseNonConditionalType();
  8196. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8197. return type;
  8198. }
  8199. const node = this.startNodeAtNode(type);
  8200. node.checkType = type;
  8201. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8202. this.expect(17);
  8203. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8204. this.expect(14);
  8205. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8206. return this.finishNode(node, "TSConditionalType");
  8207. }
  8208. isAbstractConstructorSignature() {
  8209. return this.isContextual(122) && this.lookahead().type === 77;
  8210. }
  8211. tsParseNonConditionalType() {
  8212. if (this.tsIsStartOfFunctionType()) {
  8213. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8214. }
  8215. if (this.match(77)) {
  8216. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8217. } else if (this.isAbstractConstructorSignature()) {
  8218. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8219. }
  8220. return this.tsParseUnionTypeOrHigher();
  8221. }
  8222. tsParseTypeAssertion() {
  8223. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8224. this.raise(TSErrors.ReservedTypeAssertion, {
  8225. at: this.state.startLoc
  8226. });
  8227. }
  8228. const node = this.startNode();
  8229. node.typeAnnotation = this.tsInType(() => {
  8230. this.next();
  8231. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8232. });
  8233. this.expect(48);
  8234. node.expression = this.parseMaybeUnary();
  8235. return this.finishNode(node, "TSTypeAssertion");
  8236. }
  8237. tsParseHeritageClause(token) {
  8238. const originalStartLoc = this.state.startLoc;
  8239. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8240. const node = this.startNode();
  8241. node.expression = this.tsParseEntityName();
  8242. if (this.match(47)) {
  8243. node.typeParameters = this.tsParseTypeArguments();
  8244. }
  8245. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8246. });
  8247. if (!delimitedList.length) {
  8248. this.raise(TSErrors.EmptyHeritageClauseType, {
  8249. at: originalStartLoc,
  8250. token
  8251. });
  8252. }
  8253. return delimitedList;
  8254. }
  8255. tsParseInterfaceDeclaration(node, properties = {}) {
  8256. if (this.hasFollowingLineBreak()) return null;
  8257. this.expectContextual(127);
  8258. if (properties.declare) node.declare = true;
  8259. if (tokenIsIdentifier(this.state.type)) {
  8260. node.id = this.parseIdentifier();
  8261. this.checkIdentifier(node.id, BIND_TS_INTERFACE);
  8262. } else {
  8263. node.id = null;
  8264. this.raise(TSErrors.MissingInterfaceName, {
  8265. at: this.state.startLoc
  8266. });
  8267. }
  8268. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers.bind(this));
  8269. if (this.eat(81)) {
  8270. node.extends = this.tsParseHeritageClause("extends");
  8271. }
  8272. const body = this.startNode();
  8273. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8274. node.body = this.finishNode(body, "TSInterfaceBody");
  8275. return this.finishNode(node, "TSInterfaceDeclaration");
  8276. }
  8277. tsParseTypeAliasDeclaration(node) {
  8278. node.id = this.parseIdentifier();
  8279. this.checkIdentifier(node.id, BIND_TS_TYPE);
  8280. node.typeAnnotation = this.tsInType(() => {
  8281. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers.bind(this));
  8282. this.expect(29);
  8283. if (this.isContextual(112) && this.lookahead().type !== 16) {
  8284. const node = this.startNode();
  8285. this.next();
  8286. return this.finishNode(node, "TSIntrinsicKeyword");
  8287. }
  8288. return this.tsParseType();
  8289. });
  8290. this.semicolon();
  8291. return this.finishNode(node, "TSTypeAliasDeclaration");
  8292. }
  8293. tsInNoContext(cb) {
  8294. const oldContext = this.state.context;
  8295. this.state.context = [oldContext[0]];
  8296. try {
  8297. return cb();
  8298. } finally {
  8299. this.state.context = oldContext;
  8300. }
  8301. }
  8302. tsInType(cb) {
  8303. const oldInType = this.state.inType;
  8304. this.state.inType = true;
  8305. try {
  8306. return cb();
  8307. } finally {
  8308. this.state.inType = oldInType;
  8309. }
  8310. }
  8311. tsInDisallowConditionalTypesContext(cb) {
  8312. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8313. this.state.inDisallowConditionalTypesContext = true;
  8314. try {
  8315. return cb();
  8316. } finally {
  8317. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8318. }
  8319. }
  8320. tsInAllowConditionalTypesContext(cb) {
  8321. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8322. this.state.inDisallowConditionalTypesContext = false;
  8323. try {
  8324. return cb();
  8325. } finally {
  8326. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8327. }
  8328. }
  8329. tsEatThenParseType(token) {
  8330. return !this.match(token) ? undefined : this.tsNextThenParseType();
  8331. }
  8332. tsExpectThenParseType(token) {
  8333. return this.tsDoThenParseType(() => this.expect(token));
  8334. }
  8335. tsNextThenParseType() {
  8336. return this.tsDoThenParseType(() => this.next());
  8337. }
  8338. tsDoThenParseType(cb) {
  8339. return this.tsInType(() => {
  8340. cb();
  8341. return this.tsParseType();
  8342. });
  8343. }
  8344. tsParseEnumMember() {
  8345. const node = this.startNode();
  8346. node.id = this.match(131) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8347. if (this.eat(29)) {
  8348. node.initializer = super.parseMaybeAssignAllowIn();
  8349. }
  8350. return this.finishNode(node, "TSEnumMember");
  8351. }
  8352. tsParseEnumDeclaration(node, properties = {}) {
  8353. if (properties.const) node.const = true;
  8354. if (properties.declare) node.declare = true;
  8355. this.expectContextual(124);
  8356. node.id = this.parseIdentifier();
  8357. this.checkIdentifier(node.id, node.const ? BIND_TS_CONST_ENUM : BIND_TS_ENUM);
  8358. this.expect(5);
  8359. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8360. this.expect(8);
  8361. return this.finishNode(node, "TSEnumDeclaration");
  8362. }
  8363. tsParseModuleBlock() {
  8364. const node = this.startNode();
  8365. this.scope.enter(SCOPE_OTHER);
  8366. this.expect(5);
  8367. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8368. this.scope.exit();
  8369. return this.finishNode(node, "TSModuleBlock");
  8370. }
  8371. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8372. node.id = this.parseIdentifier();
  8373. if (!nested) {
  8374. this.checkIdentifier(node.id, BIND_TS_NAMESPACE);
  8375. }
  8376. if (this.eat(16)) {
  8377. const inner = this.startNode();
  8378. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8379. node.body = inner;
  8380. } else {
  8381. this.scope.enter(SCOPE_TS_MODULE);
  8382. this.prodParam.enter(PARAM);
  8383. node.body = this.tsParseModuleBlock();
  8384. this.prodParam.exit();
  8385. this.scope.exit();
  8386. }
  8387. return this.finishNode(node, "TSModuleDeclaration");
  8388. }
  8389. tsParseAmbientExternalModuleDeclaration(node) {
  8390. if (this.isContextual(110)) {
  8391. node.global = true;
  8392. node.id = this.parseIdentifier();
  8393. } else if (this.match(131)) {
  8394. node.id = super.parseStringLiteral(this.state.value);
  8395. } else {
  8396. this.unexpected();
  8397. }
  8398. if (this.match(5)) {
  8399. this.scope.enter(SCOPE_TS_MODULE);
  8400. this.prodParam.enter(PARAM);
  8401. node.body = this.tsParseModuleBlock();
  8402. this.prodParam.exit();
  8403. this.scope.exit();
  8404. } else {
  8405. this.semicolon();
  8406. }
  8407. return this.finishNode(node, "TSModuleDeclaration");
  8408. }
  8409. tsParseImportEqualsDeclaration(node, isExport) {
  8410. node.isExport = isExport || false;
  8411. node.id = this.parseIdentifier();
  8412. this.checkIdentifier(node.id, BIND_FLAGS_TS_IMPORT);
  8413. this.expect(29);
  8414. const moduleReference = this.tsParseModuleReference();
  8415. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8416. this.raise(TSErrors.ImportAliasHasImportType, {
  8417. at: moduleReference
  8418. });
  8419. }
  8420. node.moduleReference = moduleReference;
  8421. this.semicolon();
  8422. return this.finishNode(node, "TSImportEqualsDeclaration");
  8423. }
  8424. tsIsExternalModuleReference() {
  8425. return this.isContextual(117) && this.lookaheadCharCode() === 40;
  8426. }
  8427. tsParseModuleReference() {
  8428. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  8429. }
  8430. tsParseExternalModuleReference() {
  8431. const node = this.startNode();
  8432. this.expectContextual(117);
  8433. this.expect(10);
  8434. if (!this.match(131)) {
  8435. throw this.unexpected();
  8436. }
  8437. node.expression = super.parseExprAtom();
  8438. this.expect(11);
  8439. return this.finishNode(node, "TSExternalModuleReference");
  8440. }
  8441. tsLookAhead(f) {
  8442. const state = this.state.clone();
  8443. const res = f();
  8444. this.state = state;
  8445. return res;
  8446. }
  8447. tsTryParseAndCatch(f) {
  8448. const result = this.tryParse(abort =>
  8449. f() || abort());
  8450. if (result.aborted || !result.node) return undefined;
  8451. if (result.error) this.state = result.failState;
  8452. return result.node;
  8453. }
  8454. tsTryParse(f) {
  8455. const state = this.state.clone();
  8456. const result = f();
  8457. if (result !== undefined && result !== false) {
  8458. return result;
  8459. } else {
  8460. this.state = state;
  8461. return undefined;
  8462. }
  8463. }
  8464. tsTryParseDeclare(nany) {
  8465. if (this.isLineTerminator()) {
  8466. return;
  8467. }
  8468. let starttype = this.state.type;
  8469. let kind;
  8470. if (this.isContextual(99)) {
  8471. starttype = 74;
  8472. kind = "let";
  8473. }
  8474. return this.tsInAmbientContext(() => {
  8475. if (starttype === 68) {
  8476. nany.declare = true;
  8477. return super.parseFunctionStatement(nany, false, true);
  8478. }
  8479. if (starttype === 80) {
  8480. nany.declare = true;
  8481. return this.parseClass(nany, true, false);
  8482. }
  8483. if (starttype === 124) {
  8484. return this.tsParseEnumDeclaration(nany, {
  8485. declare: true
  8486. });
  8487. }
  8488. if (starttype === 110) {
  8489. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8490. }
  8491. if (starttype === 75 || starttype === 74) {
  8492. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8493. nany.declare = true;
  8494. return this.parseVarStatement(nany, kind || this.state.value, true);
  8495. }
  8496. this.expect(75);
  8497. return this.tsParseEnumDeclaration(nany, {
  8498. const: true,
  8499. declare: true
  8500. });
  8501. }
  8502. if (starttype === 127) {
  8503. const result = this.tsParseInterfaceDeclaration(nany, {
  8504. declare: true
  8505. });
  8506. if (result) return result;
  8507. }
  8508. if (tokenIsIdentifier(starttype)) {
  8509. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8510. }
  8511. });
  8512. }
  8513. tsTryParseExportDeclaration() {
  8514. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  8515. }
  8516. tsParseExpressionStatement(node, expr, decorators) {
  8517. switch (expr.name) {
  8518. case "declare":
  8519. {
  8520. const declaration = this.tsTryParseDeclare(node);
  8521. if (declaration) {
  8522. declaration.declare = true;
  8523. return declaration;
  8524. }
  8525. break;
  8526. }
  8527. case "global":
  8528. if (this.match(5)) {
  8529. this.scope.enter(SCOPE_TS_MODULE);
  8530. this.prodParam.enter(PARAM);
  8531. const mod = node;
  8532. mod.global = true;
  8533. mod.id = expr;
  8534. mod.body = this.tsParseModuleBlock();
  8535. this.scope.exit();
  8536. this.prodParam.exit();
  8537. return this.finishNode(mod, "TSModuleDeclaration");
  8538. }
  8539. break;
  8540. default:
  8541. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8542. }
  8543. }
  8544. tsParseDeclaration(node, value, next, decorators) {
  8545. switch (value) {
  8546. case "abstract":
  8547. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8548. return this.tsParseAbstractDeclaration(node, decorators);
  8549. }
  8550. break;
  8551. case "module":
  8552. if (this.tsCheckLineTerminator(next)) {
  8553. if (this.match(131)) {
  8554. return this.tsParseAmbientExternalModuleDeclaration(node);
  8555. } else if (tokenIsIdentifier(this.state.type)) {
  8556. return this.tsParseModuleOrNamespaceDeclaration(node);
  8557. }
  8558. }
  8559. break;
  8560. case "namespace":
  8561. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8562. return this.tsParseModuleOrNamespaceDeclaration(node);
  8563. }
  8564. break;
  8565. case "type":
  8566. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8567. return this.tsParseTypeAliasDeclaration(node);
  8568. }
  8569. break;
  8570. }
  8571. }
  8572. tsCheckLineTerminator(next) {
  8573. if (next) {
  8574. if (this.hasFollowingLineBreak()) return false;
  8575. this.next();
  8576. return true;
  8577. }
  8578. return !this.isLineTerminator();
  8579. }
  8580. tsTryParseGenericAsyncArrowFunction(startLoc) {
  8581. if (!this.match(47)) {
  8582. return undefined;
  8583. }
  8584. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8585. this.state.maybeInArrowParameters = true;
  8586. const res = this.tsTryParseAndCatch(() => {
  8587. const node = this.startNodeAt(startLoc);
  8588. node.typeParameters = this.tsParseTypeParameters();
  8589. super.parseFunctionParams(node);
  8590. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  8591. this.expect(19);
  8592. return node;
  8593. });
  8594. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  8595. if (!res) {
  8596. return undefined;
  8597. }
  8598. return super.parseArrowExpression(res, null, true);
  8599. }
  8600. tsParseTypeArgumentsInExpression() {
  8601. if (this.reScan_lt() !== 47) {
  8602. return undefined;
  8603. }
  8604. return this.tsParseTypeArguments();
  8605. }
  8606. tsParseTypeArguments() {
  8607. const node = this.startNode();
  8608. node.params = this.tsInType(() =>
  8609. this.tsInNoContext(() => {
  8610. this.expect(47);
  8611. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  8612. }));
  8613. if (node.params.length === 0) {
  8614. this.raise(TSErrors.EmptyTypeArguments, {
  8615. at: node
  8616. });
  8617. }
  8618. this.expect(48);
  8619. return this.finishNode(node, "TSTypeParameterInstantiation");
  8620. }
  8621. tsIsDeclarationStart() {
  8622. return tokenIsTSDeclarationStart(this.state.type);
  8623. }
  8624. isExportDefaultSpecifier() {
  8625. if (this.tsIsDeclarationStart()) return false;
  8626. return super.isExportDefaultSpecifier();
  8627. }
  8628. parseAssignableListItem(allowModifiers, decorators) {
  8629. const startLoc = this.state.startLoc;
  8630. let accessibility;
  8631. let readonly = false;
  8632. let override = false;
  8633. if (allowModifiers !== undefined) {
  8634. const modified = {};
  8635. this.tsParseModifiers({
  8636. modified,
  8637. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  8638. });
  8639. accessibility = modified.accessibility;
  8640. override = modified.override;
  8641. readonly = modified.readonly;
  8642. if (allowModifiers === false && (accessibility || readonly || override)) {
  8643. this.raise(TSErrors.UnexpectedParameterModifier, {
  8644. at: startLoc
  8645. });
  8646. }
  8647. }
  8648. const left = this.parseMaybeDefault();
  8649. this.parseAssignableListItemTypes(left);
  8650. const elt = this.parseMaybeDefault(left.loc.start, left);
  8651. if (accessibility || readonly || override) {
  8652. const pp = this.startNodeAt(startLoc);
  8653. if (decorators.length) {
  8654. pp.decorators = decorators;
  8655. }
  8656. if (accessibility) pp.accessibility = accessibility;
  8657. if (readonly) pp.readonly = readonly;
  8658. if (override) pp.override = override;
  8659. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  8660. this.raise(TSErrors.UnsupportedParameterPropertyKind, {
  8661. at: pp
  8662. });
  8663. }
  8664. pp.parameter = elt;
  8665. return this.finishNode(pp, "TSParameterProperty");
  8666. }
  8667. if (decorators.length) {
  8668. left.decorators = decorators;
  8669. }
  8670. return elt;
  8671. }
  8672. isSimpleParameter(node) {
  8673. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  8674. }
  8675. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  8676. if (this.match(14)) {
  8677. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  8678. }
  8679. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  8680. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  8681. return this.finishNode(node, bodilessType);
  8682. }
  8683. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  8684. this.raise(TSErrors.DeclareFunctionHasImplementation, {
  8685. at: node
  8686. });
  8687. if (node.declare) {
  8688. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  8689. }
  8690. }
  8691. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  8692. }
  8693. registerFunctionStatementId(node) {
  8694. if (!node.body && node.id) {
  8695. this.checkIdentifier(node.id, BIND_TS_AMBIENT);
  8696. } else {
  8697. super.registerFunctionStatementId(node);
  8698. }
  8699. }
  8700. tsCheckForInvalidTypeCasts(items) {
  8701. items.forEach(node => {
  8702. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  8703. this.raise(TSErrors.UnexpectedTypeAnnotation, {
  8704. at: node.typeAnnotation
  8705. });
  8706. }
  8707. });
  8708. }
  8709. toReferencedList(exprList,
  8710. isInParens) {
  8711. this.tsCheckForInvalidTypeCasts(exprList);
  8712. return exprList;
  8713. }
  8714. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  8715. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  8716. if (node.type === "ArrayExpression") {
  8717. this.tsCheckForInvalidTypeCasts(node.elements);
  8718. }
  8719. return node;
  8720. }
  8721. parseSubscript(base, startLoc, noCalls, state) {
  8722. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  8723. this.state.canStartJSXElement = false;
  8724. this.next();
  8725. const nonNullExpression = this.startNodeAt(startLoc);
  8726. nonNullExpression.expression = base;
  8727. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  8728. }
  8729. let isOptionalCall = false;
  8730. if (this.match(18) && this.lookaheadCharCode() === 60) {
  8731. if (noCalls) {
  8732. state.stop = true;
  8733. return base;
  8734. }
  8735. state.optionalChainMember = isOptionalCall = true;
  8736. this.next();
  8737. }
  8738. if (this.match(47) || this.match(51)) {
  8739. let missingParenErrorLoc;
  8740. const result = this.tsTryParseAndCatch(() => {
  8741. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  8742. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  8743. if (asyncArrowFn) {
  8744. return asyncArrowFn;
  8745. }
  8746. }
  8747. const typeArguments = this.tsParseTypeArgumentsInExpression();
  8748. if (!typeArguments) return;
  8749. if (isOptionalCall && !this.match(10)) {
  8750. missingParenErrorLoc = this.state.curPosition();
  8751. return;
  8752. }
  8753. if (tokenIsTemplate(this.state.type)) {
  8754. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  8755. result.typeParameters = typeArguments;
  8756. return result;
  8757. }
  8758. if (!noCalls && this.eat(10)) {
  8759. const node = this.startNodeAt(startLoc);
  8760. node.callee = base;
  8761. node.arguments = this.parseCallExpressionArguments(11, false);
  8762. this.tsCheckForInvalidTypeCasts(node.arguments);
  8763. node.typeParameters = typeArguments;
  8764. if (state.optionalChainMember) {
  8765. node.optional = isOptionalCall;
  8766. }
  8767. return this.finishCallExpression(node, state.optionalChainMember);
  8768. }
  8769. const tokenType = this.state.type;
  8770. if (
  8771. tokenType === 48 ||
  8772. tokenType === 52 ||
  8773. tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  8774. return;
  8775. }
  8776. const node = this.startNodeAt(startLoc);
  8777. node.expression = base;
  8778. node.typeParameters = typeArguments;
  8779. return this.finishNode(node, "TSInstantiationExpression");
  8780. });
  8781. if (missingParenErrorLoc) {
  8782. this.unexpected(missingParenErrorLoc, 10);
  8783. }
  8784. if (result) {
  8785. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  8786. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
  8787. at: this.state.startLoc
  8788. });
  8789. }
  8790. return result;
  8791. }
  8792. }
  8793. return super.parseSubscript(base, startLoc, noCalls, state);
  8794. }
  8795. parseNewCallee(node) {
  8796. var _callee$extra;
  8797. super.parseNewCallee(node);
  8798. const {
  8799. callee
  8800. } = node;
  8801. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  8802. node.typeParameters = callee.typeParameters;
  8803. node.callee = callee.expression;
  8804. }
  8805. }
  8806. parseExprOp(left, leftStartLoc, minPrec) {
  8807. let isSatisfies;
  8808. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(118)))) {
  8809. const node = this.startNodeAt(leftStartLoc);
  8810. node.expression = left;
  8811. node.typeAnnotation = this.tsInType(() => {
  8812. this.next();
  8813. if (this.match(75)) {
  8814. if (isSatisfies) {
  8815. this.raise(Errors.UnexpectedKeyword, {
  8816. at: this.state.startLoc,
  8817. keyword: "const"
  8818. });
  8819. }
  8820. return this.tsParseTypeReference();
  8821. }
  8822. return this.tsParseType();
  8823. });
  8824. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  8825. this.reScan_lt_gt();
  8826. return this.parseExprOp(
  8827. node, leftStartLoc, minPrec);
  8828. }
  8829. return super.parseExprOp(left, leftStartLoc, minPrec);
  8830. }
  8831. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  8832. if (!this.state.isAmbientContext) {
  8833. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  8834. }
  8835. }
  8836. checkImportReflection(node) {
  8837. super.checkImportReflection(node);
  8838. if (node.module && node.importKind !== "value") {
  8839. this.raise(TSErrors.ImportReflectionHasImportType, {
  8840. at: node.specifiers[0].loc.start
  8841. });
  8842. }
  8843. }
  8844. checkDuplicateExports() {}
  8845. parseImport(node) {
  8846. node.importKind = "value";
  8847. if (tokenIsIdentifier(this.state.type) || this.match(55) || this.match(5)) {
  8848. let ahead = this.lookahead();
  8849. if (this.isContextual(128) &&
  8850. ahead.type !== 12 &&
  8851. ahead.type !== 97 &&
  8852. ahead.type !== 29) {
  8853. node.importKind = "type";
  8854. this.next();
  8855. ahead = this.lookahead();
  8856. }
  8857. if (tokenIsIdentifier(this.state.type) && ahead.type === 29) {
  8858. return this.tsParseImportEqualsDeclaration(node);
  8859. }
  8860. }
  8861. const importNode = super.parseImport(node);
  8862. if (importNode.importKind === "type" &&
  8863. importNode.specifiers.length > 1 &&
  8864. importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  8865. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
  8866. at: importNode
  8867. });
  8868. }
  8869. return importNode;
  8870. }
  8871. parseExport(node, decorators) {
  8872. if (this.match(83)) {
  8873. this.next();
  8874. if (this.isContextual(128) && this.lookaheadCharCode() !== 61) {
  8875. node.importKind = "type";
  8876. this.next();
  8877. } else {
  8878. node.importKind = "value";
  8879. }
  8880. return this.tsParseImportEqualsDeclaration(node, true);
  8881. } else if (this.eat(29)) {
  8882. const assign = node;
  8883. assign.expression = super.parseExpression();
  8884. this.semicolon();
  8885. return this.finishNode(assign, "TSExportAssignment");
  8886. } else if (this.eatContextual(93)) {
  8887. const decl = node;
  8888. this.expectContextual(126);
  8889. decl.id = this.parseIdentifier();
  8890. this.semicolon();
  8891. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  8892. } else {
  8893. if (this.isContextual(128) && this.lookahead().type === 5) {
  8894. this.next();
  8895. node.exportKind = "type";
  8896. } else {
  8897. node.exportKind = "value";
  8898. }
  8899. return super.parseExport(node, decorators);
  8900. }
  8901. }
  8902. isAbstractClass() {
  8903. return this.isContextual(122) && this.lookahead().type === 80;
  8904. }
  8905. parseExportDefaultExpression() {
  8906. if (this.isAbstractClass()) {
  8907. const cls = this.startNode();
  8908. this.next();
  8909. cls.abstract = true;
  8910. return this.parseClass(cls, true, true);
  8911. }
  8912. if (this.match(127)) {
  8913. const result = this.tsParseInterfaceDeclaration(this.startNode());
  8914. if (result) return result;
  8915. }
  8916. return super.parseExportDefaultExpression();
  8917. }
  8918. parseVarStatement(node, kind, allowMissingInitializer = false) {
  8919. const {
  8920. isAmbientContext
  8921. } = this.state;
  8922. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  8923. if (!isAmbientContext) return declaration;
  8924. for (const {
  8925. id,
  8926. init
  8927. } of declaration.declarations) {
  8928. if (!init) continue;
  8929. if (kind !== "const" || !!id.typeAnnotation) {
  8930. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
  8931. at: init
  8932. });
  8933. } else if (init.type !== "StringLiteral" && init.type !== "BooleanLiteral" && init.type !== "NumericLiteral" && init.type !== "BigIntLiteral" && (init.type !== "TemplateLiteral" || init.expressions.length > 0) && !isPossiblyLiteralEnum(init)) {
  8934. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
  8935. at: init
  8936. });
  8937. }
  8938. }
  8939. return declaration;
  8940. }
  8941. parseStatementContent(context, topLevel, decorators) {
  8942. if (this.match(75) && this.isLookaheadContextual("enum")) {
  8943. const node = this.startNode();
  8944. this.expect(75);
  8945. return this.tsParseEnumDeclaration(node, {
  8946. const: true
  8947. });
  8948. }
  8949. if (this.isContextual(124)) {
  8950. return this.tsParseEnumDeclaration(this.startNode());
  8951. }
  8952. if (this.isContextual(127)) {
  8953. const result = this.tsParseInterfaceDeclaration(this.startNode());
  8954. if (result) return result;
  8955. }
  8956. return super.parseStatementContent(context, topLevel, decorators);
  8957. }
  8958. parseAccessModifier() {
  8959. return this.tsParseModifier(["public", "protected", "private"]);
  8960. }
  8961. tsHasSomeModifiers(member, modifiers) {
  8962. return modifiers.some(modifier => {
  8963. if (tsIsAccessModifier(modifier)) {
  8964. return member.accessibility === modifier;
  8965. }
  8966. return !!member[modifier];
  8967. });
  8968. }
  8969. tsIsStartOfStaticBlocks() {
  8970. return this.isContextual(104) && this.lookaheadCharCode() === 123;
  8971. }
  8972. parseClassMember(classBody, member, state) {
  8973. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  8974. this.tsParseModifiers({
  8975. modified: member,
  8976. allowedModifiers: modifiers,
  8977. disallowedModifiers: ["in", "out"],
  8978. stopOnStartOfClassStaticBlock: true,
  8979. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  8980. });
  8981. const callParseClassMemberWithIsStatic = () => {
  8982. if (this.tsIsStartOfStaticBlocks()) {
  8983. this.next();
  8984. this.next();
  8985. if (this.tsHasSomeModifiers(member, modifiers)) {
  8986. this.raise(TSErrors.StaticBlockCannotHaveModifier, {
  8987. at: this.state.curPosition()
  8988. });
  8989. }
  8990. super.parseClassStaticBlock(classBody, member);
  8991. } else {
  8992. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  8993. }
  8994. };
  8995. if (member.declare) {
  8996. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  8997. } else {
  8998. callParseClassMemberWithIsStatic();
  8999. }
  9000. }
  9001. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9002. const idx = this.tsTryParseIndexSignature(member);
  9003. if (idx) {
  9004. classBody.body.push(idx);
  9005. if (member.abstract) {
  9006. this.raise(TSErrors.IndexSignatureHasAbstract, {
  9007. at: member
  9008. });
  9009. }
  9010. if (member.accessibility) {
  9011. this.raise(TSErrors.IndexSignatureHasAccessibility, {
  9012. at: member,
  9013. modifier: member.accessibility
  9014. });
  9015. }
  9016. if (member.declare) {
  9017. this.raise(TSErrors.IndexSignatureHasDeclare, {
  9018. at: member
  9019. });
  9020. }
  9021. if (member.override) {
  9022. this.raise(TSErrors.IndexSignatureHasOverride, {
  9023. at: member
  9024. });
  9025. }
  9026. return;
  9027. }
  9028. if (!this.state.inAbstractClass && member.abstract) {
  9029. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
  9030. at: member
  9031. });
  9032. }
  9033. if (member.override) {
  9034. if (!state.hadSuperClass) {
  9035. this.raise(TSErrors.OverrideNotInSubClass, {
  9036. at: member
  9037. });
  9038. }
  9039. }
  9040. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9041. }
  9042. parsePostMemberNameModifiers(methodOrProp) {
  9043. const optional = this.eat(17);
  9044. if (optional) methodOrProp.optional = true;
  9045. if (methodOrProp.readonly && this.match(10)) {
  9046. this.raise(TSErrors.ClassMethodHasReadonly, {
  9047. at: methodOrProp
  9048. });
  9049. }
  9050. if (methodOrProp.declare && this.match(10)) {
  9051. this.raise(TSErrors.ClassMethodHasDeclare, {
  9052. at: methodOrProp
  9053. });
  9054. }
  9055. }
  9056. parseExpressionStatement(node, expr, decorators) {
  9057. const decl = expr.type === "Identifier" ?
  9058. this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9059. return decl || super.parseExpressionStatement(node, expr, decorators);
  9060. }
  9061. shouldParseExportDeclaration() {
  9062. if (this.tsIsDeclarationStart()) return true;
  9063. return super.shouldParseExportDeclaration();
  9064. }
  9065. parseConditional(expr, startLoc, refExpressionErrors) {
  9066. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9067. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9068. }
  9069. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9070. if (!result.node) {
  9071. if (result.error) {
  9072. super.setOptionalParametersError(refExpressionErrors, result.error);
  9073. }
  9074. return expr;
  9075. }
  9076. if (result.error) this.state = result.failState;
  9077. return result.node;
  9078. }
  9079. parseParenItem(node, startLoc) {
  9080. node = super.parseParenItem(node, startLoc);
  9081. if (this.eat(17)) {
  9082. node.optional = true;
  9083. this.resetEndLocation(node);
  9084. }
  9085. if (this.match(14)) {
  9086. const typeCastNode = this.startNodeAt(startLoc);
  9087. typeCastNode.expression = node;
  9088. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9089. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9090. }
  9091. return node;
  9092. }
  9093. parseExportDeclaration(node) {
  9094. if (!this.state.isAmbientContext && this.isContextual(123)) {
  9095. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9096. }
  9097. const startLoc = this.state.startLoc;
  9098. const isDeclare = this.eatContextual(123);
  9099. if (isDeclare && (this.isContextual(123) || !this.shouldParseExportDeclaration())) {
  9100. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
  9101. at: this.state.startLoc
  9102. });
  9103. }
  9104. const isIdentifier = tokenIsIdentifier(this.state.type);
  9105. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9106. if (!declaration) return null;
  9107. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9108. node.exportKind = "type";
  9109. }
  9110. if (isDeclare) {
  9111. this.resetStartLocation(declaration, startLoc);
  9112. declaration.declare = true;
  9113. }
  9114. return declaration;
  9115. }
  9116. parseClassId(node, isStatement, optionalId,
  9117. bindingType) {
  9118. if ((!isStatement || optionalId) && this.isContextual(111)) {
  9119. return;
  9120. }
  9121. super.parseClassId(node, isStatement, optionalId, node.declare ? BIND_TS_AMBIENT : BIND_CLASS);
  9122. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers.bind(this));
  9123. if (typeParameters) node.typeParameters = typeParameters;
  9124. }
  9125. parseClassPropertyAnnotation(node) {
  9126. if (!node.optional && this.eat(35)) {
  9127. node.definite = true;
  9128. }
  9129. const type = this.tsTryParseTypeAnnotation();
  9130. if (type) node.typeAnnotation = type;
  9131. }
  9132. parseClassProperty(node) {
  9133. this.parseClassPropertyAnnotation(node);
  9134. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9135. this.raise(TSErrors.DeclareClassFieldHasInitializer, {
  9136. at: this.state.startLoc
  9137. });
  9138. }
  9139. if (node.abstract && this.match(29)) {
  9140. const {
  9141. key
  9142. } = node;
  9143. this.raise(TSErrors.AbstractPropertyHasInitializer, {
  9144. at: this.state.startLoc,
  9145. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9146. });
  9147. }
  9148. return super.parseClassProperty(node);
  9149. }
  9150. parseClassPrivateProperty(node) {
  9151. if (node.abstract) {
  9152. this.raise(TSErrors.PrivateElementHasAbstract, {
  9153. at: node
  9154. });
  9155. }
  9156. if (node.accessibility) {
  9157. this.raise(TSErrors.PrivateElementHasAccessibility, {
  9158. at: node,
  9159. modifier: node.accessibility
  9160. });
  9161. }
  9162. this.parseClassPropertyAnnotation(node);
  9163. return super.parseClassPrivateProperty(node);
  9164. }
  9165. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9166. const typeParameters = this.tsTryParseTypeParameters();
  9167. if (typeParameters && isConstructor) {
  9168. this.raise(TSErrors.ConstructorHasTypeParameters, {
  9169. at: typeParameters
  9170. });
  9171. }
  9172. const {
  9173. declare = false,
  9174. kind
  9175. } = method;
  9176. if (declare && (kind === "get" || kind === "set")) {
  9177. this.raise(TSErrors.DeclareAccessor, {
  9178. at: method,
  9179. kind
  9180. });
  9181. }
  9182. if (typeParameters) method.typeParameters = typeParameters;
  9183. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9184. }
  9185. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9186. const typeParameters = this.tsTryParseTypeParameters();
  9187. if (typeParameters) method.typeParameters = typeParameters;
  9188. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9189. }
  9190. declareClassPrivateMethodInScope(node, kind) {
  9191. if (node.type === "TSDeclareMethod") return;
  9192. if (node.type === "MethodDefinition" && !node.value.body) return;
  9193. super.declareClassPrivateMethodInScope(node, kind);
  9194. }
  9195. parseClassSuper(node) {
  9196. super.parseClassSuper(node);
  9197. if (node.superClass && (this.match(47) || this.match(51))) {
  9198. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9199. }
  9200. if (this.eatContextual(111)) {
  9201. node.implements = this.tsParseHeritageClause("implements");
  9202. }
  9203. }
  9204. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9205. const typeParameters = this.tsTryParseTypeParameters();
  9206. if (typeParameters) prop.typeParameters = typeParameters;
  9207. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9208. }
  9209. parseFunctionParams(node, allowModifiers) {
  9210. const typeParameters = this.tsTryParseTypeParameters();
  9211. if (typeParameters) node.typeParameters = typeParameters;
  9212. super.parseFunctionParams(node, allowModifiers);
  9213. }
  9214. parseVarId(decl, kind) {
  9215. super.parseVarId(decl, kind);
  9216. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9217. decl.definite = true;
  9218. }
  9219. const type = this.tsTryParseTypeAnnotation();
  9220. if (type) {
  9221. decl.id.typeAnnotation = type;
  9222. this.resetEndLocation(decl.id);
  9223. }
  9224. }
  9225. parseAsyncArrowFromCallExpression(node, call) {
  9226. if (this.match(14)) {
  9227. node.returnType = this.tsParseTypeAnnotation();
  9228. }
  9229. return super.parseAsyncArrowFromCallExpression(node, call);
  9230. }
  9231. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9232. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2, _jsx4, _typeCast3;
  9233. let state;
  9234. let jsx;
  9235. let typeCast;
  9236. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  9237. state = this.state.clone();
  9238. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9239. if (!jsx.error) return jsx.node;
  9240. const {
  9241. context
  9242. } = this.state;
  9243. const currentContext = context[context.length - 1];
  9244. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9245. context.pop();
  9246. }
  9247. }
  9248. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9249. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9250. }
  9251. if (!state || state === this.state) state = this.state.clone();
  9252. let typeParameters;
  9253. const arrow = this.tryParse(abort => {
  9254. var _expr$extra, _typeParameters;
  9255. typeParameters = this.tsParseTypeParameters();
  9256. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9257. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9258. abort();
  9259. }
  9260. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9261. this.resetStartLocationFromNode(expr, typeParameters);
  9262. }
  9263. expr.typeParameters = typeParameters;
  9264. return expr;
  9265. }, state);
  9266. if (!arrow.error && !arrow.aborted) {
  9267. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9268. return arrow.node;
  9269. }
  9270. if (!jsx) {
  9271. assert(!this.hasPlugin("jsx"));
  9272. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9273. if (!typeCast.error) return typeCast.node;
  9274. }
  9275. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9276. this.state = jsx.failState;
  9277. return jsx.node;
  9278. }
  9279. if (arrow.node) {
  9280. this.state = arrow.failState;
  9281. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9282. return arrow.node;
  9283. }
  9284. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9285. this.state = typeCast.failState;
  9286. return typeCast.node;
  9287. }
  9288. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  9289. if (arrow.thrown) throw arrow.error;
  9290. if ((_typeCast2 = typeCast) != null && _typeCast2.thrown) throw typeCast.error;
  9291. throw ((_jsx4 = jsx) == null ? void 0 : _jsx4.error) || arrow.error || ((_typeCast3 = typeCast) == null ? void 0 : _typeCast3.error);
  9292. }
  9293. reportReservedArrowTypeParam(node) {
  9294. var _node$extra;
  9295. if (node.params.length === 1 && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9296. this.raise(TSErrors.ReservedArrowTypeParam, {
  9297. at: node
  9298. });
  9299. }
  9300. }
  9301. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9302. if (!this.hasPlugin("jsx") && this.match(47)) {
  9303. return this.tsParseTypeAssertion();
  9304. } else {
  9305. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9306. }
  9307. }
  9308. parseArrow(node) {
  9309. if (this.match(14)) {
  9310. const result = this.tryParse(abort => {
  9311. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9312. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9313. return returnType;
  9314. });
  9315. if (result.aborted) return;
  9316. if (!result.thrown) {
  9317. if (result.error) this.state = result.failState;
  9318. node.returnType = result.node;
  9319. }
  9320. }
  9321. return super.parseArrow(node);
  9322. }
  9323. parseAssignableListItemTypes(param) {
  9324. if (this.eat(17)) {
  9325. if (param.type !== "Identifier" && !this.state.isAmbientContext && !this.state.inType) {
  9326. this.raise(TSErrors.PatternIsOptional, {
  9327. at: param
  9328. });
  9329. }
  9330. param.optional = true;
  9331. }
  9332. const type = this.tsTryParseTypeAnnotation();
  9333. if (type) param.typeAnnotation = type;
  9334. this.resetEndLocation(param);
  9335. return param;
  9336. }
  9337. isAssignable(node, isBinding) {
  9338. switch (node.type) {
  9339. case "TSTypeCastExpression":
  9340. return this.isAssignable(node.expression, isBinding);
  9341. case "TSParameterProperty":
  9342. return true;
  9343. default:
  9344. return super.isAssignable(node, isBinding);
  9345. }
  9346. }
  9347. toAssignable(node, isLHS = false) {
  9348. switch (node.type) {
  9349. case "ParenthesizedExpression":
  9350. this.toAssignableParenthesizedExpression(node, isLHS);
  9351. break;
  9352. case "TSAsExpression":
  9353. case "TSSatisfiesExpression":
  9354. case "TSNonNullExpression":
  9355. case "TSTypeAssertion":
  9356. if (isLHS) {
  9357. this.expressionScope.recordArrowParemeterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
  9358. at: node
  9359. });
  9360. } else {
  9361. this.raise(TSErrors.UnexpectedTypeCastInParameter, {
  9362. at: node
  9363. });
  9364. }
  9365. this.toAssignable(node.expression, isLHS);
  9366. break;
  9367. case "AssignmentExpression":
  9368. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9369. node.left = this.typeCastToParameter(node.left);
  9370. }
  9371. default:
  9372. super.toAssignable(node, isLHS);
  9373. }
  9374. }
  9375. toAssignableParenthesizedExpression(node, isLHS) {
  9376. switch (node.expression.type) {
  9377. case "TSAsExpression":
  9378. case "TSSatisfiesExpression":
  9379. case "TSNonNullExpression":
  9380. case "TSTypeAssertion":
  9381. case "ParenthesizedExpression":
  9382. this.toAssignable(node.expression, isLHS);
  9383. break;
  9384. default:
  9385. super.toAssignable(node, isLHS);
  9386. }
  9387. }
  9388. checkToRestConversion(node, allowPattern) {
  9389. switch (node.type) {
  9390. case "TSAsExpression":
  9391. case "TSSatisfiesExpression":
  9392. case "TSTypeAssertion":
  9393. case "TSNonNullExpression":
  9394. this.checkToRestConversion(node.expression, false);
  9395. break;
  9396. default:
  9397. super.checkToRestConversion(node, allowPattern);
  9398. }
  9399. }
  9400. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9401. return getOwn$1({
  9402. TSTypeCastExpression: true,
  9403. TSParameterProperty: "parameter",
  9404. TSNonNullExpression: "expression",
  9405. TSAsExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
  9406. TSSatisfiesExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
  9407. TSTypeAssertion: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true]
  9408. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9409. }
  9410. parseBindingAtom() {
  9411. switch (this.state.type) {
  9412. case 78:
  9413. return this.parseIdentifier(true);
  9414. default:
  9415. return super.parseBindingAtom();
  9416. }
  9417. }
  9418. parseMaybeDecoratorArguments(expr) {
  9419. if (this.match(47) || this.match(51)) {
  9420. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9421. if (this.match(10)) {
  9422. const call = super.parseMaybeDecoratorArguments(expr);
  9423. call.typeParameters = typeArguments;
  9424. return call;
  9425. }
  9426. this.unexpected(null, 10);
  9427. }
  9428. return super.parseMaybeDecoratorArguments(expr);
  9429. }
  9430. checkCommaAfterRest(close) {
  9431. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9432. this.next();
  9433. return false;
  9434. } else {
  9435. return super.checkCommaAfterRest(close);
  9436. }
  9437. }
  9438. isClassMethod() {
  9439. return this.match(47) || super.isClassMethod();
  9440. }
  9441. isClassProperty() {
  9442. return this.match(35) || this.match(14) || super.isClassProperty();
  9443. }
  9444. parseMaybeDefault(startLoc, left) {
  9445. const node = super.parseMaybeDefault(startLoc, left);
  9446. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9447. this.raise(TSErrors.TypeAnnotationAfterAssign, {
  9448. at: node.typeAnnotation
  9449. });
  9450. }
  9451. return node;
  9452. }
  9453. getTokenFromCode(code) {
  9454. if (this.state.inType) {
  9455. if (code === 62) {
  9456. return this.finishOp(48, 1);
  9457. }
  9458. if (code === 60) {
  9459. return this.finishOp(47, 1);
  9460. }
  9461. }
  9462. return super.getTokenFromCode(code);
  9463. }
  9464. reScan_lt_gt() {
  9465. const {
  9466. type
  9467. } = this.state;
  9468. if (type === 47) {
  9469. this.state.pos -= 1;
  9470. this.readToken_lt();
  9471. } else if (type === 48) {
  9472. this.state.pos -= 1;
  9473. this.readToken_gt();
  9474. }
  9475. }
  9476. reScan_lt() {
  9477. const {
  9478. type
  9479. } = this.state;
  9480. if (type === 51) {
  9481. this.state.pos -= 2;
  9482. this.finishOp(47, 1);
  9483. return 47;
  9484. }
  9485. return type;
  9486. }
  9487. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9488. for (let i = 0; i < exprList.length; i++) {
  9489. const expr = exprList[i];
  9490. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9491. exprList[i] = this.typeCastToParameter(expr);
  9492. }
  9493. }
  9494. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9495. }
  9496. typeCastToParameter(node) {
  9497. node.expression.typeAnnotation = node.typeAnnotation;
  9498. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9499. return node.expression;
  9500. }
  9501. shouldParseArrow(params) {
  9502. if (this.match(14)) {
  9503. return params.every(expr => this.isAssignable(expr, true));
  9504. }
  9505. return super.shouldParseArrow(params);
  9506. }
  9507. shouldParseAsyncArrow() {
  9508. return this.match(14) || super.shouldParseAsyncArrow();
  9509. }
  9510. canHaveLeadingDecorator() {
  9511. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9512. }
  9513. jsxParseOpeningElementAfterName(node) {
  9514. if (this.match(47) || this.match(51)) {
  9515. const typeArguments = this.tsTryParseAndCatch(() =>
  9516. this.tsParseTypeArgumentsInExpression());
  9517. if (typeArguments) node.typeParameters = typeArguments;
  9518. }
  9519. return super.jsxParseOpeningElementAfterName(node);
  9520. }
  9521. getGetterSetterExpectedParamCount(method) {
  9522. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9523. const params = this.getObjectOrClassMethodParams(method);
  9524. const firstParam = params[0];
  9525. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9526. return hasContextParam ? baseCount + 1 : baseCount;
  9527. }
  9528. parseCatchClauseParam() {
  9529. const param = super.parseCatchClauseParam();
  9530. const type = this.tsTryParseTypeAnnotation();
  9531. if (type) {
  9532. param.typeAnnotation = type;
  9533. this.resetEndLocation(param);
  9534. }
  9535. return param;
  9536. }
  9537. tsInAmbientContext(cb) {
  9538. const oldIsAmbientContext = this.state.isAmbientContext;
  9539. this.state.isAmbientContext = true;
  9540. try {
  9541. return cb();
  9542. } finally {
  9543. this.state.isAmbientContext = oldIsAmbientContext;
  9544. }
  9545. }
  9546. parseClass(node, isStatement, optionalId) {
  9547. const oldInAbstractClass = this.state.inAbstractClass;
  9548. this.state.inAbstractClass = !!node.abstract;
  9549. try {
  9550. return super.parseClass(node, isStatement, optionalId);
  9551. } finally {
  9552. this.state.inAbstractClass = oldInAbstractClass;
  9553. }
  9554. }
  9555. tsParseAbstractDeclaration(node, decorators) {
  9556. if (this.match(80)) {
  9557. node.abstract = true;
  9558. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  9559. } else if (this.isContextual(127)) {
  9560. if (!this.hasFollowingLineBreak()) {
  9561. node.abstract = true;
  9562. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
  9563. at: node
  9564. });
  9565. return this.tsParseInterfaceDeclaration(node);
  9566. }
  9567. } else {
  9568. this.unexpected(null, 80);
  9569. }
  9570. }
  9571. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  9572. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  9573. if (method.abstract) {
  9574. const hasBody = this.hasPlugin("estree") ?
  9575. !!method.value.body : !!method.body;
  9576. if (hasBody) {
  9577. const {
  9578. key
  9579. } = method;
  9580. this.raise(TSErrors.AbstractMethodHasImplementation, {
  9581. at: method,
  9582. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9583. });
  9584. }
  9585. }
  9586. return method;
  9587. }
  9588. tsParseTypeParameterName() {
  9589. const typeName = this.parseIdentifier();
  9590. return typeName.name;
  9591. }
  9592. shouldParseAsAmbientContext() {
  9593. return !!this.getPluginOption("typescript", "dts");
  9594. }
  9595. parse() {
  9596. if (this.shouldParseAsAmbientContext()) {
  9597. this.state.isAmbientContext = true;
  9598. }
  9599. return super.parse();
  9600. }
  9601. getExpression() {
  9602. if (this.shouldParseAsAmbientContext()) {
  9603. this.state.isAmbientContext = true;
  9604. }
  9605. return super.getExpression();
  9606. }
  9607. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  9608. if (!isString && isMaybeTypeOnly) {
  9609. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  9610. return this.finishNode(node, "ExportSpecifier");
  9611. }
  9612. node.exportKind = "value";
  9613. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  9614. }
  9615. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly,
  9616. bindingType) {
  9617. if (!importedIsString && isMaybeTypeOnly) {
  9618. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  9619. return this.finishNode(specifier, "ImportSpecifier");
  9620. }
  9621. specifier.importKind = "value";
  9622. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
  9623. }
  9624. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  9625. const leftOfAsKey = isImport ? "imported" : "local";
  9626. const rightOfAsKey = isImport ? "local" : "exported";
  9627. let leftOfAs = node[leftOfAsKey];
  9628. let rightOfAs;
  9629. let hasTypeSpecifier = false;
  9630. let canParseAsKeyword = true;
  9631. const loc = leftOfAs.loc.start;
  9632. if (this.isContextual(93)) {
  9633. const firstAs = this.parseIdentifier();
  9634. if (this.isContextual(93)) {
  9635. const secondAs = this.parseIdentifier();
  9636. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9637. hasTypeSpecifier = true;
  9638. leftOfAs = firstAs;
  9639. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9640. canParseAsKeyword = false;
  9641. } else {
  9642. rightOfAs = secondAs;
  9643. canParseAsKeyword = false;
  9644. }
  9645. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9646. canParseAsKeyword = false;
  9647. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9648. } else {
  9649. hasTypeSpecifier = true;
  9650. leftOfAs = firstAs;
  9651. }
  9652. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9653. hasTypeSpecifier = true;
  9654. if (isImport) {
  9655. leftOfAs = this.parseIdentifier(true);
  9656. if (!this.isContextual(93)) {
  9657. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  9658. }
  9659. } else {
  9660. leftOfAs = this.parseModuleExportName();
  9661. }
  9662. }
  9663. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  9664. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
  9665. at: loc
  9666. });
  9667. }
  9668. node[leftOfAsKey] = leftOfAs;
  9669. node[rightOfAsKey] = rightOfAs;
  9670. const kindKey = isImport ? "importKind" : "exportKind";
  9671. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  9672. if (canParseAsKeyword && this.eatContextual(93)) {
  9673. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9674. }
  9675. if (!node[rightOfAsKey]) {
  9676. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  9677. }
  9678. if (isImport) {
  9679. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
  9680. }
  9681. }
  9682. });
  9683. function isPossiblyLiteralEnum(expression) {
  9684. if (expression.type !== "MemberExpression") return false;
  9685. const {
  9686. computed,
  9687. property
  9688. } = expression;
  9689. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  9690. return false;
  9691. }
  9692. return isUncomputedMemberExpressionChain(expression.object);
  9693. }
  9694. function isUncomputedMemberExpressionChain(expression) {
  9695. if (expression.type === "Identifier") return true;
  9696. if (expression.type !== "MemberExpression") return false;
  9697. if (expression.computed) return false;
  9698. return isUncomputedMemberExpressionChain(expression.object);
  9699. }
  9700. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  9701. ClassNameIsRequired: "A class name is required.",
  9702. UnexpectedSpace: "Unexpected space in placeholder."
  9703. });
  9704. var placeholders = (superClass => class PlaceholdersParserMixin extends superClass {
  9705. parsePlaceholder(expectedNode) {
  9706. if (this.match(142)) {
  9707. const node = this.startNode();
  9708. this.next();
  9709. this.assertNoSpace();
  9710. node.name = super.parseIdentifier(true);
  9711. this.assertNoSpace();
  9712. this.expect(142);
  9713. return this.finishPlaceholder(node, expectedNode);
  9714. }
  9715. }
  9716. finishPlaceholder(node, expectedNode) {
  9717. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  9718. node.expectedNode = expectedNode;
  9719. return isFinished ? node : this.finishNode(node, "Placeholder");
  9720. }
  9721. getTokenFromCode(code) {
  9722. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  9723. return this.finishOp(142, 2);
  9724. }
  9725. return super.getTokenFromCode(code);
  9726. }
  9727. parseExprAtom(refExpressionErrors) {
  9728. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  9729. }
  9730. parseIdentifier(liberal) {
  9731. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  9732. }
  9733. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9734. if (word !== undefined) {
  9735. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9736. }
  9737. }
  9738. parseBindingAtom() {
  9739. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  9740. }
  9741. isValidLVal(type, isParenthesized, binding) {
  9742. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  9743. }
  9744. toAssignable(node, isLHS) {
  9745. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  9746. node.expectedNode = "Pattern";
  9747. } else {
  9748. super.toAssignable(node, isLHS);
  9749. }
  9750. }
  9751. hasFollowingIdentifier(context) {
  9752. if (super.hasFollowingIdentifier(context)) {
  9753. return true;
  9754. }
  9755. if (context) return false;
  9756. const nextToken = this.lookahead();
  9757. if (nextToken.type === 142) {
  9758. return true;
  9759. }
  9760. return false;
  9761. }
  9762. verifyBreakContinue(node, isBreak) {
  9763. if (node.label && node.label.type === "Placeholder") return;
  9764. super.verifyBreakContinue(node, isBreak);
  9765. }
  9766. parseExpressionStatement(node, expr) {
  9767. if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) {
  9768. return super.parseExpressionStatement(node, expr);
  9769. }
  9770. if (this.match(14)) {
  9771. const stmt = node;
  9772. stmt.label = this.finishPlaceholder(expr, "Identifier");
  9773. this.next();
  9774. stmt.body = super.parseStatement("label");
  9775. return this.finishNode(stmt, "LabeledStatement");
  9776. }
  9777. this.semicolon();
  9778. node.name = expr.name;
  9779. return this.finishPlaceholder(node, "Statement");
  9780. }
  9781. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  9782. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  9783. }
  9784. parseFunctionId(requireId) {
  9785. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  9786. }
  9787. parseClass(node, isStatement, optionalId) {
  9788. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  9789. this.next();
  9790. const oldStrict = this.state.strict;
  9791. const placeholder = this.parsePlaceholder("Identifier");
  9792. if (placeholder) {
  9793. if (this.match(81) || this.match(142) || this.match(5)) {
  9794. node.id = placeholder;
  9795. } else if (optionalId || !isStatement) {
  9796. node.id = null;
  9797. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  9798. return this.finishNode(node, type);
  9799. } else {
  9800. throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
  9801. at: this.state.startLoc
  9802. });
  9803. }
  9804. } else {
  9805. this.parseClassId(node, isStatement, optionalId);
  9806. }
  9807. super.parseClassSuper(node);
  9808. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  9809. return this.finishNode(node, type);
  9810. }
  9811. parseExport(node, decorators) {
  9812. const placeholder = this.parsePlaceholder("Identifier");
  9813. if (!placeholder) return super.parseExport(node, decorators);
  9814. if (!this.isContextual(97) && !this.match(12)) {
  9815. node.specifiers = [];
  9816. node.source = null;
  9817. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  9818. return this.finishNode(node, "ExportNamedDeclaration");
  9819. }
  9820. this.expectPlugin("exportDefaultFrom");
  9821. const specifier = this.startNode();
  9822. specifier.exported = placeholder;
  9823. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  9824. return super.parseExport(node, decorators);
  9825. }
  9826. isExportDefaultSpecifier() {
  9827. if (this.match(65)) {
  9828. const next = this.nextTokenStart();
  9829. if (this.isUnparsedContextual(next, "from")) {
  9830. if (this.input.startsWith(tokenLabelName(142), this.nextTokenStartSince(next + 4))) {
  9831. return true;
  9832. }
  9833. }
  9834. }
  9835. return super.isExportDefaultSpecifier();
  9836. }
  9837. maybeParseExportDefaultSpecifier(node) {
  9838. if (node.specifiers && node.specifiers.length > 0) {
  9839. return true;
  9840. }
  9841. return super.maybeParseExportDefaultSpecifier(node);
  9842. }
  9843. checkExport(node) {
  9844. const {
  9845. specifiers
  9846. } = node;
  9847. if (specifiers != null && specifiers.length) {
  9848. node.specifiers = specifiers.filter(
  9849. node => node.exported.type === "Placeholder");
  9850. }
  9851. super.checkExport(node);
  9852. node.specifiers = specifiers;
  9853. }
  9854. parseImport(node) {
  9855. const placeholder = this.parsePlaceholder("Identifier");
  9856. if (!placeholder) return super.parseImport(node);
  9857. node.specifiers = [];
  9858. if (!this.isContextual(97) && !this.match(12)) {
  9859. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  9860. this.semicolon();
  9861. return this.finishNode(node, "ImportDeclaration");
  9862. }
  9863. const specifier = this.startNodeAtNode(placeholder);
  9864. specifier.local = placeholder;
  9865. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  9866. if (this.eat(12)) {
  9867. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  9868. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  9869. }
  9870. this.expectContextual(97);
  9871. node.source = this.parseImportSource();
  9872. this.semicolon();
  9873. return this.finishNode(node, "ImportDeclaration");
  9874. }
  9875. parseImportSource() {
  9876. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  9877. }
  9878. assertNoSpace() {
  9879. if (this.state.start > this.state.lastTokEndLoc.index) {
  9880. this.raise(PlaceholderErrors.UnexpectedSpace, {
  9881. at: this.state.lastTokEndLoc
  9882. });
  9883. }
  9884. }
  9885. });
  9886. var v8intrinsic = (superClass => class V8IntrinsicMixin extends superClass {
  9887. parseV8Intrinsic() {
  9888. if (this.match(54)) {
  9889. const v8IntrinsicStartLoc = this.state.startLoc;
  9890. const node = this.startNode();
  9891. this.next();
  9892. if (tokenIsIdentifier(this.state.type)) {
  9893. const name = this.parseIdentifierName();
  9894. const identifier = this.createIdentifier(node, name);
  9895. identifier.type = "V8IntrinsicIdentifier";
  9896. if (this.match(10)) {
  9897. return identifier;
  9898. }
  9899. }
  9900. this.unexpected(v8IntrinsicStartLoc);
  9901. }
  9902. }
  9903. parseExprAtom(refExpressionErrors) {
  9904. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  9905. }
  9906. });
  9907. function hasPlugin(plugins, expectedConfig) {
  9908. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  9909. const expectedKeys = Object.keys(expectedOptions);
  9910. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  9911. return plugins.some(p => {
  9912. if (typeof p === "string") {
  9913. return expectedOptionsIsEmpty && p === expectedName;
  9914. } else {
  9915. const [pluginName, pluginOptions] = p;
  9916. if (pluginName !== expectedName) {
  9917. return false;
  9918. }
  9919. for (const key of expectedKeys) {
  9920. if (pluginOptions[key] !== expectedOptions[key]) {
  9921. return false;
  9922. }
  9923. }
  9924. return true;
  9925. }
  9926. });
  9927. }
  9928. function getPluginOption(plugins, name, option) {
  9929. const plugin = plugins.find(plugin => {
  9930. if (Array.isArray(plugin)) {
  9931. return plugin[0] === name;
  9932. } else {
  9933. return plugin === name;
  9934. }
  9935. });
  9936. if (plugin && Array.isArray(plugin) && plugin.length > 1) {
  9937. return plugin[1][option];
  9938. }
  9939. return null;
  9940. }
  9941. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  9942. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  9943. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  9944. function validatePlugins(plugins) {
  9945. if (hasPlugin(plugins, "decorators")) {
  9946. if (hasPlugin(plugins, "decorators-legacy")) {
  9947. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  9948. }
  9949. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  9950. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  9951. throw new Error("'decoratorsBeforeExport' must be a boolean.");
  9952. }
  9953. const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
  9954. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  9955. throw new Error("'allowCallParenthesized' must be a boolean.");
  9956. }
  9957. }
  9958. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  9959. throw new Error("Cannot combine flow and typescript plugins.");
  9960. }
  9961. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  9962. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  9963. }
  9964. if (hasPlugin(plugins, "pipelineOperator")) {
  9965. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  9966. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  9967. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  9968. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  9969. }
  9970. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  9971. syntaxType: "hash"
  9972. }]);
  9973. if (proposal === "hack") {
  9974. if (hasPlugin(plugins, "placeholders")) {
  9975. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  9976. }
  9977. if (hasPlugin(plugins, "v8intrinsic")) {
  9978. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  9979. }
  9980. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  9981. if (!TOPIC_TOKENS.includes(topicToken)) {
  9982. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  9983. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  9984. }
  9985. if (topicToken === "#" && tupleSyntaxIsHash) {
  9986. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  9987. }
  9988. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  9989. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  9990. }
  9991. }
  9992. if (hasPlugin(plugins, "moduleAttributes")) {
  9993. {
  9994. if (hasPlugin(plugins, "importAssertions")) {
  9995. throw new Error("Cannot combine importAssertions and moduleAttributes plugins.");
  9996. }
  9997. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  9998. if (moduleAttributesVersionPluginOption !== "may-2020") {
  9999. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10000. }
  10001. }
  10002. }
  10003. if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  10004. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10005. }
  10006. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  10007. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10008. error.missingPlugins = "doExpressions";
  10009. throw error;
  10010. }
  10011. }
  10012. const mixinPlugins = {
  10013. estree,
  10014. jsx,
  10015. flow,
  10016. typescript,
  10017. v8intrinsic,
  10018. placeholders
  10019. };
  10020. const mixinPluginNames = Object.keys(mixinPlugins);
  10021. const defaultOptions = {
  10022. sourceType: "script",
  10023. sourceFilename: undefined,
  10024. startColumn: 0,
  10025. startLine: 1,
  10026. allowAwaitOutsideFunction: false,
  10027. allowReturnOutsideFunction: false,
  10028. allowImportExportEverywhere: false,
  10029. allowSuperOutsideMethod: false,
  10030. allowUndeclaredExports: false,
  10031. plugins: [],
  10032. strictMode: null,
  10033. ranges: false,
  10034. tokens: false,
  10035. createParenthesizedExpressions: false,
  10036. errorRecovery: false,
  10037. attachComment: true
  10038. };
  10039. function getOptions(opts) {
  10040. const options = {};
  10041. for (const key of Object.keys(defaultOptions)) {
  10042. options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key];
  10043. }
  10044. return options;
  10045. }
  10046. const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  10047. const unwrapParenthesizedExpression = node => {
  10048. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  10049. };
  10050. class LValParser extends NodeUtils {
  10051. toAssignable(node, isLHS = false) {
  10052. var _node$extra, _node$extra3;
  10053. let parenthesized = undefined;
  10054. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  10055. parenthesized = unwrapParenthesizedExpression(node);
  10056. if (isLHS) {
  10057. if (parenthesized.type === "Identifier") {
  10058. this.expressionScope.recordArrowParemeterBindingError(Errors.InvalidParenthesizedAssignment, {
  10059. at: node
  10060. });
  10061. } else if (parenthesized.type !== "MemberExpression") {
  10062. this.raise(Errors.InvalidParenthesizedAssignment, {
  10063. at: node
  10064. });
  10065. }
  10066. } else {
  10067. this.raise(Errors.InvalidParenthesizedAssignment, {
  10068. at: node
  10069. });
  10070. }
  10071. }
  10072. switch (node.type) {
  10073. case "Identifier":
  10074. case "ObjectPattern":
  10075. case "ArrayPattern":
  10076. case "AssignmentPattern":
  10077. case "RestElement":
  10078. break;
  10079. case "ObjectExpression":
  10080. node.type = "ObjectPattern";
  10081. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  10082. var _node$extra2;
  10083. const prop = node.properties[i];
  10084. const isLast = i === last;
  10085. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  10086. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  10087. this.raise(Errors.RestTrailingComma, {
  10088. at: node.extra.trailingCommaLoc
  10089. });
  10090. }
  10091. }
  10092. break;
  10093. case "ObjectProperty":
  10094. {
  10095. const {
  10096. key,
  10097. value
  10098. } = node;
  10099. if (this.isPrivateName(key)) {
  10100. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  10101. }
  10102. this.toAssignable(value, isLHS);
  10103. break;
  10104. }
  10105. case "SpreadElement":
  10106. {
  10107. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  10108. }
  10109. case "ArrayExpression":
  10110. node.type = "ArrayPattern";
  10111. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  10112. break;
  10113. case "AssignmentExpression":
  10114. if (node.operator !== "=") {
  10115. this.raise(Errors.MissingEqInAssignment, {
  10116. at: node.left.loc.end
  10117. });
  10118. }
  10119. node.type = "AssignmentPattern";
  10120. delete node.operator;
  10121. this.toAssignable(node.left, isLHS);
  10122. break;
  10123. case "ParenthesizedExpression":
  10124. this.toAssignable(parenthesized, isLHS);
  10125. break;
  10126. }
  10127. }
  10128. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  10129. if (prop.type === "ObjectMethod") {
  10130. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
  10131. at: prop.key
  10132. });
  10133. } else if (prop.type === "SpreadElement") {
  10134. prop.type = "RestElement";
  10135. const arg = prop.argument;
  10136. this.checkToRestConversion(arg, false);
  10137. this.toAssignable(arg, isLHS);
  10138. if (!isLast) {
  10139. this.raise(Errors.RestTrailingComma, {
  10140. at: prop
  10141. });
  10142. }
  10143. } else {
  10144. this.toAssignable(prop, isLHS);
  10145. }
  10146. }
  10147. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  10148. const end = exprList.length - 1;
  10149. for (let i = 0; i <= end; i++) {
  10150. const elt = exprList[i];
  10151. if (!elt) continue;
  10152. if (elt.type === "SpreadElement") {
  10153. elt.type = "RestElement";
  10154. const arg = elt.argument;
  10155. this.checkToRestConversion(arg, true);
  10156. this.toAssignable(arg, isLHS);
  10157. } else {
  10158. this.toAssignable(elt, isLHS);
  10159. }
  10160. if (elt.type === "RestElement") {
  10161. if (i < end) {
  10162. this.raise(Errors.RestTrailingComma, {
  10163. at: elt
  10164. });
  10165. } else if (trailingCommaLoc) {
  10166. this.raise(Errors.RestTrailingComma, {
  10167. at: trailingCommaLoc
  10168. });
  10169. }
  10170. }
  10171. }
  10172. }
  10173. isAssignable(node, isBinding) {
  10174. switch (node.type) {
  10175. case "Identifier":
  10176. case "ObjectPattern":
  10177. case "ArrayPattern":
  10178. case "AssignmentPattern":
  10179. case "RestElement":
  10180. return true;
  10181. case "ObjectExpression":
  10182. {
  10183. const last = node.properties.length - 1;
  10184. return node.properties.every((prop, i) => {
  10185. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  10186. });
  10187. }
  10188. case "ObjectProperty":
  10189. return this.isAssignable(node.value);
  10190. case "SpreadElement":
  10191. return this.isAssignable(node.argument);
  10192. case "ArrayExpression":
  10193. return node.elements.every(element => element === null || this.isAssignable(element));
  10194. case "AssignmentExpression":
  10195. return node.operator === "=";
  10196. case "ParenthesizedExpression":
  10197. return this.isAssignable(node.expression);
  10198. case "MemberExpression":
  10199. case "OptionalMemberExpression":
  10200. return !isBinding;
  10201. default:
  10202. return false;
  10203. }
  10204. }
  10205. toReferencedList(exprList,
  10206. isParenthesizedExpr) {
  10207. return exprList;
  10208. }
  10209. toReferencedListDeep(exprList, isParenthesizedExpr) {
  10210. this.toReferencedList(exprList, isParenthesizedExpr);
  10211. for (const expr of exprList) {
  10212. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  10213. this.toReferencedListDeep(expr.elements);
  10214. }
  10215. }
  10216. }
  10217. parseSpread(refExpressionErrors) {
  10218. const node = this.startNode();
  10219. this.next();
  10220. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  10221. return this.finishNode(node, "SpreadElement");
  10222. }
  10223. parseRestBinding() {
  10224. const node = this.startNode();
  10225. this.next();
  10226. node.argument = this.parseBindingAtom();
  10227. return this.finishNode(node, "RestElement");
  10228. }
  10229. parseBindingAtom() {
  10230. switch (this.state.type) {
  10231. case 0:
  10232. {
  10233. const node = this.startNode();
  10234. this.next();
  10235. node.elements = this.parseBindingList(3, 93, true);
  10236. return this.finishNode(node, "ArrayPattern");
  10237. }
  10238. case 5:
  10239. return this.parseObjectLike(8, true);
  10240. }
  10241. return this.parseIdentifier();
  10242. }
  10243. parseBindingList(close, closeCharCode, allowEmpty, allowModifiers) {
  10244. const elts = [];
  10245. let first = true;
  10246. while (!this.eat(close)) {
  10247. if (first) {
  10248. first = false;
  10249. } else {
  10250. this.expect(12);
  10251. }
  10252. if (allowEmpty && this.match(12)) {
  10253. elts.push(null);
  10254. } else if (this.eat(close)) {
  10255. break;
  10256. } else if (this.match(21)) {
  10257. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding()));
  10258. if (!this.checkCommaAfterRest(closeCharCode)) {
  10259. this.expect(close);
  10260. break;
  10261. }
  10262. } else {
  10263. const decorators = [];
  10264. if (this.match(26) && this.hasPlugin("decorators")) {
  10265. this.raise(Errors.UnsupportedParameterDecorator, {
  10266. at: this.state.startLoc
  10267. });
  10268. }
  10269. while (this.match(26)) {
  10270. decorators.push(this.parseDecorator());
  10271. }
  10272. elts.push(this.parseAssignableListItem(allowModifiers, decorators));
  10273. }
  10274. }
  10275. return elts;
  10276. }
  10277. parseBindingRestProperty(prop) {
  10278. this.next();
  10279. prop.argument = this.parseIdentifier();
  10280. this.checkCommaAfterRest(125);
  10281. return this.finishNode(prop, "RestElement");
  10282. }
  10283. parseBindingProperty() {
  10284. const prop = this.startNode();
  10285. const {
  10286. type,
  10287. startLoc
  10288. } = this.state;
  10289. if (type === 21) {
  10290. return this.parseBindingRestProperty(prop);
  10291. } else if (type === 136) {
  10292. this.expectPlugin("destructuringPrivate", startLoc);
  10293. this.classScope.usePrivateName(this.state.value, startLoc);
  10294. prop.key = this.parsePrivateName();
  10295. } else {
  10296. this.parsePropertyName(prop);
  10297. }
  10298. prop.method = false;
  10299. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  10300. }
  10301. parseAssignableListItem(allowModifiers, decorators) {
  10302. const left = this.parseMaybeDefault();
  10303. this.parseAssignableListItemTypes(left);
  10304. const elt = this.parseMaybeDefault(left.loc.start, left);
  10305. if (decorators.length) {
  10306. left.decorators = decorators;
  10307. }
  10308. return elt;
  10309. }
  10310. parseAssignableListItemTypes(param) {
  10311. return param;
  10312. }
  10313. parseMaybeDefault(startLoc, left) {
  10314. var _startLoc, _left;
  10315. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  10316. left = (_left = left) != null ? _left : this.parseBindingAtom();
  10317. if (!this.eat(29)) return left;
  10318. const node = this.startNodeAt(startLoc);
  10319. node.left = left;
  10320. node.right = this.parseMaybeAssignAllowIn();
  10321. return this.finishNode(node, "AssignmentPattern");
  10322. }
  10323. isValidLVal(type,
  10324. isUnparenthesizedInAssign,
  10325. binding) {
  10326. return getOwn({
  10327. AssignmentPattern: "left",
  10328. RestElement: "argument",
  10329. ObjectProperty: "value",
  10330. ParenthesizedExpression: "expression",
  10331. ArrayPattern: "elements",
  10332. ObjectPattern: "properties"
  10333. },
  10334. type);
  10335. }
  10336. checkLVal(expression, {
  10337. in: ancestor,
  10338. binding = BIND_NONE,
  10339. checkClashes = false,
  10340. strictModeChanged = false,
  10341. allowingSloppyLetBinding = !(binding & BIND_SCOPE_LEXICAL),
  10342. hasParenthesizedAncestor = false
  10343. }) {
  10344. var _expression$extra;
  10345. const type = expression.type;
  10346. if (this.isObjectMethod(expression)) return;
  10347. if (type === "MemberExpression") {
  10348. if (binding !== BIND_NONE) {
  10349. this.raise(Errors.InvalidPropertyBindingPattern, {
  10350. at: expression
  10351. });
  10352. }
  10353. return;
  10354. }
  10355. if (expression.type === "Identifier") {
  10356. this.checkIdentifier(expression, binding, strictModeChanged, allowingSloppyLetBinding);
  10357. const {
  10358. name
  10359. } = expression;
  10360. if (checkClashes) {
  10361. if (checkClashes.has(name)) {
  10362. this.raise(Errors.ParamDupe, {
  10363. at: expression
  10364. });
  10365. } else {
  10366. checkClashes.add(name);
  10367. }
  10368. }
  10369. return;
  10370. }
  10371. const validity = this.isValidLVal(expression.type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  10372. if (validity === true) return;
  10373. if (validity === false) {
  10374. const ParseErrorClass = binding === BIND_NONE ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  10375. this.raise(ParseErrorClass, {
  10376. at: expression,
  10377. ancestor: ancestor.type === "UpdateExpression" ? {
  10378. type: "UpdateExpression",
  10379. prefix: ancestor.prefix
  10380. } : {
  10381. type: ancestor.type
  10382. }
  10383. });
  10384. return;
  10385. }
  10386. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  10387. const nextAncestor = expression.type === "ArrayPattern" || expression.type === "ObjectPattern" || expression.type === "ParenthesizedExpression" ? expression : ancestor;
  10388. for (const child of [].concat(expression[key])) {
  10389. if (child) {
  10390. this.checkLVal(child, {
  10391. in: nextAncestor,
  10392. binding,
  10393. checkClashes,
  10394. allowingSloppyLetBinding,
  10395. strictModeChanged,
  10396. hasParenthesizedAncestor: isParenthesizedExpression
  10397. });
  10398. }
  10399. }
  10400. }
  10401. checkIdentifier(at, bindingType, strictModeChanged = false, allowLetBinding = !(bindingType & BIND_SCOPE_LEXICAL)) {
  10402. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  10403. if (bindingType === BIND_NONE) {
  10404. this.raise(Errors.StrictEvalArguments, {
  10405. at,
  10406. referenceName: at.name
  10407. });
  10408. } else {
  10409. this.raise(Errors.StrictEvalArgumentsBinding, {
  10410. at,
  10411. bindingName: at.name
  10412. });
  10413. }
  10414. }
  10415. if (!allowLetBinding && at.name === "let") {
  10416. this.raise(Errors.LetInLexicalBinding, {
  10417. at
  10418. });
  10419. }
  10420. if (!(bindingType & BIND_NONE)) {
  10421. this.declareNameFromIdentifier(at, bindingType);
  10422. }
  10423. }
  10424. declareNameFromIdentifier(identifier, binding) {
  10425. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  10426. }
  10427. checkToRestConversion(node, allowPattern) {
  10428. switch (node.type) {
  10429. case "ParenthesizedExpression":
  10430. this.checkToRestConversion(node.expression, allowPattern);
  10431. break;
  10432. case "Identifier":
  10433. case "MemberExpression":
  10434. break;
  10435. case "ArrayExpression":
  10436. case "ObjectExpression":
  10437. if (allowPattern) break;
  10438. default:
  10439. this.raise(Errors.InvalidRestAssignmentPattern, {
  10440. at: node
  10441. });
  10442. }
  10443. }
  10444. checkCommaAfterRest(close) {
  10445. if (!this.match(12)) {
  10446. return false;
  10447. }
  10448. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
  10449. at: this.state.startLoc
  10450. });
  10451. return true;
  10452. }
  10453. }
  10454. class ExpressionParser extends LValParser {
  10455. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10456. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed ||
  10457. prop.shorthand) {
  10458. return;
  10459. }
  10460. const key = prop.key;
  10461. const name = key.type === "Identifier" ? key.name : key.value;
  10462. if (name === "__proto__") {
  10463. if (isRecord) {
  10464. this.raise(Errors.RecordNoProto, {
  10465. at: key
  10466. });
  10467. return;
  10468. }
  10469. if (protoRef.used) {
  10470. if (refExpressionErrors) {
  10471. if (refExpressionErrors.doubleProtoLoc === null) {
  10472. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10473. }
  10474. } else {
  10475. this.raise(Errors.DuplicateProto, {
  10476. at: key
  10477. });
  10478. }
  10479. }
  10480. protoRef.used = true;
  10481. }
  10482. }
  10483. shouldExitDescending(expr, potentialArrowAt) {
  10484. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  10485. }
  10486. getExpression() {
  10487. this.enterInitialScopes();
  10488. this.nextToken();
  10489. const expr = this.parseExpression();
  10490. if (!this.match(137)) {
  10491. this.unexpected();
  10492. }
  10493. this.finalizeRemainingComments();
  10494. expr.comments = this.state.comments;
  10495. expr.errors = this.state.errors;
  10496. if (this.options.tokens) {
  10497. expr.tokens = this.tokens;
  10498. }
  10499. return expr;
  10500. }
  10501. parseExpression(disallowIn, refExpressionErrors) {
  10502. if (disallowIn) {
  10503. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10504. }
  10505. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10506. }
  10507. parseExpressionBase(refExpressionErrors) {
  10508. const startLoc = this.state.startLoc;
  10509. const expr = this.parseMaybeAssign(refExpressionErrors);
  10510. if (this.match(12)) {
  10511. const node = this.startNodeAt(startLoc);
  10512. node.expressions = [expr];
  10513. while (this.eat(12)) {
  10514. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10515. }
  10516. this.toReferencedList(node.expressions);
  10517. return this.finishNode(node, "SequenceExpression");
  10518. }
  10519. return expr;
  10520. }
  10521. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10522. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10523. }
  10524. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10525. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10526. }
  10527. setOptionalParametersError(refExpressionErrors, resultError) {
  10528. var _resultError$loc;
  10529. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10530. }
  10531. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10532. const startLoc = this.state.startLoc;
  10533. if (this.isContextual(106)) {
  10534. if (this.prodParam.hasYield) {
  10535. let left = this.parseYield();
  10536. if (afterLeftParse) {
  10537. left = afterLeftParse.call(this, left, startLoc);
  10538. }
  10539. return left;
  10540. }
  10541. }
  10542. let ownExpressionErrors;
  10543. if (refExpressionErrors) {
  10544. ownExpressionErrors = false;
  10545. } else {
  10546. refExpressionErrors = new ExpressionErrors();
  10547. ownExpressionErrors = true;
  10548. }
  10549. const {
  10550. type
  10551. } = this.state;
  10552. if (type === 10 || tokenIsIdentifier(type)) {
  10553. this.state.potentialArrowAt = this.state.start;
  10554. }
  10555. let left = this.parseMaybeConditional(refExpressionErrors);
  10556. if (afterLeftParse) {
  10557. left = afterLeftParse.call(this, left, startLoc);
  10558. }
  10559. if (tokenIsAssignment(this.state.type)) {
  10560. const node = this.startNodeAt(startLoc);
  10561. const operator = this.state.value;
  10562. node.operator = operator;
  10563. if (this.match(29)) {
  10564. this.toAssignable(left, true);
  10565. node.left = left;
  10566. const startIndex = startLoc.index;
  10567. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10568. refExpressionErrors.doubleProtoLoc = null;
  10569. }
  10570. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10571. refExpressionErrors.shorthandAssignLoc = null;
  10572. }
  10573. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10574. this.checkDestructuringPrivate(refExpressionErrors);
  10575. refExpressionErrors.privateKeyLoc = null;
  10576. }
  10577. } else {
  10578. node.left = left;
  10579. }
  10580. this.next();
  10581. node.right = this.parseMaybeAssign();
  10582. this.checkLVal(left, {
  10583. in: this.finishNode(node, "AssignmentExpression")
  10584. });
  10585. return node;
  10586. } else if (ownExpressionErrors) {
  10587. this.checkExpressionErrors(refExpressionErrors, true);
  10588. }
  10589. return left;
  10590. }
  10591. parseMaybeConditional(refExpressionErrors) {
  10592. const startLoc = this.state.startLoc;
  10593. const potentialArrowAt = this.state.potentialArrowAt;
  10594. const expr = this.parseExprOps(refExpressionErrors);
  10595. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10596. return expr;
  10597. }
  10598. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10599. }
  10600. parseConditional(expr, startLoc,
  10601. refExpressionErrors) {
  10602. if (this.eat(17)) {
  10603. const node = this.startNodeAt(startLoc);
  10604. node.test = expr;
  10605. node.consequent = this.parseMaybeAssignAllowIn();
  10606. this.expect(14);
  10607. node.alternate = this.parseMaybeAssign();
  10608. return this.finishNode(node, "ConditionalExpression");
  10609. }
  10610. return expr;
  10611. }
  10612. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10613. return this.match(136) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10614. }
  10615. parseExprOps(refExpressionErrors) {
  10616. const startLoc = this.state.startLoc;
  10617. const potentialArrowAt = this.state.potentialArrowAt;
  10618. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10619. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10620. return expr;
  10621. }
  10622. return this.parseExprOp(expr, startLoc, -1);
  10623. }
  10624. parseExprOp(left, leftStartLoc, minPrec) {
  10625. if (this.isPrivateName(left)) {
  10626. const value = this.getPrivateNameSV(left);
  10627. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10628. this.raise(Errors.PrivateInExpectedIn, {
  10629. at: left,
  10630. identifierName: value
  10631. });
  10632. }
  10633. this.classScope.usePrivateName(value, left.loc.start);
  10634. }
  10635. const op = this.state.type;
  10636. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10637. let prec = tokenOperatorPrecedence(op);
  10638. if (prec > minPrec) {
  10639. if (op === 39) {
  10640. this.expectPlugin("pipelineOperator");
  10641. if (this.state.inFSharpPipelineDirectBody) {
  10642. return left;
  10643. }
  10644. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10645. }
  10646. const node = this.startNodeAt(leftStartLoc);
  10647. node.left = left;
  10648. node.operator = this.state.value;
  10649. const logical = op === 41 || op === 42;
  10650. const coalesce = op === 40;
  10651. if (coalesce) {
  10652. prec = tokenOperatorPrecedence(42);
  10653. }
  10654. this.next();
  10655. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10656. proposal: "minimal"
  10657. }])) {
  10658. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10659. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
  10660. at: this.state.startLoc
  10661. });
  10662. }
  10663. }
  10664. node.right = this.parseExprOpRightExpr(op, prec);
  10665. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10666. const nextOp = this.state.type;
  10667. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10668. throw this.raise(Errors.MixingCoalesceWithLogical, {
  10669. at: this.state.startLoc
  10670. });
  10671. }
  10672. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10673. }
  10674. }
  10675. return left;
  10676. }
  10677. parseExprOpRightExpr(op, prec) {
  10678. const startLoc = this.state.startLoc;
  10679. switch (op) {
  10680. case 39:
  10681. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10682. case "hack":
  10683. return this.withTopicBindingContext(() => {
  10684. return this.parseHackPipeBody();
  10685. });
  10686. case "smart":
  10687. return this.withTopicBindingContext(() => {
  10688. if (this.prodParam.hasYield && this.isContextual(106)) {
  10689. throw this.raise(Errors.PipeBodyIsTighter, {
  10690. at: this.state.startLoc
  10691. });
  10692. }
  10693. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10694. });
  10695. case "fsharp":
  10696. return this.withSoloAwaitPermittingContext(() => {
  10697. return this.parseFSharpPipelineBody(prec);
  10698. });
  10699. }
  10700. default:
  10701. return this.parseExprOpBaseRightExpr(op, prec);
  10702. }
  10703. }
  10704. parseExprOpBaseRightExpr(op, prec) {
  10705. const startLoc = this.state.startLoc;
  10706. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10707. }
  10708. parseHackPipeBody() {
  10709. var _body$extra;
  10710. const {
  10711. startLoc
  10712. } = this.state;
  10713. const body = this.parseMaybeAssign();
  10714. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(
  10715. body.type);
  10716. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10717. this.raise(Errors.PipeUnparenthesizedBody, {
  10718. at: startLoc,
  10719. type: body.type
  10720. });
  10721. }
  10722. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10723. this.raise(Errors.PipeTopicUnused, {
  10724. at: startLoc
  10725. });
  10726. }
  10727. return body;
  10728. }
  10729. checkExponentialAfterUnary(node) {
  10730. if (this.match(57)) {
  10731. this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
  10732. at: node.argument
  10733. });
  10734. }
  10735. }
  10736. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10737. const startLoc = this.state.startLoc;
  10738. const isAwait = this.isContextual(96);
  10739. if (isAwait && this.isAwaitAllowed()) {
  10740. this.next();
  10741. const expr = this.parseAwait(startLoc);
  10742. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10743. return expr;
  10744. }
  10745. const update = this.match(34);
  10746. const node = this.startNode();
  10747. if (tokenIsPrefix(this.state.type)) {
  10748. node.operator = this.state.value;
  10749. node.prefix = true;
  10750. if (this.match(72)) {
  10751. this.expectPlugin("throwExpressions");
  10752. }
  10753. const isDelete = this.match(89);
  10754. this.next();
  10755. node.argument = this.parseMaybeUnary(null, true);
  10756. this.checkExpressionErrors(refExpressionErrors, true);
  10757. if (this.state.strict && isDelete) {
  10758. const arg = node.argument;
  10759. if (arg.type === "Identifier") {
  10760. this.raise(Errors.StrictDelete, {
  10761. at: node
  10762. });
  10763. } else if (this.hasPropertyAsPrivateName(arg)) {
  10764. this.raise(Errors.DeletePrivateField, {
  10765. at: node
  10766. });
  10767. }
  10768. }
  10769. if (!update) {
  10770. if (!sawUnary) {
  10771. this.checkExponentialAfterUnary(node);
  10772. }
  10773. return this.finishNode(node, "UnaryExpression");
  10774. }
  10775. }
  10776. const expr = this.parseUpdate(
  10777. node, update, refExpressionErrors);
  10778. if (isAwait) {
  10779. const {
  10780. type
  10781. } = this.state;
  10782. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10783. if (startsExpr && !this.isAmbiguousAwait()) {
  10784. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
  10785. at: startLoc
  10786. });
  10787. return this.parseAwait(startLoc);
  10788. }
  10789. }
  10790. return expr;
  10791. }
  10792. parseUpdate(node, update, refExpressionErrors) {
  10793. if (update) {
  10794. const updateExpressionNode = node;
  10795. this.checkLVal(updateExpressionNode.argument, {
  10796. in: this.finishNode(updateExpressionNode, "UpdateExpression")
  10797. });
  10798. return node;
  10799. }
  10800. const startLoc = this.state.startLoc;
  10801. let expr = this.parseExprSubscripts(refExpressionErrors);
  10802. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10803. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10804. const node = this.startNodeAt(startLoc);
  10805. node.operator = this.state.value;
  10806. node.prefix = false;
  10807. node.argument = expr;
  10808. this.next();
  10809. this.checkLVal(expr, {
  10810. in: expr = this.finishNode(node, "UpdateExpression")
  10811. });
  10812. }
  10813. return expr;
  10814. }
  10815. parseExprSubscripts(refExpressionErrors) {
  10816. const startLoc = this.state.startLoc;
  10817. const potentialArrowAt = this.state.potentialArrowAt;
  10818. const expr = this.parseExprAtom(refExpressionErrors);
  10819. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10820. return expr;
  10821. }
  10822. return this.parseSubscripts(expr, startLoc);
  10823. }
  10824. parseSubscripts(base, startLoc, noCalls) {
  10825. const state = {
  10826. optionalChainMember: false,
  10827. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10828. stop: false
  10829. };
  10830. do {
  10831. base = this.parseSubscript(base, startLoc, noCalls, state);
  10832. state.maybeAsyncArrow = false;
  10833. } while (!state.stop);
  10834. return base;
  10835. }
  10836. parseSubscript(base, startLoc, noCalls, state) {
  10837. const {
  10838. type
  10839. } = this.state;
  10840. if (!noCalls && type === 15) {
  10841. return this.parseBind(base, startLoc, noCalls, state);
  10842. } else if (tokenIsTemplate(type)) {
  10843. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10844. }
  10845. let optional = false;
  10846. if (type === 18) {
  10847. if (noCalls && this.lookaheadCharCode() === 40) {
  10848. state.stop = true;
  10849. return base;
  10850. }
  10851. state.optionalChainMember = optional = true;
  10852. this.next();
  10853. }
  10854. if (!noCalls && this.match(10)) {
  10855. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10856. } else {
  10857. const computed = this.eat(0);
  10858. if (computed || optional || this.eat(16)) {
  10859. return this.parseMember(base, startLoc, state, computed, optional);
  10860. } else {
  10861. state.stop = true;
  10862. return base;
  10863. }
  10864. }
  10865. }
  10866. parseMember(base, startLoc, state, computed, optional) {
  10867. const node = this.startNodeAt(startLoc);
  10868. node.object = base;
  10869. node.computed = computed;
  10870. if (computed) {
  10871. node.property = this.parseExpression();
  10872. this.expect(3);
  10873. } else if (this.match(136)) {
  10874. if (base.type === "Super") {
  10875. this.raise(Errors.SuperPrivateField, {
  10876. at: startLoc
  10877. });
  10878. }
  10879. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10880. node.property = this.parsePrivateName();
  10881. } else {
  10882. node.property = this.parseIdentifier(true);
  10883. }
  10884. if (state.optionalChainMember) {
  10885. node.optional = optional;
  10886. return this.finishNode(node, "OptionalMemberExpression");
  10887. } else {
  10888. return this.finishNode(node, "MemberExpression");
  10889. }
  10890. }
  10891. parseBind(base, startLoc, noCalls, state) {
  10892. const node = this.startNodeAt(startLoc);
  10893. node.object = base;
  10894. this.next();
  10895. node.callee = this.parseNoCallExpr();
  10896. state.stop = true;
  10897. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10898. }
  10899. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10900. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10901. let refExpressionErrors = null;
  10902. this.state.maybeInArrowParameters = true;
  10903. this.next();
  10904. const node = this.startNodeAt(startLoc);
  10905. node.callee = base;
  10906. const {
  10907. maybeAsyncArrow,
  10908. optionalChainMember
  10909. } = state;
  10910. if (maybeAsyncArrow) {
  10911. this.expressionScope.enter(newAsyncArrowScope());
  10912. refExpressionErrors = new ExpressionErrors();
  10913. }
  10914. if (optionalChainMember) {
  10915. node.optional = optional;
  10916. }
  10917. if (optional) {
  10918. node.arguments = this.parseCallExpressionArguments(11);
  10919. } else {
  10920. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super",
  10921. node, refExpressionErrors);
  10922. }
  10923. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10924. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10925. state.stop = true;
  10926. this.checkDestructuringPrivate(refExpressionErrors);
  10927. this.expressionScope.validateAsPattern();
  10928. this.expressionScope.exit();
  10929. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  10930. } else {
  10931. if (maybeAsyncArrow) {
  10932. this.checkExpressionErrors(refExpressionErrors, true);
  10933. this.expressionScope.exit();
  10934. }
  10935. this.toReferencedArguments(finishedNode);
  10936. }
  10937. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10938. return finishedNode;
  10939. }
  10940. toReferencedArguments(node, isParenthesizedExpr) {
  10941. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  10942. }
  10943. parseTaggedTemplateExpression(base, startLoc, state) {
  10944. const node = this.startNodeAt(startLoc);
  10945. node.tag = base;
  10946. node.quasi = this.parseTemplate(true);
  10947. if (state.optionalChainMember) {
  10948. this.raise(Errors.OptionalChainingNoTemplate, {
  10949. at: startLoc
  10950. });
  10951. }
  10952. return this.finishNode(node, "TaggedTemplateExpression");
  10953. }
  10954. atPossibleAsyncArrow(base) {
  10955. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() &&
  10956. base.end - base.start === 5 && base.start === this.state.potentialArrowAt;
  10957. }
  10958. finishCallExpression(node, optional) {
  10959. if (node.callee.type === "Import") {
  10960. if (node.arguments.length === 2) {
  10961. {
  10962. if (!this.hasPlugin("moduleAttributes")) {
  10963. this.expectPlugin("importAssertions");
  10964. }
  10965. }
  10966. }
  10967. if (node.arguments.length === 0 || node.arguments.length > 2) {
  10968. this.raise(Errors.ImportCallArity, {
  10969. at: node,
  10970. maxArgumentCount: this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  10971. });
  10972. } else {
  10973. for (const arg of node.arguments) {
  10974. if (arg.type === "SpreadElement") {
  10975. this.raise(Errors.ImportCallSpreadArgument, {
  10976. at: arg
  10977. });
  10978. }
  10979. }
  10980. }
  10981. }
  10982. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  10983. }
  10984. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  10985. const elts = [];
  10986. let first = true;
  10987. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10988. this.state.inFSharpPipelineDirectBody = false;
  10989. while (!this.eat(close)) {
  10990. if (first) {
  10991. first = false;
  10992. } else {
  10993. this.expect(12);
  10994. if (this.match(close)) {
  10995. if (dynamicImport && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  10996. this.raise(Errors.ImportCallArgumentTrailingComma, {
  10997. at: this.state.lastTokStartLoc
  10998. });
  10999. }
  11000. if (nodeForExtra) {
  11001. this.addTrailingCommaExtraToNode(nodeForExtra);
  11002. }
  11003. this.next();
  11004. break;
  11005. }
  11006. }
  11007. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  11008. }
  11009. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11010. return elts;
  11011. }
  11012. shouldParseAsyncArrow() {
  11013. return this.match(19) && !this.canInsertSemicolon();
  11014. }
  11015. parseAsyncArrowFromCallExpression(node, call) {
  11016. var _call$extra;
  11017. this.resetPreviousNodeTrailingComments(call);
  11018. this.expect(19);
  11019. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11020. if (call.innerComments) {
  11021. setInnerComments(node, call.innerComments);
  11022. }
  11023. if (call.callee.trailingComments) {
  11024. setInnerComments(node, call.callee.trailingComments);
  11025. }
  11026. return node;
  11027. }
  11028. parseNoCallExpr() {
  11029. const startLoc = this.state.startLoc;
  11030. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11031. }
  11032. parseExprAtom(refExpressionErrors) {
  11033. let node;
  11034. let decorators = null;
  11035. const {
  11036. type
  11037. } = this.state;
  11038. switch (type) {
  11039. case 79:
  11040. return this.parseSuper();
  11041. case 83:
  11042. node = this.startNode();
  11043. this.next();
  11044. if (this.match(16)) {
  11045. return this.parseImportMetaProperty(node);
  11046. }
  11047. if (!this.match(10)) {
  11048. this.raise(Errors.UnsupportedImport, {
  11049. at: this.state.lastTokStartLoc
  11050. });
  11051. }
  11052. return this.finishNode(node, "Import");
  11053. case 78:
  11054. node = this.startNode();
  11055. this.next();
  11056. return this.finishNode(node, "ThisExpression");
  11057. case 90:
  11058. {
  11059. return this.parseDo(this.startNode(), false);
  11060. }
  11061. case 56:
  11062. case 31:
  11063. {
  11064. this.readRegexp();
  11065. return this.parseRegExpLiteral(this.state.value);
  11066. }
  11067. case 132:
  11068. return this.parseNumericLiteral(this.state.value);
  11069. case 133:
  11070. return this.parseBigIntLiteral(this.state.value);
  11071. case 134:
  11072. return this.parseDecimalLiteral(this.state.value);
  11073. case 131:
  11074. return this.parseStringLiteral(this.state.value);
  11075. case 84:
  11076. return this.parseNullLiteral();
  11077. case 85:
  11078. return this.parseBooleanLiteral(true);
  11079. case 86:
  11080. return this.parseBooleanLiteral(false);
  11081. case 10:
  11082. {
  11083. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11084. return this.parseParenAndDistinguishExpression(canBeArrow);
  11085. }
  11086. case 2:
  11087. case 1:
  11088. {
  11089. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11090. }
  11091. case 0:
  11092. {
  11093. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11094. }
  11095. case 6:
  11096. case 7:
  11097. {
  11098. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11099. }
  11100. case 5:
  11101. {
  11102. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11103. }
  11104. case 68:
  11105. return this.parseFunctionOrFunctionSent();
  11106. case 26:
  11107. decorators = this.parseDecorators();
  11108. case 80:
  11109. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11110. case 77:
  11111. return this.parseNewOrNewTarget();
  11112. case 25:
  11113. case 24:
  11114. return this.parseTemplate(false);
  11115. case 15:
  11116. {
  11117. node = this.startNode();
  11118. this.next();
  11119. node.object = null;
  11120. const callee = node.callee = this.parseNoCallExpr();
  11121. if (callee.type === "MemberExpression") {
  11122. return this.finishNode(node, "BindExpression");
  11123. } else {
  11124. throw this.raise(Errors.UnsupportedBind, {
  11125. at: callee
  11126. });
  11127. }
  11128. }
  11129. case 136:
  11130. {
  11131. this.raise(Errors.PrivateInExpectedIn, {
  11132. at: this.state.startLoc,
  11133. identifierName: this.state.value
  11134. });
  11135. return this.parsePrivateName();
  11136. }
  11137. case 33:
  11138. {
  11139. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11140. }
  11141. case 32:
  11142. {
  11143. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11144. }
  11145. case 37:
  11146. case 38:
  11147. {
  11148. return this.parseTopicReference("hack");
  11149. }
  11150. case 44:
  11151. case 54:
  11152. case 27:
  11153. {
  11154. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11155. if (pipeProposal) {
  11156. return this.parseTopicReference(pipeProposal);
  11157. } else {
  11158. throw this.unexpected();
  11159. }
  11160. }
  11161. case 47:
  11162. {
  11163. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11164. if (isIdentifierStart(lookaheadCh) ||
  11165. lookaheadCh === 62) {
  11166. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11167. break;
  11168. } else {
  11169. throw this.unexpected();
  11170. }
  11171. }
  11172. default:
  11173. if (tokenIsIdentifier(type)) {
  11174. if (this.isContextual(125) && this.lookaheadCharCode() === 123 && !this.hasFollowingLineBreak()) {
  11175. return this.parseModuleExpression();
  11176. }
  11177. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11178. const containsEsc = this.state.containsEsc;
  11179. const id = this.parseIdentifier();
  11180. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11181. const {
  11182. type
  11183. } = this.state;
  11184. if (type === 68) {
  11185. this.resetPreviousNodeTrailingComments(id);
  11186. this.next();
  11187. return this.parseFunction(this.startNodeAtNode(id), undefined, true);
  11188. } else if (tokenIsIdentifier(type)) {
  11189. if (this.lookaheadCharCode() === 61) {
  11190. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11191. } else {
  11192. return id;
  11193. }
  11194. } else if (type === 90) {
  11195. this.resetPreviousNodeTrailingComments(id);
  11196. return this.parseDo(this.startNodeAtNode(id), true);
  11197. }
  11198. }
  11199. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11200. this.next();
  11201. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11202. }
  11203. return id;
  11204. } else {
  11205. throw this.unexpected();
  11206. }
  11207. }
  11208. }
  11209. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11210. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11211. if (pipeProposal) {
  11212. this.state.type = topicTokenType;
  11213. this.state.value = topicTokenValue;
  11214. this.state.pos--;
  11215. this.state.end--;
  11216. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11217. return this.parseTopicReference(pipeProposal);
  11218. } else {
  11219. throw this.unexpected();
  11220. }
  11221. }
  11222. parseTopicReference(pipeProposal) {
  11223. const node = this.startNode();
  11224. const startLoc = this.state.startLoc;
  11225. const tokenType = this.state.type;
  11226. this.next();
  11227. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11228. }
  11229. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11230. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11231. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" :
  11232. "TopicReference";
  11233. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11234. this.raise(
  11235. pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed :
  11236. Errors.PipeTopicUnbound, {
  11237. at: startLoc
  11238. });
  11239. }
  11240. this.registerTopicReference();
  11241. return this.finishNode(node, nodeType);
  11242. } else {
  11243. throw this.raise(Errors.PipeTopicUnconfiguredToken, {
  11244. at: startLoc,
  11245. token: tokenLabelName(tokenType)
  11246. });
  11247. }
  11248. }
  11249. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11250. switch (pipeProposal) {
  11251. case "hack":
  11252. {
  11253. return this.hasPlugin(["pipelineOperator", {
  11254. topicToken: tokenLabelName(tokenType)
  11255. }]);
  11256. }
  11257. case "smart":
  11258. return tokenType === 27;
  11259. default:
  11260. throw this.raise(Errors.PipeTopicRequiresHackPipes, {
  11261. at: startLoc
  11262. });
  11263. }
  11264. }
  11265. parseAsyncArrowUnaryFunction(node) {
  11266. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11267. const params = [this.parseIdentifier()];
  11268. this.prodParam.exit();
  11269. if (this.hasPrecedingLineBreak()) {
  11270. this.raise(Errors.LineTerminatorBeforeArrow, {
  11271. at: this.state.curPosition()
  11272. });
  11273. }
  11274. this.expect(19);
  11275. return this.parseArrowExpression(node, params, true);
  11276. }
  11277. parseDo(node, isAsync) {
  11278. this.expectPlugin("doExpressions");
  11279. if (isAsync) {
  11280. this.expectPlugin("asyncDoExpressions");
  11281. }
  11282. node.async = isAsync;
  11283. this.next();
  11284. const oldLabels = this.state.labels;
  11285. this.state.labels = [];
  11286. if (isAsync) {
  11287. this.prodParam.enter(PARAM_AWAIT);
  11288. node.body = this.parseBlock();
  11289. this.prodParam.exit();
  11290. } else {
  11291. node.body = this.parseBlock();
  11292. }
  11293. this.state.labels = oldLabels;
  11294. return this.finishNode(node, "DoExpression");
  11295. }
  11296. parseSuper() {
  11297. const node = this.startNode();
  11298. this.next();
  11299. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  11300. this.raise(Errors.SuperNotAllowed, {
  11301. at: node
  11302. });
  11303. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  11304. this.raise(Errors.UnexpectedSuper, {
  11305. at: node
  11306. });
  11307. }
  11308. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11309. this.raise(Errors.UnsupportedSuper, {
  11310. at: node
  11311. });
  11312. }
  11313. return this.finishNode(node, "Super");
  11314. }
  11315. parsePrivateName() {
  11316. const node = this.startNode();
  11317. const id = this.startNodeAt(
  11318. createPositionWithColumnOffset(this.state.startLoc, 1));
  11319. const name = this.state.value;
  11320. this.next();
  11321. node.id = this.createIdentifier(id, name);
  11322. return this.finishNode(node, "PrivateName");
  11323. }
  11324. parseFunctionOrFunctionSent() {
  11325. const node = this.startNode();
  11326. this.next();
  11327. if (this.prodParam.hasYield && this.match(16)) {
  11328. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11329. this.next();
  11330. if (this.match(102)) {
  11331. this.expectPlugin("functionSent");
  11332. } else if (!this.hasPlugin("functionSent")) {
  11333. this.unexpected();
  11334. }
  11335. return this.parseMetaProperty(node, meta, "sent");
  11336. }
  11337. return this.parseFunction(node);
  11338. }
  11339. parseMetaProperty(node, meta, propertyName) {
  11340. node.meta = meta;
  11341. const containsEsc = this.state.containsEsc;
  11342. node.property = this.parseIdentifier(true);
  11343. if (node.property.name !== propertyName || containsEsc) {
  11344. this.raise(Errors.UnsupportedMetaProperty, {
  11345. at: node.property,
  11346. target: meta.name,
  11347. onlyValidPropertyName: propertyName
  11348. });
  11349. }
  11350. return this.finishNode(node, "MetaProperty");
  11351. }
  11352. parseImportMetaProperty(node) {
  11353. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11354. this.next();
  11355. if (this.isContextual(100)) {
  11356. if (!this.inModule) {
  11357. this.raise(Errors.ImportMetaOutsideModule, {
  11358. at: id
  11359. });
  11360. }
  11361. this.sawUnambiguousESM = true;
  11362. }
  11363. return this.parseMetaProperty(node, id, "meta");
  11364. }
  11365. parseLiteralAtNode(value, type, node) {
  11366. this.addExtra(node, "rawValue", value);
  11367. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  11368. node.value = value;
  11369. this.next();
  11370. return this.finishNode(node, type);
  11371. }
  11372. parseLiteral(value, type) {
  11373. const node = this.startNode();
  11374. return this.parseLiteralAtNode(value, type, node);
  11375. }
  11376. parseStringLiteral(value) {
  11377. return this.parseLiteral(value, "StringLiteral");
  11378. }
  11379. parseNumericLiteral(value) {
  11380. return this.parseLiteral(value, "NumericLiteral");
  11381. }
  11382. parseBigIntLiteral(value) {
  11383. return this.parseLiteral(value, "BigIntLiteral");
  11384. }
  11385. parseDecimalLiteral(value) {
  11386. return this.parseLiteral(value, "DecimalLiteral");
  11387. }
  11388. parseRegExpLiteral(value) {
  11389. const node = this.parseLiteral(value.value, "RegExpLiteral");
  11390. node.pattern = value.pattern;
  11391. node.flags = value.flags;
  11392. return node;
  11393. }
  11394. parseBooleanLiteral(value) {
  11395. const node = this.startNode();
  11396. node.value = value;
  11397. this.next();
  11398. return this.finishNode(node, "BooleanLiteral");
  11399. }
  11400. parseNullLiteral() {
  11401. const node = this.startNode();
  11402. this.next();
  11403. return this.finishNode(node, "NullLiteral");
  11404. }
  11405. parseParenAndDistinguishExpression(canBeArrow) {
  11406. const startLoc = this.state.startLoc;
  11407. let val;
  11408. this.next();
  11409. this.expressionScope.enter(newArrowHeadScope());
  11410. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11411. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11412. this.state.maybeInArrowParameters = true;
  11413. this.state.inFSharpPipelineDirectBody = false;
  11414. const innerStartLoc = this.state.startLoc;
  11415. const exprList = [];
  11416. const refExpressionErrors = new ExpressionErrors();
  11417. let first = true;
  11418. let spreadStartLoc;
  11419. let optionalCommaStartLoc;
  11420. while (!this.match(11)) {
  11421. if (first) {
  11422. first = false;
  11423. } else {
  11424. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11425. if (this.match(11)) {
  11426. optionalCommaStartLoc = this.state.startLoc;
  11427. break;
  11428. }
  11429. }
  11430. if (this.match(21)) {
  11431. const spreadNodeStartLoc = this.state.startLoc;
  11432. spreadStartLoc = this.state.startLoc;
  11433. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11434. if (!this.checkCommaAfterRest(41)) {
  11435. break;
  11436. }
  11437. } else {
  11438. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11439. }
  11440. }
  11441. const innerEndLoc = this.state.lastTokEndLoc;
  11442. this.expect(11);
  11443. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11444. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11445. let arrowNode = this.startNodeAt(startLoc);
  11446. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11447. this.checkDestructuringPrivate(refExpressionErrors);
  11448. this.expressionScope.validateAsPattern();
  11449. this.expressionScope.exit();
  11450. this.parseArrowExpression(arrowNode, exprList, false);
  11451. return arrowNode;
  11452. }
  11453. this.expressionScope.exit();
  11454. if (!exprList.length) {
  11455. this.unexpected(this.state.lastTokStartLoc);
  11456. }
  11457. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11458. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11459. this.checkExpressionErrors(refExpressionErrors, true);
  11460. this.toReferencedListDeep(exprList, true);
  11461. if (exprList.length > 1) {
  11462. val = this.startNodeAt(innerStartLoc);
  11463. val.expressions = exprList;
  11464. this.finishNode(val, "SequenceExpression");
  11465. this.resetEndLocation(val, innerEndLoc);
  11466. } else {
  11467. val = exprList[0];
  11468. }
  11469. return this.wrapParenthesis(startLoc,
  11470. val);
  11471. }
  11472. wrapParenthesis(startLoc, expression) {
  11473. if (!this.options.createParenthesizedExpressions) {
  11474. this.addExtra(expression, "parenthesized", true);
  11475. this.addExtra(expression, "parenStart", startLoc.index);
  11476. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11477. return expression;
  11478. }
  11479. const parenExpression = this.startNodeAt(startLoc);
  11480. parenExpression.expression = expression;
  11481. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11482. }
  11483. shouldParseArrow(params) {
  11484. return !this.canInsertSemicolon();
  11485. }
  11486. parseArrow(node) {
  11487. if (this.eat(19)) {
  11488. return node;
  11489. }
  11490. }
  11491. parseParenItem(node,
  11492. startLoc) {
  11493. return node;
  11494. }
  11495. parseNewOrNewTarget() {
  11496. const node = this.startNode();
  11497. this.next();
  11498. if (this.match(16)) {
  11499. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11500. this.next();
  11501. const metaProp = this.parseMetaProperty(node, meta, "target");
  11502. if (!this.scope.inNonArrowFunction && !this.scope.inClass) {
  11503. this.raise(Errors.UnexpectedNewTarget, {
  11504. at: metaProp
  11505. });
  11506. }
  11507. return metaProp;
  11508. }
  11509. return this.parseNew(node);
  11510. }
  11511. parseNew(node) {
  11512. this.parseNewCallee(node);
  11513. if (this.eat(10)) {
  11514. const args = this.parseExprList(11);
  11515. this.toReferencedList(args);
  11516. node.arguments = args;
  11517. } else {
  11518. node.arguments = [];
  11519. }
  11520. return this.finishNode(node, "NewExpression");
  11521. }
  11522. parseNewCallee(node) {
  11523. node.callee = this.parseNoCallExpr();
  11524. if (node.callee.type === "Import") {
  11525. this.raise(Errors.ImportCallNotNewExpression, {
  11526. at: node.callee
  11527. });
  11528. } else if (this.isOptionalChain(node.callee)) {
  11529. this.raise(Errors.OptionalChainingNoNew, {
  11530. at: this.state.lastTokEndLoc
  11531. });
  11532. } else if (this.eat(18)) {
  11533. this.raise(Errors.OptionalChainingNoNew, {
  11534. at: this.state.startLoc
  11535. });
  11536. }
  11537. }
  11538. parseTemplateElement(isTagged) {
  11539. const {
  11540. start,
  11541. startLoc,
  11542. end,
  11543. value
  11544. } = this.state;
  11545. const elemStart = start + 1;
  11546. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11547. if (value === null) {
  11548. if (!isTagged) {
  11549. this.raise(Errors.InvalidEscapeSequenceTemplate, {
  11550. at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)
  11551. });
  11552. }
  11553. }
  11554. const isTail = this.match(24);
  11555. const endOffset = isTail ? -1 : -2;
  11556. const elemEnd = end + endOffset;
  11557. elem.value = {
  11558. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11559. cooked: value === null ? null : value.slice(1, endOffset)
  11560. };
  11561. elem.tail = isTail;
  11562. this.next();
  11563. const finishedNode = this.finishNode(elem, "TemplateElement");
  11564. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11565. return finishedNode;
  11566. }
  11567. parseTemplate(isTagged) {
  11568. const node = this.startNode();
  11569. node.expressions = [];
  11570. let curElt = this.parseTemplateElement(isTagged);
  11571. node.quasis = [curElt];
  11572. while (!curElt.tail) {
  11573. node.expressions.push(this.parseTemplateSubstitution());
  11574. this.readTemplateContinuation();
  11575. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  11576. }
  11577. return this.finishNode(node, "TemplateLiteral");
  11578. }
  11579. parseTemplateSubstitution() {
  11580. return this.parseExpression();
  11581. }
  11582. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11583. if (isRecord) {
  11584. this.expectPlugin("recordAndTuple");
  11585. }
  11586. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11587. this.state.inFSharpPipelineDirectBody = false;
  11588. const propHash = Object.create(null);
  11589. let first = true;
  11590. const node = this.startNode();
  11591. node.properties = [];
  11592. this.next();
  11593. while (!this.match(close)) {
  11594. if (first) {
  11595. first = false;
  11596. } else {
  11597. this.expect(12);
  11598. if (this.match(close)) {
  11599. this.addTrailingCommaExtraToNode(
  11600. node);
  11601. break;
  11602. }
  11603. }
  11604. let prop;
  11605. if (isPattern) {
  11606. prop = this.parseBindingProperty();
  11607. } else {
  11608. prop = this.parsePropertyDefinition(refExpressionErrors);
  11609. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11610. }
  11611. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11612. this.raise(Errors.InvalidRecordProperty, {
  11613. at: prop
  11614. });
  11615. }
  11616. if (prop.shorthand) {
  11617. this.addExtra(prop, "shorthand", true);
  11618. }
  11619. node.properties.push(prop);
  11620. }
  11621. this.next();
  11622. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11623. let type = "ObjectExpression";
  11624. if (isPattern) {
  11625. type = "ObjectPattern";
  11626. } else if (isRecord) {
  11627. type = "RecordExpression";
  11628. }
  11629. return this.finishNode(node, type);
  11630. }
  11631. addTrailingCommaExtraToNode(node) {
  11632. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  11633. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11634. }
  11635. maybeAsyncOrAccessorProp(prop) {
  11636. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11637. }
  11638. parsePropertyDefinition(refExpressionErrors) {
  11639. let decorators = [];
  11640. if (this.match(26)) {
  11641. if (this.hasPlugin("decorators")) {
  11642. this.raise(Errors.UnsupportedPropertyDecorator, {
  11643. at: this.state.startLoc
  11644. });
  11645. }
  11646. while (this.match(26)) {
  11647. decorators.push(this.parseDecorator());
  11648. }
  11649. }
  11650. const prop = this.startNode();
  11651. let isAsync = false;
  11652. let isAccessor = false;
  11653. let startLoc;
  11654. if (this.match(21)) {
  11655. if (decorators.length) this.unexpected();
  11656. return this.parseSpread();
  11657. }
  11658. if (decorators.length) {
  11659. prop.decorators = decorators;
  11660. decorators = [];
  11661. }
  11662. prop.method = false;
  11663. if (refExpressionErrors) {
  11664. startLoc = this.state.startLoc;
  11665. }
  11666. let isGenerator = this.eat(55);
  11667. this.parsePropertyNamePrefixOperator(prop);
  11668. const containsEsc = this.state.containsEsc;
  11669. const key = this.parsePropertyName(prop, refExpressionErrors);
  11670. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11671. const keyName = key.name;
  11672. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11673. isAsync = true;
  11674. this.resetPreviousNodeTrailingComments(key);
  11675. isGenerator = this.eat(55);
  11676. this.parsePropertyName(prop);
  11677. }
  11678. if (keyName === "get" || keyName === "set") {
  11679. isAccessor = true;
  11680. this.resetPreviousNodeTrailingComments(key);
  11681. prop.kind = keyName;
  11682. if (this.match(55)) {
  11683. isGenerator = true;
  11684. this.raise(Errors.AccessorIsGenerator, {
  11685. at: this.state.curPosition(),
  11686. kind: keyName
  11687. });
  11688. this.next();
  11689. }
  11690. this.parsePropertyName(prop);
  11691. }
  11692. }
  11693. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11694. }
  11695. getGetterSetterExpectedParamCount(method) {
  11696. return method.kind === "get" ? 0 : 1;
  11697. }
  11698. getObjectOrClassMethodParams(method) {
  11699. return method.params;
  11700. }
  11701. checkGetterSetterParams(method) {
  11702. var _params;
  11703. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11704. const params = this.getObjectOrClassMethodParams(method);
  11705. if (params.length !== paramCount) {
  11706. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  11707. at: method
  11708. });
  11709. }
  11710. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11711. this.raise(Errors.BadSetterRestParameter, {
  11712. at: method
  11713. });
  11714. }
  11715. }
  11716. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11717. if (isAccessor) {
  11718. const finishedProp = this.parseMethod(prop,
  11719. isGenerator, false, false, false, "ObjectMethod");
  11720. this.checkGetterSetterParams(finishedProp);
  11721. return finishedProp;
  11722. }
  11723. if (isAsync || isGenerator || this.match(10)) {
  11724. if (isPattern) this.unexpected();
  11725. prop.kind = "method";
  11726. prop.method = true;
  11727. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11728. }
  11729. }
  11730. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11731. prop.shorthand = false;
  11732. if (this.eat(14)) {
  11733. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11734. return this.finishNode(prop, "ObjectProperty");
  11735. }
  11736. if (!prop.computed && prop.key.type === "Identifier") {
  11737. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11738. if (isPattern) {
  11739. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11740. } else if (this.match(29)) {
  11741. const shorthandAssignLoc = this.state.startLoc;
  11742. if (refExpressionErrors != null) {
  11743. if (refExpressionErrors.shorthandAssignLoc === null) {
  11744. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11745. }
  11746. } else {
  11747. this.raise(Errors.InvalidCoverInitializedName, {
  11748. at: shorthandAssignLoc
  11749. });
  11750. }
  11751. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11752. } else {
  11753. prop.value = cloneIdentifier(prop.key);
  11754. }
  11755. prop.shorthand = true;
  11756. return this.finishNode(prop, "ObjectProperty");
  11757. }
  11758. }
  11759. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11760. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11761. if (!node) this.unexpected();
  11762. return node;
  11763. }
  11764. parsePropertyName(prop, refExpressionErrors) {
  11765. if (this.eat(0)) {
  11766. prop.computed = true;
  11767. prop.key = this.parseMaybeAssignAllowIn();
  11768. this.expect(3);
  11769. } else {
  11770. const {
  11771. type,
  11772. value
  11773. } = this.state;
  11774. let key;
  11775. if (tokenIsKeywordOrIdentifier(type)) {
  11776. key = this.parseIdentifier(true);
  11777. } else {
  11778. switch (type) {
  11779. case 132:
  11780. key = this.parseNumericLiteral(value);
  11781. break;
  11782. case 131:
  11783. key = this.parseStringLiteral(value);
  11784. break;
  11785. case 133:
  11786. key = this.parseBigIntLiteral(value);
  11787. break;
  11788. case 134:
  11789. key = this.parseDecimalLiteral(value);
  11790. break;
  11791. case 136:
  11792. {
  11793. const privateKeyLoc = this.state.startLoc;
  11794. if (refExpressionErrors != null) {
  11795. if (refExpressionErrors.privateKeyLoc === null) {
  11796. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11797. }
  11798. } else {
  11799. this.raise(Errors.UnexpectedPrivateField, {
  11800. at: privateKeyLoc
  11801. });
  11802. }
  11803. key = this.parsePrivateName();
  11804. break;
  11805. }
  11806. default:
  11807. throw this.unexpected();
  11808. }
  11809. }
  11810. prop.key = key;
  11811. if (type !== 136) {
  11812. prop.computed = false;
  11813. }
  11814. }
  11815. return prop.key;
  11816. }
  11817. initFunction(node, isAsync) {
  11818. node.id = null;
  11819. node.generator = false;
  11820. node.async = !!isAsync;
  11821. }
  11822. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11823. this.initFunction(node, isAsync);
  11824. node.generator = !!isGenerator;
  11825. const allowModifiers = isConstructor;
  11826. this.scope.enter(SCOPE_FUNCTION | SCOPE_SUPER | (inClassScope ? SCOPE_CLASS : 0) | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  11827. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11828. this.parseFunctionParams(node, allowModifiers);
  11829. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11830. this.prodParam.exit();
  11831. this.scope.exit();
  11832. return finishedNode;
  11833. }
  11834. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11835. if (isTuple) {
  11836. this.expectPlugin("recordAndTuple");
  11837. }
  11838. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11839. this.state.inFSharpPipelineDirectBody = false;
  11840. const node = this.startNode();
  11841. this.next();
  11842. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors,
  11843. node);
  11844. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11845. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11846. }
  11847. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11848. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  11849. let flags = functionFlags(isAsync, false);
  11850. if (!this.match(5) && this.prodParam.hasIn) {
  11851. flags |= PARAM_IN;
  11852. }
  11853. this.prodParam.enter(flags);
  11854. this.initFunction(node, isAsync);
  11855. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11856. if (params) {
  11857. this.state.maybeInArrowParameters = true;
  11858. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11859. }
  11860. this.state.maybeInArrowParameters = false;
  11861. this.parseFunctionBody(node, true);
  11862. this.prodParam.exit();
  11863. this.scope.exit();
  11864. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11865. return this.finishNode(node, "ArrowFunctionExpression");
  11866. }
  11867. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11868. this.toAssignableList(params, trailingCommaLoc, false);
  11869. node.params = params;
  11870. }
  11871. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11872. this.parseFunctionBody(node, false, isMethod);
  11873. return this.finishNode(node, type);
  11874. }
  11875. parseFunctionBody(node, allowExpression, isMethod = false) {
  11876. const isExpression = allowExpression && !this.match(5);
  11877. this.expressionScope.enter(newExpressionScope());
  11878. if (isExpression) {
  11879. node.body = this.parseMaybeAssign();
  11880. this.checkParams(node, false, allowExpression, false);
  11881. } else {
  11882. const oldStrict = this.state.strict;
  11883. const oldLabels = this.state.labels;
  11884. this.state.labels = [];
  11885. this.prodParam.enter(this.prodParam.currentFlags() | PARAM_RETURN);
  11886. node.body = this.parseBlock(true, false,
  11887. hasStrictModeDirective => {
  11888. const nonSimple = !this.isSimpleParamList(node.params);
  11889. if (hasStrictModeDirective && nonSimple) {
  11890. this.raise(Errors.IllegalLanguageModeDirective, {
  11891. at:
  11892. (node.kind === "method" || node.kind === "constructor") &&
  11893. !!node.key ?
  11894. node.key.loc.end : node
  11895. });
  11896. }
  11897. const strictModeChanged = !oldStrict && this.state.strict;
  11898. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11899. if (this.state.strict && node.id) {
  11900. this.checkIdentifier(node.id, BIND_OUTSIDE, strictModeChanged);
  11901. }
  11902. });
  11903. this.prodParam.exit();
  11904. this.state.labels = oldLabels;
  11905. }
  11906. this.expressionScope.exit();
  11907. }
  11908. isSimpleParameter(node) {
  11909. return node.type === "Identifier";
  11910. }
  11911. isSimpleParamList(params) {
  11912. for (let i = 0, len = params.length; i < len; i++) {
  11913. if (!this.isSimpleParameter(params[i])) return false;
  11914. }
  11915. return true;
  11916. }
  11917. checkParams(node, allowDuplicates,
  11918. isArrowFunction, strictModeChanged = true) {
  11919. const checkClashes = !allowDuplicates && new Set();
  11920. const formalParameters = {
  11921. type: "FormalParameters"
  11922. };
  11923. for (const param of node.params) {
  11924. this.checkLVal(param, {
  11925. in: formalParameters,
  11926. binding: BIND_VAR,
  11927. checkClashes,
  11928. strictModeChanged
  11929. });
  11930. }
  11931. }
  11932. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11933. const elts = [];
  11934. let first = true;
  11935. while (!this.eat(close)) {
  11936. if (first) {
  11937. first = false;
  11938. } else {
  11939. this.expect(12);
  11940. if (this.match(close)) {
  11941. if (nodeForExtra) {
  11942. this.addTrailingCommaExtraToNode(nodeForExtra);
  11943. }
  11944. this.next();
  11945. break;
  11946. }
  11947. }
  11948. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11949. }
  11950. return elts;
  11951. }
  11952. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  11953. let elt;
  11954. if (this.match(12)) {
  11955. if (!allowEmpty) {
  11956. this.raise(Errors.UnexpectedToken, {
  11957. at: this.state.curPosition(),
  11958. unexpected: ","
  11959. });
  11960. }
  11961. elt = null;
  11962. } else if (this.match(21)) {
  11963. const spreadNodeStartLoc = this.state.startLoc;
  11964. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  11965. } else if (this.match(17)) {
  11966. this.expectPlugin("partialApplication");
  11967. if (!allowPlaceholder) {
  11968. this.raise(Errors.UnexpectedArgumentPlaceholder, {
  11969. at: this.state.startLoc
  11970. });
  11971. }
  11972. const node = this.startNode();
  11973. this.next();
  11974. elt = this.finishNode(node, "ArgumentPlaceholder");
  11975. } else {
  11976. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  11977. }
  11978. return elt;
  11979. }
  11980. parseIdentifier(liberal) {
  11981. const node = this.startNode();
  11982. const name = this.parseIdentifierName(liberal);
  11983. return this.createIdentifier(node, name);
  11984. }
  11985. createIdentifier(node, name) {
  11986. node.name = name;
  11987. node.loc.identifierName = name;
  11988. return this.finishNode(node, "Identifier");
  11989. }
  11990. parseIdentifierName(liberal) {
  11991. let name;
  11992. const {
  11993. startLoc,
  11994. type
  11995. } = this.state;
  11996. if (tokenIsKeywordOrIdentifier(type)) {
  11997. name = this.state.value;
  11998. } else {
  11999. throw this.unexpected();
  12000. }
  12001. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12002. if (liberal) {
  12003. if (tokenIsKeyword) {
  12004. this.replaceToken(130);
  12005. }
  12006. } else {
  12007. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12008. }
  12009. this.next();
  12010. return name;
  12011. }
  12012. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12013. if (word.length > 10) {
  12014. return;
  12015. }
  12016. if (!canBeReservedWord(word)) {
  12017. return;
  12018. }
  12019. if (word === "yield") {
  12020. if (this.prodParam.hasYield) {
  12021. this.raise(Errors.YieldBindingIdentifier, {
  12022. at: startLoc
  12023. });
  12024. return;
  12025. }
  12026. } else if (word === "await") {
  12027. if (this.prodParam.hasAwait) {
  12028. this.raise(Errors.AwaitBindingIdentifier, {
  12029. at: startLoc
  12030. });
  12031. return;
  12032. }
  12033. if (this.scope.inStaticBlock) {
  12034. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
  12035. at: startLoc
  12036. });
  12037. return;
  12038. }
  12039. this.expressionScope.recordAsyncArrowParametersError({
  12040. at: startLoc
  12041. });
  12042. } else if (word === "arguments") {
  12043. if (this.scope.inClassAndNotInNonArrowFunction) {
  12044. this.raise(Errors.ArgumentsInClass, {
  12045. at: startLoc
  12046. });
  12047. return;
  12048. }
  12049. }
  12050. if (checkKeywords && isKeyword(word)) {
  12051. this.raise(Errors.UnexpectedKeyword, {
  12052. at: startLoc,
  12053. keyword: word
  12054. });
  12055. return;
  12056. }
  12057. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12058. if (reservedTest(word, this.inModule)) {
  12059. this.raise(Errors.UnexpectedReservedWord, {
  12060. at: startLoc,
  12061. reservedWord: word
  12062. });
  12063. }
  12064. }
  12065. isAwaitAllowed() {
  12066. if (this.prodParam.hasAwait) return true;
  12067. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  12068. return true;
  12069. }
  12070. return false;
  12071. }
  12072. parseAwait(startLoc) {
  12073. const node = this.startNodeAt(startLoc);
  12074. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
  12075. at: node
  12076. });
  12077. if (this.eat(55)) {
  12078. this.raise(Errors.ObsoleteAwaitStar, {
  12079. at: node
  12080. });
  12081. }
  12082. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  12083. if (this.isAmbiguousAwait()) {
  12084. this.ambiguousScriptDifferentAst = true;
  12085. } else {
  12086. this.sawUnambiguousESM = true;
  12087. }
  12088. }
  12089. if (!this.state.soloAwait) {
  12090. node.argument = this.parseMaybeUnary(null, true);
  12091. }
  12092. return this.finishNode(node, "AwaitExpression");
  12093. }
  12094. isAmbiguousAwait() {
  12095. if (this.hasPrecedingLineBreak()) return true;
  12096. const {
  12097. type
  12098. } = this.state;
  12099. return (
  12100. type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 101 && !this.state.containsEsc ||
  12101. type === 135 || type === 56 ||
  12102. this.hasPlugin("v8intrinsic") && type === 54
  12103. );
  12104. }
  12105. parseYield() {
  12106. const node = this.startNode();
  12107. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
  12108. at: node
  12109. });
  12110. this.next();
  12111. let delegating = false;
  12112. let argument = null;
  12113. if (!this.hasPrecedingLineBreak()) {
  12114. delegating = this.eat(55);
  12115. switch (this.state.type) {
  12116. case 13:
  12117. case 137:
  12118. case 8:
  12119. case 11:
  12120. case 3:
  12121. case 9:
  12122. case 14:
  12123. case 12:
  12124. if (!delegating) break;
  12125. default:
  12126. argument = this.parseMaybeAssign();
  12127. }
  12128. }
  12129. node.delegate = delegating;
  12130. node.argument = argument;
  12131. return this.finishNode(node, "YieldExpression");
  12132. }
  12133. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12134. if (this.hasPlugin(["pipelineOperator", {
  12135. proposal: "smart"
  12136. }])) {
  12137. if (left.type === "SequenceExpression") {
  12138. this.raise(Errors.PipelineHeadSequenceExpression, {
  12139. at: leftStartLoc
  12140. });
  12141. }
  12142. }
  12143. }
  12144. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12145. if (this.isSimpleReference(childExpr)) {
  12146. const bodyNode = this.startNodeAt(startLoc);
  12147. bodyNode.callee = childExpr;
  12148. return this.finishNode(bodyNode, "PipelineBareFunction");
  12149. } else {
  12150. const bodyNode = this.startNodeAt(startLoc);
  12151. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12152. bodyNode.expression = childExpr;
  12153. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12154. }
  12155. }
  12156. isSimpleReference(expression) {
  12157. switch (expression.type) {
  12158. case "MemberExpression":
  12159. return !expression.computed && this.isSimpleReference(expression.object);
  12160. case "Identifier":
  12161. return true;
  12162. default:
  12163. return false;
  12164. }
  12165. }
  12166. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12167. if (this.match(19)) {
  12168. throw this.raise(Errors.PipelineBodyNoArrow, {
  12169. at: this.state.startLoc
  12170. });
  12171. }
  12172. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12173. this.raise(Errors.PipelineTopicUnused, {
  12174. at: startLoc
  12175. });
  12176. }
  12177. }
  12178. withTopicBindingContext(callback) {
  12179. const outerContextTopicState = this.state.topicContext;
  12180. this.state.topicContext = {
  12181. maxNumOfResolvableTopics: 1,
  12182. maxTopicIndex: null
  12183. };
  12184. try {
  12185. return callback();
  12186. } finally {
  12187. this.state.topicContext = outerContextTopicState;
  12188. }
  12189. }
  12190. withSmartMixTopicForbiddingContext(callback) {
  12191. if (this.hasPlugin(["pipelineOperator", {
  12192. proposal: "smart"
  12193. }])) {
  12194. const outerContextTopicState = this.state.topicContext;
  12195. this.state.topicContext = {
  12196. maxNumOfResolvableTopics: 0,
  12197. maxTopicIndex: null
  12198. };
  12199. try {
  12200. return callback();
  12201. } finally {
  12202. this.state.topicContext = outerContextTopicState;
  12203. }
  12204. } else {
  12205. return callback();
  12206. }
  12207. }
  12208. withSoloAwaitPermittingContext(callback) {
  12209. const outerContextSoloAwaitState = this.state.soloAwait;
  12210. this.state.soloAwait = true;
  12211. try {
  12212. return callback();
  12213. } finally {
  12214. this.state.soloAwait = outerContextSoloAwaitState;
  12215. }
  12216. }
  12217. allowInAnd(callback) {
  12218. const flags = this.prodParam.currentFlags();
  12219. const prodParamToSet = PARAM_IN & ~flags;
  12220. if (prodParamToSet) {
  12221. this.prodParam.enter(flags | PARAM_IN);
  12222. try {
  12223. return callback();
  12224. } finally {
  12225. this.prodParam.exit();
  12226. }
  12227. }
  12228. return callback();
  12229. }
  12230. disallowInAnd(callback) {
  12231. const flags = this.prodParam.currentFlags();
  12232. const prodParamToClear = PARAM_IN & flags;
  12233. if (prodParamToClear) {
  12234. this.prodParam.enter(flags & ~PARAM_IN);
  12235. try {
  12236. return callback();
  12237. } finally {
  12238. this.prodParam.exit();
  12239. }
  12240. }
  12241. return callback();
  12242. }
  12243. registerTopicReference() {
  12244. this.state.topicContext.maxTopicIndex = 0;
  12245. }
  12246. topicReferenceIsAllowedInCurrentContext() {
  12247. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12248. }
  12249. topicReferenceWasUsedInCurrentContext() {
  12250. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12251. }
  12252. parseFSharpPipelineBody(prec) {
  12253. const startLoc = this.state.startLoc;
  12254. this.state.potentialArrowAt = this.state.start;
  12255. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12256. this.state.inFSharpPipelineDirectBody = true;
  12257. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12258. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12259. return ret;
  12260. }
  12261. parseModuleExpression() {
  12262. this.expectPlugin("moduleBlocks");
  12263. const node = this.startNode();
  12264. this.next();
  12265. if (!this.match(5)) {
  12266. this.unexpected(null, 5);
  12267. }
  12268. const program = this.startNodeAt(this.state.endLoc);
  12269. this.next();
  12270. const revertScopes = this.initializeScopes(true);
  12271. this.enterInitialScopes();
  12272. try {
  12273. node.body = this.parseProgram(program, 8, "module");
  12274. } finally {
  12275. revertScopes();
  12276. }
  12277. return this.finishNode(node, "ModuleExpression");
  12278. }
  12279. parsePropertyNamePrefixOperator(
  12280. prop) {}
  12281. }
  12282. const loopLabel = {
  12283. kind: "loop"
  12284. },
  12285. switchLabel = {
  12286. kind: "switch"
  12287. };
  12288. const FUNC_NO_FLAGS = 0b000,
  12289. FUNC_STATEMENT = 0b001,
  12290. FUNC_HANGING_STATEMENT = 0b010,
  12291. FUNC_NULLABLE_ID = 0b100;
  12292. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12293. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12294. function babel7CompatTokens(tokens, input) {
  12295. for (let i = 0; i < tokens.length; i++) {
  12296. const token = tokens[i];
  12297. const {
  12298. type
  12299. } = token;
  12300. if (typeof type === "number") {
  12301. {
  12302. if (type === 136) {
  12303. const {
  12304. loc,
  12305. start,
  12306. value,
  12307. end
  12308. } = token;
  12309. const hashEndPos = start + 1;
  12310. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12311. tokens.splice(i, 1, new Token({
  12312. type: getExportedToken(27),
  12313. value: "#",
  12314. start: start,
  12315. end: hashEndPos,
  12316. startLoc: loc.start,
  12317. endLoc: hashEndLoc
  12318. }), new Token({
  12319. type: getExportedToken(130),
  12320. value: value,
  12321. start: hashEndPos,
  12322. end: end,
  12323. startLoc: hashEndLoc,
  12324. endLoc: loc.end
  12325. }));
  12326. i++;
  12327. continue;
  12328. }
  12329. if (tokenIsTemplate(type)) {
  12330. const {
  12331. loc,
  12332. start,
  12333. value,
  12334. end
  12335. } = token;
  12336. const backquoteEnd = start + 1;
  12337. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12338. let startToken;
  12339. if (input.charCodeAt(start) === 96) {
  12340. startToken = new Token({
  12341. type: getExportedToken(22),
  12342. value: "`",
  12343. start: start,
  12344. end: backquoteEnd,
  12345. startLoc: loc.start,
  12346. endLoc: backquoteEndLoc
  12347. });
  12348. } else {
  12349. startToken = new Token({
  12350. type: getExportedToken(8),
  12351. value: "}",
  12352. start: start,
  12353. end: backquoteEnd,
  12354. startLoc: loc.start,
  12355. endLoc: backquoteEndLoc
  12356. });
  12357. }
  12358. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12359. if (type === 24) {
  12360. templateElementEnd = end - 1;
  12361. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12362. templateValue = value === null ? null : value.slice(1, -1);
  12363. endToken = new Token({
  12364. type: getExportedToken(22),
  12365. value: "`",
  12366. start: templateElementEnd,
  12367. end: end,
  12368. startLoc: templateElementEndLoc,
  12369. endLoc: loc.end
  12370. });
  12371. } else {
  12372. templateElementEnd = end - 2;
  12373. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12374. templateValue = value === null ? null : value.slice(1, -2);
  12375. endToken = new Token({
  12376. type: getExportedToken(23),
  12377. value: "${",
  12378. start: templateElementEnd,
  12379. end: end,
  12380. startLoc: templateElementEndLoc,
  12381. endLoc: loc.end
  12382. });
  12383. }
  12384. tokens.splice(i, 1, startToken, new Token({
  12385. type: getExportedToken(20),
  12386. value: templateValue,
  12387. start: backquoteEnd,
  12388. end: templateElementEnd,
  12389. startLoc: backquoteEndLoc,
  12390. endLoc: templateElementEndLoc
  12391. }), endToken);
  12392. i += 2;
  12393. continue;
  12394. }
  12395. }
  12396. token.type = getExportedToken(type);
  12397. }
  12398. }
  12399. return tokens;
  12400. }
  12401. class StatementParser extends ExpressionParser {
  12402. parseTopLevel(file, program) {
  12403. file.program = this.parseProgram(program);
  12404. file.comments = this.state.comments;
  12405. if (this.options.tokens) {
  12406. file.tokens = babel7CompatTokens(this.tokens, this.input);
  12407. }
  12408. return this.finishNode(file, "File");
  12409. }
  12410. parseProgram(program, end = 137, sourceType = this.options.sourceType) {
  12411. program.sourceType = sourceType;
  12412. program.interpreter = this.parseInterpreterDirective();
  12413. this.parseBlockBody(program, true, true, end);
  12414. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  12415. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12416. this.raise(Errors.ModuleExportUndefined, {
  12417. at,
  12418. localName
  12419. });
  12420. }
  12421. }
  12422. let finishedProgram;
  12423. if (end === 137) {
  12424. finishedProgram = this.finishNode(program, "Program");
  12425. } else {
  12426. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12427. }
  12428. return finishedProgram;
  12429. }
  12430. stmtToDirective(stmt) {
  12431. const directive = stmt;
  12432. directive.type = "Directive";
  12433. directive.value = directive.expression;
  12434. delete directive.expression;
  12435. const directiveLiteral = directive.value;
  12436. const expressionValue = directiveLiteral.value;
  12437. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  12438. const val = directiveLiteral.value = raw.slice(1, -1);
  12439. this.addExtra(directiveLiteral, "raw", raw);
  12440. this.addExtra(directiveLiteral, "rawValue", val);
  12441. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12442. directiveLiteral.type = "DirectiveLiteral";
  12443. return directive;
  12444. }
  12445. parseInterpreterDirective() {
  12446. if (!this.match(28)) {
  12447. return null;
  12448. }
  12449. const node = this.startNode();
  12450. node.value = this.state.value;
  12451. this.next();
  12452. return this.finishNode(node, "InterpreterDirective");
  12453. }
  12454. isLet(context) {
  12455. if (!this.isContextual(99)) {
  12456. return false;
  12457. }
  12458. return this.hasFollowingIdentifier(context);
  12459. }
  12460. hasFollowingIdentifier(context) {
  12461. const next = this.nextTokenStart();
  12462. const nextCh = this.codePointAtPos(next);
  12463. if (nextCh === 92 || nextCh === 91) {
  12464. return true;
  12465. }
  12466. if (context) return false;
  12467. if (nextCh === 123) return true;
  12468. if (isIdentifierStart(nextCh)) {
  12469. keywordRelationalOperator.lastIndex = next;
  12470. if (keywordRelationalOperator.test(this.input)) {
  12471. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12472. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12473. return false;
  12474. }
  12475. }
  12476. return true;
  12477. }
  12478. return false;
  12479. }
  12480. startsUsingForOf() {
  12481. const lookahead = this.lookahead();
  12482. if (lookahead.type === 101 && !lookahead.containsEsc) {
  12483. return false;
  12484. } else {
  12485. this.expectPlugin("explicitResourceManagement");
  12486. return true;
  12487. }
  12488. }
  12489. parseStatement(context, topLevel) {
  12490. let decorators = null;
  12491. if (this.match(26)) {
  12492. decorators = this.parseDecorators(true);
  12493. }
  12494. return this.parseStatementContent(context, topLevel, decorators);
  12495. }
  12496. parseStatementContent(context, topLevel, decorators) {
  12497. const starttype = this.state.type;
  12498. const node = this.startNode();
  12499. switch (starttype) {
  12500. case 60:
  12501. return this.parseBreakContinueStatement(node, true);
  12502. case 63:
  12503. return this.parseBreakContinueStatement(node, false);
  12504. case 64:
  12505. return this.parseDebuggerStatement(node);
  12506. case 90:
  12507. return this.parseDoStatement(node);
  12508. case 91:
  12509. return this.parseForStatement(node);
  12510. case 68:
  12511. if (this.lookaheadCharCode() === 46) break;
  12512. if (context) {
  12513. if (this.state.strict) {
  12514. this.raise(Errors.StrictFunction, {
  12515. at: this.state.startLoc
  12516. });
  12517. } else if (context !== "if" && context !== "label") {
  12518. this.raise(Errors.SloppyFunction, {
  12519. at: this.state.startLoc
  12520. });
  12521. }
  12522. }
  12523. return this.parseFunctionStatement(node, false, !context);
  12524. case 80:
  12525. if (context) this.unexpected();
  12526. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12527. case 69:
  12528. return this.parseIfStatement(node);
  12529. case 70:
  12530. return this.parseReturnStatement(node);
  12531. case 71:
  12532. return this.parseSwitchStatement(node);
  12533. case 72:
  12534. return this.parseThrowStatement(node);
  12535. case 73:
  12536. return this.parseTryStatement(node);
  12537. case 105:
  12538. if (this.hasFollowingLineBreak()) {
  12539. break;
  12540. }
  12541. case 99:
  12542. if (this.state.containsEsc || !this.hasFollowingIdentifier(context)) {
  12543. break;
  12544. }
  12545. case 75:
  12546. case 74:
  12547. {
  12548. const kind = this.state.value;
  12549. if (kind === "using") {
  12550. this.expectPlugin("explicitResourceManagement");
  12551. if (!this.scope.inModule && this.scope.inTopLevel) {
  12552. this.raise(Errors.UnexpectedUsingDeclaration, {
  12553. at: this.state.startLoc
  12554. });
  12555. }
  12556. }
  12557. if (context && kind !== "var") {
  12558. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12559. at: this.state.startLoc
  12560. });
  12561. }
  12562. return this.parseVarStatement(node, kind);
  12563. }
  12564. case 92:
  12565. return this.parseWhileStatement(node);
  12566. case 76:
  12567. return this.parseWithStatement(node);
  12568. case 5:
  12569. return this.parseBlock();
  12570. case 13:
  12571. return this.parseEmptyStatement(node);
  12572. case 83:
  12573. {
  12574. const nextTokenCharCode = this.lookaheadCharCode();
  12575. if (nextTokenCharCode === 40 ||
  12576. nextTokenCharCode === 46) {
  12577. break;
  12578. }
  12579. }
  12580. case 82:
  12581. {
  12582. if (!this.options.allowImportExportEverywhere && !topLevel) {
  12583. this.raise(Errors.UnexpectedImportExport, {
  12584. at: this.state.startLoc
  12585. });
  12586. }
  12587. this.next();
  12588. let result;
  12589. if (starttype === 83) {
  12590. result = this.parseImport(node);
  12591. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12592. this.sawUnambiguousESM = true;
  12593. }
  12594. } else {
  12595. result = this.parseExport(node, decorators);
  12596. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12597. this.sawUnambiguousESM = true;
  12598. }
  12599. }
  12600. this.assertModuleNodeAllowed(result);
  12601. return result;
  12602. }
  12603. default:
  12604. {
  12605. if (this.isAsyncFunction()) {
  12606. if (context) {
  12607. this.raise(Errors.AsyncFunctionInSingleStatementContext, {
  12608. at: this.state.startLoc
  12609. });
  12610. }
  12611. this.next();
  12612. return this.parseFunctionStatement(node, true, !context);
  12613. }
  12614. }
  12615. }
  12616. const maybeName = this.state.value;
  12617. const expr = this.parseExpression();
  12618. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  12619. return this.parseLabeledStatement(node, maybeName,
  12620. expr, context);
  12621. } else {
  12622. return this.parseExpressionStatement(node, expr, decorators);
  12623. }
  12624. }
  12625. assertModuleNodeAllowed(node) {
  12626. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  12627. this.raise(Errors.ImportOutsideModule, {
  12628. at: node
  12629. });
  12630. }
  12631. }
  12632. decoratorsEnabledBeforeExport() {
  12633. if (this.hasPlugin("decorators-legacy")) return true;
  12634. return this.hasPlugin("decorators") && !!this.getPluginOption("decorators", "decoratorsBeforeExport");
  12635. }
  12636. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12637. if (maybeDecorators) {
  12638. classNode.decorators = maybeDecorators;
  12639. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12640. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12641. }
  12642. return classNode;
  12643. }
  12644. canHaveLeadingDecorator() {
  12645. return this.match(80);
  12646. }
  12647. parseDecorators(allowExport) {
  12648. const decorators = [];
  12649. do {
  12650. decorators.push(this.parseDecorator());
  12651. } while (this.match(26));
  12652. if (this.match(82)) {
  12653. if (!allowExport) {
  12654. this.unexpected();
  12655. }
  12656. if (!this.decoratorsEnabledBeforeExport()) {
  12657. this.raise(Errors.DecoratorExportClass, {
  12658. at: this.state.startLoc
  12659. });
  12660. }
  12661. } else if (!this.canHaveLeadingDecorator()) {
  12662. throw this.raise(Errors.UnexpectedLeadingDecorator, {
  12663. at: this.state.startLoc
  12664. });
  12665. }
  12666. return decorators;
  12667. }
  12668. parseDecorator() {
  12669. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12670. const node = this.startNode();
  12671. this.next();
  12672. if (this.hasPlugin("decorators")) {
  12673. const startLoc = this.state.startLoc;
  12674. let expr;
  12675. if (this.match(10)) {
  12676. const startLoc = this.state.startLoc;
  12677. this.next();
  12678. expr = this.parseExpression();
  12679. this.expect(11);
  12680. expr = this.wrapParenthesis(startLoc, expr);
  12681. const paramsStartLoc = this.state.startLoc;
  12682. node.expression = this.parseMaybeDecoratorArguments(expr);
  12683. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12684. this.raise(Errors.DecoratorArgumentsOutsideParentheses, {
  12685. at: paramsStartLoc
  12686. });
  12687. }
  12688. } else {
  12689. expr = this.parseIdentifier(false);
  12690. while (this.eat(16)) {
  12691. const node = this.startNodeAt(startLoc);
  12692. node.object = expr;
  12693. if (this.match(136)) {
  12694. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12695. node.property = this.parsePrivateName();
  12696. } else {
  12697. node.property = this.parseIdentifier(true);
  12698. }
  12699. node.computed = false;
  12700. expr = this.finishNode(node, "MemberExpression");
  12701. }
  12702. node.expression = this.parseMaybeDecoratorArguments(expr);
  12703. }
  12704. } else {
  12705. node.expression = this.parseExprSubscripts();
  12706. }
  12707. return this.finishNode(node, "Decorator");
  12708. }
  12709. parseMaybeDecoratorArguments(expr) {
  12710. if (this.eat(10)) {
  12711. const node = this.startNodeAtNode(expr);
  12712. node.callee = expr;
  12713. node.arguments = this.parseCallExpressionArguments(11, false);
  12714. this.toReferencedList(node.arguments);
  12715. return this.finishNode(node, "CallExpression");
  12716. }
  12717. return expr;
  12718. }
  12719. parseBreakContinueStatement(node, isBreak) {
  12720. this.next();
  12721. if (this.isLineTerminator()) {
  12722. node.label = null;
  12723. } else {
  12724. node.label = this.parseIdentifier();
  12725. this.semicolon();
  12726. }
  12727. this.verifyBreakContinue(node, isBreak);
  12728. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12729. }
  12730. verifyBreakContinue(node, isBreak) {
  12731. let i;
  12732. for (i = 0; i < this.state.labels.length; ++i) {
  12733. const lab = this.state.labels[i];
  12734. if (node.label == null || lab.name === node.label.name) {
  12735. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  12736. if (node.label && isBreak) break;
  12737. }
  12738. }
  12739. if (i === this.state.labels.length) {
  12740. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12741. this.raise(Errors.IllegalBreakContinue, {
  12742. at: node,
  12743. type
  12744. });
  12745. }
  12746. }
  12747. parseDebuggerStatement(node) {
  12748. this.next();
  12749. this.semicolon();
  12750. return this.finishNode(node, "DebuggerStatement");
  12751. }
  12752. parseHeaderExpression() {
  12753. this.expect(10);
  12754. const val = this.parseExpression();
  12755. this.expect(11);
  12756. return val;
  12757. }
  12758. parseDoStatement(node) {
  12759. this.next();
  12760. this.state.labels.push(loopLabel);
  12761. node.body =
  12762. this.withSmartMixTopicForbiddingContext(() =>
  12763. this.parseStatement("do"));
  12764. this.state.labels.pop();
  12765. this.expect(92);
  12766. node.test = this.parseHeaderExpression();
  12767. this.eat(13);
  12768. return this.finishNode(node, "DoWhileStatement");
  12769. }
  12770. parseForStatement(node) {
  12771. this.next();
  12772. this.state.labels.push(loopLabel);
  12773. let awaitAt = null;
  12774. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  12775. awaitAt = this.state.lastTokStartLoc;
  12776. }
  12777. this.scope.enter(SCOPE_OTHER);
  12778. this.expect(10);
  12779. if (this.match(13)) {
  12780. if (awaitAt !== null) {
  12781. this.unexpected(awaitAt);
  12782. }
  12783. return this.parseFor(node, null);
  12784. }
  12785. const startsWithLet = this.isContextual(99);
  12786. const startsWithUsing = this.isContextual(105) && !this.hasFollowingLineBreak();
  12787. const isLetOrUsing = startsWithLet && this.hasFollowingIdentifier() || startsWithUsing && this.hasFollowingIdentifier() && this.startsUsingForOf();
  12788. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12789. const initNode = this.startNode();
  12790. const kind = this.state.value;
  12791. this.next();
  12792. this.parseVar(initNode, true, kind);
  12793. const init = this.finishNode(initNode, "VariableDeclaration");
  12794. const isForIn = this.match(58);
  12795. if (isForIn && startsWithUsing) {
  12796. this.raise(Errors.ForInUsing, {
  12797. at: init
  12798. });
  12799. }
  12800. if ((isForIn || this.isContextual(101)) && init.declarations.length === 1) {
  12801. return this.parseForIn(node, init, awaitAt);
  12802. }
  12803. if (awaitAt !== null) {
  12804. this.unexpected(awaitAt);
  12805. }
  12806. return this.parseFor(node, init);
  12807. }
  12808. const startsWithAsync = this.isContextual(95);
  12809. const refExpressionErrors = new ExpressionErrors();
  12810. const init = this.parseExpression(true, refExpressionErrors);
  12811. const isForOf = this.isContextual(101);
  12812. if (isForOf) {
  12813. if (startsWithLet) {
  12814. this.raise(Errors.ForOfLet, {
  12815. at: init
  12816. });
  12817. }
  12818. if (
  12819. awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12820. this.raise(Errors.ForOfAsync, {
  12821. at: init
  12822. });
  12823. }
  12824. }
  12825. if (isForOf || this.match(58)) {
  12826. this.checkDestructuringPrivate(refExpressionErrors);
  12827. this.toAssignable(init, true);
  12828. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12829. this.checkLVal(init, {
  12830. in: {
  12831. type
  12832. }
  12833. });
  12834. return this.parseForIn(node,
  12835. init, awaitAt);
  12836. } else {
  12837. this.checkExpressionErrors(refExpressionErrors, true);
  12838. }
  12839. if (awaitAt !== null) {
  12840. this.unexpected(awaitAt);
  12841. }
  12842. return this.parseFor(node, init);
  12843. }
  12844. parseFunctionStatement(node, isAsync, declarationPosition) {
  12845. this.next();
  12846. return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), isAsync);
  12847. }
  12848. parseIfStatement(node) {
  12849. this.next();
  12850. node.test = this.parseHeaderExpression();
  12851. node.consequent = this.parseStatement("if");
  12852. node.alternate = this.eat(66) ? this.parseStatement("if") : null;
  12853. return this.finishNode(node, "IfStatement");
  12854. }
  12855. parseReturnStatement(node) {
  12856. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  12857. this.raise(Errors.IllegalReturn, {
  12858. at: this.state.startLoc
  12859. });
  12860. }
  12861. this.next();
  12862. if (this.isLineTerminator()) {
  12863. node.argument = null;
  12864. } else {
  12865. node.argument = this.parseExpression();
  12866. this.semicolon();
  12867. }
  12868. return this.finishNode(node, "ReturnStatement");
  12869. }
  12870. parseSwitchStatement(node) {
  12871. this.next();
  12872. node.discriminant = this.parseHeaderExpression();
  12873. const cases = node.cases = [];
  12874. this.expect(5);
  12875. this.state.labels.push(switchLabel);
  12876. this.scope.enter(SCOPE_OTHER);
  12877. let cur;
  12878. for (let sawDefault; !this.match(8);) {
  12879. if (this.match(61) || this.match(65)) {
  12880. const isCase = this.match(61);
  12881. if (cur) this.finishNode(cur, "SwitchCase");
  12882. cases.push(cur = this.startNode());
  12883. cur.consequent = [];
  12884. this.next();
  12885. if (isCase) {
  12886. cur.test = this.parseExpression();
  12887. } else {
  12888. if (sawDefault) {
  12889. this.raise(Errors.MultipleDefaultsInSwitch, {
  12890. at: this.state.lastTokStartLoc
  12891. });
  12892. }
  12893. sawDefault = true;
  12894. cur.test = null;
  12895. }
  12896. this.expect(14);
  12897. } else {
  12898. if (cur) {
  12899. cur.consequent.push(this.parseStatement(null));
  12900. } else {
  12901. this.unexpected();
  12902. }
  12903. }
  12904. }
  12905. this.scope.exit();
  12906. if (cur) this.finishNode(cur, "SwitchCase");
  12907. this.next();
  12908. this.state.labels.pop();
  12909. return this.finishNode(node, "SwitchStatement");
  12910. }
  12911. parseThrowStatement(node) {
  12912. this.next();
  12913. if (this.hasPrecedingLineBreak()) {
  12914. this.raise(Errors.NewlineAfterThrow, {
  12915. at: this.state.lastTokEndLoc
  12916. });
  12917. }
  12918. node.argument = this.parseExpression();
  12919. this.semicolon();
  12920. return this.finishNode(node, "ThrowStatement");
  12921. }
  12922. parseCatchClauseParam() {
  12923. const param = this.parseBindingAtom();
  12924. const simple = param.type === "Identifier";
  12925. this.scope.enter(simple ? SCOPE_SIMPLE_CATCH : 0);
  12926. this.checkLVal(param, {
  12927. in: {
  12928. type: "CatchClause"
  12929. },
  12930. binding: BIND_LEXICAL,
  12931. allowingSloppyLetBinding: true
  12932. });
  12933. return param;
  12934. }
  12935. parseTryStatement(node) {
  12936. this.next();
  12937. node.block = this.parseBlock();
  12938. node.handler = null;
  12939. if (this.match(62)) {
  12940. const clause = this.startNode();
  12941. this.next();
  12942. if (this.match(10)) {
  12943. this.expect(10);
  12944. clause.param = this.parseCatchClauseParam();
  12945. this.expect(11);
  12946. } else {
  12947. clause.param = null;
  12948. this.scope.enter(SCOPE_OTHER);
  12949. }
  12950. clause.body =
  12951. this.withSmartMixTopicForbiddingContext(() =>
  12952. this.parseBlock(false, false));
  12953. this.scope.exit();
  12954. node.handler = this.finishNode(clause, "CatchClause");
  12955. }
  12956. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  12957. if (!node.handler && !node.finalizer) {
  12958. this.raise(Errors.NoCatchOrFinally, {
  12959. at: node
  12960. });
  12961. }
  12962. return this.finishNode(node, "TryStatement");
  12963. }
  12964. parseVarStatement(node, kind, allowMissingInitializer = false) {
  12965. this.next();
  12966. this.parseVar(node, false, kind, allowMissingInitializer);
  12967. this.semicolon();
  12968. return this.finishNode(node, "VariableDeclaration");
  12969. }
  12970. parseWhileStatement(node) {
  12971. this.next();
  12972. node.test = this.parseHeaderExpression();
  12973. this.state.labels.push(loopLabel);
  12974. node.body =
  12975. this.withSmartMixTopicForbiddingContext(() =>
  12976. this.parseStatement("while"));
  12977. this.state.labels.pop();
  12978. return this.finishNode(node, "WhileStatement");
  12979. }
  12980. parseWithStatement(node) {
  12981. if (this.state.strict) {
  12982. this.raise(Errors.StrictWith, {
  12983. at: this.state.startLoc
  12984. });
  12985. }
  12986. this.next();
  12987. node.object = this.parseHeaderExpression();
  12988. node.body =
  12989. this.withSmartMixTopicForbiddingContext(() =>
  12990. this.parseStatement("with"));
  12991. return this.finishNode(node, "WithStatement");
  12992. }
  12993. parseEmptyStatement(node) {
  12994. this.next();
  12995. return this.finishNode(node, "EmptyStatement");
  12996. }
  12997. parseLabeledStatement(node, maybeName, expr, context) {
  12998. for (const label of this.state.labels) {
  12999. if (label.name === maybeName) {
  13000. this.raise(Errors.LabelRedeclaration, {
  13001. at: expr,
  13002. labelName: maybeName
  13003. });
  13004. }
  13005. }
  13006. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
  13007. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13008. const label = this.state.labels[i];
  13009. if (label.statementStart === node.start) {
  13010. label.statementStart = this.state.start;
  13011. label.kind = kind;
  13012. } else {
  13013. break;
  13014. }
  13015. }
  13016. this.state.labels.push({
  13017. name: maybeName,
  13018. kind: kind,
  13019. statementStart: this.state.start
  13020. });
  13021. node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
  13022. this.state.labels.pop();
  13023. node.label = expr;
  13024. return this.finishNode(node, "LabeledStatement");
  13025. }
  13026. parseExpressionStatement(node, expr,
  13027. decorators) {
  13028. node.expression = expr;
  13029. this.semicolon();
  13030. return this.finishNode(node, "ExpressionStatement");
  13031. }
  13032. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13033. const node = this.startNode();
  13034. if (allowDirectives) {
  13035. this.state.strictErrors.clear();
  13036. }
  13037. this.expect(5);
  13038. if (createNewLexicalScope) {
  13039. this.scope.enter(SCOPE_OTHER);
  13040. }
  13041. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13042. if (createNewLexicalScope) {
  13043. this.scope.exit();
  13044. }
  13045. return this.finishNode(node, "BlockStatement");
  13046. }
  13047. isValidDirective(stmt) {
  13048. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13049. }
  13050. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13051. const body = node.body = [];
  13052. const directives = node.directives = [];
  13053. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13054. }
  13055. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13056. const oldStrict = this.state.strict;
  13057. let hasStrictModeDirective = false;
  13058. let parsedNonDirective = false;
  13059. while (!this.match(end)) {
  13060. const stmt = this.parseStatement(null, topLevel);
  13061. if (directives && !parsedNonDirective) {
  13062. if (this.isValidDirective(stmt)) {
  13063. const directive = this.stmtToDirective(stmt);
  13064. directives.push(directive);
  13065. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13066. hasStrictModeDirective = true;
  13067. this.setStrict(true);
  13068. }
  13069. continue;
  13070. }
  13071. parsedNonDirective = true;
  13072. this.state.strictErrors.clear();
  13073. }
  13074. body.push(stmt);
  13075. }
  13076. if (afterBlockParse) {
  13077. afterBlockParse.call(this, hasStrictModeDirective);
  13078. }
  13079. if (!oldStrict) {
  13080. this.setStrict(false);
  13081. }
  13082. this.next();
  13083. }
  13084. parseFor(node, init) {
  13085. node.init = init;
  13086. this.semicolon(false);
  13087. node.test = this.match(13) ? null : this.parseExpression();
  13088. this.semicolon(false);
  13089. node.update = this.match(11) ? null : this.parseExpression();
  13090. this.expect(11);
  13091. node.body =
  13092. this.withSmartMixTopicForbiddingContext(() =>
  13093. this.parseStatement("for"));
  13094. this.scope.exit();
  13095. this.state.labels.pop();
  13096. return this.finishNode(node, "ForStatement");
  13097. }
  13098. parseForIn(node, init, awaitAt) {
  13099. const isForIn = this.match(58);
  13100. this.next();
  13101. if (isForIn) {
  13102. if (awaitAt !== null) this.unexpected(awaitAt);
  13103. } else {
  13104. node.await = awaitAt !== null;
  13105. }
  13106. if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) {
  13107. this.raise(Errors.ForInOfLoopInitializer, {
  13108. at: init,
  13109. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13110. });
  13111. }
  13112. if (init.type === "AssignmentPattern") {
  13113. this.raise(Errors.InvalidLhs, {
  13114. at: init,
  13115. ancestor: {
  13116. type: "ForStatement"
  13117. }
  13118. });
  13119. }
  13120. node.left = init;
  13121. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13122. this.expect(11);
  13123. node.body =
  13124. this.withSmartMixTopicForbiddingContext(() =>
  13125. this.parseStatement("for"));
  13126. this.scope.exit();
  13127. this.state.labels.pop();
  13128. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13129. }
  13130. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13131. const declarations = node.declarations = [];
  13132. node.kind = kind;
  13133. for (;;) {
  13134. const decl = this.startNode();
  13135. this.parseVarId(decl, kind);
  13136. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13137. if (decl.init === null && !allowMissingInitializer) {
  13138. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(101)))) {
  13139. this.raise(Errors.DeclarationMissingInitializer, {
  13140. at: this.state.lastTokEndLoc,
  13141. kind: "destructuring"
  13142. });
  13143. } else if (kind === "const" && !(this.match(58) || this.isContextual(101))) {
  13144. this.raise(Errors.DeclarationMissingInitializer, {
  13145. at: this.state.lastTokEndLoc,
  13146. kind: "const"
  13147. });
  13148. }
  13149. }
  13150. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13151. if (!this.eat(12)) break;
  13152. }
  13153. return node;
  13154. }
  13155. parseVarId(decl, kind) {
  13156. const id = this.parseBindingAtom();
  13157. if (kind === "using" && id.type !== "Identifier") {
  13158. this.raise(Errors.UsingDeclarationHasBindingPattern, {
  13159. at: id
  13160. });
  13161. }
  13162. this.checkLVal(id, {
  13163. in: {
  13164. type: "VariableDeclarator"
  13165. },
  13166. binding: kind === "var" ? BIND_VAR : BIND_LEXICAL
  13167. });
  13168. decl.id = id;
  13169. }
  13170. parseFunction(node, statement = FUNC_NO_FLAGS, isAsync = false) {
  13171. const isStatement = statement & FUNC_STATEMENT;
  13172. const isHangingStatement = statement & FUNC_HANGING_STATEMENT;
  13173. const requireId = !!isStatement && !(statement & FUNC_NULLABLE_ID);
  13174. this.initFunction(node, isAsync);
  13175. if (this.match(55) && isHangingStatement) {
  13176. this.raise(Errors.GeneratorInSingleStatementContext, {
  13177. at: this.state.startLoc
  13178. });
  13179. }
  13180. node.generator = this.eat(55);
  13181. if (isStatement) {
  13182. node.id = this.parseFunctionId(requireId);
  13183. }
  13184. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13185. this.state.maybeInArrowParameters = false;
  13186. this.scope.enter(SCOPE_FUNCTION);
  13187. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13188. if (!isStatement) {
  13189. node.id = this.parseFunctionId();
  13190. }
  13191. this.parseFunctionParams(node, false);
  13192. this.withSmartMixTopicForbiddingContext(() => {
  13193. this.parseFunctionBodyAndFinish(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
  13194. });
  13195. this.prodParam.exit();
  13196. this.scope.exit();
  13197. if (isStatement && !isHangingStatement) {
  13198. this.registerFunctionStatementId(node);
  13199. }
  13200. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13201. return node;
  13202. }
  13203. parseFunctionId(requireId) {
  13204. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13205. }
  13206. parseFunctionParams(node, allowModifiers) {
  13207. this.expect(10);
  13208. this.expressionScope.enter(newParameterDeclarationScope());
  13209. node.params = this.parseBindingList(11, 41, false, allowModifiers);
  13210. this.expressionScope.exit();
  13211. }
  13212. registerFunctionStatementId(node) {
  13213. if (!node.id) return;
  13214. this.scope.declareName(node.id.name, this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION, node.id.loc.start);
  13215. }
  13216. parseClass(node, isStatement, optionalId) {
  13217. this.next();
  13218. const oldStrict = this.state.strict;
  13219. this.state.strict = true;
  13220. this.parseClassId(node, isStatement, optionalId);
  13221. this.parseClassSuper(node);
  13222. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13223. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13224. }
  13225. isClassProperty() {
  13226. return this.match(29) || this.match(13) || this.match(8);
  13227. }
  13228. isClassMethod() {
  13229. return this.match(10);
  13230. }
  13231. isNonstaticConstructor(method) {
  13232. return !method.computed && !method.static && (method.key.name === "constructor" ||
  13233. method.key.value === "constructor");
  13234. }
  13235. parseClassBody(hadSuperClass, oldStrict) {
  13236. this.classScope.enter();
  13237. const state = {
  13238. hadConstructor: false,
  13239. hadSuperClass
  13240. };
  13241. let decorators = [];
  13242. const classBody = this.startNode();
  13243. classBody.body = [];
  13244. this.expect(5);
  13245. this.withSmartMixTopicForbiddingContext(() => {
  13246. while (!this.match(8)) {
  13247. if (this.eat(13)) {
  13248. if (decorators.length > 0) {
  13249. throw this.raise(Errors.DecoratorSemicolon, {
  13250. at: this.state.lastTokEndLoc
  13251. });
  13252. }
  13253. continue;
  13254. }
  13255. if (this.match(26)) {
  13256. decorators.push(this.parseDecorator());
  13257. continue;
  13258. }
  13259. const member = this.startNode();
  13260. if (decorators.length) {
  13261. member.decorators = decorators;
  13262. this.resetStartLocationFromNode(member, decorators[0]);
  13263. decorators = [];
  13264. }
  13265. this.parseClassMember(classBody, member, state);
  13266. if (
  13267. member.kind === "constructor" &&
  13268. member.decorators &&
  13269. member.decorators.length > 0) {
  13270. this.raise(Errors.DecoratorConstructor, {
  13271. at: member
  13272. });
  13273. }
  13274. }
  13275. });
  13276. this.state.strict = oldStrict;
  13277. this.next();
  13278. if (decorators.length) {
  13279. throw this.raise(Errors.TrailingDecorator, {
  13280. at: this.state.startLoc
  13281. });
  13282. }
  13283. this.classScope.exit();
  13284. return this.finishNode(classBody, "ClassBody");
  13285. }
  13286. parseClassMemberFromModifier(classBody, member) {
  13287. const key = this.parseIdentifier(true);
  13288. if (this.isClassMethod()) {
  13289. const method = member;
  13290. method.kind = "method";
  13291. method.computed = false;
  13292. method.key = key;
  13293. method.static = false;
  13294. this.pushClassMethod(classBody, method, false, false, false, false);
  13295. return true;
  13296. } else if (this.isClassProperty()) {
  13297. const prop = member;
  13298. prop.computed = false;
  13299. prop.key = key;
  13300. prop.static = false;
  13301. classBody.body.push(this.parseClassProperty(prop));
  13302. return true;
  13303. }
  13304. this.resetPreviousNodeTrailingComments(key);
  13305. return false;
  13306. }
  13307. parseClassMember(classBody, member, state) {
  13308. const isStatic = this.isContextual(104);
  13309. if (isStatic) {
  13310. if (this.parseClassMemberFromModifier(classBody, member)) {
  13311. return;
  13312. }
  13313. if (this.eat(5)) {
  13314. this.parseClassStaticBlock(classBody, member);
  13315. return;
  13316. }
  13317. }
  13318. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13319. }
  13320. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13321. const publicMethod = member;
  13322. const privateMethod = member;
  13323. const publicProp = member;
  13324. const privateProp = member;
  13325. const accessorProp = member;
  13326. const method = publicMethod;
  13327. const publicMember = publicMethod;
  13328. member.static = isStatic;
  13329. this.parsePropertyNamePrefixOperator(member);
  13330. if (this.eat(55)) {
  13331. method.kind = "method";
  13332. const isPrivateName = this.match(136);
  13333. this.parseClassElementName(method);
  13334. if (isPrivateName) {
  13335. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13336. return;
  13337. }
  13338. if (this.isNonstaticConstructor(publicMethod)) {
  13339. this.raise(Errors.ConstructorIsGenerator, {
  13340. at: publicMethod.key
  13341. });
  13342. }
  13343. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13344. return;
  13345. }
  13346. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  13347. const isPrivate = this.match(136);
  13348. const key = this.parseClassElementName(member);
  13349. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13350. this.parsePostMemberNameModifiers(publicMember);
  13351. if (this.isClassMethod()) {
  13352. method.kind = "method";
  13353. if (isPrivate) {
  13354. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13355. return;
  13356. }
  13357. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13358. let allowsDirectSuper = false;
  13359. if (isConstructor) {
  13360. publicMethod.kind = "constructor";
  13361. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13362. this.raise(Errors.DuplicateConstructor, {
  13363. at: key
  13364. });
  13365. }
  13366. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13367. this.raise(Errors.OverrideOnConstructor, {
  13368. at: key
  13369. });
  13370. }
  13371. state.hadConstructor = true;
  13372. allowsDirectSuper = state.hadSuperClass;
  13373. }
  13374. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13375. } else if (this.isClassProperty()) {
  13376. if (isPrivate) {
  13377. this.pushClassPrivateProperty(classBody, privateProp);
  13378. } else {
  13379. this.pushClassProperty(classBody, publicProp);
  13380. }
  13381. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  13382. this.resetPreviousNodeTrailingComments(key);
  13383. const isGenerator = this.eat(55);
  13384. if (publicMember.optional) {
  13385. this.unexpected(maybeQuestionTokenStartLoc);
  13386. }
  13387. method.kind = "method";
  13388. const isPrivate = this.match(136);
  13389. this.parseClassElementName(method);
  13390. this.parsePostMemberNameModifiers(publicMember);
  13391. if (isPrivate) {
  13392. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13393. } else {
  13394. if (this.isNonstaticConstructor(publicMethod)) {
  13395. this.raise(Errors.ConstructorIsAsync, {
  13396. at: publicMethod.key
  13397. });
  13398. }
  13399. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13400. }
  13401. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
  13402. this.resetPreviousNodeTrailingComments(key);
  13403. method.kind = key.name;
  13404. const isPrivate = this.match(136);
  13405. this.parseClassElementName(publicMethod);
  13406. if (isPrivate) {
  13407. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13408. } else {
  13409. if (this.isNonstaticConstructor(publicMethod)) {
  13410. this.raise(Errors.ConstructorIsAccessor, {
  13411. at: publicMethod.key
  13412. });
  13413. }
  13414. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13415. }
  13416. this.checkGetterSetterParams(publicMethod);
  13417. } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
  13418. this.expectPlugin("decoratorAutoAccessors");
  13419. this.resetPreviousNodeTrailingComments(key);
  13420. const isPrivate = this.match(136);
  13421. this.parseClassElementName(publicProp);
  13422. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13423. } else if (this.isLineTerminator()) {
  13424. if (isPrivate) {
  13425. this.pushClassPrivateProperty(classBody, privateProp);
  13426. } else {
  13427. this.pushClassProperty(classBody, publicProp);
  13428. }
  13429. } else {
  13430. this.unexpected();
  13431. }
  13432. }
  13433. parseClassElementName(member) {
  13434. const {
  13435. type,
  13436. value
  13437. } = this.state;
  13438. if ((type === 130 || type === 131) && member.static && value === "prototype") {
  13439. this.raise(Errors.StaticPrototype, {
  13440. at: this.state.startLoc
  13441. });
  13442. }
  13443. if (type === 136) {
  13444. if (value === "constructor") {
  13445. this.raise(Errors.ConstructorClassPrivateField, {
  13446. at: this.state.startLoc
  13447. });
  13448. }
  13449. const key = this.parsePrivateName();
  13450. member.key = key;
  13451. return key;
  13452. }
  13453. return this.parsePropertyName(member);
  13454. }
  13455. parseClassStaticBlock(classBody, member) {
  13456. var _member$decorators;
  13457. this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER);
  13458. const oldLabels = this.state.labels;
  13459. this.state.labels = [];
  13460. this.prodParam.enter(PARAM);
  13461. const body = member.body = [];
  13462. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13463. this.prodParam.exit();
  13464. this.scope.exit();
  13465. this.state.labels = oldLabels;
  13466. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13467. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13468. this.raise(Errors.DecoratorStaticBlock, {
  13469. at: member
  13470. });
  13471. }
  13472. }
  13473. pushClassProperty(classBody, prop) {
  13474. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  13475. this.raise(Errors.ConstructorClassField, {
  13476. at: prop.key
  13477. });
  13478. }
  13479. classBody.body.push(this.parseClassProperty(prop));
  13480. }
  13481. pushClassPrivateProperty(classBody, prop) {
  13482. const node = this.parseClassPrivateProperty(prop);
  13483. classBody.body.push(node);
  13484. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  13485. }
  13486. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13487. if (!isPrivate && !prop.computed) {
  13488. const key = prop.key;
  13489. if (key.name === "constructor" || key.value === "constructor") {
  13490. this.raise(Errors.ConstructorClassField, {
  13491. at: key
  13492. });
  13493. }
  13494. }
  13495. const node = this.parseClassAccessorProperty(prop);
  13496. classBody.body.push(node);
  13497. if (isPrivate) {
  13498. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  13499. }
  13500. }
  13501. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13502. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13503. }
  13504. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13505. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13506. classBody.body.push(node);
  13507. const kind = node.kind === "get" ? node.static ? CLASS_ELEMENT_STATIC_GETTER : CLASS_ELEMENT_INSTANCE_GETTER : node.kind === "set" ? node.static ? CLASS_ELEMENT_STATIC_SETTER : CLASS_ELEMENT_INSTANCE_SETTER : CLASS_ELEMENT_OTHER;
  13508. this.declareClassPrivateMethodInScope(node, kind);
  13509. }
  13510. declareClassPrivateMethodInScope(node, kind) {
  13511. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13512. }
  13513. parsePostMemberNameModifiers(
  13514. methodOrProp) {}
  13515. parseClassPrivateProperty(node) {
  13516. this.parseInitializer(node);
  13517. this.semicolon();
  13518. return this.finishNode(node, "ClassPrivateProperty");
  13519. }
  13520. parseClassProperty(node) {
  13521. this.parseInitializer(node);
  13522. this.semicolon();
  13523. return this.finishNode(node, "ClassProperty");
  13524. }
  13525. parseClassAccessorProperty(node) {
  13526. this.parseInitializer(node);
  13527. this.semicolon();
  13528. return this.finishNode(node, "ClassAccessorProperty");
  13529. }
  13530. parseInitializer(node) {
  13531. this.scope.enter(SCOPE_CLASS | SCOPE_SUPER);
  13532. this.expressionScope.enter(newExpressionScope());
  13533. this.prodParam.enter(PARAM);
  13534. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13535. this.expressionScope.exit();
  13536. this.prodParam.exit();
  13537. this.scope.exit();
  13538. }
  13539. parseClassId(node, isStatement, optionalId, bindingType = BIND_CLASS) {
  13540. if (tokenIsIdentifier(this.state.type)) {
  13541. node.id = this.parseIdentifier();
  13542. if (isStatement) {
  13543. this.declareNameFromIdentifier(node.id, bindingType);
  13544. }
  13545. } else {
  13546. if (optionalId || !isStatement) {
  13547. node.id = null;
  13548. } else {
  13549. throw this.raise(Errors.MissingClassName, {
  13550. at: this.state.startLoc
  13551. });
  13552. }
  13553. }
  13554. }
  13555. parseClassSuper(node) {
  13556. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13557. }
  13558. parseExport(node, decorators) {
  13559. const hasDefault = this.maybeParseExportDefaultSpecifier(
  13560. node);
  13561. const parseAfterDefault = !hasDefault || this.eat(12);
  13562. const hasStar = parseAfterDefault && this.eatExportStar(
  13563. node);
  13564. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(
  13565. node);
  13566. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13567. const isFromRequired = hasDefault || hasStar;
  13568. if (hasStar && !hasNamespace) {
  13569. if (hasDefault) this.unexpected();
  13570. if (decorators) {
  13571. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13572. at: node
  13573. });
  13574. }
  13575. this.parseExportFrom(node, true);
  13576. return this.finishNode(node, "ExportAllDeclaration");
  13577. }
  13578. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(
  13579. node);
  13580. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers || hasNamespace && parseAfterNamespace && !hasSpecifiers) {
  13581. throw this.unexpected(null, 5);
  13582. }
  13583. let hasDeclaration;
  13584. if (isFromRequired || hasSpecifiers) {
  13585. hasDeclaration = false;
  13586. if (decorators) {
  13587. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13588. at: node
  13589. });
  13590. }
  13591. this.parseExportFrom(node, isFromRequired);
  13592. } else {
  13593. hasDeclaration = this.maybeParseExportDeclaration(node);
  13594. }
  13595. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13596. var _node2$declaration;
  13597. const node2 = node;
  13598. this.checkExport(node2, true, false, !!node2.source);
  13599. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13600. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13601. } else if (decorators) {
  13602. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13603. at: node
  13604. });
  13605. }
  13606. return this.finishNode(node2, "ExportNamedDeclaration");
  13607. }
  13608. if (this.eat(65)) {
  13609. const node2 = node;
  13610. const decl = this.parseExportDefaultExpression();
  13611. node2.declaration = decl;
  13612. if (decl.type === "ClassDeclaration") {
  13613. this.maybeTakeDecorators(decorators, decl, node2);
  13614. } else if (decorators) {
  13615. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13616. at: node
  13617. });
  13618. }
  13619. this.checkExport(node2, true, true);
  13620. return this.finishNode(node2, "ExportDefaultDeclaration");
  13621. }
  13622. throw this.unexpected(null, 5);
  13623. }
  13624. eatExportStar(node) {
  13625. return this.eat(55);
  13626. }
  13627. maybeParseExportDefaultSpecifier(node) {
  13628. if (this.isExportDefaultSpecifier()) {
  13629. this.expectPlugin("exportDefaultFrom");
  13630. const specifier = this.startNode();
  13631. specifier.exported = this.parseIdentifier(true);
  13632. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13633. return true;
  13634. }
  13635. return false;
  13636. }
  13637. maybeParseExportNamespaceSpecifier(node) {
  13638. if (this.isContextual(93)) {
  13639. if (!node.specifiers) node.specifiers = [];
  13640. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13641. this.next();
  13642. specifier.exported = this.parseModuleExportName();
  13643. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13644. return true;
  13645. }
  13646. return false;
  13647. }
  13648. maybeParseExportNamedSpecifiers(node) {
  13649. if (this.match(5)) {
  13650. if (!node.specifiers) node.specifiers = [];
  13651. const isTypeExport = node.exportKind === "type";
  13652. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13653. node.source = null;
  13654. node.declaration = null;
  13655. if (this.hasPlugin("importAssertions")) {
  13656. node.assertions = [];
  13657. }
  13658. return true;
  13659. }
  13660. return false;
  13661. }
  13662. maybeParseExportDeclaration(node) {
  13663. if (this.shouldParseExportDeclaration()) {
  13664. node.specifiers = [];
  13665. node.source = null;
  13666. if (this.hasPlugin("importAssertions")) {
  13667. node.assertions = [];
  13668. }
  13669. node.declaration = this.parseExportDeclaration(node);
  13670. return true;
  13671. }
  13672. return false;
  13673. }
  13674. isAsyncFunction() {
  13675. if (!this.isContextual(95)) return false;
  13676. const next = this.nextTokenStart();
  13677. return !lineBreak.test(this.input.slice(this.state.pos, next)) && this.isUnparsedContextual(next, "function");
  13678. }
  13679. parseExportDefaultExpression() {
  13680. const expr = this.startNode();
  13681. const isAsync = this.isAsyncFunction();
  13682. if (this.match(68) || isAsync) {
  13683. this.next();
  13684. if (isAsync) {
  13685. this.next();
  13686. }
  13687. return this.parseFunction(expr, FUNC_STATEMENT | FUNC_NULLABLE_ID, isAsync);
  13688. }
  13689. if (this.match(80)) {
  13690. return this.parseClass(expr, true, true);
  13691. }
  13692. if (this.match(26)) {
  13693. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport")) {
  13694. this.raise(Errors.DecoratorBeforeExport, {
  13695. at: this.state.startLoc
  13696. });
  13697. }
  13698. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13699. }
  13700. if (this.match(75) || this.match(74) || this.isLet()) {
  13701. throw this.raise(Errors.UnsupportedDefaultExport, {
  13702. at: this.state.startLoc
  13703. });
  13704. }
  13705. const res = this.parseMaybeAssignAllowIn();
  13706. this.semicolon();
  13707. return res;
  13708. }
  13709. parseExportDeclaration(
  13710. node) {
  13711. if (this.match(80)) {
  13712. const node = this.parseClass(this.startNode(), true, false);
  13713. return node;
  13714. }
  13715. return this.parseStatement(null);
  13716. }
  13717. isExportDefaultSpecifier() {
  13718. const {
  13719. type
  13720. } = this.state;
  13721. if (tokenIsIdentifier(type)) {
  13722. if (type === 95 && !this.state.containsEsc || type === 99) {
  13723. return false;
  13724. }
  13725. if ((type === 128 || type === 127) && !this.state.containsEsc) {
  13726. const {
  13727. type: nextType
  13728. } = this.lookahead();
  13729. if (tokenIsIdentifier(nextType) && nextType !== 97 || nextType === 5) {
  13730. this.expectOnePlugin(["flow", "typescript"]);
  13731. return false;
  13732. }
  13733. }
  13734. } else if (!this.match(65)) {
  13735. return false;
  13736. }
  13737. const next = this.nextTokenStart();
  13738. const hasFrom = this.isUnparsedContextual(next, "from");
  13739. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13740. return true;
  13741. }
  13742. if (this.match(65) && hasFrom) {
  13743. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13744. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13745. }
  13746. return false;
  13747. }
  13748. parseExportFrom(node, expect) {
  13749. if (this.eatContextual(97)) {
  13750. node.source = this.parseImportSource();
  13751. this.checkExport(node);
  13752. const assertions = this.maybeParseImportAssertions();
  13753. if (assertions) {
  13754. node.assertions = assertions;
  13755. this.checkJSONModuleImport(node);
  13756. }
  13757. } else if (expect) {
  13758. this.unexpected();
  13759. }
  13760. this.semicolon();
  13761. }
  13762. shouldParseExportDeclaration() {
  13763. const {
  13764. type
  13765. } = this.state;
  13766. if (type === 26) {
  13767. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13768. if (this.hasPlugin("decorators")) {
  13769. if (this.getPluginOption("decorators", "decoratorsBeforeExport")) {
  13770. throw this.raise(Errors.DecoratorBeforeExport, {
  13771. at: this.state.startLoc
  13772. });
  13773. }
  13774. return true;
  13775. }
  13776. }
  13777. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13778. }
  13779. checkExport(node, checkNames, isDefault, isFrom) {
  13780. if (checkNames) {
  13781. if (isDefault) {
  13782. this.checkDuplicateExports(node, "default");
  13783. if (this.hasPlugin("exportDefaultFrom")) {
  13784. var _declaration$extra;
  13785. const declaration = node.declaration;
  13786. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 &&
  13787. !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13788. this.raise(Errors.ExportDefaultFromAsIdentifier, {
  13789. at: declaration
  13790. });
  13791. }
  13792. }
  13793. } else if (node.specifiers && node.specifiers.length) {
  13794. for (const specifier of node.specifiers) {
  13795. const {
  13796. exported
  13797. } = specifier;
  13798. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13799. this.checkDuplicateExports(specifier, exportName);
  13800. if (!isFrom && specifier.local) {
  13801. const {
  13802. local
  13803. } = specifier;
  13804. if (local.type !== "Identifier") {
  13805. this.raise(Errors.ExportBindingIsString, {
  13806. at: specifier,
  13807. localName: local.value,
  13808. exportName
  13809. });
  13810. } else {
  13811. this.checkReservedWord(local.name, local.loc.start, true, false);
  13812. this.scope.checkLocalExport(local);
  13813. }
  13814. }
  13815. }
  13816. } else if (node.declaration) {
  13817. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  13818. const id = node.declaration.id;
  13819. if (!id) throw new Error("Assertion failure");
  13820. this.checkDuplicateExports(node, id.name);
  13821. } else if (node.declaration.type === "VariableDeclaration") {
  13822. for (const declaration of node.declaration.declarations) {
  13823. this.checkDeclaration(declaration.id);
  13824. }
  13825. }
  13826. }
  13827. }
  13828. }
  13829. checkDeclaration(node) {
  13830. if (node.type === "Identifier") {
  13831. this.checkDuplicateExports(node, node.name);
  13832. } else if (node.type === "ObjectPattern") {
  13833. for (const prop of node.properties) {
  13834. this.checkDeclaration(prop);
  13835. }
  13836. } else if (node.type === "ArrayPattern") {
  13837. for (const elem of node.elements) {
  13838. if (elem) {
  13839. this.checkDeclaration(elem);
  13840. }
  13841. }
  13842. } else if (node.type === "ObjectProperty") {
  13843. this.checkDeclaration(node.value);
  13844. } else if (node.type === "RestElement") {
  13845. this.checkDeclaration(node.argument);
  13846. } else if (node.type === "AssignmentPattern") {
  13847. this.checkDeclaration(node.left);
  13848. }
  13849. }
  13850. checkDuplicateExports(node, exportName) {
  13851. if (this.exportedIdentifiers.has(exportName)) {
  13852. if (exportName === "default") {
  13853. this.raise(Errors.DuplicateDefaultExport, {
  13854. at: node
  13855. });
  13856. } else {
  13857. this.raise(Errors.DuplicateExport, {
  13858. at: node,
  13859. exportName
  13860. });
  13861. }
  13862. }
  13863. this.exportedIdentifiers.add(exportName);
  13864. }
  13865. parseExportSpecifiers(isInTypeExport) {
  13866. const nodes = [];
  13867. let first = true;
  13868. this.expect(5);
  13869. while (!this.eat(8)) {
  13870. if (first) {
  13871. first = false;
  13872. } else {
  13873. this.expect(12);
  13874. if (this.eat(8)) break;
  13875. }
  13876. const isMaybeTypeOnly = this.isContextual(128);
  13877. const isString = this.match(131);
  13878. const node = this.startNode();
  13879. node.local = this.parseModuleExportName();
  13880. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13881. }
  13882. return nodes;
  13883. }
  13884. parseExportSpecifier(node, isString,
  13885. isInTypeExport, isMaybeTypeOnly
  13886. ) {
  13887. if (this.eatContextual(93)) {
  13888. node.exported = this.parseModuleExportName();
  13889. } else if (isString) {
  13890. node.exported = cloneStringLiteral(node.local);
  13891. } else if (!node.exported) {
  13892. node.exported = cloneIdentifier(node.local);
  13893. }
  13894. return this.finishNode(node, "ExportSpecifier");
  13895. }
  13896. parseModuleExportName() {
  13897. if (this.match(131)) {
  13898. const result = this.parseStringLiteral(this.state.value);
  13899. const surrogate = result.value.match(loneSurrogate);
  13900. if (surrogate) {
  13901. this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
  13902. at: result,
  13903. surrogateCharCode: surrogate[0].charCodeAt(0)
  13904. });
  13905. }
  13906. return result;
  13907. }
  13908. return this.parseIdentifier(true);
  13909. }
  13910. isJSONModuleImport(node) {
  13911. if (node.assertions != null) {
  13912. return node.assertions.some(({
  13913. key,
  13914. value
  13915. }) => {
  13916. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  13917. });
  13918. }
  13919. return false;
  13920. }
  13921. checkImportReflection(node) {
  13922. if (node.module) {
  13923. var _node$assertions;
  13924. if (node.specifiers.length !== 1 || node.specifiers[0].type !== "ImportDefaultSpecifier") {
  13925. this.raise(Errors.ImportReflectionNotBinding, {
  13926. at: node.specifiers[0].loc.start
  13927. });
  13928. }
  13929. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  13930. this.raise(Errors.ImportReflectionHasAssertion, {
  13931. at: node.specifiers[0].loc.start
  13932. });
  13933. }
  13934. }
  13935. }
  13936. checkJSONModuleImport(node) {
  13937. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  13938. const {
  13939. specifiers
  13940. } = node;
  13941. if (specifiers != null) {
  13942. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  13943. let imported;
  13944. if (specifier.type === "ExportSpecifier") {
  13945. imported = specifier.local;
  13946. } else if (specifier.type === "ImportSpecifier") {
  13947. imported = specifier.imported;
  13948. }
  13949. if (imported !== undefined) {
  13950. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  13951. }
  13952. });
  13953. if (nonDefaultNamedSpecifier !== undefined) {
  13954. this.raise(Errors.ImportJSONBindingNotDefault, {
  13955. at: nonDefaultNamedSpecifier.loc.start
  13956. });
  13957. }
  13958. }
  13959. }
  13960. }
  13961. parseMaybeImportReflection(node) {
  13962. let isImportReflection = false;
  13963. if (this.isContextual(125)) {
  13964. const lookahead = this.lookahead();
  13965. if (tokenIsIdentifier(lookahead.type)) {
  13966. if (lookahead.type !== 97) {
  13967. isImportReflection = true;
  13968. } else {
  13969. const nextNextTokenFirstChar = this.input.charCodeAt(this.nextTokenStartSince(lookahead.end));
  13970. if (nextNextTokenFirstChar === 102) {
  13971. isImportReflection = true;
  13972. }
  13973. }
  13974. } else {
  13975. isImportReflection = true;
  13976. }
  13977. }
  13978. if (isImportReflection) {
  13979. this.expectPlugin("importReflection");
  13980. this.next();
  13981. node.module = true;
  13982. } else if (this.hasPlugin("importReflection")) {
  13983. node.module = false;
  13984. }
  13985. }
  13986. parseImport(node) {
  13987. node.specifiers = [];
  13988. if (!this.match(131)) {
  13989. this.parseMaybeImportReflection(node);
  13990. const hasDefault = this.maybeParseDefaultImportSpecifier(node);
  13991. const parseNext = !hasDefault || this.eat(12);
  13992. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  13993. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  13994. this.expectContextual(97);
  13995. }
  13996. node.source = this.parseImportSource();
  13997. const assertions = this.maybeParseImportAssertions();
  13998. if (assertions) {
  13999. node.assertions = assertions;
  14000. } else {
  14001. const attributes = this.maybeParseModuleAttributes();
  14002. if (attributes) {
  14003. node.attributes = attributes;
  14004. }
  14005. }
  14006. this.checkImportReflection(node);
  14007. this.checkJSONModuleImport(node);
  14008. this.semicolon();
  14009. return this.finishNode(node, "ImportDeclaration");
  14010. }
  14011. parseImportSource() {
  14012. if (!this.match(131)) this.unexpected();
  14013. return this.parseExprAtom();
  14014. }
  14015. shouldParseDefaultImport(node) {
  14016. return tokenIsIdentifier(this.state.type);
  14017. }
  14018. parseImportSpecifierLocal(node, specifier, type) {
  14019. specifier.local = this.parseIdentifier();
  14020. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14021. }
  14022. finishImportSpecifier(specifier, type, bindingType = BIND_LEXICAL) {
  14023. this.checkLVal(specifier.local, {
  14024. in: specifier,
  14025. binding: bindingType
  14026. });
  14027. return this.finishNode(specifier, type);
  14028. }
  14029. parseAssertEntries() {
  14030. const attrs = [];
  14031. const attrNames = new Set();
  14032. do {
  14033. if (this.match(8)) {
  14034. break;
  14035. }
  14036. const node = this.startNode();
  14037. const keyName = this.state.value;
  14038. if (attrNames.has(keyName)) {
  14039. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14040. at: this.state.startLoc,
  14041. key: keyName
  14042. });
  14043. }
  14044. attrNames.add(keyName);
  14045. if (this.match(131)) {
  14046. node.key = this.parseStringLiteral(keyName);
  14047. } else {
  14048. node.key = this.parseIdentifier(true);
  14049. }
  14050. this.expect(14);
  14051. if (!this.match(131)) {
  14052. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14053. at: this.state.startLoc
  14054. });
  14055. }
  14056. node.value = this.parseStringLiteral(this.state.value);
  14057. attrs.push(this.finishNode(node, "ImportAttribute"));
  14058. } while (this.eat(12));
  14059. return attrs;
  14060. }
  14061. maybeParseModuleAttributes() {
  14062. if (this.match(76) && !this.hasPrecedingLineBreak()) {
  14063. this.expectPlugin("moduleAttributes");
  14064. this.next();
  14065. } else {
  14066. if (this.hasPlugin("moduleAttributes")) return [];
  14067. return null;
  14068. }
  14069. const attrs = [];
  14070. const attributes = new Set();
  14071. do {
  14072. const node = this.startNode();
  14073. node.key = this.parseIdentifier(true);
  14074. if (node.key.name !== "type") {
  14075. this.raise(Errors.ModuleAttributeDifferentFromType, {
  14076. at: node.key
  14077. });
  14078. }
  14079. if (attributes.has(node.key.name)) {
  14080. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14081. at: node.key,
  14082. key: node.key.name
  14083. });
  14084. }
  14085. attributes.add(node.key.name);
  14086. this.expect(14);
  14087. if (!this.match(131)) {
  14088. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14089. at: this.state.startLoc
  14090. });
  14091. }
  14092. node.value = this.parseStringLiteral(this.state.value);
  14093. this.finishNode(node, "ImportAttribute");
  14094. attrs.push(node);
  14095. } while (this.eat(12));
  14096. return attrs;
  14097. }
  14098. maybeParseImportAssertions() {
  14099. if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14100. this.expectPlugin("importAssertions");
  14101. this.next();
  14102. } else {
  14103. if (this.hasPlugin("importAssertions")) return [];
  14104. return null;
  14105. }
  14106. this.eat(5);
  14107. const attrs = this.parseAssertEntries();
  14108. this.eat(8);
  14109. return attrs;
  14110. }
  14111. maybeParseDefaultImportSpecifier(node) {
  14112. if (this.shouldParseDefaultImport(node)) {
  14113. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14114. return true;
  14115. }
  14116. return false;
  14117. }
  14118. maybeParseStarImportSpecifier(node) {
  14119. if (this.match(55)) {
  14120. const specifier = this.startNode();
  14121. this.next();
  14122. this.expectContextual(93);
  14123. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14124. return true;
  14125. }
  14126. return false;
  14127. }
  14128. parseNamedImportSpecifiers(node) {
  14129. let first = true;
  14130. this.expect(5);
  14131. while (!this.eat(8)) {
  14132. if (first) {
  14133. first = false;
  14134. } else {
  14135. if (this.eat(14)) {
  14136. throw this.raise(Errors.DestructureNamedImport, {
  14137. at: this.state.startLoc
  14138. });
  14139. }
  14140. this.expect(12);
  14141. if (this.eat(8)) break;
  14142. }
  14143. const specifier = this.startNode();
  14144. const importedIsString = this.match(131);
  14145. const isMaybeTypeOnly = this.isContextual(128);
  14146. specifier.imported = this.parseModuleExportName();
  14147. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14148. node.specifiers.push(importSpecifier);
  14149. }
  14150. }
  14151. parseImportSpecifier(specifier, importedIsString,
  14152. isInTypeOnlyImport, isMaybeTypeOnly, bindingType
  14153. ) {
  14154. if (this.eatContextual(93)) {
  14155. specifier.local = this.parseIdentifier();
  14156. } else {
  14157. const {
  14158. imported
  14159. } = specifier;
  14160. if (importedIsString) {
  14161. throw this.raise(Errors.ImportBindingIsString, {
  14162. at: specifier,
  14163. importName: imported.value
  14164. });
  14165. }
  14166. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14167. if (!specifier.local) {
  14168. specifier.local = cloneIdentifier(imported);
  14169. }
  14170. }
  14171. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14172. }
  14173. isThisParam(param) {
  14174. return param.type === "Identifier" && param.name === "this";
  14175. }
  14176. }
  14177. class Parser extends StatementParser {
  14178. constructor(options, input) {
  14179. options = getOptions(options);
  14180. super(options, input);
  14181. this.options = options;
  14182. this.initializeScopes();
  14183. this.plugins = pluginsMap(this.options.plugins);
  14184. this.filename = options.sourceFilename;
  14185. }
  14186. getScopeHandler() {
  14187. return ScopeHandler;
  14188. }
  14189. parse() {
  14190. this.enterInitialScopes();
  14191. const file = this.startNode();
  14192. const program = this.startNode();
  14193. this.nextToken();
  14194. file.errors = null;
  14195. this.parseTopLevel(file, program);
  14196. file.errors = this.state.errors;
  14197. return file;
  14198. }
  14199. }
  14200. function pluginsMap(plugins) {
  14201. const pluginMap = new Map();
  14202. for (const plugin of plugins) {
  14203. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  14204. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  14205. }
  14206. return pluginMap;
  14207. }
  14208. function parse(input, options) {
  14209. var _options;
  14210. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14211. options = Object.assign({}, options);
  14212. try {
  14213. options.sourceType = "module";
  14214. const parser = getParser(options, input);
  14215. const ast = parser.parse();
  14216. if (parser.sawUnambiguousESM) {
  14217. return ast;
  14218. }
  14219. if (parser.ambiguousScriptDifferentAst) {
  14220. try {
  14221. options.sourceType = "script";
  14222. return getParser(options, input).parse();
  14223. } catch (_unused) {}
  14224. } else {
  14225. ast.program.sourceType = "script";
  14226. }
  14227. return ast;
  14228. } catch (moduleError) {
  14229. try {
  14230. options.sourceType = "script";
  14231. return getParser(options, input).parse();
  14232. } catch (_unused2) {}
  14233. throw moduleError;
  14234. }
  14235. } else {
  14236. return getParser(options, input).parse();
  14237. }
  14238. }
  14239. function parseExpression(input, options) {
  14240. const parser = getParser(options, input);
  14241. if (parser.options.strictMode) {
  14242. parser.state.strict = true;
  14243. }
  14244. return parser.getExpression();
  14245. }
  14246. function generateExportedTokenTypes(internalTokenTypes) {
  14247. const tokenTypes = {};
  14248. for (const typeName of Object.keys(internalTokenTypes)) {
  14249. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14250. }
  14251. return tokenTypes;
  14252. }
  14253. const tokTypes = generateExportedTokenTypes(tt);
  14254. function getParser(options, input) {
  14255. let cls = Parser;
  14256. if (options != null && options.plugins) {
  14257. validatePlugins(options.plugins);
  14258. cls = getParserClass(options.plugins);
  14259. }
  14260. return new cls(options, input);
  14261. }
  14262. const parserClassCache = {};
  14263. function getParserClass(pluginsFromOptions) {
  14264. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  14265. const key = pluginList.join("/");
  14266. let cls = parserClassCache[key];
  14267. if (!cls) {
  14268. cls = Parser;
  14269. for (const plugin of pluginList) {
  14270. cls = mixinPlugins[plugin](cls);
  14271. }
  14272. parserClassCache[key] = cls;
  14273. }
  14274. return cls;
  14275. }
  14276. exports.parse = parse;
  14277. exports.parseExpression = parseExpression;
  14278. exports.tokTypes = tokTypes;
  14279. //# sourceMappingURL=index.js.map