index.js 464 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667
  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. const ParseErrorCodes = Object.freeze({
  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) => object[key], this);
  50. },
  51. set(value) {
  52. keys.reduce((item, key, i) => i === last ? item[key] = value : item[key], this);
  53. }
  54. });
  55. const instantiate = (constructor, properties, descriptors) => Object.keys(descriptors).map(key => [key, descriptors[key]]).filter(([, descriptor]) => !!descriptor).map(([key, descriptor]) => [key, typeof descriptor === "function" ? {
  56. value: descriptor,
  57. enumerable: false
  58. } : typeof descriptor.reflect === "string" ? Object.assign({}, descriptor, reflect(descriptor.reflect.split("."))) : descriptor]).reduce((instance, [key, descriptor]) => Object.defineProperty(instance, key, Object.assign({
  59. configurable: true
  60. }, descriptor)), Object.assign(new constructor(), properties));
  61. var ModuleErrors = (_ => ({
  62. ImportMetaOutsideModule: _(`import.meta may appear only with 'sourceType: "module"'`, {
  63. code: ParseErrorCodes.SourceTypeModuleError
  64. }),
  65. ImportOutsideModule: _(`'import' and 'export' may appear only with 'sourceType: "module"'`, {
  66. code: ParseErrorCodes.SourceTypeModuleError
  67. })
  68. }));
  69. const NodeDescriptions = {
  70. ArrayPattern: "array destructuring pattern",
  71. AssignmentExpression: "assignment expression",
  72. AssignmentPattern: "assignment expression",
  73. ArrowFunctionExpression: "arrow function expression",
  74. ConditionalExpression: "conditional expression",
  75. ForOfStatement: "for-of statement",
  76. ForInStatement: "for-in statement",
  77. ForStatement: "for-loop",
  78. FormalParameters: "function parameter list",
  79. Identifier: "identifier",
  80. ObjectPattern: "object destructuring pattern",
  81. ParenthesizedExpression: "parenthesized expression",
  82. RestElement: "rest element",
  83. UpdateExpression: {
  84. true: "prefix operation",
  85. false: "postfix operation"
  86. },
  87. VariableDeclarator: "variable declaration",
  88. YieldExpression: "yield expression"
  89. };
  90. const toNodeDescription = ({
  91. type,
  92. prefix
  93. }) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
  94. var StandardErrors = (_ => ({
  95. AccessorIsGenerator: _(({
  96. kind
  97. }) => `A ${kind}ter cannot be a generator.`),
  98. ArgumentsInClass: _("'arguments' is only allowed in functions and class methods."),
  99. AsyncFunctionInSingleStatementContext: _("Async functions can only be declared at the top level or inside a block."),
  100. AwaitBindingIdentifier: _("Can not use 'await' as identifier inside an async function."),
  101. AwaitBindingIdentifierInStaticBlock: _("Can not use 'await' as identifier inside a static block."),
  102. AwaitExpressionFormalParameter: _("'await' is not allowed in async function parameters."),
  103. AwaitNotInAsyncContext: _("'await' is only allowed within async functions and at the top levels of modules."),
  104. AwaitNotInAsyncFunction: _("'await' is only allowed within async functions."),
  105. BadGetterArity: _("A 'get' accesor must not have any formal parameters."),
  106. BadSetterArity: _("A 'set' accesor must have exactly one formal parameter."),
  107. BadSetterRestParameter: _("A 'set' accesor function argument must not be a rest parameter."),
  108. ConstructorClassField: _("Classes may not have a field named 'constructor'."),
  109. ConstructorClassPrivateField: _("Classes may not have a private field named '#constructor'."),
  110. ConstructorIsAccessor: _("Class constructor may not be an accessor."),
  111. ConstructorIsAsync: _("Constructor can't be an async function."),
  112. ConstructorIsGenerator: _("Constructor can't be a generator."),
  113. DeclarationMissingInitializer: _(({
  114. kind
  115. }) => `Missing initializer in ${kind} declaration.`),
  116. DecoratorBeforeExport: _("Decorators must be placed *before* the 'export' keyword. You can set the 'decoratorsBeforeExport' option to false to use the 'export @decorator class {}' syntax."),
  117. DecoratorConstructor: _("Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?"),
  118. DecoratorExportClass: _("Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead."),
  119. DecoratorSemicolon: _("Decorators must not be followed by a semicolon."),
  120. DecoratorStaticBlock: _("Decorators can't be used with a static block."),
  121. DeletePrivateField: _("Deleting a private field is not allowed."),
  122. DestructureNamedImport: _("ES2015 named imports do not destructure. Use another statement for destructuring after the import."),
  123. DuplicateConstructor: _("Duplicate constructor in the same class."),
  124. DuplicateDefaultExport: _("Only one default export allowed per module."),
  125. DuplicateExport: _(({
  126. exportName
  127. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`),
  128. DuplicateProto: _("Redefinition of __proto__ property."),
  129. DuplicateRegExpFlags: _("Duplicate regular expression flag."),
  130. ElementAfterRest: _("Rest element must be last element."),
  131. EscapedCharNotAnIdentifier: _("Invalid Unicode escape."),
  132. ExportBindingIsString: _(({
  133. localName,
  134. exportName
  135. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`),
  136. ExportDefaultFromAsIdentifier: _("'from' is not allowed as an identifier after 'export default'."),
  137. ForInOfLoopInitializer: _(({
  138. type
  139. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`),
  140. ForOfAsync: _("The left-hand side of a for-of loop may not be 'async'."),
  141. ForOfLet: _("The left-hand side of a for-of loop may not start with 'let'."),
  142. GeneratorInSingleStatementContext: _("Generators can only be declared at the top level or inside a block."),
  143. IllegalBreakContinue: _(({
  144. type
  145. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`),
  146. IllegalLanguageModeDirective: _("Illegal 'use strict' directive in function with non-simple parameter list."),
  147. IllegalReturn: _("'return' outside of function."),
  148. ImportBindingIsString: _(({
  149. importName
  150. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`),
  151. ImportCallArgumentTrailingComma: _("Trailing comma is disallowed inside import(...) arguments."),
  152. ImportCallArity: _(({
  153. maxArgumentCount
  154. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`),
  155. ImportCallNotNewExpression: _("Cannot use new with import(...)."),
  156. ImportCallSpreadArgument: _("`...` is not allowed in `import()`."),
  157. ImportJSONBindingNotDefault: _("A JSON module can only be imported with `default`."),
  158. IncompatibleRegExpUVFlags: _("The 'u' and 'v' regular expression flags cannot be enabled at the same time."),
  159. InvalidBigIntLiteral: _("Invalid BigIntLiteral."),
  160. InvalidCodePoint: _("Code point out of bounds."),
  161. InvalidCoverInitializedName: _("Invalid shorthand property initializer."),
  162. InvalidDecimal: _("Invalid decimal."),
  163. InvalidDigit: _(({
  164. radix
  165. }) => `Expected number in radix ${radix}.`),
  166. InvalidEscapeSequence: _("Bad character escape sequence."),
  167. InvalidEscapeSequenceTemplate: _("Invalid escape sequence in template."),
  168. InvalidEscapedReservedWord: _(({
  169. reservedWord
  170. }) => `Escape sequence in keyword ${reservedWord}.`),
  171. InvalidIdentifier: _(({
  172. identifierName
  173. }) => `Invalid identifier ${identifierName}.`),
  174. InvalidLhs: _(({
  175. ancestor
  176. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`),
  177. InvalidLhsBinding: _(({
  178. ancestor
  179. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`),
  180. InvalidNumber: _("Invalid number."),
  181. InvalidOrMissingExponent: _("Floating-point numbers require a valid exponent after the 'e'."),
  182. InvalidOrUnexpectedToken: _(({
  183. unexpected
  184. }) => `Unexpected character '${unexpected}'.`),
  185. InvalidParenthesizedAssignment: _("Invalid parenthesized assignment pattern."),
  186. InvalidPrivateFieldResolution: _(({
  187. identifierName
  188. }) => `Private name #${identifierName} is not defined.`),
  189. InvalidPropertyBindingPattern: _("Binding member expression."),
  190. InvalidRecordProperty: _("Only properties and spread elements are allowed in record definitions."),
  191. InvalidRestAssignmentPattern: _("Invalid rest operator's argument."),
  192. LabelRedeclaration: _(({
  193. labelName
  194. }) => `Label '${labelName}' is already declared.`),
  195. LetInLexicalBinding: _("'let' is not allowed to be used as a name in 'let' or 'const' declarations."),
  196. LineTerminatorBeforeArrow: _("No line break is allowed before '=>'."),
  197. MalformedRegExpFlags: _("Invalid regular expression flag."),
  198. MissingClassName: _("A class name is required."),
  199. MissingEqInAssignment: _("Only '=' operator can be used for specifying default value."),
  200. MissingSemicolon: _("Missing semicolon."),
  201. MissingPlugin: _(({
  202. missingPlugin
  203. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`),
  204. MissingOneOfPlugins: _(({
  205. missingPlugin
  206. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`),
  207. MissingUnicodeEscape: _("Expecting Unicode escape sequence \\uXXXX."),
  208. MixingCoalesceWithLogical: _("Nullish coalescing operator(??) requires parens when mixing with logical operators."),
  209. ModuleAttributeDifferentFromType: _("The only accepted module attribute is `type`."),
  210. ModuleAttributeInvalidValue: _("Only string literals are allowed as module attribute values."),
  211. ModuleAttributesWithDuplicateKeys: _(({
  212. key
  213. }) => `Duplicate key "${key}" is not allowed in module attributes.`),
  214. ModuleExportNameHasLoneSurrogate: _(({
  215. surrogateCharCode
  216. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`),
  217. ModuleExportUndefined: _(({
  218. localName
  219. }) => `Export '${localName}' is not defined.`),
  220. MultipleDefaultsInSwitch: _("Multiple default clauses."),
  221. NewlineAfterThrow: _("Illegal newline after throw."),
  222. NoCatchOrFinally: _("Missing catch or finally clause."),
  223. NumberIdentifier: _("Identifier directly after number."),
  224. NumericSeparatorInEscapeSequence: _("Numeric separators are not allowed inside unicode escape sequences or hex escape sequences."),
  225. ObsoleteAwaitStar: _("'await*' has been removed from the async functions proposal. Use Promise.all() instead."),
  226. OptionalChainingNoNew: _("Constructors in/after an Optional Chain are not allowed."),
  227. OptionalChainingNoTemplate: _("Tagged Template Literals are not allowed in optionalChain."),
  228. OverrideOnConstructor: _("'override' modifier cannot appear on a constructor declaration."),
  229. ParamDupe: _("Argument name clash."),
  230. PatternHasAccessor: _("Object pattern can't contain getter or setter."),
  231. PatternHasMethod: _("Object pattern can't contain methods."),
  232. PrivateInExpectedIn: _(({
  233. identifierName
  234. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`),
  235. PrivateNameRedeclaration: _(({
  236. identifierName
  237. }) => `Duplicate private name #${identifierName}.`),
  238. RecordExpressionBarIncorrectEndSyntaxType: _("Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'."),
  239. RecordExpressionBarIncorrectStartSyntaxType: _("Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'."),
  240. RecordExpressionHashIncorrectStartSyntaxType: _("Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'."),
  241. RecordNoProto: _("'__proto__' is not allowed in Record expressions."),
  242. RestTrailingComma: _("Unexpected trailing comma after rest element."),
  243. 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."),
  244. StaticPrototype: _("Classes may not have static property named prototype."),
  245. 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?"),
  246. SuperPrivateField: _("Private fields can't be accessed on super."),
  247. TrailingDecorator: _("Decorators must be attached to a class element."),
  248. TupleExpressionBarIncorrectEndSyntaxType: _("Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'."),
  249. TupleExpressionBarIncorrectStartSyntaxType: _("Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'."),
  250. TupleExpressionHashIncorrectStartSyntaxType: _("Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'."),
  251. UnexpectedArgumentPlaceholder: _("Unexpected argument placeholder."),
  252. UnexpectedAwaitAfterPipelineBody: _('Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.'),
  253. UnexpectedDigitAfterHash: _("Unexpected digit after hash token."),
  254. UnexpectedImportExport: _("'import' and 'export' may only appear at the top level."),
  255. UnexpectedKeyword: _(({
  256. keyword
  257. }) => `Unexpected keyword '${keyword}'.`),
  258. UnexpectedLeadingDecorator: _("Leading decorators must be attached to a class declaration."),
  259. UnexpectedLexicalDeclaration: _("Lexical declaration cannot appear in a single-statement context."),
  260. UnexpectedNewTarget: _("`new.target` can only be used in functions or class properties."),
  261. UnexpectedNumericSeparator: _("A numeric separator is only allowed between two digits."),
  262. UnexpectedPrivateField: _("Unexpected private name."),
  263. UnexpectedReservedWord: _(({
  264. reservedWord
  265. }) => `Unexpected reserved word '${reservedWord}'.`),
  266. UnexpectedSuper: _("'super' is only allowed in object methods and classes."),
  267. UnexpectedToken: _(({
  268. expected,
  269. unexpected
  270. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`),
  271. UnexpectedTokenUnaryExponentiation: _("Illegal expression. Wrap left hand side or entire exponentiation in parentheses."),
  272. UnsupportedBind: _("Binding should be performed on object property."),
  273. UnsupportedDecoratorExport: _("A decorated export must export a class declaration."),
  274. UnsupportedDefaultExport: _("Only expressions, functions or classes are allowed as the `default` export."),
  275. UnsupportedImport: _("`import` can only be used in `import()` or `import.meta`."),
  276. UnsupportedMetaProperty: _(({
  277. target,
  278. onlyValidPropertyName
  279. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`),
  280. UnsupportedParameterDecorator: _("Decorators cannot be used to decorate parameters."),
  281. UnsupportedPropertyDecorator: _("Decorators cannot be used to decorate object literal properties."),
  282. UnsupportedSuper: _("'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop])."),
  283. UnterminatedComment: _("Unterminated comment."),
  284. UnterminatedRegExp: _("Unterminated regular expression."),
  285. UnterminatedString: _("Unterminated string constant."),
  286. UnterminatedTemplate: _("Unterminated template."),
  287. VarRedeclaration: _(({
  288. identifierName
  289. }) => `Identifier '${identifierName}' has already been declared.`),
  290. YieldBindingIdentifier: _("Can not use 'yield' as identifier inside a generator."),
  291. YieldInParameter: _("Yield expression is not allowed in formal parameters."),
  292. ZeroDigitNumericSeparator: _("Numeric separator can not be used after leading 0.")
  293. }));
  294. var StrictModeErrors = (_ => ({
  295. StrictDelete: _("Deleting local variable in strict mode."),
  296. StrictEvalArguments: _(({
  297. referenceName
  298. }) => `Assigning to '${referenceName}' in strict mode.`),
  299. StrictEvalArgumentsBinding: _(({
  300. bindingName
  301. }) => `Binding '${bindingName}' in strict mode.`),
  302. StrictFunction: _("In strict mode code, functions can only be declared at top level or inside a block."),
  303. StrictNumericEscape: _("The only valid numeric escape in strict mode is '\\0'."),
  304. StrictOctalLiteral: _("Legacy octal literals are not allowed in strict mode."),
  305. StrictWith: _("'with' in strict mode.")
  306. }));
  307. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  308. var PipelineOperatorErrors = (_ => ({
  309. PipeBodyIsTighter: _("Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence."),
  310. PipeTopicRequiresHackPipes: _('Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'),
  311. PipeTopicUnbound: _("Topic reference is unbound; it must be inside a pipe body."),
  312. PipeTopicUnconfiguredToken: _(({
  313. token
  314. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`),
  315. PipeTopicUnused: _("Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once."),
  316. PipeUnparenthesizedBody: _(({
  317. type
  318. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  319. type
  320. })}; please wrap it in parentheses.`),
  321. PipelineBodyNoArrow: _('Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.'),
  322. PipelineBodySequenceExpression: _("Pipeline body may not be a comma-separated sequence expression."),
  323. PipelineHeadSequenceExpression: _("Pipeline head should not be a comma-separated sequence expression."),
  324. PipelineTopicUnused: _("Pipeline is in topic style but does not use topic reference."),
  325. PrimaryTopicNotAllowed: _("Topic reference was used in a lexical context without topic binding."),
  326. PrimaryTopicRequiresSmartPipeline: _('Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.')
  327. }));
  328. const _excluded$1 = ["toMessage"];
  329. function toParseErrorConstructor(_ref) {
  330. let {
  331. toMessage
  332. } = _ref,
  333. properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  334. return function constructor({
  335. loc,
  336. details
  337. }) {
  338. return instantiate(SyntaxError, Object.assign({}, properties, {
  339. loc
  340. }), {
  341. clone(overrides = {}) {
  342. const loc = overrides.loc || {};
  343. return constructor({
  344. 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),
  345. details: Object.assign({}, this.details, overrides.details)
  346. });
  347. },
  348. details: {
  349. value: details,
  350. enumerable: false
  351. },
  352. message: {
  353. get() {
  354. return `${toMessage(this.details)} (${this.loc.line}:${this.loc.column})`;
  355. },
  356. set(value) {
  357. Object.defineProperty(this, "message", {
  358. value
  359. });
  360. }
  361. },
  362. pos: {
  363. reflect: "loc.index",
  364. enumerable: true
  365. },
  366. missingPlugin: "missingPlugin" in details && {
  367. reflect: "details.missingPlugin",
  368. enumerable: true
  369. }
  370. });
  371. };
  372. }
  373. function toParseErrorCredentials(toMessageOrMessage, credentials) {
  374. return Object.assign({
  375. toMessage: typeof toMessageOrMessage === "string" ? () => toMessageOrMessage : toMessageOrMessage
  376. }, credentials);
  377. }
  378. function ParseErrorEnum(argument, syntaxPlugin) {
  379. if (Array.isArray(argument)) {
  380. return toParseErrorCredentialsMap => ParseErrorEnum(toParseErrorCredentialsMap, argument[0]);
  381. }
  382. const partialCredentials = argument(toParseErrorCredentials);
  383. const ParseErrorConstructors = {};
  384. for (const reasonCode of Object.keys(partialCredentials)) {
  385. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  386. code: ParseErrorCodes.SyntaxError,
  387. reasonCode
  388. }, syntaxPlugin ? {
  389. syntaxPlugin
  390. } : {}, partialCredentials[reasonCode]));
  391. }
  392. return ParseErrorConstructors;
  393. }
  394. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  395. const {
  396. defineProperty
  397. } = Object;
  398. const toUnenumerable = (object, key) => defineProperty(object, key, {
  399. enumerable: false,
  400. value: object[key]
  401. });
  402. function toESTreeLocation(node) {
  403. node.loc.start && toUnenumerable(node.loc.start, "index");
  404. node.loc.end && toUnenumerable(node.loc.end, "index");
  405. return node;
  406. }
  407. var estree = (superClass => class extends superClass {
  408. parse() {
  409. const file = toESTreeLocation(super.parse());
  410. if (this.options.tokens) {
  411. file.tokens = file.tokens.map(toESTreeLocation);
  412. }
  413. return file;
  414. }
  415. parseRegExpLiteral({
  416. pattern,
  417. flags
  418. }) {
  419. let regex = null;
  420. try {
  421. regex = new RegExp(pattern, flags);
  422. } catch (e) {}
  423. const node = this.estreeParseLiteral(regex);
  424. node.regex = {
  425. pattern,
  426. flags
  427. };
  428. return node;
  429. }
  430. parseBigIntLiteral(value) {
  431. let bigInt;
  432. try {
  433. bigInt = BigInt(value);
  434. } catch (_unused) {
  435. bigInt = null;
  436. }
  437. const node = this.estreeParseLiteral(bigInt);
  438. node.bigint = String(node.value || value);
  439. return node;
  440. }
  441. parseDecimalLiteral(value) {
  442. const decimal = null;
  443. const node = this.estreeParseLiteral(decimal);
  444. node.decimal = String(node.value || value);
  445. return node;
  446. }
  447. estreeParseLiteral(value) {
  448. return this.parseLiteral(value, "Literal");
  449. }
  450. parseStringLiteral(value) {
  451. return this.estreeParseLiteral(value);
  452. }
  453. parseNumericLiteral(value) {
  454. return this.estreeParseLiteral(value);
  455. }
  456. parseNullLiteral() {
  457. return this.estreeParseLiteral(null);
  458. }
  459. parseBooleanLiteral(value) {
  460. return this.estreeParseLiteral(value);
  461. }
  462. directiveToStmt(directive) {
  463. const directiveLiteral = directive.value;
  464. const stmt = this.startNodeAt(directive.start, directive.loc.start);
  465. const expression = this.startNodeAt(directiveLiteral.start, directiveLiteral.loc.start);
  466. expression.value = directiveLiteral.extra.expressionValue;
  467. expression.raw = directiveLiteral.extra.raw;
  468. stmt.expression = this.finishNodeAt(expression, "Literal", directiveLiteral.loc.end);
  469. stmt.directive = directiveLiteral.extra.raw.slice(1, -1);
  470. return this.finishNodeAt(stmt, "ExpressionStatement", directive.loc.end);
  471. }
  472. initFunction(node, isAsync) {
  473. super.initFunction(node, isAsync);
  474. node.expression = false;
  475. }
  476. checkDeclaration(node) {
  477. if (node != null && this.isObjectProperty(node)) {
  478. this.checkDeclaration(node.value);
  479. } else {
  480. super.checkDeclaration(node);
  481. }
  482. }
  483. getObjectOrClassMethodParams(method) {
  484. return method.value.params;
  485. }
  486. isValidDirective(stmt) {
  487. var _stmt$expression$extr;
  488. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  489. }
  490. parseBlockBody(node, ...args) {
  491. super.parseBlockBody(node, ...args);
  492. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  493. node.body = directiveStatements.concat(node.body);
  494. delete node.directives;
  495. }
  496. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  497. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  498. if (method.typeParameters) {
  499. method.value.typeParameters = method.typeParameters;
  500. delete method.typeParameters;
  501. }
  502. classBody.body.push(method);
  503. }
  504. parsePrivateName() {
  505. const node = super.parsePrivateName();
  506. {
  507. if (!this.getPluginOption("estree", "classFeatures")) {
  508. return node;
  509. }
  510. }
  511. return this.convertPrivateNameToPrivateIdentifier(node);
  512. }
  513. convertPrivateNameToPrivateIdentifier(node) {
  514. const name = super.getPrivateNameSV(node);
  515. node = node;
  516. delete node.id;
  517. node.name = name;
  518. node.type = "PrivateIdentifier";
  519. return node;
  520. }
  521. isPrivateName(node) {
  522. {
  523. if (!this.getPluginOption("estree", "classFeatures")) {
  524. return super.isPrivateName(node);
  525. }
  526. }
  527. return node.type === "PrivateIdentifier";
  528. }
  529. getPrivateNameSV(node) {
  530. {
  531. if (!this.getPluginOption("estree", "classFeatures")) {
  532. return super.getPrivateNameSV(node);
  533. }
  534. }
  535. return node.name;
  536. }
  537. parseLiteral(value, type) {
  538. const node = super.parseLiteral(value, type);
  539. node.raw = node.extra.raw;
  540. delete node.extra;
  541. return node;
  542. }
  543. parseFunctionBody(node, allowExpression, isMethod = false) {
  544. super.parseFunctionBody(node, allowExpression, isMethod);
  545. node.expression = node.body.type !== "BlockStatement";
  546. }
  547. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  548. let funcNode = this.startNode();
  549. funcNode.kind = node.kind;
  550. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  551. funcNode.type = "FunctionExpression";
  552. delete funcNode.kind;
  553. node.value = funcNode;
  554. if (type === "ClassPrivateMethod") {
  555. node.computed = false;
  556. }
  557. type = "MethodDefinition";
  558. return this.finishNode(node, type);
  559. }
  560. parseClassProperty(...args) {
  561. const propertyNode = super.parseClassProperty(...args);
  562. {
  563. if (!this.getPluginOption("estree", "classFeatures")) {
  564. return propertyNode;
  565. }
  566. }
  567. propertyNode.type = "PropertyDefinition";
  568. return propertyNode;
  569. }
  570. parseClassPrivateProperty(...args) {
  571. const propertyNode = super.parseClassPrivateProperty(...args);
  572. {
  573. if (!this.getPluginOption("estree", "classFeatures")) {
  574. return propertyNode;
  575. }
  576. }
  577. propertyNode.type = "PropertyDefinition";
  578. propertyNode.computed = false;
  579. return propertyNode;
  580. }
  581. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  582. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  583. if (node) {
  584. node.type = "Property";
  585. if (node.kind === "method") node.kind = "init";
  586. node.shorthand = false;
  587. }
  588. return node;
  589. }
  590. parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors) {
  591. const node = super.parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors);
  592. if (node) {
  593. node.kind = "init";
  594. node.type = "Property";
  595. }
  596. return node;
  597. }
  598. isValidLVal(type, ...rest) {
  599. return type === "Property" ? "value" : super.isValidLVal(type, ...rest);
  600. }
  601. isAssignable(node, isBinding) {
  602. if (node != null && this.isObjectProperty(node)) {
  603. return this.isAssignable(node.value, isBinding);
  604. }
  605. return super.isAssignable(node, isBinding);
  606. }
  607. toAssignable(node, isLHS = false) {
  608. if (node != null && this.isObjectProperty(node)) {
  609. const {
  610. key,
  611. value
  612. } = node;
  613. if (this.isPrivateName(key)) {
  614. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  615. }
  616. this.toAssignable(value, isLHS);
  617. } else {
  618. super.toAssignable(node, isLHS);
  619. }
  620. }
  621. toAssignableObjectExpressionProp(prop) {
  622. if (prop.kind === "get" || prop.kind === "set") {
  623. this.raise(Errors.PatternHasAccessor, {
  624. at: prop.key
  625. });
  626. } else if (prop.method) {
  627. this.raise(Errors.PatternHasMethod, {
  628. at: prop.key
  629. });
  630. } else {
  631. super.toAssignableObjectExpressionProp(...arguments);
  632. }
  633. }
  634. finishCallExpression(node, optional) {
  635. super.finishCallExpression(node, optional);
  636. if (node.callee.type === "Import") {
  637. node.type = "ImportExpression";
  638. node.source = node.arguments[0];
  639. if (this.hasPlugin("importAssertions")) {
  640. var _node$arguments$;
  641. node.attributes = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  642. }
  643. delete node.arguments;
  644. delete node.callee;
  645. }
  646. return node;
  647. }
  648. toReferencedArguments(node) {
  649. if (node.type === "ImportExpression") {
  650. return;
  651. }
  652. super.toReferencedArguments(node);
  653. }
  654. parseExport(node) {
  655. super.parseExport(node);
  656. switch (node.type) {
  657. case "ExportAllDeclaration":
  658. node.exported = null;
  659. break;
  660. case "ExportNamedDeclaration":
  661. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  662. node.type = "ExportAllDeclaration";
  663. node.exported = node.specifiers[0].exported;
  664. delete node.specifiers;
  665. }
  666. break;
  667. }
  668. return node;
  669. }
  670. parseSubscript(base, startPos, startLoc, noCalls, state) {
  671. const node = super.parseSubscript(base, startPos, startLoc, noCalls, state);
  672. if (state.optionalChainMember) {
  673. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  674. node.type = node.type.substring(8);
  675. }
  676. if (state.stop) {
  677. const chain = this.startNodeAtNode(node);
  678. chain.expression = node;
  679. return this.finishNode(chain, "ChainExpression");
  680. }
  681. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  682. node.optional = false;
  683. }
  684. return node;
  685. }
  686. hasPropertyAsPrivateName(node) {
  687. if (node.type === "ChainExpression") {
  688. node = node.expression;
  689. }
  690. return super.hasPropertyAsPrivateName(node);
  691. }
  692. isOptionalChain(node) {
  693. return node.type === "ChainExpression";
  694. }
  695. isObjectProperty(node) {
  696. return node.type === "Property" && node.kind === "init" && !node.method;
  697. }
  698. isObjectMethod(node) {
  699. return node.method || node.kind === "get" || node.kind === "set";
  700. }
  701. finishNodeAt(node, type, endLoc) {
  702. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  703. }
  704. resetStartLocation(node, start, startLoc) {
  705. super.resetStartLocation(node, start, startLoc);
  706. toESTreeLocation(node);
  707. }
  708. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  709. super.resetEndLocation(node, endLoc);
  710. toESTreeLocation(node);
  711. }
  712. });
  713. class TokContext {
  714. constructor(token, preserveSpace) {
  715. this.token = void 0;
  716. this.preserveSpace = void 0;
  717. this.token = token;
  718. this.preserveSpace = !!preserveSpace;
  719. }
  720. }
  721. const types = {
  722. brace: new TokContext("{"),
  723. j_oTag: new TokContext("<tag"),
  724. j_cTag: new TokContext("</tag"),
  725. j_expr: new TokContext("<tag>...</tag>", true)
  726. };
  727. {
  728. types.template = new TokContext("`", true);
  729. }
  730. const beforeExpr = true;
  731. const startsExpr = true;
  732. const isLoop = true;
  733. const isAssign = true;
  734. const prefix = true;
  735. const postfix = true;
  736. class ExportedTokenType {
  737. constructor(label, conf = {}) {
  738. this.label = void 0;
  739. this.keyword = void 0;
  740. this.beforeExpr = void 0;
  741. this.startsExpr = void 0;
  742. this.rightAssociative = void 0;
  743. this.isLoop = void 0;
  744. this.isAssign = void 0;
  745. this.prefix = void 0;
  746. this.postfix = void 0;
  747. this.binop = void 0;
  748. this.label = label;
  749. this.keyword = conf.keyword;
  750. this.beforeExpr = !!conf.beforeExpr;
  751. this.startsExpr = !!conf.startsExpr;
  752. this.rightAssociative = !!conf.rightAssociative;
  753. this.isLoop = !!conf.isLoop;
  754. this.isAssign = !!conf.isAssign;
  755. this.prefix = !!conf.prefix;
  756. this.postfix = !!conf.postfix;
  757. this.binop = conf.binop != null ? conf.binop : null;
  758. {
  759. this.updateContext = null;
  760. }
  761. }
  762. }
  763. const keywords$1 = new Map();
  764. function createKeyword(name, options = {}) {
  765. options.keyword = name;
  766. const token = createToken(name, options);
  767. keywords$1.set(name, token);
  768. return token;
  769. }
  770. function createBinop(name, binop) {
  771. return createToken(name, {
  772. beforeExpr,
  773. binop
  774. });
  775. }
  776. let tokenTypeCounter = -1;
  777. const tokenTypes = [];
  778. const tokenLabels = [];
  779. const tokenBinops = [];
  780. const tokenBeforeExprs = [];
  781. const tokenStartsExprs = [];
  782. const tokenPrefixes = [];
  783. function createToken(name, options = {}) {
  784. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  785. ++tokenTypeCounter;
  786. tokenLabels.push(name);
  787. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  788. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  789. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  790. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  791. tokenTypes.push(new ExportedTokenType(name, options));
  792. return tokenTypeCounter;
  793. }
  794. function createKeywordLike(name, options = {}) {
  795. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  796. ++tokenTypeCounter;
  797. keywords$1.set(name, tokenTypeCounter);
  798. tokenLabels.push(name);
  799. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  800. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  801. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  802. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  803. tokenTypes.push(new ExportedTokenType("name", options));
  804. return tokenTypeCounter;
  805. }
  806. const tt = {
  807. bracketL: createToken("[", {
  808. beforeExpr,
  809. startsExpr
  810. }),
  811. bracketHashL: createToken("#[", {
  812. beforeExpr,
  813. startsExpr
  814. }),
  815. bracketBarL: createToken("[|", {
  816. beforeExpr,
  817. startsExpr
  818. }),
  819. bracketR: createToken("]"),
  820. bracketBarR: createToken("|]"),
  821. braceL: createToken("{", {
  822. beforeExpr,
  823. startsExpr
  824. }),
  825. braceBarL: createToken("{|", {
  826. beforeExpr,
  827. startsExpr
  828. }),
  829. braceHashL: createToken("#{", {
  830. beforeExpr,
  831. startsExpr
  832. }),
  833. braceR: createToken("}"),
  834. braceBarR: createToken("|}"),
  835. parenL: createToken("(", {
  836. beforeExpr,
  837. startsExpr
  838. }),
  839. parenR: createToken(")"),
  840. comma: createToken(",", {
  841. beforeExpr
  842. }),
  843. semi: createToken(";", {
  844. beforeExpr
  845. }),
  846. colon: createToken(":", {
  847. beforeExpr
  848. }),
  849. doubleColon: createToken("::", {
  850. beforeExpr
  851. }),
  852. dot: createToken("."),
  853. question: createToken("?", {
  854. beforeExpr
  855. }),
  856. questionDot: createToken("?."),
  857. arrow: createToken("=>", {
  858. beforeExpr
  859. }),
  860. template: createToken("template"),
  861. ellipsis: createToken("...", {
  862. beforeExpr
  863. }),
  864. backQuote: createToken("`", {
  865. startsExpr
  866. }),
  867. dollarBraceL: createToken("${", {
  868. beforeExpr,
  869. startsExpr
  870. }),
  871. templateTail: createToken("...`", {
  872. startsExpr
  873. }),
  874. templateNonTail: createToken("...${", {
  875. beforeExpr,
  876. startsExpr
  877. }),
  878. at: createToken("@"),
  879. hash: createToken("#", {
  880. startsExpr
  881. }),
  882. interpreterDirective: createToken("#!..."),
  883. eq: createToken("=", {
  884. beforeExpr,
  885. isAssign
  886. }),
  887. assign: createToken("_=", {
  888. beforeExpr,
  889. isAssign
  890. }),
  891. slashAssign: createToken("_=", {
  892. beforeExpr,
  893. isAssign
  894. }),
  895. xorAssign: createToken("_=", {
  896. beforeExpr,
  897. isAssign
  898. }),
  899. moduloAssign: createToken("_=", {
  900. beforeExpr,
  901. isAssign
  902. }),
  903. incDec: createToken("++/--", {
  904. prefix,
  905. postfix,
  906. startsExpr
  907. }),
  908. bang: createToken("!", {
  909. beforeExpr,
  910. prefix,
  911. startsExpr
  912. }),
  913. tilde: createToken("~", {
  914. beforeExpr,
  915. prefix,
  916. startsExpr
  917. }),
  918. doubleCaret: createToken("^^", {
  919. startsExpr
  920. }),
  921. doubleAt: createToken("@@", {
  922. startsExpr
  923. }),
  924. pipeline: createBinop("|>", 0),
  925. nullishCoalescing: createBinop("??", 1),
  926. logicalOR: createBinop("||", 1),
  927. logicalAND: createBinop("&&", 2),
  928. bitwiseOR: createBinop("|", 3),
  929. bitwiseXOR: createBinop("^", 4),
  930. bitwiseAND: createBinop("&", 5),
  931. equality: createBinop("==/!=/===/!==", 6),
  932. lt: createBinop("</>/<=/>=", 7),
  933. gt: createBinop("</>/<=/>=", 7),
  934. relational: createBinop("</>/<=/>=", 7),
  935. bitShift: createBinop("<</>>/>>>", 8),
  936. bitShiftL: createBinop("<</>>/>>>", 8),
  937. bitShiftR: createBinop("<</>>/>>>", 8),
  938. plusMin: createToken("+/-", {
  939. beforeExpr,
  940. binop: 9,
  941. prefix,
  942. startsExpr
  943. }),
  944. modulo: createToken("%", {
  945. binop: 10,
  946. startsExpr
  947. }),
  948. star: createToken("*", {
  949. binop: 10
  950. }),
  951. slash: createBinop("/", 10),
  952. exponent: createToken("**", {
  953. beforeExpr,
  954. binop: 11,
  955. rightAssociative: true
  956. }),
  957. _in: createKeyword("in", {
  958. beforeExpr,
  959. binop: 7
  960. }),
  961. _instanceof: createKeyword("instanceof", {
  962. beforeExpr,
  963. binop: 7
  964. }),
  965. _break: createKeyword("break"),
  966. _case: createKeyword("case", {
  967. beforeExpr
  968. }),
  969. _catch: createKeyword("catch"),
  970. _continue: createKeyword("continue"),
  971. _debugger: createKeyword("debugger"),
  972. _default: createKeyword("default", {
  973. beforeExpr
  974. }),
  975. _else: createKeyword("else", {
  976. beforeExpr
  977. }),
  978. _finally: createKeyword("finally"),
  979. _function: createKeyword("function", {
  980. startsExpr
  981. }),
  982. _if: createKeyword("if"),
  983. _return: createKeyword("return", {
  984. beforeExpr
  985. }),
  986. _switch: createKeyword("switch"),
  987. _throw: createKeyword("throw", {
  988. beforeExpr,
  989. prefix,
  990. startsExpr
  991. }),
  992. _try: createKeyword("try"),
  993. _var: createKeyword("var"),
  994. _const: createKeyword("const"),
  995. _with: createKeyword("with"),
  996. _new: createKeyword("new", {
  997. beforeExpr,
  998. startsExpr
  999. }),
  1000. _this: createKeyword("this", {
  1001. startsExpr
  1002. }),
  1003. _super: createKeyword("super", {
  1004. startsExpr
  1005. }),
  1006. _class: createKeyword("class", {
  1007. startsExpr
  1008. }),
  1009. _extends: createKeyword("extends", {
  1010. beforeExpr
  1011. }),
  1012. _export: createKeyword("export"),
  1013. _import: createKeyword("import", {
  1014. startsExpr
  1015. }),
  1016. _null: createKeyword("null", {
  1017. startsExpr
  1018. }),
  1019. _true: createKeyword("true", {
  1020. startsExpr
  1021. }),
  1022. _false: createKeyword("false", {
  1023. startsExpr
  1024. }),
  1025. _typeof: createKeyword("typeof", {
  1026. beforeExpr,
  1027. prefix,
  1028. startsExpr
  1029. }),
  1030. _void: createKeyword("void", {
  1031. beforeExpr,
  1032. prefix,
  1033. startsExpr
  1034. }),
  1035. _delete: createKeyword("delete", {
  1036. beforeExpr,
  1037. prefix,
  1038. startsExpr
  1039. }),
  1040. _do: createKeyword("do", {
  1041. isLoop,
  1042. beforeExpr
  1043. }),
  1044. _for: createKeyword("for", {
  1045. isLoop
  1046. }),
  1047. _while: createKeyword("while", {
  1048. isLoop
  1049. }),
  1050. _as: createKeywordLike("as", {
  1051. startsExpr
  1052. }),
  1053. _assert: createKeywordLike("assert", {
  1054. startsExpr
  1055. }),
  1056. _async: createKeywordLike("async", {
  1057. startsExpr
  1058. }),
  1059. _await: createKeywordLike("await", {
  1060. startsExpr
  1061. }),
  1062. _from: createKeywordLike("from", {
  1063. startsExpr
  1064. }),
  1065. _get: createKeywordLike("get", {
  1066. startsExpr
  1067. }),
  1068. _let: createKeywordLike("let", {
  1069. startsExpr
  1070. }),
  1071. _meta: createKeywordLike("meta", {
  1072. startsExpr
  1073. }),
  1074. _of: createKeywordLike("of", {
  1075. startsExpr
  1076. }),
  1077. _sent: createKeywordLike("sent", {
  1078. startsExpr
  1079. }),
  1080. _set: createKeywordLike("set", {
  1081. startsExpr
  1082. }),
  1083. _static: createKeywordLike("static", {
  1084. startsExpr
  1085. }),
  1086. _yield: createKeywordLike("yield", {
  1087. startsExpr
  1088. }),
  1089. _asserts: createKeywordLike("asserts", {
  1090. startsExpr
  1091. }),
  1092. _checks: createKeywordLike("checks", {
  1093. startsExpr
  1094. }),
  1095. _exports: createKeywordLike("exports", {
  1096. startsExpr
  1097. }),
  1098. _global: createKeywordLike("global", {
  1099. startsExpr
  1100. }),
  1101. _implements: createKeywordLike("implements", {
  1102. startsExpr
  1103. }),
  1104. _intrinsic: createKeywordLike("intrinsic", {
  1105. startsExpr
  1106. }),
  1107. _infer: createKeywordLike("infer", {
  1108. startsExpr
  1109. }),
  1110. _is: createKeywordLike("is", {
  1111. startsExpr
  1112. }),
  1113. _mixins: createKeywordLike("mixins", {
  1114. startsExpr
  1115. }),
  1116. _proto: createKeywordLike("proto", {
  1117. startsExpr
  1118. }),
  1119. _require: createKeywordLike("require", {
  1120. startsExpr
  1121. }),
  1122. _keyof: createKeywordLike("keyof", {
  1123. startsExpr
  1124. }),
  1125. _readonly: createKeywordLike("readonly", {
  1126. startsExpr
  1127. }),
  1128. _unique: createKeywordLike("unique", {
  1129. startsExpr
  1130. }),
  1131. _abstract: createKeywordLike("abstract", {
  1132. startsExpr
  1133. }),
  1134. _declare: createKeywordLike("declare", {
  1135. startsExpr
  1136. }),
  1137. _enum: createKeywordLike("enum", {
  1138. startsExpr
  1139. }),
  1140. _module: createKeywordLike("module", {
  1141. startsExpr
  1142. }),
  1143. _namespace: createKeywordLike("namespace", {
  1144. startsExpr
  1145. }),
  1146. _interface: createKeywordLike("interface", {
  1147. startsExpr
  1148. }),
  1149. _type: createKeywordLike("type", {
  1150. startsExpr
  1151. }),
  1152. _opaque: createKeywordLike("opaque", {
  1153. startsExpr
  1154. }),
  1155. name: createToken("name", {
  1156. startsExpr
  1157. }),
  1158. string: createToken("string", {
  1159. startsExpr
  1160. }),
  1161. num: createToken("num", {
  1162. startsExpr
  1163. }),
  1164. bigint: createToken("bigint", {
  1165. startsExpr
  1166. }),
  1167. decimal: createToken("decimal", {
  1168. startsExpr
  1169. }),
  1170. regexp: createToken("regexp", {
  1171. startsExpr
  1172. }),
  1173. privateName: createToken("#name", {
  1174. startsExpr
  1175. }),
  1176. eof: createToken("eof"),
  1177. jsxName: createToken("jsxName"),
  1178. jsxText: createToken("jsxText", {
  1179. beforeExpr: true
  1180. }),
  1181. jsxTagStart: createToken("jsxTagStart", {
  1182. startsExpr: true
  1183. }),
  1184. jsxTagEnd: createToken("jsxTagEnd"),
  1185. placeholder: createToken("%%", {
  1186. startsExpr: true
  1187. })
  1188. };
  1189. function tokenIsIdentifier(token) {
  1190. return token >= 93 && token <= 128;
  1191. }
  1192. function tokenKeywordOrIdentifierIsKeyword(token) {
  1193. return token <= 92;
  1194. }
  1195. function tokenIsKeywordOrIdentifier(token) {
  1196. return token >= 58 && token <= 128;
  1197. }
  1198. function tokenIsLiteralPropertyName(token) {
  1199. return token >= 58 && token <= 132;
  1200. }
  1201. function tokenComesBeforeExpression(token) {
  1202. return tokenBeforeExprs[token];
  1203. }
  1204. function tokenCanStartExpression(token) {
  1205. return tokenStartsExprs[token];
  1206. }
  1207. function tokenIsAssignment(token) {
  1208. return token >= 29 && token <= 33;
  1209. }
  1210. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1211. return token >= 125 && token <= 127;
  1212. }
  1213. function tokenIsLoop(token) {
  1214. return token >= 90 && token <= 92;
  1215. }
  1216. function tokenIsKeyword(token) {
  1217. return token >= 58 && token <= 92;
  1218. }
  1219. function tokenIsOperator(token) {
  1220. return token >= 39 && token <= 59;
  1221. }
  1222. function tokenIsPostfix(token) {
  1223. return token === 34;
  1224. }
  1225. function tokenIsPrefix(token) {
  1226. return tokenPrefixes[token];
  1227. }
  1228. function tokenIsTSTypeOperator(token) {
  1229. return token >= 117 && token <= 119;
  1230. }
  1231. function tokenIsTSDeclarationStart(token) {
  1232. return token >= 120 && token <= 126;
  1233. }
  1234. function tokenLabelName(token) {
  1235. return tokenLabels[token];
  1236. }
  1237. function tokenOperatorPrecedence(token) {
  1238. return tokenBinops[token];
  1239. }
  1240. function tokenIsRightAssociative(token) {
  1241. return token === 57;
  1242. }
  1243. function tokenIsTemplate(token) {
  1244. return token >= 24 && token <= 25;
  1245. }
  1246. function getExportedToken(token) {
  1247. return tokenTypes[token];
  1248. }
  1249. {
  1250. tokenTypes[8].updateContext = context => {
  1251. context.pop();
  1252. };
  1253. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1254. context.push(types.brace);
  1255. };
  1256. tokenTypes[22].updateContext = context => {
  1257. if (context[context.length - 1] === types.template) {
  1258. context.pop();
  1259. } else {
  1260. context.push(types.template);
  1261. }
  1262. };
  1263. tokenTypes[138].updateContext = context => {
  1264. context.push(types.j_expr, types.j_oTag);
  1265. };
  1266. }
  1267. 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";
  1268. 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\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-\u0ecd\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";
  1269. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1270. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1271. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1272. 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, 85, 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, 190, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1070, 4050, 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, 46, 2, 18, 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, 482, 44, 11, 6, 17, 0, 322, 29, 19, 43, 1269, 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, 4152, 8, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938];
  1273. 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, 154, 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, 161, 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, 19306, 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, 262, 6, 10, 9, 357, 0, 62, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1274. function isInAstralSet(code, set) {
  1275. let pos = 0x10000;
  1276. for (let i = 0, length = set.length; i < length; i += 2) {
  1277. pos += set[i];
  1278. if (pos > code) return false;
  1279. pos += set[i + 1];
  1280. if (pos >= code) return true;
  1281. }
  1282. return false;
  1283. }
  1284. function isIdentifierStart(code) {
  1285. if (code < 65) return code === 36;
  1286. if (code <= 90) return true;
  1287. if (code < 97) return code === 95;
  1288. if (code <= 122) return true;
  1289. if (code <= 0xffff) {
  1290. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1291. }
  1292. return isInAstralSet(code, astralIdentifierStartCodes);
  1293. }
  1294. function isIdentifierChar(code) {
  1295. if (code < 48) return code === 36;
  1296. if (code < 58) return true;
  1297. if (code < 65) return false;
  1298. if (code <= 90) return true;
  1299. if (code < 97) return code === 95;
  1300. if (code <= 122) return true;
  1301. if (code <= 0xffff) {
  1302. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1303. }
  1304. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1305. }
  1306. const reservedWords = {
  1307. 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"],
  1308. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1309. strictBind: ["eval", "arguments"]
  1310. };
  1311. const keywords = new Set(reservedWords.keyword);
  1312. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1313. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1314. function isReservedWord(word, inModule) {
  1315. return inModule && word === "await" || word === "enum";
  1316. }
  1317. function isStrictReservedWord(word, inModule) {
  1318. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1319. }
  1320. function isStrictBindOnlyReservedWord(word) {
  1321. return reservedWordsStrictBindSet.has(word);
  1322. }
  1323. function isStrictBindReservedWord(word, inModule) {
  1324. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1325. }
  1326. function isKeyword(word) {
  1327. return keywords.has(word);
  1328. }
  1329. function isIteratorStart(current, next, next2) {
  1330. return current === 64 && next === 64 && isIdentifierStart(next2);
  1331. }
  1332. const reservedWordLikeSet = new Set(["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete", "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield", "eval", "arguments", "enum", "await"]);
  1333. function canBeReservedWord(word) {
  1334. return reservedWordLikeSet.has(word);
  1335. }
  1336. const SCOPE_OTHER = 0b000000000,
  1337. SCOPE_PROGRAM = 0b000000001,
  1338. SCOPE_FUNCTION = 0b000000010,
  1339. SCOPE_ARROW = 0b000000100,
  1340. SCOPE_SIMPLE_CATCH = 0b000001000,
  1341. SCOPE_SUPER = 0b000010000,
  1342. SCOPE_DIRECT_SUPER = 0b000100000,
  1343. SCOPE_CLASS = 0b001000000,
  1344. SCOPE_STATIC_BLOCK = 0b010000000,
  1345. SCOPE_TS_MODULE = 0b100000000,
  1346. SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_TS_MODULE;
  1347. const BIND_KIND_VALUE = 0b000000000001,
  1348. BIND_KIND_TYPE = 0b000000000010,
  1349. BIND_SCOPE_VAR = 0b000000000100,
  1350. BIND_SCOPE_LEXICAL = 0b000000001000,
  1351. BIND_SCOPE_FUNCTION = 0b000000010000,
  1352. BIND_FLAGS_NONE = 0b000001000000,
  1353. BIND_FLAGS_CLASS = 0b000010000000,
  1354. BIND_FLAGS_TS_ENUM = 0b000100000000,
  1355. BIND_FLAGS_TS_CONST_ENUM = 0b001000000000,
  1356. BIND_FLAGS_TS_EXPORT_ONLY = 0b010000000000,
  1357. BIND_FLAGS_FLOW_DECLARE_FN = 0b100000000000;
  1358. const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS,
  1359. BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0,
  1360. BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0,
  1361. BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0,
  1362. BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS,
  1363. BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0,
  1364. BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM,
  1365. BIND_TS_AMBIENT = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1366. BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE,
  1367. BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE,
  1368. BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM,
  1369. BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1370. BIND_FLOW_DECLARE_FN = BIND_FLAGS_FLOW_DECLARE_FN;
  1371. const CLASS_ELEMENT_FLAG_STATIC = 0b100,
  1372. CLASS_ELEMENT_KIND_GETTER = 0b010,
  1373. CLASS_ELEMENT_KIND_SETTER = 0b001,
  1374. CLASS_ELEMENT_KIND_ACCESSOR = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_KIND_SETTER;
  1375. const CLASS_ELEMENT_STATIC_GETTER = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_FLAG_STATIC,
  1376. CLASS_ELEMENT_STATIC_SETTER = CLASS_ELEMENT_KIND_SETTER | CLASS_ELEMENT_FLAG_STATIC,
  1377. CLASS_ELEMENT_INSTANCE_GETTER = CLASS_ELEMENT_KIND_GETTER,
  1378. CLASS_ELEMENT_INSTANCE_SETTER = CLASS_ELEMENT_KIND_SETTER,
  1379. CLASS_ELEMENT_OTHER = 0;
  1380. class BaseParser {
  1381. constructor() {
  1382. this.sawUnambiguousESM = false;
  1383. this.ambiguousScriptDifferentAst = false;
  1384. }
  1385. hasPlugin(pluginConfig) {
  1386. if (typeof pluginConfig === "string") {
  1387. return this.plugins.has(pluginConfig);
  1388. } else {
  1389. const [pluginName, pluginOptions] = pluginConfig;
  1390. if (!this.hasPlugin(pluginName)) {
  1391. return false;
  1392. }
  1393. const actualOptions = this.plugins.get(pluginName);
  1394. for (const key of Object.keys(pluginOptions)) {
  1395. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1396. return false;
  1397. }
  1398. }
  1399. return true;
  1400. }
  1401. }
  1402. getPluginOption(plugin, name) {
  1403. var _this$plugins$get;
  1404. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1405. }
  1406. }
  1407. function setTrailingComments(node, comments) {
  1408. if (node.trailingComments === undefined) {
  1409. node.trailingComments = comments;
  1410. } else {
  1411. node.trailingComments.unshift(...comments);
  1412. }
  1413. }
  1414. function setLeadingComments(node, comments) {
  1415. if (node.leadingComments === undefined) {
  1416. node.leadingComments = comments;
  1417. } else {
  1418. node.leadingComments.unshift(...comments);
  1419. }
  1420. }
  1421. function setInnerComments(node, comments) {
  1422. if (node.innerComments === undefined) {
  1423. node.innerComments = comments;
  1424. } else {
  1425. node.innerComments.unshift(...comments);
  1426. }
  1427. }
  1428. function adjustInnerComments(node, elements, commentWS) {
  1429. let lastElement = null;
  1430. let i = elements.length;
  1431. while (lastElement === null && i > 0) {
  1432. lastElement = elements[--i];
  1433. }
  1434. if (lastElement === null || lastElement.start > commentWS.start) {
  1435. setInnerComments(node, commentWS.comments);
  1436. } else {
  1437. setTrailingComments(lastElement, commentWS.comments);
  1438. }
  1439. }
  1440. class CommentsParser extends BaseParser {
  1441. addComment(comment) {
  1442. if (this.filename) comment.loc.filename = this.filename;
  1443. this.state.comments.push(comment);
  1444. }
  1445. processComment(node) {
  1446. const {
  1447. commentStack
  1448. } = this.state;
  1449. const commentStackLength = commentStack.length;
  1450. if (commentStackLength === 0) return;
  1451. let i = commentStackLength - 1;
  1452. const lastCommentWS = commentStack[i];
  1453. if (lastCommentWS.start === node.end) {
  1454. lastCommentWS.leadingNode = node;
  1455. i--;
  1456. }
  1457. const {
  1458. start: nodeStart
  1459. } = node;
  1460. for (; i >= 0; i--) {
  1461. const commentWS = commentStack[i];
  1462. const commentEnd = commentWS.end;
  1463. if (commentEnd > nodeStart) {
  1464. commentWS.containingNode = node;
  1465. this.finalizeComment(commentWS);
  1466. commentStack.splice(i, 1);
  1467. } else {
  1468. if (commentEnd === nodeStart) {
  1469. commentWS.trailingNode = node;
  1470. }
  1471. break;
  1472. }
  1473. }
  1474. }
  1475. finalizeComment(commentWS) {
  1476. const {
  1477. comments
  1478. } = commentWS;
  1479. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1480. if (commentWS.leadingNode !== null) {
  1481. setTrailingComments(commentWS.leadingNode, comments);
  1482. }
  1483. if (commentWS.trailingNode !== null) {
  1484. setLeadingComments(commentWS.trailingNode, comments);
  1485. }
  1486. } else {
  1487. const {
  1488. containingNode: node,
  1489. start: commentStart
  1490. } = commentWS;
  1491. if (this.input.charCodeAt(commentStart - 1) === 44) {
  1492. switch (node.type) {
  1493. case "ObjectExpression":
  1494. case "ObjectPattern":
  1495. case "RecordExpression":
  1496. adjustInnerComments(node, node.properties, commentWS);
  1497. break;
  1498. case "CallExpression":
  1499. case "OptionalCallExpression":
  1500. adjustInnerComments(node, node.arguments, commentWS);
  1501. break;
  1502. case "FunctionDeclaration":
  1503. case "FunctionExpression":
  1504. case "ArrowFunctionExpression":
  1505. case "ObjectMethod":
  1506. case "ClassMethod":
  1507. case "ClassPrivateMethod":
  1508. adjustInnerComments(node, node.params, commentWS);
  1509. break;
  1510. case "ArrayExpression":
  1511. case "ArrayPattern":
  1512. case "TupleExpression":
  1513. adjustInnerComments(node, node.elements, commentWS);
  1514. break;
  1515. case "ExportNamedDeclaration":
  1516. case "ImportDeclaration":
  1517. adjustInnerComments(node, node.specifiers, commentWS);
  1518. break;
  1519. default:
  1520. {
  1521. setInnerComments(node, comments);
  1522. }
  1523. }
  1524. } else {
  1525. setInnerComments(node, comments);
  1526. }
  1527. }
  1528. }
  1529. finalizeRemainingComments() {
  1530. const {
  1531. commentStack
  1532. } = this.state;
  1533. for (let i = commentStack.length - 1; i >= 0; i--) {
  1534. this.finalizeComment(commentStack[i]);
  1535. }
  1536. this.state.commentStack = [];
  1537. }
  1538. resetPreviousNodeTrailingComments(node) {
  1539. const {
  1540. commentStack
  1541. } = this.state;
  1542. const {
  1543. length
  1544. } = commentStack;
  1545. if (length === 0) return;
  1546. const commentWS = commentStack[length - 1];
  1547. if (commentWS.leadingNode === node) {
  1548. commentWS.leadingNode = null;
  1549. }
  1550. }
  1551. takeSurroundingComments(node, start, end) {
  1552. const {
  1553. commentStack
  1554. } = this.state;
  1555. const commentStackLength = commentStack.length;
  1556. if (commentStackLength === 0) return;
  1557. let i = commentStackLength - 1;
  1558. for (; i >= 0; i--) {
  1559. const commentWS = commentStack[i];
  1560. const commentEnd = commentWS.end;
  1561. const commentStart = commentWS.start;
  1562. if (commentStart === end) {
  1563. commentWS.leadingNode = node;
  1564. } else if (commentEnd === start) {
  1565. commentWS.trailingNode = node;
  1566. } else if (commentEnd < start) {
  1567. break;
  1568. }
  1569. }
  1570. }
  1571. }
  1572. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  1573. const lineBreakG = new RegExp(lineBreak.source, "g");
  1574. function isNewLine(code) {
  1575. switch (code) {
  1576. case 10:
  1577. case 13:
  1578. case 8232:
  1579. case 8233:
  1580. return true;
  1581. default:
  1582. return false;
  1583. }
  1584. }
  1585. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1586. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/y;
  1587. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  1588. function isWhitespace(code) {
  1589. switch (code) {
  1590. case 0x0009:
  1591. case 0x000b:
  1592. case 0x000c:
  1593. case 32:
  1594. case 160:
  1595. case 5760:
  1596. case 0x2000:
  1597. case 0x2001:
  1598. case 0x2002:
  1599. case 0x2003:
  1600. case 0x2004:
  1601. case 0x2005:
  1602. case 0x2006:
  1603. case 0x2007:
  1604. case 0x2008:
  1605. case 0x2009:
  1606. case 0x200a:
  1607. case 0x202f:
  1608. case 0x205f:
  1609. case 0x3000:
  1610. case 0xfeff:
  1611. return true;
  1612. default:
  1613. return false;
  1614. }
  1615. }
  1616. class State {
  1617. constructor() {
  1618. this.strict = void 0;
  1619. this.curLine = void 0;
  1620. this.lineStart = void 0;
  1621. this.startLoc = void 0;
  1622. this.endLoc = void 0;
  1623. this.errors = [];
  1624. this.potentialArrowAt = -1;
  1625. this.noArrowAt = [];
  1626. this.noArrowParamsConversionAt = [];
  1627. this.maybeInArrowParameters = false;
  1628. this.inType = false;
  1629. this.noAnonFunctionType = false;
  1630. this.hasFlowComment = false;
  1631. this.isAmbientContext = false;
  1632. this.inAbstractClass = false;
  1633. this.inDisallowConditionalTypesContext = false;
  1634. this.topicContext = {
  1635. maxNumOfResolvableTopics: 0,
  1636. maxTopicIndex: null
  1637. };
  1638. this.soloAwait = false;
  1639. this.inFSharpPipelineDirectBody = false;
  1640. this.labels = [];
  1641. this.decoratorStack = [[]];
  1642. this.comments = [];
  1643. this.commentStack = [];
  1644. this.pos = 0;
  1645. this.type = 135;
  1646. this.value = null;
  1647. this.start = 0;
  1648. this.end = 0;
  1649. this.lastTokEndLoc = null;
  1650. this.lastTokStartLoc = null;
  1651. this.lastTokStart = 0;
  1652. this.context = [types.brace];
  1653. this.canStartJSXElement = true;
  1654. this.containsEsc = false;
  1655. this.strictErrors = new Map();
  1656. this.tokensLength = 0;
  1657. }
  1658. init({
  1659. strictMode,
  1660. sourceType,
  1661. startLine,
  1662. startColumn
  1663. }) {
  1664. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1665. this.curLine = startLine;
  1666. this.lineStart = -startColumn;
  1667. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  1668. }
  1669. curPosition() {
  1670. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  1671. }
  1672. clone(skipArrays) {
  1673. const state = new State();
  1674. const keys = Object.keys(this);
  1675. for (let i = 0, length = keys.length; i < length; i++) {
  1676. const key = keys[i];
  1677. let val = this[key];
  1678. if (!skipArrays && Array.isArray(val)) {
  1679. val = val.slice();
  1680. }
  1681. state[key] = val;
  1682. }
  1683. return state;
  1684. }
  1685. }
  1686. const _excluded = ["at"],
  1687. _excluded2 = ["at"];
  1688. var _isDigit = function isDigit(code) {
  1689. return code >= 48 && code <= 57;
  1690. };
  1691. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  1692. const forbiddenNumericSeparatorSiblings = {
  1693. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  1694. hex: new Set([46, 88, 95, 120])
  1695. };
  1696. const isAllowedNumericSeparatorSibling = {
  1697. bin: ch => ch === 48 || ch === 49,
  1698. oct: ch => ch >= 48 && ch <= 55,
  1699. dec: ch => ch >= 48 && ch <= 57,
  1700. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  1701. };
  1702. class Token {
  1703. constructor(state) {
  1704. this.type = state.type;
  1705. this.value = state.value;
  1706. this.start = state.start;
  1707. this.end = state.end;
  1708. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  1709. }
  1710. }
  1711. class Tokenizer extends CommentsParser {
  1712. constructor(options, input) {
  1713. super();
  1714. this.isLookahead = void 0;
  1715. this.tokens = [];
  1716. this.state = new State();
  1717. this.state.init(options);
  1718. this.input = input;
  1719. this.length = input.length;
  1720. this.isLookahead = false;
  1721. }
  1722. pushToken(token) {
  1723. this.tokens.length = this.state.tokensLength;
  1724. this.tokens.push(token);
  1725. ++this.state.tokensLength;
  1726. }
  1727. next() {
  1728. this.checkKeywordEscapes();
  1729. if (this.options.tokens) {
  1730. this.pushToken(new Token(this.state));
  1731. }
  1732. this.state.lastTokStart = this.state.start;
  1733. this.state.lastTokEndLoc = this.state.endLoc;
  1734. this.state.lastTokStartLoc = this.state.startLoc;
  1735. this.nextToken();
  1736. }
  1737. eat(type) {
  1738. if (this.match(type)) {
  1739. this.next();
  1740. return true;
  1741. } else {
  1742. return false;
  1743. }
  1744. }
  1745. match(type) {
  1746. return this.state.type === type;
  1747. }
  1748. createLookaheadState(state) {
  1749. return {
  1750. pos: state.pos,
  1751. value: null,
  1752. type: state.type,
  1753. start: state.start,
  1754. end: state.end,
  1755. context: [this.curContext()],
  1756. inType: state.inType,
  1757. startLoc: state.startLoc,
  1758. lastTokEndLoc: state.lastTokEndLoc,
  1759. curLine: state.curLine,
  1760. lineStart: state.lineStart,
  1761. curPosition: state.curPosition
  1762. };
  1763. }
  1764. lookahead() {
  1765. const old = this.state;
  1766. this.state = this.createLookaheadState(old);
  1767. this.isLookahead = true;
  1768. this.nextToken();
  1769. this.isLookahead = false;
  1770. const curr = this.state;
  1771. this.state = old;
  1772. return curr;
  1773. }
  1774. nextTokenStart() {
  1775. return this.nextTokenStartSince(this.state.pos);
  1776. }
  1777. nextTokenStartSince(pos) {
  1778. skipWhiteSpace.lastIndex = pos;
  1779. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  1780. }
  1781. lookaheadCharCode() {
  1782. return this.input.charCodeAt(this.nextTokenStart());
  1783. }
  1784. codePointAtPos(pos) {
  1785. let cp = this.input.charCodeAt(pos);
  1786. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  1787. const trail = this.input.charCodeAt(pos);
  1788. if ((trail & 0xfc00) === 0xdc00) {
  1789. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  1790. }
  1791. }
  1792. return cp;
  1793. }
  1794. setStrict(strict) {
  1795. this.state.strict = strict;
  1796. if (strict) {
  1797. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
  1798. at
  1799. }));
  1800. this.state.strictErrors.clear();
  1801. }
  1802. }
  1803. curContext() {
  1804. return this.state.context[this.state.context.length - 1];
  1805. }
  1806. nextToken() {
  1807. this.skipSpace();
  1808. this.state.start = this.state.pos;
  1809. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  1810. if (this.state.pos >= this.length) {
  1811. this.finishToken(135);
  1812. return;
  1813. }
  1814. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  1815. }
  1816. skipBlockComment() {
  1817. let startLoc;
  1818. if (!this.isLookahead) startLoc = this.state.curPosition();
  1819. const start = this.state.pos;
  1820. const end = this.input.indexOf("*/", start + 2);
  1821. if (end === -1) {
  1822. throw this.raise(Errors.UnterminatedComment, {
  1823. at: this.state.curPosition()
  1824. });
  1825. }
  1826. this.state.pos = end + 2;
  1827. lineBreakG.lastIndex = start + 2;
  1828. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  1829. ++this.state.curLine;
  1830. this.state.lineStart = lineBreakG.lastIndex;
  1831. }
  1832. if (this.isLookahead) return;
  1833. const comment = {
  1834. type: "CommentBlock",
  1835. value: this.input.slice(start + 2, end),
  1836. start,
  1837. end: end + 2,
  1838. loc: new SourceLocation(startLoc, this.state.curPosition())
  1839. };
  1840. if (this.options.tokens) this.pushToken(comment);
  1841. return comment;
  1842. }
  1843. skipLineComment(startSkip) {
  1844. const start = this.state.pos;
  1845. let startLoc;
  1846. if (!this.isLookahead) startLoc = this.state.curPosition();
  1847. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  1848. if (this.state.pos < this.length) {
  1849. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  1850. ch = this.input.charCodeAt(this.state.pos);
  1851. }
  1852. }
  1853. if (this.isLookahead) return;
  1854. const end = this.state.pos;
  1855. const value = this.input.slice(start + startSkip, end);
  1856. const comment = {
  1857. type: "CommentLine",
  1858. value,
  1859. start,
  1860. end,
  1861. loc: new SourceLocation(startLoc, this.state.curPosition())
  1862. };
  1863. if (this.options.tokens) this.pushToken(comment);
  1864. return comment;
  1865. }
  1866. skipSpace() {
  1867. const spaceStart = this.state.pos;
  1868. const comments = [];
  1869. loop: while (this.state.pos < this.length) {
  1870. const ch = this.input.charCodeAt(this.state.pos);
  1871. switch (ch) {
  1872. case 32:
  1873. case 160:
  1874. case 9:
  1875. ++this.state.pos;
  1876. break;
  1877. case 13:
  1878. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  1879. ++this.state.pos;
  1880. }
  1881. case 10:
  1882. case 8232:
  1883. case 8233:
  1884. ++this.state.pos;
  1885. ++this.state.curLine;
  1886. this.state.lineStart = this.state.pos;
  1887. break;
  1888. case 47:
  1889. switch (this.input.charCodeAt(this.state.pos + 1)) {
  1890. case 42:
  1891. {
  1892. const comment = this.skipBlockComment();
  1893. if (comment !== undefined) {
  1894. this.addComment(comment);
  1895. if (this.options.attachComment) comments.push(comment);
  1896. }
  1897. break;
  1898. }
  1899. case 47:
  1900. {
  1901. const comment = this.skipLineComment(2);
  1902. if (comment !== undefined) {
  1903. this.addComment(comment);
  1904. if (this.options.attachComment) comments.push(comment);
  1905. }
  1906. break;
  1907. }
  1908. default:
  1909. break loop;
  1910. }
  1911. break;
  1912. default:
  1913. if (isWhitespace(ch)) {
  1914. ++this.state.pos;
  1915. } else if (ch === 45 && !this.inModule) {
  1916. const pos = this.state.pos;
  1917. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  1918. const comment = this.skipLineComment(3);
  1919. if (comment !== undefined) {
  1920. this.addComment(comment);
  1921. if (this.options.attachComment) comments.push(comment);
  1922. }
  1923. } else {
  1924. break loop;
  1925. }
  1926. } else if (ch === 60 && !this.inModule) {
  1927. const pos = this.state.pos;
  1928. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  1929. const comment = this.skipLineComment(4);
  1930. if (comment !== undefined) {
  1931. this.addComment(comment);
  1932. if (this.options.attachComment) comments.push(comment);
  1933. }
  1934. } else {
  1935. break loop;
  1936. }
  1937. } else {
  1938. break loop;
  1939. }
  1940. }
  1941. }
  1942. if (comments.length > 0) {
  1943. const end = this.state.pos;
  1944. const CommentWhitespace = {
  1945. start: spaceStart,
  1946. end,
  1947. comments,
  1948. leadingNode: null,
  1949. trailingNode: null,
  1950. containingNode: null
  1951. };
  1952. this.state.commentStack.push(CommentWhitespace);
  1953. }
  1954. }
  1955. finishToken(type, val) {
  1956. this.state.end = this.state.pos;
  1957. this.state.endLoc = this.state.curPosition();
  1958. const prevType = this.state.type;
  1959. this.state.type = type;
  1960. this.state.value = val;
  1961. if (!this.isLookahead) {
  1962. this.updateContext(prevType);
  1963. }
  1964. }
  1965. replaceToken(type) {
  1966. this.state.type = type;
  1967. this.updateContext();
  1968. }
  1969. readToken_numberSign() {
  1970. if (this.state.pos === 0 && this.readToken_interpreter()) {
  1971. return;
  1972. }
  1973. const nextPos = this.state.pos + 1;
  1974. const next = this.codePointAtPos(nextPos);
  1975. if (next >= 48 && next <= 57) {
  1976. throw this.raise(Errors.UnexpectedDigitAfterHash, {
  1977. at: this.state.curPosition()
  1978. });
  1979. }
  1980. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  1981. this.expectPlugin("recordAndTuple");
  1982. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "hash") {
  1983. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
  1984. at: this.state.curPosition()
  1985. });
  1986. }
  1987. this.state.pos += 2;
  1988. if (next === 123) {
  1989. this.finishToken(7);
  1990. } else {
  1991. this.finishToken(1);
  1992. }
  1993. } else if (isIdentifierStart(next)) {
  1994. ++this.state.pos;
  1995. this.finishToken(134, this.readWord1(next));
  1996. } else if (next === 92) {
  1997. ++this.state.pos;
  1998. this.finishToken(134, this.readWord1());
  1999. } else {
  2000. this.finishOp(27, 1);
  2001. }
  2002. }
  2003. readToken_dot() {
  2004. const next = this.input.charCodeAt(this.state.pos + 1);
  2005. if (next >= 48 && next <= 57) {
  2006. this.readNumber(true);
  2007. return;
  2008. }
  2009. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2010. this.state.pos += 3;
  2011. this.finishToken(21);
  2012. } else {
  2013. ++this.state.pos;
  2014. this.finishToken(16);
  2015. }
  2016. }
  2017. readToken_slash() {
  2018. const next = this.input.charCodeAt(this.state.pos + 1);
  2019. if (next === 61) {
  2020. this.finishOp(31, 2);
  2021. } else {
  2022. this.finishOp(56, 1);
  2023. }
  2024. }
  2025. readToken_interpreter() {
  2026. if (this.state.pos !== 0 || this.length < 2) return false;
  2027. let ch = this.input.charCodeAt(this.state.pos + 1);
  2028. if (ch !== 33) return false;
  2029. const start = this.state.pos;
  2030. this.state.pos += 1;
  2031. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2032. ch = this.input.charCodeAt(this.state.pos);
  2033. }
  2034. const value = this.input.slice(start + 2, this.state.pos);
  2035. this.finishToken(28, value);
  2036. return true;
  2037. }
  2038. readToken_mult_modulo(code) {
  2039. let type = code === 42 ? 55 : 54;
  2040. let width = 1;
  2041. let next = this.input.charCodeAt(this.state.pos + 1);
  2042. if (code === 42 && next === 42) {
  2043. width++;
  2044. next = this.input.charCodeAt(this.state.pos + 2);
  2045. type = 57;
  2046. }
  2047. if (next === 61 && !this.state.inType) {
  2048. width++;
  2049. type = code === 37 ? 33 : 30;
  2050. }
  2051. this.finishOp(type, width);
  2052. }
  2053. readToken_pipe_amp(code) {
  2054. const next = this.input.charCodeAt(this.state.pos + 1);
  2055. if (next === code) {
  2056. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2057. this.finishOp(30, 3);
  2058. } else {
  2059. this.finishOp(code === 124 ? 41 : 42, 2);
  2060. }
  2061. return;
  2062. }
  2063. if (code === 124) {
  2064. if (next === 62) {
  2065. this.finishOp(39, 2);
  2066. return;
  2067. }
  2068. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2069. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2070. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
  2071. at: this.state.curPosition()
  2072. });
  2073. }
  2074. this.state.pos += 2;
  2075. this.finishToken(9);
  2076. return;
  2077. }
  2078. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2079. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2080. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
  2081. at: this.state.curPosition()
  2082. });
  2083. }
  2084. this.state.pos += 2;
  2085. this.finishToken(4);
  2086. return;
  2087. }
  2088. }
  2089. if (next === 61) {
  2090. this.finishOp(30, 2);
  2091. return;
  2092. }
  2093. this.finishOp(code === 124 ? 43 : 45, 1);
  2094. }
  2095. readToken_caret() {
  2096. const next = this.input.charCodeAt(this.state.pos + 1);
  2097. if (next === 61 && !this.state.inType) {
  2098. this.finishOp(32, 2);
  2099. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2100. proposal: "hack",
  2101. topicToken: "^^"
  2102. }])) {
  2103. this.finishOp(37, 2);
  2104. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2105. if (lookaheadCh === 94) {
  2106. throw this.unexpected();
  2107. }
  2108. } else {
  2109. this.finishOp(44, 1);
  2110. }
  2111. }
  2112. readToken_atSign() {
  2113. const next = this.input.charCodeAt(this.state.pos + 1);
  2114. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2115. proposal: "hack",
  2116. topicToken: "@@"
  2117. }])) {
  2118. this.finishOp(38, 2);
  2119. } else {
  2120. this.finishOp(26, 1);
  2121. }
  2122. }
  2123. readToken_plus_min(code) {
  2124. const next = this.input.charCodeAt(this.state.pos + 1);
  2125. if (next === code) {
  2126. this.finishOp(34, 2);
  2127. return;
  2128. }
  2129. if (next === 61) {
  2130. this.finishOp(30, 2);
  2131. } else {
  2132. this.finishOp(53, 1);
  2133. }
  2134. }
  2135. readToken_lt() {
  2136. const {
  2137. pos
  2138. } = this.state;
  2139. const next = this.input.charCodeAt(pos + 1);
  2140. if (next === 60) {
  2141. if (this.input.charCodeAt(pos + 2) === 61) {
  2142. this.finishOp(30, 3);
  2143. return;
  2144. }
  2145. this.finishOp(51, 2);
  2146. return;
  2147. }
  2148. if (next === 61) {
  2149. this.finishOp(49, 2);
  2150. return;
  2151. }
  2152. this.finishOp(47, 1);
  2153. }
  2154. readToken_gt() {
  2155. const {
  2156. pos
  2157. } = this.state;
  2158. const next = this.input.charCodeAt(pos + 1);
  2159. if (next === 62) {
  2160. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2161. if (this.input.charCodeAt(pos + size) === 61) {
  2162. this.finishOp(30, size + 1);
  2163. return;
  2164. }
  2165. this.finishOp(52, size);
  2166. return;
  2167. }
  2168. if (next === 61) {
  2169. this.finishOp(49, 2);
  2170. return;
  2171. }
  2172. this.finishOp(48, 1);
  2173. }
  2174. readToken_eq_excl(code) {
  2175. const next = this.input.charCodeAt(this.state.pos + 1);
  2176. if (next === 61) {
  2177. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2178. return;
  2179. }
  2180. if (code === 61 && next === 62) {
  2181. this.state.pos += 2;
  2182. this.finishToken(19);
  2183. return;
  2184. }
  2185. this.finishOp(code === 61 ? 29 : 35, 1);
  2186. }
  2187. readToken_question() {
  2188. const next = this.input.charCodeAt(this.state.pos + 1);
  2189. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2190. if (next === 63) {
  2191. if (next2 === 61) {
  2192. this.finishOp(30, 3);
  2193. } else {
  2194. this.finishOp(40, 2);
  2195. }
  2196. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2197. this.state.pos += 2;
  2198. this.finishToken(18);
  2199. } else {
  2200. ++this.state.pos;
  2201. this.finishToken(17);
  2202. }
  2203. }
  2204. getTokenFromCode(code) {
  2205. switch (code) {
  2206. case 46:
  2207. this.readToken_dot();
  2208. return;
  2209. case 40:
  2210. ++this.state.pos;
  2211. this.finishToken(10);
  2212. return;
  2213. case 41:
  2214. ++this.state.pos;
  2215. this.finishToken(11);
  2216. return;
  2217. case 59:
  2218. ++this.state.pos;
  2219. this.finishToken(13);
  2220. return;
  2221. case 44:
  2222. ++this.state.pos;
  2223. this.finishToken(12);
  2224. return;
  2225. case 91:
  2226. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2227. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2228. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
  2229. at: this.state.curPosition()
  2230. });
  2231. }
  2232. this.state.pos += 2;
  2233. this.finishToken(2);
  2234. } else {
  2235. ++this.state.pos;
  2236. this.finishToken(0);
  2237. }
  2238. return;
  2239. case 93:
  2240. ++this.state.pos;
  2241. this.finishToken(3);
  2242. return;
  2243. case 123:
  2244. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2245. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2246. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
  2247. at: this.state.curPosition()
  2248. });
  2249. }
  2250. this.state.pos += 2;
  2251. this.finishToken(6);
  2252. } else {
  2253. ++this.state.pos;
  2254. this.finishToken(5);
  2255. }
  2256. return;
  2257. case 125:
  2258. ++this.state.pos;
  2259. this.finishToken(8);
  2260. return;
  2261. case 58:
  2262. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2263. this.finishOp(15, 2);
  2264. } else {
  2265. ++this.state.pos;
  2266. this.finishToken(14);
  2267. }
  2268. return;
  2269. case 63:
  2270. this.readToken_question();
  2271. return;
  2272. case 96:
  2273. this.readTemplateToken();
  2274. return;
  2275. case 48:
  2276. {
  2277. const next = this.input.charCodeAt(this.state.pos + 1);
  2278. if (next === 120 || next === 88) {
  2279. this.readRadixNumber(16);
  2280. return;
  2281. }
  2282. if (next === 111 || next === 79) {
  2283. this.readRadixNumber(8);
  2284. return;
  2285. }
  2286. if (next === 98 || next === 66) {
  2287. this.readRadixNumber(2);
  2288. return;
  2289. }
  2290. }
  2291. case 49:
  2292. case 50:
  2293. case 51:
  2294. case 52:
  2295. case 53:
  2296. case 54:
  2297. case 55:
  2298. case 56:
  2299. case 57:
  2300. this.readNumber(false);
  2301. return;
  2302. case 34:
  2303. case 39:
  2304. this.readString(code);
  2305. return;
  2306. case 47:
  2307. this.readToken_slash();
  2308. return;
  2309. case 37:
  2310. case 42:
  2311. this.readToken_mult_modulo(code);
  2312. return;
  2313. case 124:
  2314. case 38:
  2315. this.readToken_pipe_amp(code);
  2316. return;
  2317. case 94:
  2318. this.readToken_caret();
  2319. return;
  2320. case 43:
  2321. case 45:
  2322. this.readToken_plus_min(code);
  2323. return;
  2324. case 60:
  2325. this.readToken_lt();
  2326. return;
  2327. case 62:
  2328. this.readToken_gt();
  2329. return;
  2330. case 61:
  2331. case 33:
  2332. this.readToken_eq_excl(code);
  2333. return;
  2334. case 126:
  2335. this.finishOp(36, 1);
  2336. return;
  2337. case 64:
  2338. this.readToken_atSign();
  2339. return;
  2340. case 35:
  2341. this.readToken_numberSign();
  2342. return;
  2343. case 92:
  2344. this.readWord();
  2345. return;
  2346. default:
  2347. if (isIdentifierStart(code)) {
  2348. this.readWord(code);
  2349. return;
  2350. }
  2351. }
  2352. throw this.raise(Errors.InvalidOrUnexpectedToken, {
  2353. at: this.state.curPosition(),
  2354. unexpected: String.fromCodePoint(code)
  2355. });
  2356. }
  2357. finishOp(type, size) {
  2358. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2359. this.state.pos += size;
  2360. this.finishToken(type, str);
  2361. }
  2362. readRegexp() {
  2363. const startLoc = this.state.startLoc;
  2364. const start = this.state.start + 1;
  2365. let escaped, inClass;
  2366. let {
  2367. pos
  2368. } = this.state;
  2369. for (;; ++pos) {
  2370. if (pos >= this.length) {
  2371. throw this.raise(Errors.UnterminatedRegExp, {
  2372. at: createPositionWithColumnOffset(startLoc, 1)
  2373. });
  2374. }
  2375. const ch = this.input.charCodeAt(pos);
  2376. if (isNewLine(ch)) {
  2377. throw this.raise(Errors.UnterminatedRegExp, {
  2378. at: createPositionWithColumnOffset(startLoc, 1)
  2379. });
  2380. }
  2381. if (escaped) {
  2382. escaped = false;
  2383. } else {
  2384. if (ch === 91) {
  2385. inClass = true;
  2386. } else if (ch === 93 && inClass) {
  2387. inClass = false;
  2388. } else if (ch === 47 && !inClass) {
  2389. break;
  2390. }
  2391. escaped = ch === 92;
  2392. }
  2393. }
  2394. const content = this.input.slice(start, pos);
  2395. ++pos;
  2396. let mods = "";
  2397. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  2398. while (pos < this.length) {
  2399. const cp = this.codePointAtPos(pos);
  2400. const char = String.fromCharCode(cp);
  2401. if (VALID_REGEX_FLAGS.has(cp)) {
  2402. if (cp === 118) {
  2403. this.expectPlugin("regexpUnicodeSets", nextPos());
  2404. if (mods.includes("u")) {
  2405. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2406. at: nextPos()
  2407. });
  2408. }
  2409. } else if (cp === 117) {
  2410. if (mods.includes("v")) {
  2411. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2412. at: nextPos()
  2413. });
  2414. }
  2415. }
  2416. if (mods.includes(char)) {
  2417. this.raise(Errors.DuplicateRegExpFlags, {
  2418. at: nextPos()
  2419. });
  2420. }
  2421. } else if (isIdentifierChar(cp) || cp === 92) {
  2422. this.raise(Errors.MalformedRegExpFlags, {
  2423. at: nextPos()
  2424. });
  2425. } else {
  2426. break;
  2427. }
  2428. ++pos;
  2429. mods += char;
  2430. }
  2431. this.state.pos = pos;
  2432. this.finishToken(133, {
  2433. pattern: content,
  2434. flags: mods
  2435. });
  2436. }
  2437. readInt(radix, len, forceLen, allowNumSeparator = true) {
  2438. const start = this.state.pos;
  2439. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2440. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2441. let invalid = false;
  2442. let total = 0;
  2443. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2444. const code = this.input.charCodeAt(this.state.pos);
  2445. let val;
  2446. if (code === 95 && allowNumSeparator !== "bail") {
  2447. const prev = this.input.charCodeAt(this.state.pos - 1);
  2448. const next = this.input.charCodeAt(this.state.pos + 1);
  2449. if (!allowNumSeparator) {
  2450. this.raise(Errors.NumericSeparatorInEscapeSequence, {
  2451. at: this.state.curPosition()
  2452. });
  2453. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2454. this.raise(Errors.UnexpectedNumericSeparator, {
  2455. at: this.state.curPosition()
  2456. });
  2457. }
  2458. ++this.state.pos;
  2459. continue;
  2460. }
  2461. if (code >= 97) {
  2462. val = code - 97 + 10;
  2463. } else if (code >= 65) {
  2464. val = code - 65 + 10;
  2465. } else if (_isDigit(code)) {
  2466. val = code - 48;
  2467. } else {
  2468. val = Infinity;
  2469. }
  2470. if (val >= radix) {
  2471. if (this.options.errorRecovery && val <= 9) {
  2472. val = 0;
  2473. this.raise(Errors.InvalidDigit, {
  2474. at: this.state.curPosition(),
  2475. radix
  2476. });
  2477. } else if (forceLen) {
  2478. val = 0;
  2479. invalid = true;
  2480. } else {
  2481. break;
  2482. }
  2483. }
  2484. ++this.state.pos;
  2485. total = total * radix + val;
  2486. }
  2487. if (this.state.pos === start || len != null && this.state.pos - start !== len || invalid) {
  2488. return null;
  2489. }
  2490. return total;
  2491. }
  2492. readRadixNumber(radix) {
  2493. const startLoc = this.state.curPosition();
  2494. let isBigInt = false;
  2495. this.state.pos += 2;
  2496. const val = this.readInt(radix);
  2497. if (val == null) {
  2498. this.raise(Errors.InvalidDigit, {
  2499. at: createPositionWithColumnOffset(startLoc, 2),
  2500. radix
  2501. });
  2502. }
  2503. const next = this.input.charCodeAt(this.state.pos);
  2504. if (next === 110) {
  2505. ++this.state.pos;
  2506. isBigInt = true;
  2507. } else if (next === 109) {
  2508. throw this.raise(Errors.InvalidDecimal, {
  2509. at: startLoc
  2510. });
  2511. }
  2512. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  2513. throw this.raise(Errors.NumberIdentifier, {
  2514. at: this.state.curPosition()
  2515. });
  2516. }
  2517. if (isBigInt) {
  2518. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  2519. this.finishToken(131, str);
  2520. return;
  2521. }
  2522. this.finishToken(130, val);
  2523. }
  2524. readNumber(startsWithDot) {
  2525. const start = this.state.pos;
  2526. const startLoc = this.state.curPosition();
  2527. let isFloat = false;
  2528. let isBigInt = false;
  2529. let isDecimal = false;
  2530. let hasExponent = false;
  2531. let isOctal = false;
  2532. if (!startsWithDot && this.readInt(10) === null) {
  2533. this.raise(Errors.InvalidNumber, {
  2534. at: this.state.curPosition()
  2535. });
  2536. }
  2537. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  2538. if (hasLeadingZero) {
  2539. const integer = this.input.slice(start, this.state.pos);
  2540. this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
  2541. at: startLoc
  2542. });
  2543. if (!this.state.strict) {
  2544. const underscorePos = integer.indexOf("_");
  2545. if (underscorePos > 0) {
  2546. this.raise(Errors.ZeroDigitNumericSeparator, {
  2547. at: createPositionWithColumnOffset(startLoc, underscorePos)
  2548. });
  2549. }
  2550. }
  2551. isOctal = hasLeadingZero && !/[89]/.test(integer);
  2552. }
  2553. let next = this.input.charCodeAt(this.state.pos);
  2554. if (next === 46 && !isOctal) {
  2555. ++this.state.pos;
  2556. this.readInt(10);
  2557. isFloat = true;
  2558. next = this.input.charCodeAt(this.state.pos);
  2559. }
  2560. if ((next === 69 || next === 101) && !isOctal) {
  2561. next = this.input.charCodeAt(++this.state.pos);
  2562. if (next === 43 || next === 45) {
  2563. ++this.state.pos;
  2564. }
  2565. if (this.readInt(10) === null) {
  2566. this.raise(Errors.InvalidOrMissingExponent, {
  2567. at: startLoc
  2568. });
  2569. }
  2570. isFloat = true;
  2571. hasExponent = true;
  2572. next = this.input.charCodeAt(this.state.pos);
  2573. }
  2574. if (next === 110) {
  2575. if (isFloat || hasLeadingZero) {
  2576. this.raise(Errors.InvalidBigIntLiteral, {
  2577. at: startLoc
  2578. });
  2579. }
  2580. ++this.state.pos;
  2581. isBigInt = true;
  2582. }
  2583. if (next === 109) {
  2584. this.expectPlugin("decimal", this.state.curPosition());
  2585. if (hasExponent || hasLeadingZero) {
  2586. this.raise(Errors.InvalidDecimal, {
  2587. at: startLoc
  2588. });
  2589. }
  2590. ++this.state.pos;
  2591. isDecimal = true;
  2592. }
  2593. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  2594. throw this.raise(Errors.NumberIdentifier, {
  2595. at: this.state.curPosition()
  2596. });
  2597. }
  2598. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  2599. if (isBigInt) {
  2600. this.finishToken(131, str);
  2601. return;
  2602. }
  2603. if (isDecimal) {
  2604. this.finishToken(132, str);
  2605. return;
  2606. }
  2607. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  2608. this.finishToken(130, val);
  2609. }
  2610. readCodePoint(throwOnInvalid) {
  2611. const ch = this.input.charCodeAt(this.state.pos);
  2612. let code;
  2613. if (ch === 123) {
  2614. ++this.state.pos;
  2615. code = this.readHexChar(this.input.indexOf("}", this.state.pos) - this.state.pos, true, throwOnInvalid);
  2616. ++this.state.pos;
  2617. if (code !== null && code > 0x10ffff) {
  2618. if (throwOnInvalid) {
  2619. this.raise(Errors.InvalidCodePoint, {
  2620. at: this.state.curPosition()
  2621. });
  2622. } else {
  2623. return null;
  2624. }
  2625. }
  2626. } else {
  2627. code = this.readHexChar(4, false, throwOnInvalid);
  2628. }
  2629. return code;
  2630. }
  2631. readString(quote) {
  2632. let out = "",
  2633. chunkStart = ++this.state.pos;
  2634. for (;;) {
  2635. if (this.state.pos >= this.length) {
  2636. throw this.raise(Errors.UnterminatedString, {
  2637. at: this.state.startLoc
  2638. });
  2639. }
  2640. const ch = this.input.charCodeAt(this.state.pos);
  2641. if (ch === quote) break;
  2642. if (ch === 92) {
  2643. out += this.input.slice(chunkStart, this.state.pos);
  2644. out += this.readEscapedChar(false);
  2645. chunkStart = this.state.pos;
  2646. } else if (ch === 8232 || ch === 8233) {
  2647. ++this.state.pos;
  2648. ++this.state.curLine;
  2649. this.state.lineStart = this.state.pos;
  2650. } else if (isNewLine(ch)) {
  2651. throw this.raise(Errors.UnterminatedString, {
  2652. at: this.state.startLoc
  2653. });
  2654. } else {
  2655. ++this.state.pos;
  2656. }
  2657. }
  2658. out += this.input.slice(chunkStart, this.state.pos++);
  2659. this.finishToken(129, out);
  2660. }
  2661. readTemplateContinuation() {
  2662. if (!this.match(8)) {
  2663. this.unexpected(null, 8);
  2664. }
  2665. this.state.pos--;
  2666. this.readTemplateToken();
  2667. }
  2668. readTemplateToken() {
  2669. let out = "",
  2670. chunkStart = this.state.pos,
  2671. containsInvalid = false;
  2672. ++this.state.pos;
  2673. for (;;) {
  2674. if (this.state.pos >= this.length) {
  2675. throw this.raise(Errors.UnterminatedTemplate, {
  2676. at: createPositionWithColumnOffset(this.state.startLoc, 1)
  2677. });
  2678. }
  2679. const ch = this.input.charCodeAt(this.state.pos);
  2680. if (ch === 96) {
  2681. ++this.state.pos;
  2682. out += this.input.slice(chunkStart, this.state.pos);
  2683. this.finishToken(24, containsInvalid ? null : out);
  2684. return;
  2685. }
  2686. if (ch === 36 && this.input.charCodeAt(this.state.pos + 1) === 123) {
  2687. this.state.pos += 2;
  2688. out += this.input.slice(chunkStart, this.state.pos);
  2689. this.finishToken(25, containsInvalid ? null : out);
  2690. return;
  2691. }
  2692. if (ch === 92) {
  2693. out += this.input.slice(chunkStart, this.state.pos);
  2694. const escaped = this.readEscapedChar(true);
  2695. if (escaped === null) {
  2696. containsInvalid = true;
  2697. } else {
  2698. out += escaped;
  2699. }
  2700. chunkStart = this.state.pos;
  2701. } else if (isNewLine(ch)) {
  2702. out += this.input.slice(chunkStart, this.state.pos);
  2703. ++this.state.pos;
  2704. switch (ch) {
  2705. case 13:
  2706. if (this.input.charCodeAt(this.state.pos) === 10) {
  2707. ++this.state.pos;
  2708. }
  2709. case 10:
  2710. out += "\n";
  2711. break;
  2712. default:
  2713. out += String.fromCharCode(ch);
  2714. break;
  2715. }
  2716. ++this.state.curLine;
  2717. this.state.lineStart = this.state.pos;
  2718. chunkStart = this.state.pos;
  2719. } else {
  2720. ++this.state.pos;
  2721. }
  2722. }
  2723. }
  2724. recordStrictModeErrors(toParseError, {
  2725. at
  2726. }) {
  2727. const index = at.index;
  2728. if (this.state.strict && !this.state.strictErrors.has(index)) {
  2729. this.raise(toParseError, {
  2730. at
  2731. });
  2732. } else {
  2733. this.state.strictErrors.set(index, [toParseError, at]);
  2734. }
  2735. }
  2736. readEscapedChar(inTemplate) {
  2737. const throwOnInvalid = !inTemplate;
  2738. const ch = this.input.charCodeAt(++this.state.pos);
  2739. ++this.state.pos;
  2740. switch (ch) {
  2741. case 110:
  2742. return "\n";
  2743. case 114:
  2744. return "\r";
  2745. case 120:
  2746. {
  2747. const code = this.readHexChar(2, false, throwOnInvalid);
  2748. return code === null ? null : String.fromCharCode(code);
  2749. }
  2750. case 117:
  2751. {
  2752. const code = this.readCodePoint(throwOnInvalid);
  2753. return code === null ? null : String.fromCodePoint(code);
  2754. }
  2755. case 116:
  2756. return "\t";
  2757. case 98:
  2758. return "\b";
  2759. case 118:
  2760. return "\u000b";
  2761. case 102:
  2762. return "\f";
  2763. case 13:
  2764. if (this.input.charCodeAt(this.state.pos) === 10) {
  2765. ++this.state.pos;
  2766. }
  2767. case 10:
  2768. this.state.lineStart = this.state.pos;
  2769. ++this.state.curLine;
  2770. case 8232:
  2771. case 8233:
  2772. return "";
  2773. case 56:
  2774. case 57:
  2775. if (inTemplate) {
  2776. return null;
  2777. } else {
  2778. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2779. at: createPositionWithColumnOffset(this.state.curPosition(), -1)
  2780. });
  2781. }
  2782. default:
  2783. if (ch >= 48 && ch <= 55) {
  2784. const codePos = createPositionWithColumnOffset(this.state.curPosition(), -1);
  2785. const match = this.input.slice(this.state.pos - 1, this.state.pos + 2).match(/^[0-7]+/);
  2786. let octalStr = match[0];
  2787. let octal = parseInt(octalStr, 8);
  2788. if (octal > 255) {
  2789. octalStr = octalStr.slice(0, -1);
  2790. octal = parseInt(octalStr, 8);
  2791. }
  2792. this.state.pos += octalStr.length - 1;
  2793. const next = this.input.charCodeAt(this.state.pos);
  2794. if (octalStr !== "0" || next === 56 || next === 57) {
  2795. if (inTemplate) {
  2796. return null;
  2797. } else {
  2798. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2799. at: codePos
  2800. });
  2801. }
  2802. }
  2803. return String.fromCharCode(octal);
  2804. }
  2805. return String.fromCharCode(ch);
  2806. }
  2807. }
  2808. readHexChar(len, forceLen, throwOnInvalid) {
  2809. const codeLoc = this.state.curPosition();
  2810. const n = this.readInt(16, len, forceLen, false);
  2811. if (n === null) {
  2812. if (throwOnInvalid) {
  2813. this.raise(Errors.InvalidEscapeSequence, {
  2814. at: codeLoc
  2815. });
  2816. } else {
  2817. this.state.pos = codeLoc.index - 1;
  2818. }
  2819. }
  2820. return n;
  2821. }
  2822. readWord1(firstCode) {
  2823. this.state.containsEsc = false;
  2824. let word = "";
  2825. const start = this.state.pos;
  2826. let chunkStart = this.state.pos;
  2827. if (firstCode !== undefined) {
  2828. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  2829. }
  2830. while (this.state.pos < this.length) {
  2831. const ch = this.codePointAtPos(this.state.pos);
  2832. if (isIdentifierChar(ch)) {
  2833. this.state.pos += ch <= 0xffff ? 1 : 2;
  2834. } else if (ch === 92) {
  2835. this.state.containsEsc = true;
  2836. word += this.input.slice(chunkStart, this.state.pos);
  2837. const escStart = this.state.curPosition();
  2838. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  2839. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  2840. this.raise(Errors.MissingUnicodeEscape, {
  2841. at: this.state.curPosition()
  2842. });
  2843. chunkStart = this.state.pos - 1;
  2844. continue;
  2845. }
  2846. ++this.state.pos;
  2847. const esc = this.readCodePoint(true);
  2848. if (esc !== null) {
  2849. if (!identifierCheck(esc)) {
  2850. this.raise(Errors.EscapedCharNotAnIdentifier, {
  2851. at: escStart
  2852. });
  2853. }
  2854. word += String.fromCodePoint(esc);
  2855. }
  2856. chunkStart = this.state.pos;
  2857. } else {
  2858. break;
  2859. }
  2860. }
  2861. return word + this.input.slice(chunkStart, this.state.pos);
  2862. }
  2863. readWord(firstCode) {
  2864. const word = this.readWord1(firstCode);
  2865. const type = keywords$1.get(word);
  2866. if (type !== undefined) {
  2867. this.finishToken(type, tokenLabelName(type));
  2868. } else {
  2869. this.finishToken(128, word);
  2870. }
  2871. }
  2872. checkKeywordEscapes() {
  2873. const {
  2874. type
  2875. } = this.state;
  2876. if (tokenIsKeyword(type) && this.state.containsEsc) {
  2877. this.raise(Errors.InvalidEscapedReservedWord, {
  2878. at: this.state.startLoc,
  2879. reservedWord: tokenLabelName(type)
  2880. });
  2881. }
  2882. }
  2883. raise(toParseError, raiseProperties) {
  2884. const {
  2885. at
  2886. } = raiseProperties,
  2887. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
  2888. const loc = at instanceof Position ? at : at.loc.start;
  2889. const error = toParseError({
  2890. loc,
  2891. details
  2892. });
  2893. if (!this.options.errorRecovery) throw error;
  2894. if (!this.isLookahead) this.state.errors.push(error);
  2895. return error;
  2896. }
  2897. raiseOverwrite(toParseError, raiseProperties) {
  2898. const {
  2899. at
  2900. } = raiseProperties,
  2901. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
  2902. const loc = at instanceof Position ? at : at.loc.start;
  2903. const pos = loc.index;
  2904. const errors = this.state.errors;
  2905. for (let i = errors.length - 1; i >= 0; i--) {
  2906. const error = errors[i];
  2907. if (error.loc.index === pos) {
  2908. return errors[i] = toParseError({
  2909. loc,
  2910. details
  2911. });
  2912. }
  2913. if (error.loc.index < pos) break;
  2914. }
  2915. return this.raise(toParseError, raiseProperties);
  2916. }
  2917. updateContext(prevType) {}
  2918. unexpected(loc, type) {
  2919. throw this.raise(Errors.UnexpectedToken, {
  2920. expected: type ? tokenLabelName(type) : null,
  2921. at: loc != null ? loc : this.state.startLoc
  2922. });
  2923. }
  2924. expectPlugin(pluginName, loc) {
  2925. if (this.hasPlugin(pluginName)) {
  2926. return true;
  2927. }
  2928. throw this.raise(Errors.MissingPlugin, {
  2929. at: loc != null ? loc : this.state.startLoc,
  2930. missingPlugin: [pluginName]
  2931. });
  2932. }
  2933. expectOnePlugin(pluginNames) {
  2934. if (!pluginNames.some(name => this.hasPlugin(name))) {
  2935. throw this.raise(Errors.MissingOneOfPlugins, {
  2936. at: this.state.startLoc,
  2937. missingPlugin: pluginNames
  2938. });
  2939. }
  2940. }
  2941. }
  2942. class Scope {
  2943. constructor(flags) {
  2944. this.var = new Set();
  2945. this.lexical = new Set();
  2946. this.functions = new Set();
  2947. this.flags = flags;
  2948. }
  2949. }
  2950. class ScopeHandler {
  2951. constructor(parser, inModule) {
  2952. this.parser = void 0;
  2953. this.scopeStack = [];
  2954. this.inModule = void 0;
  2955. this.undefinedExports = new Map();
  2956. this.parser = parser;
  2957. this.inModule = inModule;
  2958. }
  2959. get inFunction() {
  2960. return (this.currentVarScopeFlags() & SCOPE_FUNCTION) > 0;
  2961. }
  2962. get allowSuper() {
  2963. return (this.currentThisScopeFlags() & SCOPE_SUPER) > 0;
  2964. }
  2965. get allowDirectSuper() {
  2966. return (this.currentThisScopeFlags() & SCOPE_DIRECT_SUPER) > 0;
  2967. }
  2968. get inClass() {
  2969. return (this.currentThisScopeFlags() & SCOPE_CLASS) > 0;
  2970. }
  2971. get inClassAndNotInNonArrowFunction() {
  2972. const flags = this.currentThisScopeFlags();
  2973. return (flags & SCOPE_CLASS) > 0 && (flags & SCOPE_FUNCTION) === 0;
  2974. }
  2975. get inStaticBlock() {
  2976. for (let i = this.scopeStack.length - 1;; i--) {
  2977. const {
  2978. flags
  2979. } = this.scopeStack[i];
  2980. if (flags & SCOPE_STATIC_BLOCK) {
  2981. return true;
  2982. }
  2983. if (flags & (SCOPE_VAR | SCOPE_CLASS)) {
  2984. return false;
  2985. }
  2986. }
  2987. }
  2988. get inNonArrowFunction() {
  2989. return (this.currentThisScopeFlags() & SCOPE_FUNCTION) > 0;
  2990. }
  2991. get treatFunctionsAsVar() {
  2992. return this.treatFunctionsAsVarInScope(this.currentScope());
  2993. }
  2994. createScope(flags) {
  2995. return new Scope(flags);
  2996. }
  2997. enter(flags) {
  2998. this.scopeStack.push(this.createScope(flags));
  2999. }
  3000. exit() {
  3001. this.scopeStack.pop();
  3002. }
  3003. treatFunctionsAsVarInScope(scope) {
  3004. return !!(scope.flags & (SCOPE_FUNCTION | SCOPE_STATIC_BLOCK) || !this.parser.inModule && scope.flags & SCOPE_PROGRAM);
  3005. }
  3006. declareName(name, bindingType, loc) {
  3007. let scope = this.currentScope();
  3008. if (bindingType & BIND_SCOPE_LEXICAL || bindingType & BIND_SCOPE_FUNCTION) {
  3009. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  3010. if (bindingType & BIND_SCOPE_FUNCTION) {
  3011. scope.functions.add(name);
  3012. } else {
  3013. scope.lexical.add(name);
  3014. }
  3015. if (bindingType & BIND_SCOPE_LEXICAL) {
  3016. this.maybeExportDefined(scope, name);
  3017. }
  3018. } else if (bindingType & BIND_SCOPE_VAR) {
  3019. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  3020. scope = this.scopeStack[i];
  3021. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  3022. scope.var.add(name);
  3023. this.maybeExportDefined(scope, name);
  3024. if (scope.flags & SCOPE_VAR) break;
  3025. }
  3026. }
  3027. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  3028. this.undefinedExports.delete(name);
  3029. }
  3030. }
  3031. maybeExportDefined(scope, name) {
  3032. if (this.parser.inModule && scope.flags & SCOPE_PROGRAM) {
  3033. this.undefinedExports.delete(name);
  3034. }
  3035. }
  3036. checkRedeclarationInScope(scope, name, bindingType, loc) {
  3037. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  3038. this.parser.raise(Errors.VarRedeclaration, {
  3039. at: loc,
  3040. identifierName: name
  3041. });
  3042. }
  3043. }
  3044. isRedeclaredInScope(scope, name, bindingType) {
  3045. if (!(bindingType & BIND_KIND_VALUE)) return false;
  3046. if (bindingType & BIND_SCOPE_LEXICAL) {
  3047. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  3048. }
  3049. if (bindingType & BIND_SCOPE_FUNCTION) {
  3050. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  3051. }
  3052. return scope.lexical.has(name) && !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  3053. }
  3054. checkLocalExport(id) {
  3055. const {
  3056. name
  3057. } = id;
  3058. const topLevelScope = this.scopeStack[0];
  3059. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
  3060. this.undefinedExports.set(name, id.loc.start);
  3061. }
  3062. }
  3063. currentScope() {
  3064. return this.scopeStack[this.scopeStack.length - 1];
  3065. }
  3066. currentVarScopeFlags() {
  3067. for (let i = this.scopeStack.length - 1;; i--) {
  3068. const {
  3069. flags
  3070. } = this.scopeStack[i];
  3071. if (flags & SCOPE_VAR) {
  3072. return flags;
  3073. }
  3074. }
  3075. }
  3076. currentThisScopeFlags() {
  3077. for (let i = this.scopeStack.length - 1;; i--) {
  3078. const {
  3079. flags
  3080. } = this.scopeStack[i];
  3081. if (flags & (SCOPE_VAR | SCOPE_CLASS) && !(flags & SCOPE_ARROW)) {
  3082. return flags;
  3083. }
  3084. }
  3085. }
  3086. }
  3087. class FlowScope extends Scope {
  3088. constructor(...args) {
  3089. super(...args);
  3090. this.declareFunctions = new Set();
  3091. }
  3092. }
  3093. class FlowScopeHandler extends ScopeHandler {
  3094. createScope(flags) {
  3095. return new FlowScope(flags);
  3096. }
  3097. declareName(name, bindingType, loc) {
  3098. const scope = this.currentScope();
  3099. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  3100. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  3101. this.maybeExportDefined(scope, name);
  3102. scope.declareFunctions.add(name);
  3103. return;
  3104. }
  3105. super.declareName(...arguments);
  3106. }
  3107. isRedeclaredInScope(scope, name, bindingType) {
  3108. if (super.isRedeclaredInScope(...arguments)) return true;
  3109. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  3110. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  3111. }
  3112. return false;
  3113. }
  3114. checkLocalExport(id) {
  3115. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  3116. super.checkLocalExport(id);
  3117. }
  3118. }
  3119. }
  3120. class ClassScope {
  3121. constructor() {
  3122. this.privateNames = new Set();
  3123. this.loneAccessors = new Map();
  3124. this.undefinedPrivateNames = new Map();
  3125. }
  3126. }
  3127. class ClassScopeHandler {
  3128. constructor(parser) {
  3129. this.parser = void 0;
  3130. this.stack = [];
  3131. this.undefinedPrivateNames = new Map();
  3132. this.parser = parser;
  3133. }
  3134. current() {
  3135. return this.stack[this.stack.length - 1];
  3136. }
  3137. enter() {
  3138. this.stack.push(new ClassScope());
  3139. }
  3140. exit() {
  3141. const oldClassScope = this.stack.pop();
  3142. const current = this.current();
  3143. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3144. if (current) {
  3145. if (!current.undefinedPrivateNames.has(name)) {
  3146. current.undefinedPrivateNames.set(name, loc);
  3147. }
  3148. } else {
  3149. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3150. at: loc,
  3151. identifierName: name
  3152. });
  3153. }
  3154. }
  3155. }
  3156. declarePrivateName(name, elementType, loc) {
  3157. const {
  3158. privateNames,
  3159. loneAccessors,
  3160. undefinedPrivateNames
  3161. } = this.current();
  3162. let redefined = privateNames.has(name);
  3163. if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) {
  3164. const accessor = redefined && loneAccessors.get(name);
  3165. if (accessor) {
  3166. const oldStatic = accessor & CLASS_ELEMENT_FLAG_STATIC;
  3167. const newStatic = elementType & CLASS_ELEMENT_FLAG_STATIC;
  3168. const oldKind = accessor & CLASS_ELEMENT_KIND_ACCESSOR;
  3169. const newKind = elementType & CLASS_ELEMENT_KIND_ACCESSOR;
  3170. redefined = oldKind === newKind || oldStatic !== newStatic;
  3171. if (!redefined) loneAccessors.delete(name);
  3172. } else if (!redefined) {
  3173. loneAccessors.set(name, elementType);
  3174. }
  3175. }
  3176. if (redefined) {
  3177. this.parser.raise(Errors.PrivateNameRedeclaration, {
  3178. at: loc,
  3179. identifierName: name
  3180. });
  3181. }
  3182. privateNames.add(name);
  3183. undefinedPrivateNames.delete(name);
  3184. }
  3185. usePrivateName(name, loc) {
  3186. let classScope;
  3187. for (classScope of this.stack) {
  3188. if (classScope.privateNames.has(name)) return;
  3189. }
  3190. if (classScope) {
  3191. classScope.undefinedPrivateNames.set(name, loc);
  3192. } else {
  3193. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3194. at: loc,
  3195. identifierName: name
  3196. });
  3197. }
  3198. }
  3199. }
  3200. const kExpression = 0,
  3201. kMaybeArrowParameterDeclaration = 1,
  3202. kMaybeAsyncArrowParameterDeclaration = 2,
  3203. kParameterDeclaration = 3;
  3204. class ExpressionScope {
  3205. constructor(type = kExpression) {
  3206. this.type = void 0;
  3207. this.type = type;
  3208. }
  3209. canBeArrowParameterDeclaration() {
  3210. return this.type === kMaybeAsyncArrowParameterDeclaration || this.type === kMaybeArrowParameterDeclaration;
  3211. }
  3212. isCertainlyParameterDeclaration() {
  3213. return this.type === kParameterDeclaration;
  3214. }
  3215. }
  3216. class ArrowHeadParsingScope extends ExpressionScope {
  3217. constructor(type) {
  3218. super(type);
  3219. this.declarationErrors = new Map();
  3220. }
  3221. recordDeclarationError(ParsingErrorClass, {
  3222. at
  3223. }) {
  3224. const index = at.index;
  3225. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3226. }
  3227. clearDeclarationError(index) {
  3228. this.declarationErrors.delete(index);
  3229. }
  3230. iterateErrors(iterator) {
  3231. this.declarationErrors.forEach(iterator);
  3232. }
  3233. }
  3234. class ExpressionScopeHandler {
  3235. constructor(parser) {
  3236. this.parser = void 0;
  3237. this.stack = [new ExpressionScope()];
  3238. this.parser = parser;
  3239. }
  3240. enter(scope) {
  3241. this.stack.push(scope);
  3242. }
  3243. exit() {
  3244. this.stack.pop();
  3245. }
  3246. recordParameterInitializerError(toParseError, {
  3247. at: node
  3248. }) {
  3249. const origin = {
  3250. at: node.loc.start
  3251. };
  3252. const {
  3253. stack
  3254. } = this;
  3255. let i = stack.length - 1;
  3256. let scope = stack[i];
  3257. while (!scope.isCertainlyParameterDeclaration()) {
  3258. if (scope.canBeArrowParameterDeclaration()) {
  3259. scope.recordDeclarationError(toParseError, origin);
  3260. } else {
  3261. return;
  3262. }
  3263. scope = stack[--i];
  3264. }
  3265. this.parser.raise(toParseError, origin);
  3266. }
  3267. recordArrowParemeterBindingError(error, {
  3268. at: node
  3269. }) {
  3270. const {
  3271. stack
  3272. } = this;
  3273. const scope = stack[stack.length - 1];
  3274. const origin = {
  3275. at: node.loc.start
  3276. };
  3277. if (scope.isCertainlyParameterDeclaration()) {
  3278. this.parser.raise(error, origin);
  3279. } else if (scope.canBeArrowParameterDeclaration()) {
  3280. scope.recordDeclarationError(error, origin);
  3281. } else {
  3282. return;
  3283. }
  3284. }
  3285. recordAsyncArrowParametersError({
  3286. at
  3287. }) {
  3288. const {
  3289. stack
  3290. } = this;
  3291. let i = stack.length - 1;
  3292. let scope = stack[i];
  3293. while (scope.canBeArrowParameterDeclaration()) {
  3294. if (scope.type === kMaybeAsyncArrowParameterDeclaration) {
  3295. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
  3296. at
  3297. });
  3298. }
  3299. scope = stack[--i];
  3300. }
  3301. }
  3302. validateAsPattern() {
  3303. const {
  3304. stack
  3305. } = this;
  3306. const currentScope = stack[stack.length - 1];
  3307. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3308. currentScope.iterateErrors(([toParseError, loc]) => {
  3309. this.parser.raise(toParseError, {
  3310. at: loc
  3311. });
  3312. let i = stack.length - 2;
  3313. let scope = stack[i];
  3314. while (scope.canBeArrowParameterDeclaration()) {
  3315. scope.clearDeclarationError(loc.index);
  3316. scope = stack[--i];
  3317. }
  3318. });
  3319. }
  3320. }
  3321. function newParameterDeclarationScope() {
  3322. return new ExpressionScope(kParameterDeclaration);
  3323. }
  3324. function newArrowHeadScope() {
  3325. return new ArrowHeadParsingScope(kMaybeArrowParameterDeclaration);
  3326. }
  3327. function newAsyncArrowScope() {
  3328. return new ArrowHeadParsingScope(kMaybeAsyncArrowParameterDeclaration);
  3329. }
  3330. function newExpressionScope() {
  3331. return new ExpressionScope();
  3332. }
  3333. const PARAM = 0b0000,
  3334. PARAM_YIELD = 0b0001,
  3335. PARAM_AWAIT = 0b0010,
  3336. PARAM_RETURN = 0b0100,
  3337. PARAM_IN = 0b1000;
  3338. class ProductionParameterHandler {
  3339. constructor() {
  3340. this.stacks = [];
  3341. }
  3342. enter(flags) {
  3343. this.stacks.push(flags);
  3344. }
  3345. exit() {
  3346. this.stacks.pop();
  3347. }
  3348. currentFlags() {
  3349. return this.stacks[this.stacks.length - 1];
  3350. }
  3351. get hasAwait() {
  3352. return (this.currentFlags() & PARAM_AWAIT) > 0;
  3353. }
  3354. get hasYield() {
  3355. return (this.currentFlags() & PARAM_YIELD) > 0;
  3356. }
  3357. get hasReturn() {
  3358. return (this.currentFlags() & PARAM_RETURN) > 0;
  3359. }
  3360. get hasIn() {
  3361. return (this.currentFlags() & PARAM_IN) > 0;
  3362. }
  3363. }
  3364. function functionFlags(isAsync, isGenerator) {
  3365. return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
  3366. }
  3367. class UtilParser extends Tokenizer {
  3368. addExtra(node, key, value, enumerable = true) {
  3369. if (!node) return;
  3370. const extra = node.extra = node.extra || {};
  3371. if (enumerable) {
  3372. extra[key] = value;
  3373. } else {
  3374. Object.defineProperty(extra, key, {
  3375. enumerable,
  3376. value
  3377. });
  3378. }
  3379. }
  3380. isContextual(token) {
  3381. return this.state.type === token && !this.state.containsEsc;
  3382. }
  3383. isUnparsedContextual(nameStart, name) {
  3384. const nameEnd = nameStart + name.length;
  3385. if (this.input.slice(nameStart, nameEnd) === name) {
  3386. const nextCh = this.input.charCodeAt(nameEnd);
  3387. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3388. }
  3389. return false;
  3390. }
  3391. isLookaheadContextual(name) {
  3392. const next = this.nextTokenStart();
  3393. return this.isUnparsedContextual(next, name);
  3394. }
  3395. eatContextual(token) {
  3396. if (this.isContextual(token)) {
  3397. this.next();
  3398. return true;
  3399. }
  3400. return false;
  3401. }
  3402. expectContextual(token, toParseError) {
  3403. if (!this.eatContextual(token)) {
  3404. if (toParseError != null) {
  3405. throw this.raise(toParseError, {
  3406. at: this.state.startLoc
  3407. });
  3408. }
  3409. throw this.unexpected(null, token);
  3410. }
  3411. }
  3412. canInsertSemicolon() {
  3413. return this.match(135) || this.match(8) || this.hasPrecedingLineBreak();
  3414. }
  3415. hasPrecedingLineBreak() {
  3416. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  3417. }
  3418. hasFollowingLineBreak() {
  3419. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  3420. return skipWhiteSpaceToLineBreak.test(this.input);
  3421. }
  3422. isLineTerminator() {
  3423. return this.eat(13) || this.canInsertSemicolon();
  3424. }
  3425. semicolon(allowAsi = true) {
  3426. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3427. this.raise(Errors.MissingSemicolon, {
  3428. at: this.state.lastTokEndLoc
  3429. });
  3430. }
  3431. expect(type, loc) {
  3432. this.eat(type) || this.unexpected(loc, type);
  3433. }
  3434. tryParse(fn, oldState = this.state.clone()) {
  3435. const abortSignal = {
  3436. node: null
  3437. };
  3438. try {
  3439. const node = fn((node = null) => {
  3440. abortSignal.node = node;
  3441. throw abortSignal;
  3442. });
  3443. if (this.state.errors.length > oldState.errors.length) {
  3444. const failState = this.state;
  3445. this.state = oldState;
  3446. this.state.tokensLength = failState.tokensLength;
  3447. return {
  3448. node,
  3449. error: failState.errors[oldState.errors.length],
  3450. thrown: false,
  3451. aborted: false,
  3452. failState
  3453. };
  3454. }
  3455. return {
  3456. node,
  3457. error: null,
  3458. thrown: false,
  3459. aborted: false,
  3460. failState: null
  3461. };
  3462. } catch (error) {
  3463. const failState = this.state;
  3464. this.state = oldState;
  3465. if (error instanceof SyntaxError) {
  3466. return {
  3467. node: null,
  3468. error,
  3469. thrown: true,
  3470. aborted: false,
  3471. failState
  3472. };
  3473. }
  3474. if (error === abortSignal) {
  3475. return {
  3476. node: abortSignal.node,
  3477. error: null,
  3478. thrown: false,
  3479. aborted: true,
  3480. failState
  3481. };
  3482. }
  3483. throw error;
  3484. }
  3485. }
  3486. checkExpressionErrors(refExpressionErrors, andThrow) {
  3487. if (!refExpressionErrors) return false;
  3488. const {
  3489. shorthandAssignLoc,
  3490. doubleProtoLoc,
  3491. privateKeyLoc,
  3492. optionalParametersLoc
  3493. } = refExpressionErrors;
  3494. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3495. if (!andThrow) {
  3496. return hasErrors;
  3497. }
  3498. if (shorthandAssignLoc != null) {
  3499. this.raise(Errors.InvalidCoverInitializedName, {
  3500. at: shorthandAssignLoc
  3501. });
  3502. }
  3503. if (doubleProtoLoc != null) {
  3504. this.raise(Errors.DuplicateProto, {
  3505. at: doubleProtoLoc
  3506. });
  3507. }
  3508. if (privateKeyLoc != null) {
  3509. this.raise(Errors.UnexpectedPrivateField, {
  3510. at: privateKeyLoc
  3511. });
  3512. }
  3513. if (optionalParametersLoc != null) {
  3514. this.unexpected(optionalParametersLoc);
  3515. }
  3516. }
  3517. isLiteralPropertyName() {
  3518. return tokenIsLiteralPropertyName(this.state.type);
  3519. }
  3520. isPrivateName(node) {
  3521. return node.type === "PrivateName";
  3522. }
  3523. getPrivateNameSV(node) {
  3524. return node.id.name;
  3525. }
  3526. hasPropertyAsPrivateName(node) {
  3527. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3528. }
  3529. isOptionalChain(node) {
  3530. return node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression";
  3531. }
  3532. isObjectProperty(node) {
  3533. return node.type === "ObjectProperty";
  3534. }
  3535. isObjectMethod(node) {
  3536. return node.type === "ObjectMethod";
  3537. }
  3538. initializeScopes(inModule = this.options.sourceType === "module") {
  3539. const oldLabels = this.state.labels;
  3540. this.state.labels = [];
  3541. const oldExportedIdentifiers = this.exportedIdentifiers;
  3542. this.exportedIdentifiers = new Set();
  3543. const oldInModule = this.inModule;
  3544. this.inModule = inModule;
  3545. const oldScope = this.scope;
  3546. const ScopeHandler = this.getScopeHandler();
  3547. this.scope = new ScopeHandler(this, inModule);
  3548. const oldProdParam = this.prodParam;
  3549. this.prodParam = new ProductionParameterHandler();
  3550. const oldClassScope = this.classScope;
  3551. this.classScope = new ClassScopeHandler(this);
  3552. const oldExpressionScope = this.expressionScope;
  3553. this.expressionScope = new ExpressionScopeHandler(this);
  3554. return () => {
  3555. this.state.labels = oldLabels;
  3556. this.exportedIdentifiers = oldExportedIdentifiers;
  3557. this.inModule = oldInModule;
  3558. this.scope = oldScope;
  3559. this.prodParam = oldProdParam;
  3560. this.classScope = oldClassScope;
  3561. this.expressionScope = oldExpressionScope;
  3562. };
  3563. }
  3564. enterInitialScopes() {
  3565. let paramFlags = PARAM;
  3566. if (this.inModule) {
  3567. paramFlags |= PARAM_AWAIT;
  3568. }
  3569. this.scope.enter(SCOPE_PROGRAM);
  3570. this.prodParam.enter(paramFlags);
  3571. }
  3572. checkDestructuringPrivate(refExpressionErrors) {
  3573. const {
  3574. privateKeyLoc
  3575. } = refExpressionErrors;
  3576. if (privateKeyLoc !== null) {
  3577. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3578. }
  3579. }
  3580. }
  3581. class ExpressionErrors {
  3582. constructor() {
  3583. this.shorthandAssignLoc = null;
  3584. this.doubleProtoLoc = null;
  3585. this.privateKeyLoc = null;
  3586. this.optionalParametersLoc = null;
  3587. }
  3588. }
  3589. class Node {
  3590. constructor(parser, pos, loc) {
  3591. this.type = "";
  3592. this.start = pos;
  3593. this.end = 0;
  3594. this.loc = new SourceLocation(loc);
  3595. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3596. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3597. }
  3598. }
  3599. const NodePrototype = Node.prototype;
  3600. {
  3601. NodePrototype.__clone = function () {
  3602. const newNode = new Node();
  3603. const keys = Object.keys(this);
  3604. for (let i = 0, length = keys.length; i < length; i++) {
  3605. const key = keys[i];
  3606. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3607. newNode[key] = this[key];
  3608. }
  3609. }
  3610. return newNode;
  3611. };
  3612. }
  3613. function clonePlaceholder(node) {
  3614. return cloneIdentifier(node);
  3615. }
  3616. function cloneIdentifier(node) {
  3617. const {
  3618. type,
  3619. start,
  3620. end,
  3621. loc,
  3622. range,
  3623. extra,
  3624. name
  3625. } = node;
  3626. const cloned = Object.create(NodePrototype);
  3627. cloned.type = type;
  3628. cloned.start = start;
  3629. cloned.end = end;
  3630. cloned.loc = loc;
  3631. cloned.range = range;
  3632. cloned.extra = extra;
  3633. cloned.name = name;
  3634. if (type === "Placeholder") {
  3635. cloned.expectedNode = node.expectedNode;
  3636. }
  3637. return cloned;
  3638. }
  3639. function cloneStringLiteral(node) {
  3640. const {
  3641. type,
  3642. start,
  3643. end,
  3644. loc,
  3645. range,
  3646. extra
  3647. } = node;
  3648. if (type === "Placeholder") {
  3649. return clonePlaceholder(node);
  3650. }
  3651. const cloned = Object.create(NodePrototype);
  3652. cloned.type = type;
  3653. cloned.start = start;
  3654. cloned.end = end;
  3655. cloned.loc = loc;
  3656. cloned.range = range;
  3657. if (node.raw !== undefined) {
  3658. cloned.raw = node.raw;
  3659. } else {
  3660. cloned.extra = extra;
  3661. }
  3662. cloned.value = node.value;
  3663. return cloned;
  3664. }
  3665. class NodeUtils extends UtilParser {
  3666. startNode() {
  3667. return new Node(this, this.state.start, this.state.startLoc);
  3668. }
  3669. startNodeAt(pos, loc) {
  3670. return new Node(this, pos, loc);
  3671. }
  3672. startNodeAtNode(type) {
  3673. return this.startNodeAt(type.start, type.loc.start);
  3674. }
  3675. finishNode(node, type) {
  3676. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3677. }
  3678. finishNodeAt(node, type, endLoc) {
  3679. node.type = type;
  3680. node.end = endLoc.index;
  3681. node.loc.end = endLoc;
  3682. if (this.options.ranges) node.range[1] = endLoc.index;
  3683. if (this.options.attachComment) this.processComment(node);
  3684. return node;
  3685. }
  3686. resetStartLocation(node, start, startLoc) {
  3687. node.start = start;
  3688. node.loc.start = startLoc;
  3689. if (this.options.ranges) node.range[0] = start;
  3690. }
  3691. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3692. node.end = endLoc.index;
  3693. node.loc.end = endLoc;
  3694. if (this.options.ranges) node.range[1] = endLoc.index;
  3695. }
  3696. resetStartLocationFromNode(node, locationNode) {
  3697. this.resetStartLocation(node, locationNode.start, locationNode.loc.start);
  3698. }
  3699. }
  3700. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3701. const FlowErrors = ParseErrorEnum`flow`(_ => ({
  3702. AmbiguousConditionalArrow: _("Ambiguous expression: wrap the arrow functions in parentheses to disambiguate."),
  3703. 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."),
  3704. AssignReservedType: _(({
  3705. reservedType
  3706. }) => `Cannot overwrite reserved type ${reservedType}.`),
  3707. DeclareClassElement: _("The `declare` modifier can only appear on class fields."),
  3708. DeclareClassFieldInitializer: _("Initializers are not allowed in fields with the `declare` modifier."),
  3709. DuplicateDeclareModuleExports: _("Duplicate `declare module.exports` statement."),
  3710. EnumBooleanMemberNotInitialized: _(({
  3711. memberName,
  3712. enumName
  3713. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`),
  3714. EnumDuplicateMemberName: _(({
  3715. memberName,
  3716. enumName
  3717. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`),
  3718. EnumInconsistentMemberValues: _(({
  3719. enumName
  3720. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`),
  3721. EnumInvalidExplicitType: _(({
  3722. invalidEnumType,
  3723. enumName
  3724. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`),
  3725. EnumInvalidExplicitTypeUnknownSupplied: _(({
  3726. enumName
  3727. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`),
  3728. EnumInvalidMemberInitializerPrimaryType: _(({
  3729. enumName,
  3730. memberName,
  3731. explicitType
  3732. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`),
  3733. EnumInvalidMemberInitializerSymbolType: _(({
  3734. enumName,
  3735. memberName
  3736. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`),
  3737. EnumInvalidMemberInitializerUnknownType: _(({
  3738. enumName,
  3739. memberName
  3740. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`),
  3741. EnumInvalidMemberName: _(({
  3742. enumName,
  3743. memberName,
  3744. suggestion
  3745. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`),
  3746. EnumNumberMemberNotInitialized: _(({
  3747. enumName,
  3748. memberName
  3749. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`),
  3750. EnumStringMemberInconsistentlyInitailized: _(({
  3751. enumName
  3752. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`),
  3753. GetterMayNotHaveThisParam: _("A getter cannot have a `this` parameter."),
  3754. 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."),
  3755. InexactInsideExact: _("Explicit inexact syntax cannot appear inside an explicit exact object type."),
  3756. InexactInsideNonObject: _("Explicit inexact syntax cannot appear in class or interface definitions."),
  3757. InexactVariance: _("Explicit inexact syntax cannot have variance."),
  3758. InvalidNonTypeImportInDeclareModule: _("Imports within a `declare module` body must always be `import type` or `import typeof`."),
  3759. MissingTypeParamDefault: _("Type parameter declaration needs a default, since a preceding type parameter declaration has a default."),
  3760. NestedDeclareModule: _("`declare module` cannot be used inside another `declare module`."),
  3761. NestedFlowComment: _("Cannot have a flow comment inside another flow comment."),
  3762. PatternIsOptional: _("A binding pattern parameter cannot be optional in an implementation signature.", {
  3763. reasonCode: "OptionalBindingPattern"
  3764. }),
  3765. SetterMayNotHaveThisParam: _("A setter cannot have a `this` parameter."),
  3766. SpreadVariance: _("Spread properties cannot have variance."),
  3767. ThisParamAnnotationRequired: _("A type annotation is required for the `this` parameter."),
  3768. ThisParamBannedInConstructor: _("Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions."),
  3769. ThisParamMayNotBeOptional: _("The `this` parameter cannot be optional."),
  3770. ThisParamMustBeFirst: _("The `this` parameter must be the first function parameter."),
  3771. ThisParamNoDefault: _("The `this` parameter may not have a default value."),
  3772. TypeBeforeInitializer: _("Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`."),
  3773. TypeCastInPattern: _("The type cast expression is expected to be wrapped with parenthesis."),
  3774. UnexpectedExplicitInexactInObject: _("Explicit inexact syntax must appear at the end of an inexact object."),
  3775. UnexpectedReservedType: _(({
  3776. reservedType
  3777. }) => `Unexpected reserved type ${reservedType}.`),
  3778. UnexpectedReservedUnderscore: _("`_` is only allowed as a type argument to call or new."),
  3779. UnexpectedSpaceBetweenModuloChecks: _("Spaces between `%` and `checks` are not allowed here."),
  3780. UnexpectedSpreadType: _("Spread operator cannot appear in class or interface definitions."),
  3781. UnexpectedSubtractionOperand: _('Unexpected token, expected "number" or "bigint".'),
  3782. UnexpectedTokenAfterTypeParameter: _("Expected an arrow function after this type parameter declaration."),
  3783. UnexpectedTypeParameterBeforeAsyncArrowFunction: _("Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`."),
  3784. UnsupportedDeclareExportKind: _(({
  3785. unsupportedExportKind,
  3786. suggestion
  3787. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`),
  3788. UnsupportedStatementInDeclareModule: _("Only declares and type imports are allowed inside declare module."),
  3789. UnterminatedFlowComment: _("Unterminated flow-comment.")
  3790. }));
  3791. function isEsModuleType(bodyElement) {
  3792. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3793. }
  3794. function hasTypeImportKind(node) {
  3795. return node.importKind === "type" || node.importKind === "typeof";
  3796. }
  3797. function isMaybeDefaultImport(type) {
  3798. return tokenIsKeywordOrIdentifier(type) && type !== 97;
  3799. }
  3800. const exportSuggestions = {
  3801. const: "declare export var",
  3802. let: "declare export var",
  3803. type: "export type",
  3804. interface: "export interface"
  3805. };
  3806. function partition(list, test) {
  3807. const list1 = [];
  3808. const list2 = [];
  3809. for (let i = 0; i < list.length; i++) {
  3810. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  3811. }
  3812. return [list1, list2];
  3813. }
  3814. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  3815. var flow = (superClass => class extends superClass {
  3816. constructor(...args) {
  3817. super(...args);
  3818. this.flowPragma = undefined;
  3819. }
  3820. getScopeHandler() {
  3821. return FlowScopeHandler;
  3822. }
  3823. shouldParseTypes() {
  3824. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  3825. }
  3826. shouldParseEnums() {
  3827. return !!this.getPluginOption("flow", "enums");
  3828. }
  3829. finishToken(type, val) {
  3830. if (type !== 129 && type !== 13 && type !== 28) {
  3831. if (this.flowPragma === undefined) {
  3832. this.flowPragma = null;
  3833. }
  3834. }
  3835. return super.finishToken(type, val);
  3836. }
  3837. addComment(comment) {
  3838. if (this.flowPragma === undefined) {
  3839. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  3840. if (!matches) ; else if (matches[1] === "flow") {
  3841. this.flowPragma = "flow";
  3842. } else if (matches[1] === "noflow") {
  3843. this.flowPragma = "noflow";
  3844. } else {
  3845. throw new Error("Unexpected flow pragma");
  3846. }
  3847. }
  3848. return super.addComment(comment);
  3849. }
  3850. flowParseTypeInitialiser(tok) {
  3851. const oldInType = this.state.inType;
  3852. this.state.inType = true;
  3853. this.expect(tok || 14);
  3854. const type = this.flowParseType();
  3855. this.state.inType = oldInType;
  3856. return type;
  3857. }
  3858. flowParsePredicate() {
  3859. const node = this.startNode();
  3860. const moduloLoc = this.state.startLoc;
  3861. this.next();
  3862. this.expectContextual(107);
  3863. if (this.state.lastTokStart > moduloLoc.index + 1) {
  3864. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
  3865. at: moduloLoc
  3866. });
  3867. }
  3868. if (this.eat(10)) {
  3869. node.value = this.parseExpression();
  3870. this.expect(11);
  3871. return this.finishNode(node, "DeclaredPredicate");
  3872. } else {
  3873. return this.finishNode(node, "InferredPredicate");
  3874. }
  3875. }
  3876. flowParseTypeAndPredicateInitialiser() {
  3877. const oldInType = this.state.inType;
  3878. this.state.inType = true;
  3879. this.expect(14);
  3880. let type = null;
  3881. let predicate = null;
  3882. if (this.match(54)) {
  3883. this.state.inType = oldInType;
  3884. predicate = this.flowParsePredicate();
  3885. } else {
  3886. type = this.flowParseType();
  3887. this.state.inType = oldInType;
  3888. if (this.match(54)) {
  3889. predicate = this.flowParsePredicate();
  3890. }
  3891. }
  3892. return [type, predicate];
  3893. }
  3894. flowParseDeclareClass(node) {
  3895. this.next();
  3896. this.flowParseInterfaceish(node, true);
  3897. return this.finishNode(node, "DeclareClass");
  3898. }
  3899. flowParseDeclareFunction(node) {
  3900. this.next();
  3901. const id = node.id = this.parseIdentifier();
  3902. const typeNode = this.startNode();
  3903. const typeContainer = this.startNode();
  3904. if (this.match(47)) {
  3905. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  3906. } else {
  3907. typeNode.typeParameters = null;
  3908. }
  3909. this.expect(10);
  3910. const tmp = this.flowParseFunctionTypeParams();
  3911. typeNode.params = tmp.params;
  3912. typeNode.rest = tmp.rest;
  3913. typeNode.this = tmp._this;
  3914. this.expect(11);
  3915. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  3916. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  3917. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  3918. this.resetEndLocation(id);
  3919. this.semicolon();
  3920. this.scope.declareName(node.id.name, BIND_FLOW_DECLARE_FN, node.id.loc.start);
  3921. return this.finishNode(node, "DeclareFunction");
  3922. }
  3923. flowParseDeclare(node, insideModule) {
  3924. if (this.match(80)) {
  3925. return this.flowParseDeclareClass(node);
  3926. } else if (this.match(68)) {
  3927. return this.flowParseDeclareFunction(node);
  3928. } else if (this.match(74)) {
  3929. return this.flowParseDeclareVariable(node);
  3930. } else if (this.eatContextual(123)) {
  3931. if (this.match(16)) {
  3932. return this.flowParseDeclareModuleExports(node);
  3933. } else {
  3934. if (insideModule) {
  3935. this.raise(FlowErrors.NestedDeclareModule, {
  3936. at: this.state.lastTokStartLoc
  3937. });
  3938. }
  3939. return this.flowParseDeclareModule(node);
  3940. }
  3941. } else if (this.isContextual(126)) {
  3942. return this.flowParseDeclareTypeAlias(node);
  3943. } else if (this.isContextual(127)) {
  3944. return this.flowParseDeclareOpaqueType(node);
  3945. } else if (this.isContextual(125)) {
  3946. return this.flowParseDeclareInterface(node);
  3947. } else if (this.match(82)) {
  3948. return this.flowParseDeclareExportDeclaration(node, insideModule);
  3949. } else {
  3950. throw this.unexpected();
  3951. }
  3952. }
  3953. flowParseDeclareVariable(node) {
  3954. this.next();
  3955. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  3956. this.scope.declareName(node.id.name, BIND_VAR, node.id.loc.start);
  3957. this.semicolon();
  3958. return this.finishNode(node, "DeclareVariable");
  3959. }
  3960. flowParseDeclareModule(node) {
  3961. this.scope.enter(SCOPE_OTHER);
  3962. if (this.match(129)) {
  3963. node.id = this.parseExprAtom();
  3964. } else {
  3965. node.id = this.parseIdentifier();
  3966. }
  3967. const bodyNode = node.body = this.startNode();
  3968. const body = bodyNode.body = [];
  3969. this.expect(5);
  3970. while (!this.match(8)) {
  3971. let bodyNode = this.startNode();
  3972. if (this.match(83)) {
  3973. this.next();
  3974. if (!this.isContextual(126) && !this.match(87)) {
  3975. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
  3976. at: this.state.lastTokStartLoc
  3977. });
  3978. }
  3979. this.parseImport(bodyNode);
  3980. } else {
  3981. this.expectContextual(121, FlowErrors.UnsupportedStatementInDeclareModule);
  3982. bodyNode = this.flowParseDeclare(bodyNode, true);
  3983. }
  3984. body.push(bodyNode);
  3985. }
  3986. this.scope.exit();
  3987. this.expect(8);
  3988. this.finishNode(bodyNode, "BlockStatement");
  3989. let kind = null;
  3990. let hasModuleExport = false;
  3991. body.forEach(bodyElement => {
  3992. if (isEsModuleType(bodyElement)) {
  3993. if (kind === "CommonJS") {
  3994. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  3995. at: bodyElement
  3996. });
  3997. }
  3998. kind = "ES";
  3999. } else if (bodyElement.type === "DeclareModuleExports") {
  4000. if (hasModuleExport) {
  4001. this.raise(FlowErrors.DuplicateDeclareModuleExports, {
  4002. at: bodyElement
  4003. });
  4004. }
  4005. if (kind === "ES") {
  4006. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4007. at: bodyElement
  4008. });
  4009. }
  4010. kind = "CommonJS";
  4011. hasModuleExport = true;
  4012. }
  4013. });
  4014. node.kind = kind || "CommonJS";
  4015. return this.finishNode(node, "DeclareModule");
  4016. }
  4017. flowParseDeclareExportDeclaration(node, insideModule) {
  4018. this.expect(82);
  4019. if (this.eat(65)) {
  4020. if (this.match(68) || this.match(80)) {
  4021. node.declaration = this.flowParseDeclare(this.startNode());
  4022. } else {
  4023. node.declaration = this.flowParseType();
  4024. this.semicolon();
  4025. }
  4026. node.default = true;
  4027. return this.finishNode(node, "DeclareExportDeclaration");
  4028. } else {
  4029. if (this.match(75) || this.isLet() || (this.isContextual(126) || this.isContextual(125)) && !insideModule) {
  4030. const label = this.state.value;
  4031. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
  4032. at: this.state.startLoc,
  4033. unsupportedExportKind: label,
  4034. suggestion: exportSuggestions[label]
  4035. });
  4036. }
  4037. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(127)) {
  4038. node.declaration = this.flowParseDeclare(this.startNode());
  4039. node.default = false;
  4040. return this.finishNode(node, "DeclareExportDeclaration");
  4041. } else if (this.match(55) || this.match(5) || this.isContextual(125) || this.isContextual(126) || this.isContextual(127)) {
  4042. node = this.parseExport(node);
  4043. if (node.type === "ExportNamedDeclaration") {
  4044. node.type = "ExportDeclaration";
  4045. node.default = false;
  4046. delete node.exportKind;
  4047. }
  4048. node.type = "Declare" + node.type;
  4049. return node;
  4050. }
  4051. }
  4052. throw this.unexpected();
  4053. }
  4054. flowParseDeclareModuleExports(node) {
  4055. this.next();
  4056. this.expectContextual(108);
  4057. node.typeAnnotation = this.flowParseTypeAnnotation();
  4058. this.semicolon();
  4059. return this.finishNode(node, "DeclareModuleExports");
  4060. }
  4061. flowParseDeclareTypeAlias(node) {
  4062. this.next();
  4063. this.flowParseTypeAlias(node);
  4064. node.type = "DeclareTypeAlias";
  4065. return node;
  4066. }
  4067. flowParseDeclareOpaqueType(node) {
  4068. this.next();
  4069. this.flowParseOpaqueType(node, true);
  4070. node.type = "DeclareOpaqueType";
  4071. return node;
  4072. }
  4073. flowParseDeclareInterface(node) {
  4074. this.next();
  4075. this.flowParseInterfaceish(node);
  4076. return this.finishNode(node, "DeclareInterface");
  4077. }
  4078. flowParseInterfaceish(node, isClass = false) {
  4079. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4080. this.scope.declareName(node.id.name, isClass ? BIND_FUNCTION : BIND_LEXICAL, node.id.loc.start);
  4081. if (this.match(47)) {
  4082. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4083. } else {
  4084. node.typeParameters = null;
  4085. }
  4086. node.extends = [];
  4087. node.implements = [];
  4088. node.mixins = [];
  4089. if (this.eat(81)) {
  4090. do {
  4091. node.extends.push(this.flowParseInterfaceExtends());
  4092. } while (!isClass && this.eat(12));
  4093. }
  4094. if (this.isContextual(114)) {
  4095. this.next();
  4096. do {
  4097. node.mixins.push(this.flowParseInterfaceExtends());
  4098. } while (this.eat(12));
  4099. }
  4100. if (this.isContextual(110)) {
  4101. this.next();
  4102. do {
  4103. node.implements.push(this.flowParseInterfaceExtends());
  4104. } while (this.eat(12));
  4105. }
  4106. node.body = this.flowParseObjectType({
  4107. allowStatic: isClass,
  4108. allowExact: false,
  4109. allowSpread: false,
  4110. allowProto: isClass,
  4111. allowInexact: false
  4112. });
  4113. }
  4114. flowParseInterfaceExtends() {
  4115. const node = this.startNode();
  4116. node.id = this.flowParseQualifiedTypeIdentifier();
  4117. if (this.match(47)) {
  4118. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4119. } else {
  4120. node.typeParameters = null;
  4121. }
  4122. return this.finishNode(node, "InterfaceExtends");
  4123. }
  4124. flowParseInterface(node) {
  4125. this.flowParseInterfaceish(node);
  4126. return this.finishNode(node, "InterfaceDeclaration");
  4127. }
  4128. checkNotUnderscore(word) {
  4129. if (word === "_") {
  4130. this.raise(FlowErrors.UnexpectedReservedUnderscore, {
  4131. at: this.state.startLoc
  4132. });
  4133. }
  4134. }
  4135. checkReservedType(word, startLoc, declaration) {
  4136. if (!reservedTypes.has(word)) return;
  4137. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
  4138. at: startLoc,
  4139. reservedType: word
  4140. });
  4141. }
  4142. flowParseRestrictedIdentifier(liberal, declaration) {
  4143. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4144. return this.parseIdentifier(liberal);
  4145. }
  4146. flowParseTypeAlias(node) {
  4147. node.id = this.flowParseRestrictedIdentifier(false, true);
  4148. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  4149. if (this.match(47)) {
  4150. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4151. } else {
  4152. node.typeParameters = null;
  4153. }
  4154. node.right = this.flowParseTypeInitialiser(29);
  4155. this.semicolon();
  4156. return this.finishNode(node, "TypeAlias");
  4157. }
  4158. flowParseOpaqueType(node, declare) {
  4159. this.expectContextual(126);
  4160. node.id = this.flowParseRestrictedIdentifier(true, true);
  4161. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.loc.start);
  4162. if (this.match(47)) {
  4163. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4164. } else {
  4165. node.typeParameters = null;
  4166. }
  4167. node.supertype = null;
  4168. if (this.match(14)) {
  4169. node.supertype = this.flowParseTypeInitialiser(14);
  4170. }
  4171. node.impltype = null;
  4172. if (!declare) {
  4173. node.impltype = this.flowParseTypeInitialiser(29);
  4174. }
  4175. this.semicolon();
  4176. return this.finishNode(node, "OpaqueType");
  4177. }
  4178. flowParseTypeParameter(requireDefault = false) {
  4179. const nodeStartLoc = this.state.startLoc;
  4180. const node = this.startNode();
  4181. const variance = this.flowParseVariance();
  4182. const ident = this.flowParseTypeAnnotatableIdentifier();
  4183. node.name = ident.name;
  4184. node.variance = variance;
  4185. node.bound = ident.typeAnnotation;
  4186. if (this.match(29)) {
  4187. this.eat(29);
  4188. node.default = this.flowParseType();
  4189. } else {
  4190. if (requireDefault) {
  4191. this.raise(FlowErrors.MissingTypeParamDefault, {
  4192. at: nodeStartLoc
  4193. });
  4194. }
  4195. }
  4196. return this.finishNode(node, "TypeParameter");
  4197. }
  4198. flowParseTypeParameterDeclaration() {
  4199. const oldInType = this.state.inType;
  4200. const node = this.startNode();
  4201. node.params = [];
  4202. this.state.inType = true;
  4203. if (this.match(47) || this.match(138)) {
  4204. this.next();
  4205. } else {
  4206. this.unexpected();
  4207. }
  4208. let defaultRequired = false;
  4209. do {
  4210. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4211. node.params.push(typeParameter);
  4212. if (typeParameter.default) {
  4213. defaultRequired = true;
  4214. }
  4215. if (!this.match(48)) {
  4216. this.expect(12);
  4217. }
  4218. } while (!this.match(48));
  4219. this.expect(48);
  4220. this.state.inType = oldInType;
  4221. return this.finishNode(node, "TypeParameterDeclaration");
  4222. }
  4223. flowParseTypeParameterInstantiation() {
  4224. const node = this.startNode();
  4225. const oldInType = this.state.inType;
  4226. node.params = [];
  4227. this.state.inType = true;
  4228. this.expect(47);
  4229. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4230. this.state.noAnonFunctionType = false;
  4231. while (!this.match(48)) {
  4232. node.params.push(this.flowParseType());
  4233. if (!this.match(48)) {
  4234. this.expect(12);
  4235. }
  4236. }
  4237. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4238. this.expect(48);
  4239. this.state.inType = oldInType;
  4240. return this.finishNode(node, "TypeParameterInstantiation");
  4241. }
  4242. flowParseTypeParameterInstantiationCallOrNew() {
  4243. const node = this.startNode();
  4244. const oldInType = this.state.inType;
  4245. node.params = [];
  4246. this.state.inType = true;
  4247. this.expect(47);
  4248. while (!this.match(48)) {
  4249. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4250. if (!this.match(48)) {
  4251. this.expect(12);
  4252. }
  4253. }
  4254. this.expect(48);
  4255. this.state.inType = oldInType;
  4256. return this.finishNode(node, "TypeParameterInstantiation");
  4257. }
  4258. flowParseInterfaceType() {
  4259. const node = this.startNode();
  4260. this.expectContextual(125);
  4261. node.extends = [];
  4262. if (this.eat(81)) {
  4263. do {
  4264. node.extends.push(this.flowParseInterfaceExtends());
  4265. } while (this.eat(12));
  4266. }
  4267. node.body = this.flowParseObjectType({
  4268. allowStatic: false,
  4269. allowExact: false,
  4270. allowSpread: false,
  4271. allowProto: false,
  4272. allowInexact: false
  4273. });
  4274. return this.finishNode(node, "InterfaceTypeAnnotation");
  4275. }
  4276. flowParseObjectPropertyKey() {
  4277. return this.match(130) || this.match(129) ? this.parseExprAtom() : this.parseIdentifier(true);
  4278. }
  4279. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4280. node.static = isStatic;
  4281. if (this.lookahead().type === 14) {
  4282. node.id = this.flowParseObjectPropertyKey();
  4283. node.key = this.flowParseTypeInitialiser();
  4284. } else {
  4285. node.id = null;
  4286. node.key = this.flowParseType();
  4287. }
  4288. this.expect(3);
  4289. node.value = this.flowParseTypeInitialiser();
  4290. node.variance = variance;
  4291. return this.finishNode(node, "ObjectTypeIndexer");
  4292. }
  4293. flowParseObjectTypeInternalSlot(node, isStatic) {
  4294. node.static = isStatic;
  4295. node.id = this.flowParseObjectPropertyKey();
  4296. this.expect(3);
  4297. this.expect(3);
  4298. if (this.match(47) || this.match(10)) {
  4299. node.method = true;
  4300. node.optional = false;
  4301. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.start, node.loc.start));
  4302. } else {
  4303. node.method = false;
  4304. if (this.eat(17)) {
  4305. node.optional = true;
  4306. }
  4307. node.value = this.flowParseTypeInitialiser();
  4308. }
  4309. return this.finishNode(node, "ObjectTypeInternalSlot");
  4310. }
  4311. flowParseObjectTypeMethodish(node) {
  4312. node.params = [];
  4313. node.rest = null;
  4314. node.typeParameters = null;
  4315. node.this = null;
  4316. if (this.match(47)) {
  4317. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4318. }
  4319. this.expect(10);
  4320. if (this.match(78)) {
  4321. node.this = this.flowParseFunctionTypeParam(true);
  4322. node.this.name = null;
  4323. if (!this.match(11)) {
  4324. this.expect(12);
  4325. }
  4326. }
  4327. while (!this.match(11) && !this.match(21)) {
  4328. node.params.push(this.flowParseFunctionTypeParam(false));
  4329. if (!this.match(11)) {
  4330. this.expect(12);
  4331. }
  4332. }
  4333. if (this.eat(21)) {
  4334. node.rest = this.flowParseFunctionTypeParam(false);
  4335. }
  4336. this.expect(11);
  4337. node.returnType = this.flowParseTypeInitialiser();
  4338. return this.finishNode(node, "FunctionTypeAnnotation");
  4339. }
  4340. flowParseObjectTypeCallProperty(node, isStatic) {
  4341. const valueNode = this.startNode();
  4342. node.static = isStatic;
  4343. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4344. return this.finishNode(node, "ObjectTypeCallProperty");
  4345. }
  4346. flowParseObjectType({
  4347. allowStatic,
  4348. allowExact,
  4349. allowSpread,
  4350. allowProto,
  4351. allowInexact
  4352. }) {
  4353. const oldInType = this.state.inType;
  4354. this.state.inType = true;
  4355. const nodeStart = this.startNode();
  4356. nodeStart.callProperties = [];
  4357. nodeStart.properties = [];
  4358. nodeStart.indexers = [];
  4359. nodeStart.internalSlots = [];
  4360. let endDelim;
  4361. let exact;
  4362. let inexact = false;
  4363. if (allowExact && this.match(6)) {
  4364. this.expect(6);
  4365. endDelim = 9;
  4366. exact = true;
  4367. } else {
  4368. this.expect(5);
  4369. endDelim = 8;
  4370. exact = false;
  4371. }
  4372. nodeStart.exact = exact;
  4373. while (!this.match(endDelim)) {
  4374. let isStatic = false;
  4375. let protoStartLoc = null;
  4376. let inexactStartLoc = null;
  4377. const node = this.startNode();
  4378. if (allowProto && this.isContextual(115)) {
  4379. const lookahead = this.lookahead();
  4380. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4381. this.next();
  4382. protoStartLoc = this.state.startLoc;
  4383. allowStatic = false;
  4384. }
  4385. }
  4386. if (allowStatic && this.isContextual(104)) {
  4387. const lookahead = this.lookahead();
  4388. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4389. this.next();
  4390. isStatic = true;
  4391. }
  4392. }
  4393. const variance = this.flowParseVariance();
  4394. if (this.eat(0)) {
  4395. if (protoStartLoc != null) {
  4396. this.unexpected(protoStartLoc);
  4397. }
  4398. if (this.eat(0)) {
  4399. if (variance) {
  4400. this.unexpected(variance.loc.start);
  4401. }
  4402. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4403. } else {
  4404. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4405. }
  4406. } else if (this.match(10) || this.match(47)) {
  4407. if (protoStartLoc != null) {
  4408. this.unexpected(protoStartLoc);
  4409. }
  4410. if (variance) {
  4411. this.unexpected(variance.loc.start);
  4412. }
  4413. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4414. } else {
  4415. let kind = "init";
  4416. if (this.isContextual(98) || this.isContextual(103)) {
  4417. const lookahead = this.lookahead();
  4418. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4419. kind = this.state.value;
  4420. this.next();
  4421. }
  4422. }
  4423. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4424. if (propOrInexact === null) {
  4425. inexact = true;
  4426. inexactStartLoc = this.state.lastTokStartLoc;
  4427. } else {
  4428. nodeStart.properties.push(propOrInexact);
  4429. }
  4430. }
  4431. this.flowObjectTypeSemicolon();
  4432. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4433. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
  4434. at: inexactStartLoc
  4435. });
  4436. }
  4437. }
  4438. this.expect(endDelim);
  4439. if (allowSpread) {
  4440. nodeStart.inexact = inexact;
  4441. }
  4442. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4443. this.state.inType = oldInType;
  4444. return out;
  4445. }
  4446. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4447. if (this.eat(21)) {
  4448. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4449. if (isInexactToken) {
  4450. if (!allowSpread) {
  4451. this.raise(FlowErrors.InexactInsideNonObject, {
  4452. at: this.state.lastTokStartLoc
  4453. });
  4454. } else if (!allowInexact) {
  4455. this.raise(FlowErrors.InexactInsideExact, {
  4456. at: this.state.lastTokStartLoc
  4457. });
  4458. }
  4459. if (variance) {
  4460. this.raise(FlowErrors.InexactVariance, {
  4461. at: variance
  4462. });
  4463. }
  4464. return null;
  4465. }
  4466. if (!allowSpread) {
  4467. this.raise(FlowErrors.UnexpectedSpreadType, {
  4468. at: this.state.lastTokStartLoc
  4469. });
  4470. }
  4471. if (protoStartLoc != null) {
  4472. this.unexpected(protoStartLoc);
  4473. }
  4474. if (variance) {
  4475. this.raise(FlowErrors.SpreadVariance, {
  4476. at: variance
  4477. });
  4478. }
  4479. node.argument = this.flowParseType();
  4480. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4481. } else {
  4482. node.key = this.flowParseObjectPropertyKey();
  4483. node.static = isStatic;
  4484. node.proto = protoStartLoc != null;
  4485. node.kind = kind;
  4486. let optional = false;
  4487. if (this.match(47) || this.match(10)) {
  4488. node.method = true;
  4489. if (protoStartLoc != null) {
  4490. this.unexpected(protoStartLoc);
  4491. }
  4492. if (variance) {
  4493. this.unexpected(variance.loc.start);
  4494. }
  4495. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.start, node.loc.start));
  4496. if (kind === "get" || kind === "set") {
  4497. this.flowCheckGetterSetterParams(node);
  4498. }
  4499. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4500. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  4501. at: node.value.this
  4502. });
  4503. }
  4504. } else {
  4505. if (kind !== "init") this.unexpected();
  4506. node.method = false;
  4507. if (this.eat(17)) {
  4508. optional = true;
  4509. }
  4510. node.value = this.flowParseTypeInitialiser();
  4511. node.variance = variance;
  4512. }
  4513. node.optional = optional;
  4514. return this.finishNode(node, "ObjectTypeProperty");
  4515. }
  4516. }
  4517. flowCheckGetterSetterParams(property) {
  4518. const paramCount = property.kind === "get" ? 0 : 1;
  4519. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4520. if (property.value.this) {
  4521. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
  4522. at: property.value.this
  4523. });
  4524. }
  4525. if (length !== paramCount) {
  4526. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  4527. at: property
  4528. });
  4529. }
  4530. if (property.kind === "set" && property.value.rest) {
  4531. this.raise(Errors.BadSetterRestParameter, {
  4532. at: property
  4533. });
  4534. }
  4535. }
  4536. flowObjectTypeSemicolon() {
  4537. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4538. this.unexpected();
  4539. }
  4540. }
  4541. flowParseQualifiedTypeIdentifier(startPos, startLoc, id) {
  4542. startPos = startPos || this.state.start;
  4543. startLoc = startLoc || this.state.startLoc;
  4544. let node = id || this.flowParseRestrictedIdentifier(true);
  4545. while (this.eat(16)) {
  4546. const node2 = this.startNodeAt(startPos, startLoc);
  4547. node2.qualification = node;
  4548. node2.id = this.flowParseRestrictedIdentifier(true);
  4549. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4550. }
  4551. return node;
  4552. }
  4553. flowParseGenericType(startPos, startLoc, id) {
  4554. const node = this.startNodeAt(startPos, startLoc);
  4555. node.typeParameters = null;
  4556. node.id = this.flowParseQualifiedTypeIdentifier(startPos, startLoc, id);
  4557. if (this.match(47)) {
  4558. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4559. }
  4560. return this.finishNode(node, "GenericTypeAnnotation");
  4561. }
  4562. flowParseTypeofType() {
  4563. const node = this.startNode();
  4564. this.expect(87);
  4565. node.argument = this.flowParsePrimaryType();
  4566. return this.finishNode(node, "TypeofTypeAnnotation");
  4567. }
  4568. flowParseTupleType() {
  4569. const node = this.startNode();
  4570. node.types = [];
  4571. this.expect(0);
  4572. while (this.state.pos < this.length && !this.match(3)) {
  4573. node.types.push(this.flowParseType());
  4574. if (this.match(3)) break;
  4575. this.expect(12);
  4576. }
  4577. this.expect(3);
  4578. return this.finishNode(node, "TupleTypeAnnotation");
  4579. }
  4580. flowParseFunctionTypeParam(first) {
  4581. let name = null;
  4582. let optional = false;
  4583. let typeAnnotation = null;
  4584. const node = this.startNode();
  4585. const lh = this.lookahead();
  4586. const isThis = this.state.type === 78;
  4587. if (lh.type === 14 || lh.type === 17) {
  4588. if (isThis && !first) {
  4589. this.raise(FlowErrors.ThisParamMustBeFirst, {
  4590. at: node
  4591. });
  4592. }
  4593. name = this.parseIdentifier(isThis);
  4594. if (this.eat(17)) {
  4595. optional = true;
  4596. if (isThis) {
  4597. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  4598. at: node
  4599. });
  4600. }
  4601. }
  4602. typeAnnotation = this.flowParseTypeInitialiser();
  4603. } else {
  4604. typeAnnotation = this.flowParseType();
  4605. }
  4606. node.name = name;
  4607. node.optional = optional;
  4608. node.typeAnnotation = typeAnnotation;
  4609. return this.finishNode(node, "FunctionTypeParam");
  4610. }
  4611. reinterpretTypeAsFunctionTypeParam(type) {
  4612. const node = this.startNodeAt(type.start, type.loc.start);
  4613. node.name = null;
  4614. node.optional = false;
  4615. node.typeAnnotation = type;
  4616. return this.finishNode(node, "FunctionTypeParam");
  4617. }
  4618. flowParseFunctionTypeParams(params = []) {
  4619. let rest = null;
  4620. let _this = null;
  4621. if (this.match(78)) {
  4622. _this = this.flowParseFunctionTypeParam(true);
  4623. _this.name = null;
  4624. if (!this.match(11)) {
  4625. this.expect(12);
  4626. }
  4627. }
  4628. while (!this.match(11) && !this.match(21)) {
  4629. params.push(this.flowParseFunctionTypeParam(false));
  4630. if (!this.match(11)) {
  4631. this.expect(12);
  4632. }
  4633. }
  4634. if (this.eat(21)) {
  4635. rest = this.flowParseFunctionTypeParam(false);
  4636. }
  4637. return {
  4638. params,
  4639. rest,
  4640. _this
  4641. };
  4642. }
  4643. flowIdentToTypeAnnotation(startPos, startLoc, node, id) {
  4644. switch (id.name) {
  4645. case "any":
  4646. return this.finishNode(node, "AnyTypeAnnotation");
  4647. case "bool":
  4648. case "boolean":
  4649. return this.finishNode(node, "BooleanTypeAnnotation");
  4650. case "mixed":
  4651. return this.finishNode(node, "MixedTypeAnnotation");
  4652. case "empty":
  4653. return this.finishNode(node, "EmptyTypeAnnotation");
  4654. case "number":
  4655. return this.finishNode(node, "NumberTypeAnnotation");
  4656. case "string":
  4657. return this.finishNode(node, "StringTypeAnnotation");
  4658. case "symbol":
  4659. return this.finishNode(node, "SymbolTypeAnnotation");
  4660. default:
  4661. this.checkNotUnderscore(id.name);
  4662. return this.flowParseGenericType(startPos, startLoc, id);
  4663. }
  4664. }
  4665. flowParsePrimaryType() {
  4666. const startPos = this.state.start;
  4667. const startLoc = this.state.startLoc;
  4668. const node = this.startNode();
  4669. let tmp;
  4670. let type;
  4671. let isGroupedType = false;
  4672. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4673. switch (this.state.type) {
  4674. case 5:
  4675. return this.flowParseObjectType({
  4676. allowStatic: false,
  4677. allowExact: false,
  4678. allowSpread: true,
  4679. allowProto: false,
  4680. allowInexact: true
  4681. });
  4682. case 6:
  4683. return this.flowParseObjectType({
  4684. allowStatic: false,
  4685. allowExact: true,
  4686. allowSpread: true,
  4687. allowProto: false,
  4688. allowInexact: false
  4689. });
  4690. case 0:
  4691. this.state.noAnonFunctionType = false;
  4692. type = this.flowParseTupleType();
  4693. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4694. return type;
  4695. case 47:
  4696. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4697. this.expect(10);
  4698. tmp = this.flowParseFunctionTypeParams();
  4699. node.params = tmp.params;
  4700. node.rest = tmp.rest;
  4701. node.this = tmp._this;
  4702. this.expect(11);
  4703. this.expect(19);
  4704. node.returnType = this.flowParseType();
  4705. return this.finishNode(node, "FunctionTypeAnnotation");
  4706. case 10:
  4707. this.next();
  4708. if (!this.match(11) && !this.match(21)) {
  4709. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4710. const token = this.lookahead().type;
  4711. isGroupedType = token !== 17 && token !== 14;
  4712. } else {
  4713. isGroupedType = true;
  4714. }
  4715. }
  4716. if (isGroupedType) {
  4717. this.state.noAnonFunctionType = false;
  4718. type = this.flowParseType();
  4719. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4720. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4721. this.expect(11);
  4722. return type;
  4723. } else {
  4724. this.eat(12);
  4725. }
  4726. }
  4727. if (type) {
  4728. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4729. } else {
  4730. tmp = this.flowParseFunctionTypeParams();
  4731. }
  4732. node.params = tmp.params;
  4733. node.rest = tmp.rest;
  4734. node.this = tmp._this;
  4735. this.expect(11);
  4736. this.expect(19);
  4737. node.returnType = this.flowParseType();
  4738. node.typeParameters = null;
  4739. return this.finishNode(node, "FunctionTypeAnnotation");
  4740. case 129:
  4741. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4742. case 85:
  4743. case 86:
  4744. node.value = this.match(85);
  4745. this.next();
  4746. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4747. case 53:
  4748. if (this.state.value === "-") {
  4749. this.next();
  4750. if (this.match(130)) {
  4751. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4752. }
  4753. if (this.match(131)) {
  4754. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4755. }
  4756. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
  4757. at: this.state.startLoc
  4758. });
  4759. }
  4760. throw this.unexpected();
  4761. case 130:
  4762. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4763. case 131:
  4764. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4765. case 88:
  4766. this.next();
  4767. return this.finishNode(node, "VoidTypeAnnotation");
  4768. case 84:
  4769. this.next();
  4770. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4771. case 78:
  4772. this.next();
  4773. return this.finishNode(node, "ThisTypeAnnotation");
  4774. case 55:
  4775. this.next();
  4776. return this.finishNode(node, "ExistsTypeAnnotation");
  4777. case 87:
  4778. return this.flowParseTypeofType();
  4779. default:
  4780. if (tokenIsKeyword(this.state.type)) {
  4781. const label = tokenLabelName(this.state.type);
  4782. this.next();
  4783. return super.createIdentifier(node, label);
  4784. } else if (tokenIsIdentifier(this.state.type)) {
  4785. if (this.isContextual(125)) {
  4786. return this.flowParseInterfaceType();
  4787. }
  4788. return this.flowIdentToTypeAnnotation(startPos, startLoc, node, this.parseIdentifier());
  4789. }
  4790. }
  4791. throw this.unexpected();
  4792. }
  4793. flowParsePostfixType() {
  4794. const startPos = this.state.start;
  4795. const startLoc = this.state.startLoc;
  4796. let type = this.flowParsePrimaryType();
  4797. let seenOptionalIndexedAccess = false;
  4798. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4799. const node = this.startNodeAt(startPos, startLoc);
  4800. const optional = this.eat(18);
  4801. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  4802. this.expect(0);
  4803. if (!optional && this.match(3)) {
  4804. node.elementType = type;
  4805. this.next();
  4806. type = this.finishNode(node, "ArrayTypeAnnotation");
  4807. } else {
  4808. node.objectType = type;
  4809. node.indexType = this.flowParseType();
  4810. this.expect(3);
  4811. if (seenOptionalIndexedAccess) {
  4812. node.optional = optional;
  4813. type = this.finishNode(node, "OptionalIndexedAccessType");
  4814. } else {
  4815. type = this.finishNode(node, "IndexedAccessType");
  4816. }
  4817. }
  4818. }
  4819. return type;
  4820. }
  4821. flowParsePrefixType() {
  4822. const node = this.startNode();
  4823. if (this.eat(17)) {
  4824. node.typeAnnotation = this.flowParsePrefixType();
  4825. return this.finishNode(node, "NullableTypeAnnotation");
  4826. } else {
  4827. return this.flowParsePostfixType();
  4828. }
  4829. }
  4830. flowParseAnonFunctionWithoutParens() {
  4831. const param = this.flowParsePrefixType();
  4832. if (!this.state.noAnonFunctionType && this.eat(19)) {
  4833. const node = this.startNodeAt(param.start, param.loc.start);
  4834. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  4835. node.rest = null;
  4836. node.this = null;
  4837. node.returnType = this.flowParseType();
  4838. node.typeParameters = null;
  4839. return this.finishNode(node, "FunctionTypeAnnotation");
  4840. }
  4841. return param;
  4842. }
  4843. flowParseIntersectionType() {
  4844. const node = this.startNode();
  4845. this.eat(45);
  4846. const type = this.flowParseAnonFunctionWithoutParens();
  4847. node.types = [type];
  4848. while (this.eat(45)) {
  4849. node.types.push(this.flowParseAnonFunctionWithoutParens());
  4850. }
  4851. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  4852. }
  4853. flowParseUnionType() {
  4854. const node = this.startNode();
  4855. this.eat(43);
  4856. const type = this.flowParseIntersectionType();
  4857. node.types = [type];
  4858. while (this.eat(43)) {
  4859. node.types.push(this.flowParseIntersectionType());
  4860. }
  4861. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  4862. }
  4863. flowParseType() {
  4864. const oldInType = this.state.inType;
  4865. this.state.inType = true;
  4866. const type = this.flowParseUnionType();
  4867. this.state.inType = oldInType;
  4868. return type;
  4869. }
  4870. flowParseTypeOrImplicitInstantiation() {
  4871. if (this.state.type === 128 && this.state.value === "_") {
  4872. const startPos = this.state.start;
  4873. const startLoc = this.state.startLoc;
  4874. const node = this.parseIdentifier();
  4875. return this.flowParseGenericType(startPos, startLoc, node);
  4876. } else {
  4877. return this.flowParseType();
  4878. }
  4879. }
  4880. flowParseTypeAnnotation() {
  4881. const node = this.startNode();
  4882. node.typeAnnotation = this.flowParseTypeInitialiser();
  4883. return this.finishNode(node, "TypeAnnotation");
  4884. }
  4885. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  4886. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  4887. if (this.match(14)) {
  4888. ident.typeAnnotation = this.flowParseTypeAnnotation();
  4889. this.resetEndLocation(ident);
  4890. }
  4891. return ident;
  4892. }
  4893. typeCastToParameter(node) {
  4894. node.expression.typeAnnotation = node.typeAnnotation;
  4895. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  4896. return node.expression;
  4897. }
  4898. flowParseVariance() {
  4899. let variance = null;
  4900. if (this.match(53)) {
  4901. variance = this.startNode();
  4902. if (this.state.value === "+") {
  4903. variance.kind = "plus";
  4904. } else {
  4905. variance.kind = "minus";
  4906. }
  4907. this.next();
  4908. this.finishNode(variance, "Variance");
  4909. }
  4910. return variance;
  4911. }
  4912. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  4913. if (allowExpressionBody) {
  4914. return this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  4915. }
  4916. return super.parseFunctionBody(node, false, isMethod);
  4917. }
  4918. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  4919. if (this.match(14)) {
  4920. const typeNode = this.startNode();
  4921. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4922. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  4923. }
  4924. super.parseFunctionBodyAndFinish(node, type, isMethod);
  4925. }
  4926. parseStatement(context, topLevel) {
  4927. if (this.state.strict && this.isContextual(125)) {
  4928. const lookahead = this.lookahead();
  4929. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  4930. const node = this.startNode();
  4931. this.next();
  4932. return this.flowParseInterface(node);
  4933. }
  4934. } else if (this.shouldParseEnums() && this.isContextual(122)) {
  4935. const node = this.startNode();
  4936. this.next();
  4937. return this.flowParseEnumDeclaration(node);
  4938. }
  4939. const stmt = super.parseStatement(context, topLevel);
  4940. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  4941. this.flowPragma = null;
  4942. }
  4943. return stmt;
  4944. }
  4945. parseExpressionStatement(node, expr) {
  4946. if (expr.type === "Identifier") {
  4947. if (expr.name === "declare") {
  4948. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  4949. return this.flowParseDeclare(node);
  4950. }
  4951. } else if (tokenIsIdentifier(this.state.type)) {
  4952. if (expr.name === "interface") {
  4953. return this.flowParseInterface(node);
  4954. } else if (expr.name === "type") {
  4955. return this.flowParseTypeAlias(node);
  4956. } else if (expr.name === "opaque") {
  4957. return this.flowParseOpaqueType(node, false);
  4958. }
  4959. }
  4960. }
  4961. return super.parseExpressionStatement(node, expr);
  4962. }
  4963. shouldParseExportDeclaration() {
  4964. const {
  4965. type
  4966. } = this.state;
  4967. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 122) {
  4968. return !this.state.containsEsc;
  4969. }
  4970. return super.shouldParseExportDeclaration();
  4971. }
  4972. isExportDefaultSpecifier() {
  4973. const {
  4974. type
  4975. } = this.state;
  4976. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 122) {
  4977. return this.state.containsEsc;
  4978. }
  4979. return super.isExportDefaultSpecifier();
  4980. }
  4981. parseExportDefaultExpression() {
  4982. if (this.shouldParseEnums() && this.isContextual(122)) {
  4983. const node = this.startNode();
  4984. this.next();
  4985. return this.flowParseEnumDeclaration(node);
  4986. }
  4987. return super.parseExportDefaultExpression();
  4988. }
  4989. parseConditional(expr, startPos, startLoc, refExpressionErrors) {
  4990. if (!this.match(17)) return expr;
  4991. if (this.state.maybeInArrowParameters) {
  4992. const nextCh = this.lookaheadCharCode();
  4993. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  4994. this.setOptionalParametersError(refExpressionErrors);
  4995. return expr;
  4996. }
  4997. }
  4998. this.expect(17);
  4999. const state = this.state.clone();
  5000. const originalNoArrowAt = this.state.noArrowAt;
  5001. const node = this.startNodeAt(startPos, startLoc);
  5002. let {
  5003. consequent,
  5004. failed
  5005. } = this.tryParseConditionalConsequent();
  5006. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5007. if (failed || invalid.length > 0) {
  5008. const noArrowAt = [...originalNoArrowAt];
  5009. if (invalid.length > 0) {
  5010. this.state = state;
  5011. this.state.noArrowAt = noArrowAt;
  5012. for (let i = 0; i < invalid.length; i++) {
  5013. noArrowAt.push(invalid[i].start);
  5014. }
  5015. ({
  5016. consequent,
  5017. failed
  5018. } = this.tryParseConditionalConsequent());
  5019. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5020. }
  5021. if (failed && valid.length > 1) {
  5022. this.raise(FlowErrors.AmbiguousConditionalArrow, {
  5023. at: state.startLoc
  5024. });
  5025. }
  5026. if (failed && valid.length === 1) {
  5027. this.state = state;
  5028. noArrowAt.push(valid[0].start);
  5029. this.state.noArrowAt = noArrowAt;
  5030. ({
  5031. consequent,
  5032. failed
  5033. } = this.tryParseConditionalConsequent());
  5034. }
  5035. }
  5036. this.getArrowLikeExpressions(consequent, true);
  5037. this.state.noArrowAt = originalNoArrowAt;
  5038. this.expect(14);
  5039. node.test = expr;
  5040. node.consequent = consequent;
  5041. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5042. return this.finishNode(node, "ConditionalExpression");
  5043. }
  5044. tryParseConditionalConsequent() {
  5045. this.state.noArrowParamsConversionAt.push(this.state.start);
  5046. const consequent = this.parseMaybeAssignAllowIn();
  5047. const failed = !this.match(14);
  5048. this.state.noArrowParamsConversionAt.pop();
  5049. return {
  5050. consequent,
  5051. failed
  5052. };
  5053. }
  5054. getArrowLikeExpressions(node, disallowInvalid) {
  5055. const stack = [node];
  5056. const arrows = [];
  5057. while (stack.length !== 0) {
  5058. const node = stack.pop();
  5059. if (node.type === "ArrowFunctionExpression") {
  5060. if (node.typeParameters || !node.returnType) {
  5061. this.finishArrowValidation(node);
  5062. } else {
  5063. arrows.push(node);
  5064. }
  5065. stack.push(node.body);
  5066. } else if (node.type === "ConditionalExpression") {
  5067. stack.push(node.consequent);
  5068. stack.push(node.alternate);
  5069. }
  5070. }
  5071. if (disallowInvalid) {
  5072. arrows.forEach(node => this.finishArrowValidation(node));
  5073. return [arrows, []];
  5074. }
  5075. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5076. }
  5077. finishArrowValidation(node) {
  5078. var _node$extra;
  5079. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5080. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  5081. super.checkParams(node, false, true);
  5082. this.scope.exit();
  5083. }
  5084. forwardNoArrowParamsConversionAt(node, parse) {
  5085. let result;
  5086. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5087. this.state.noArrowParamsConversionAt.push(this.state.start);
  5088. result = parse();
  5089. this.state.noArrowParamsConversionAt.pop();
  5090. } else {
  5091. result = parse();
  5092. }
  5093. return result;
  5094. }
  5095. parseParenItem(node, startPos, startLoc) {
  5096. node = super.parseParenItem(node, startPos, startLoc);
  5097. if (this.eat(17)) {
  5098. node.optional = true;
  5099. this.resetEndLocation(node);
  5100. }
  5101. if (this.match(14)) {
  5102. const typeCastNode = this.startNodeAt(startPos, startLoc);
  5103. typeCastNode.expression = node;
  5104. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5105. return this.finishNode(typeCastNode, "TypeCastExpression");
  5106. }
  5107. return node;
  5108. }
  5109. assertModuleNodeAllowed(node) {
  5110. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5111. return;
  5112. }
  5113. super.assertModuleNodeAllowed(node);
  5114. }
  5115. parseExport(node) {
  5116. const decl = super.parseExport(node);
  5117. if (decl.type === "ExportNamedDeclaration" || decl.type === "ExportAllDeclaration") {
  5118. decl.exportKind = decl.exportKind || "value";
  5119. }
  5120. return decl;
  5121. }
  5122. parseExportDeclaration(node) {
  5123. if (this.isContextual(126)) {
  5124. node.exportKind = "type";
  5125. const declarationNode = this.startNode();
  5126. this.next();
  5127. if (this.match(5)) {
  5128. node.specifiers = this.parseExportSpecifiers(true);
  5129. this.parseExportFrom(node);
  5130. return null;
  5131. } else {
  5132. return this.flowParseTypeAlias(declarationNode);
  5133. }
  5134. } else if (this.isContextual(127)) {
  5135. node.exportKind = "type";
  5136. const declarationNode = this.startNode();
  5137. this.next();
  5138. return this.flowParseOpaqueType(declarationNode, false);
  5139. } else if (this.isContextual(125)) {
  5140. node.exportKind = "type";
  5141. const declarationNode = this.startNode();
  5142. this.next();
  5143. return this.flowParseInterface(declarationNode);
  5144. } else if (this.shouldParseEnums() && this.isContextual(122)) {
  5145. node.exportKind = "value";
  5146. const declarationNode = this.startNode();
  5147. this.next();
  5148. return this.flowParseEnumDeclaration(declarationNode);
  5149. } else {
  5150. return super.parseExportDeclaration(node);
  5151. }
  5152. }
  5153. eatExportStar(node) {
  5154. if (super.eatExportStar(...arguments)) return true;
  5155. if (this.isContextual(126) && this.lookahead().type === 55) {
  5156. node.exportKind = "type";
  5157. this.next();
  5158. this.next();
  5159. return true;
  5160. }
  5161. return false;
  5162. }
  5163. maybeParseExportNamespaceSpecifier(node) {
  5164. const {
  5165. startLoc
  5166. } = this.state;
  5167. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5168. if (hasNamespace && node.exportKind === "type") {
  5169. this.unexpected(startLoc);
  5170. }
  5171. return hasNamespace;
  5172. }
  5173. parseClassId(node, isStatement, optionalId) {
  5174. super.parseClassId(node, isStatement, optionalId);
  5175. if (this.match(47)) {
  5176. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5177. }
  5178. }
  5179. parseClassMember(classBody, member, state) {
  5180. const {
  5181. startLoc
  5182. } = this.state;
  5183. if (this.isContextual(121)) {
  5184. if (this.parseClassMemberFromModifier(classBody, member)) {
  5185. return;
  5186. }
  5187. member.declare = true;
  5188. }
  5189. super.parseClassMember(classBody, member, state);
  5190. if (member.declare) {
  5191. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5192. this.raise(FlowErrors.DeclareClassElement, {
  5193. at: startLoc
  5194. });
  5195. } else if (member.value) {
  5196. this.raise(FlowErrors.DeclareClassFieldInitializer, {
  5197. at: member.value
  5198. });
  5199. }
  5200. }
  5201. }
  5202. isIterator(word) {
  5203. return word === "iterator" || word === "asyncIterator";
  5204. }
  5205. readIterator() {
  5206. const word = super.readWord1();
  5207. const fullWord = "@@" + word;
  5208. if (!this.isIterator(word) || !this.state.inType) {
  5209. this.raise(Errors.InvalidIdentifier, {
  5210. at: this.state.curPosition(),
  5211. identifierName: fullWord
  5212. });
  5213. }
  5214. this.finishToken(128, fullWord);
  5215. }
  5216. getTokenFromCode(code) {
  5217. const next = this.input.charCodeAt(this.state.pos + 1);
  5218. if (code === 123 && next === 124) {
  5219. return this.finishOp(6, 2);
  5220. } else if (this.state.inType && (code === 62 || code === 60)) {
  5221. return this.finishOp(code === 62 ? 48 : 47, 1);
  5222. } else if (this.state.inType && code === 63) {
  5223. if (next === 46) {
  5224. return this.finishOp(18, 2);
  5225. }
  5226. return this.finishOp(17, 1);
  5227. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5228. this.state.pos += 2;
  5229. return this.readIterator();
  5230. } else {
  5231. return super.getTokenFromCode(code);
  5232. }
  5233. }
  5234. isAssignable(node, isBinding) {
  5235. if (node.type === "TypeCastExpression") {
  5236. return this.isAssignable(node.expression, isBinding);
  5237. } else {
  5238. return super.isAssignable(node, isBinding);
  5239. }
  5240. }
  5241. toAssignable(node, isLHS = false) {
  5242. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5243. node.left = this.typeCastToParameter(node.left);
  5244. }
  5245. super.toAssignable(...arguments);
  5246. }
  5247. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5248. for (let i = 0; i < exprList.length; i++) {
  5249. const expr = exprList[i];
  5250. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5251. exprList[i] = this.typeCastToParameter(expr);
  5252. }
  5253. }
  5254. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5255. }
  5256. toReferencedList(exprList, isParenthesizedExpr) {
  5257. for (let i = 0; i < exprList.length; i++) {
  5258. var _expr$extra;
  5259. const expr = exprList[i];
  5260. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5261. this.raise(FlowErrors.TypeCastInPattern, {
  5262. at: expr.typeAnnotation
  5263. });
  5264. }
  5265. }
  5266. return exprList;
  5267. }
  5268. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5269. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5270. if (canBePattern && !this.state.maybeInArrowParameters) {
  5271. this.toReferencedList(node.elements);
  5272. }
  5273. return node;
  5274. }
  5275. isValidLVal(type, ...rest) {
  5276. return type === "TypeCastExpression" || super.isValidLVal(type, ...rest);
  5277. }
  5278. parseClassProperty(node) {
  5279. if (this.match(14)) {
  5280. node.typeAnnotation = this.flowParseTypeAnnotation();
  5281. }
  5282. return super.parseClassProperty(node);
  5283. }
  5284. parseClassPrivateProperty(node) {
  5285. if (this.match(14)) {
  5286. node.typeAnnotation = this.flowParseTypeAnnotation();
  5287. }
  5288. return super.parseClassPrivateProperty(node);
  5289. }
  5290. isClassMethod() {
  5291. return this.match(47) || super.isClassMethod();
  5292. }
  5293. isClassProperty() {
  5294. return this.match(14) || super.isClassProperty();
  5295. }
  5296. isNonstaticConstructor(method) {
  5297. return !this.match(14) && super.isNonstaticConstructor(method);
  5298. }
  5299. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5300. if (method.variance) {
  5301. this.unexpected(method.variance.loc.start);
  5302. }
  5303. delete method.variance;
  5304. if (this.match(47)) {
  5305. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5306. }
  5307. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5308. if (method.params && isConstructor) {
  5309. const params = method.params;
  5310. if (params.length > 0 && this.isThisParam(params[0])) {
  5311. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5312. at: method
  5313. });
  5314. }
  5315. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5316. const params = method.value.params;
  5317. if (params.length > 0 && this.isThisParam(params[0])) {
  5318. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5319. at: method
  5320. });
  5321. }
  5322. }
  5323. }
  5324. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5325. if (method.variance) {
  5326. this.unexpected(method.variance.loc.start);
  5327. }
  5328. delete method.variance;
  5329. if (this.match(47)) {
  5330. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5331. }
  5332. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5333. }
  5334. parseClassSuper(node) {
  5335. super.parseClassSuper(node);
  5336. if (node.superClass && this.match(47)) {
  5337. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  5338. }
  5339. if (this.isContextual(110)) {
  5340. this.next();
  5341. const implemented = node.implements = [];
  5342. do {
  5343. const node = this.startNode();
  5344. node.id = this.flowParseRestrictedIdentifier(true);
  5345. if (this.match(47)) {
  5346. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5347. } else {
  5348. node.typeParameters = null;
  5349. }
  5350. implemented.push(this.finishNode(node, "ClassImplements"));
  5351. } while (this.eat(12));
  5352. }
  5353. }
  5354. checkGetterSetterParams(method) {
  5355. super.checkGetterSetterParams(method);
  5356. const params = this.getObjectOrClassMethodParams(method);
  5357. if (params.length > 0) {
  5358. const param = params[0];
  5359. if (this.isThisParam(param) && method.kind === "get") {
  5360. this.raise(FlowErrors.GetterMayNotHaveThisParam, {
  5361. at: param
  5362. });
  5363. } else if (this.isThisParam(param)) {
  5364. this.raise(FlowErrors.SetterMayNotHaveThisParam, {
  5365. at: param
  5366. });
  5367. }
  5368. }
  5369. }
  5370. parsePropertyNamePrefixOperator(node) {
  5371. node.variance = this.flowParseVariance();
  5372. }
  5373. parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5374. if (prop.variance) {
  5375. this.unexpected(prop.variance.loc.start);
  5376. }
  5377. delete prop.variance;
  5378. let typeParameters;
  5379. if (this.match(47) && !isAccessor) {
  5380. typeParameters = this.flowParseTypeParameterDeclaration();
  5381. if (!this.match(10)) this.unexpected();
  5382. }
  5383. super.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5384. if (typeParameters) {
  5385. (prop.value || prop).typeParameters = typeParameters;
  5386. }
  5387. }
  5388. parseAssignableListItemTypes(param) {
  5389. if (this.eat(17)) {
  5390. if (param.type !== "Identifier") {
  5391. this.raise(FlowErrors.PatternIsOptional, {
  5392. at: param
  5393. });
  5394. }
  5395. if (this.isThisParam(param)) {
  5396. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  5397. at: param
  5398. });
  5399. }
  5400. param.optional = true;
  5401. }
  5402. if (this.match(14)) {
  5403. param.typeAnnotation = this.flowParseTypeAnnotation();
  5404. } else if (this.isThisParam(param)) {
  5405. this.raise(FlowErrors.ThisParamAnnotationRequired, {
  5406. at: param
  5407. });
  5408. }
  5409. if (this.match(29) && this.isThisParam(param)) {
  5410. this.raise(FlowErrors.ThisParamNoDefault, {
  5411. at: param
  5412. });
  5413. }
  5414. this.resetEndLocation(param);
  5415. return param;
  5416. }
  5417. parseMaybeDefault(startPos, startLoc, left) {
  5418. const node = super.parseMaybeDefault(startPos, startLoc, left);
  5419. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5420. this.raise(FlowErrors.TypeBeforeInitializer, {
  5421. at: node.typeAnnotation
  5422. });
  5423. }
  5424. return node;
  5425. }
  5426. shouldParseDefaultImport(node) {
  5427. if (!hasTypeImportKind(node)) {
  5428. return super.shouldParseDefaultImport(node);
  5429. }
  5430. return isMaybeDefaultImport(this.state.type);
  5431. }
  5432. parseImportSpecifierLocal(node, specifier, type) {
  5433. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5434. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5435. }
  5436. maybeParseDefaultImportSpecifier(node) {
  5437. node.importKind = "value";
  5438. let kind = null;
  5439. if (this.match(87)) {
  5440. kind = "typeof";
  5441. } else if (this.isContextual(126)) {
  5442. kind = "type";
  5443. }
  5444. if (kind) {
  5445. const lh = this.lookahead();
  5446. const {
  5447. type
  5448. } = lh;
  5449. if (kind === "type" && type === 55) {
  5450. this.unexpected(null, lh.type);
  5451. }
  5452. if (isMaybeDefaultImport(type) || type === 5 || type === 55) {
  5453. this.next();
  5454. node.importKind = kind;
  5455. }
  5456. }
  5457. return super.maybeParseDefaultImportSpecifier(node);
  5458. }
  5459. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly) {
  5460. const firstIdent = specifier.imported;
  5461. let specifierTypeKind = null;
  5462. if (firstIdent.type === "Identifier") {
  5463. if (firstIdent.name === "type") {
  5464. specifierTypeKind = "type";
  5465. } else if (firstIdent.name === "typeof") {
  5466. specifierTypeKind = "typeof";
  5467. }
  5468. }
  5469. let isBinding = false;
  5470. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5471. const as_ident = this.parseIdentifier(true);
  5472. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5473. specifier.imported = as_ident;
  5474. specifier.importKind = specifierTypeKind;
  5475. specifier.local = cloneIdentifier(as_ident);
  5476. } else {
  5477. specifier.imported = firstIdent;
  5478. specifier.importKind = null;
  5479. specifier.local = this.parseIdentifier();
  5480. }
  5481. } else {
  5482. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5483. specifier.imported = this.parseIdentifier(true);
  5484. specifier.importKind = specifierTypeKind;
  5485. } else {
  5486. if (importedIsString) {
  5487. throw this.raise(Errors.ImportBindingIsString, {
  5488. at: specifier,
  5489. importName: firstIdent.value
  5490. });
  5491. }
  5492. specifier.imported = firstIdent;
  5493. specifier.importKind = null;
  5494. }
  5495. if (this.eatContextual(93)) {
  5496. specifier.local = this.parseIdentifier();
  5497. } else {
  5498. isBinding = true;
  5499. specifier.local = cloneIdentifier(specifier.imported);
  5500. }
  5501. }
  5502. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5503. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5504. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
  5505. at: specifier
  5506. });
  5507. }
  5508. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5509. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5510. }
  5511. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5512. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5513. }
  5514. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5515. }
  5516. parseBindingAtom() {
  5517. switch (this.state.type) {
  5518. case 78:
  5519. return this.parseIdentifier(true);
  5520. default:
  5521. return super.parseBindingAtom();
  5522. }
  5523. }
  5524. parseFunctionParams(node, allowModifiers) {
  5525. const kind = node.kind;
  5526. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5527. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5528. }
  5529. super.parseFunctionParams(node, allowModifiers);
  5530. }
  5531. parseVarId(decl, kind) {
  5532. super.parseVarId(decl, kind);
  5533. if (this.match(14)) {
  5534. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5535. this.resetEndLocation(decl.id);
  5536. }
  5537. }
  5538. parseAsyncArrowFromCallExpression(node, call) {
  5539. if (this.match(14)) {
  5540. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5541. this.state.noAnonFunctionType = true;
  5542. node.returnType = this.flowParseTypeAnnotation();
  5543. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5544. }
  5545. return super.parseAsyncArrowFromCallExpression(node, call);
  5546. }
  5547. shouldParseAsyncArrow() {
  5548. return this.match(14) || super.shouldParseAsyncArrow();
  5549. }
  5550. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5551. var _jsx;
  5552. let state = null;
  5553. let jsx;
  5554. if (this.hasPlugin("jsx") && (this.match(138) || this.match(47))) {
  5555. state = this.state.clone();
  5556. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5557. if (!jsx.error) return jsx.node;
  5558. const {
  5559. context
  5560. } = this.state;
  5561. const currentContext = context[context.length - 1];
  5562. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5563. context.pop();
  5564. }
  5565. }
  5566. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5567. var _jsx2, _jsx3;
  5568. state = state || this.state.clone();
  5569. let typeParameters;
  5570. const arrow = this.tryParse(abort => {
  5571. var _arrowExpression$extr;
  5572. typeParameters = this.flowParseTypeParameterDeclaration();
  5573. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5574. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5575. this.resetStartLocationFromNode(result, typeParameters);
  5576. return result;
  5577. });
  5578. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5579. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5580. if (expr.type !== "ArrowFunctionExpression") abort();
  5581. expr.typeParameters = typeParameters;
  5582. this.resetStartLocationFromNode(expr, typeParameters);
  5583. return arrowExpression;
  5584. }, state);
  5585. let arrowExpression = null;
  5586. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5587. if (!arrow.error && !arrow.aborted) {
  5588. if (arrow.node.async) {
  5589. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
  5590. at: typeParameters
  5591. });
  5592. }
  5593. return arrow.node;
  5594. }
  5595. arrowExpression = arrow.node;
  5596. }
  5597. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5598. this.state = jsx.failState;
  5599. return jsx.node;
  5600. }
  5601. if (arrowExpression) {
  5602. this.state = arrow.failState;
  5603. return arrowExpression;
  5604. }
  5605. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5606. if (arrow.thrown) throw arrow.error;
  5607. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
  5608. at: typeParameters
  5609. });
  5610. }
  5611. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5612. }
  5613. parseArrow(node) {
  5614. if (this.match(14)) {
  5615. const result = this.tryParse(() => {
  5616. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5617. this.state.noAnonFunctionType = true;
  5618. const typeNode = this.startNode();
  5619. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5620. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5621. if (this.canInsertSemicolon()) this.unexpected();
  5622. if (!this.match(19)) this.unexpected();
  5623. return typeNode;
  5624. });
  5625. if (result.thrown) return null;
  5626. if (result.error) this.state = result.failState;
  5627. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5628. }
  5629. return super.parseArrow(node);
  5630. }
  5631. shouldParseArrow(params) {
  5632. return this.match(14) || super.shouldParseArrow(params);
  5633. }
  5634. setArrowFunctionParameters(node, params) {
  5635. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5636. node.params = params;
  5637. } else {
  5638. super.setArrowFunctionParameters(node, params);
  5639. }
  5640. }
  5641. checkParams(node, allowDuplicates, isArrowFunction) {
  5642. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5643. return;
  5644. }
  5645. for (let i = 0; i < node.params.length; i++) {
  5646. if (this.isThisParam(node.params[i]) && i > 0) {
  5647. this.raise(FlowErrors.ThisParamMustBeFirst, {
  5648. at: node.params[i]
  5649. });
  5650. }
  5651. }
  5652. return super.checkParams(...arguments);
  5653. }
  5654. parseParenAndDistinguishExpression(canBeArrow) {
  5655. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  5656. }
  5657. parseSubscripts(base, startPos, startLoc, noCalls) {
  5658. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startPos) !== -1) {
  5659. this.next();
  5660. const node = this.startNodeAt(startPos, startLoc);
  5661. node.callee = base;
  5662. node.arguments = this.parseCallExpressionArguments(11, false);
  5663. base = this.finishNode(node, "CallExpression");
  5664. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5665. const state = this.state.clone();
  5666. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startPos, startLoc) || abort(), state);
  5667. if (!arrow.error && !arrow.aborted) return arrow.node;
  5668. const result = this.tryParse(() => super.parseSubscripts(base, startPos, startLoc, noCalls), state);
  5669. if (result.node && !result.error) return result.node;
  5670. if (arrow.node) {
  5671. this.state = arrow.failState;
  5672. return arrow.node;
  5673. }
  5674. if (result.node) {
  5675. this.state = result.failState;
  5676. return result.node;
  5677. }
  5678. throw arrow.error || result.error;
  5679. }
  5680. return super.parseSubscripts(base, startPos, startLoc, noCalls);
  5681. }
  5682. parseSubscript(base, startPos, startLoc, noCalls, subscriptState) {
  5683. if (this.match(18) && this.isLookaheadToken_lt()) {
  5684. subscriptState.optionalChainMember = true;
  5685. if (noCalls) {
  5686. subscriptState.stop = true;
  5687. return base;
  5688. }
  5689. this.next();
  5690. const node = this.startNodeAt(startPos, startLoc);
  5691. node.callee = base;
  5692. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5693. this.expect(10);
  5694. node.arguments = this.parseCallExpressionArguments(11, false);
  5695. node.optional = true;
  5696. return this.finishCallExpression(node, true);
  5697. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  5698. const node = this.startNodeAt(startPos, startLoc);
  5699. node.callee = base;
  5700. const result = this.tryParse(() => {
  5701. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5702. this.expect(10);
  5703. node.arguments = this.parseCallExpressionArguments(11, false);
  5704. if (subscriptState.optionalChainMember) node.optional = false;
  5705. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5706. });
  5707. if (result.node) {
  5708. if (result.error) this.state = result.failState;
  5709. return result.node;
  5710. }
  5711. }
  5712. return super.parseSubscript(base, startPos, startLoc, noCalls, subscriptState);
  5713. }
  5714. parseNewCallee(node) {
  5715. super.parseNewCallee(node);
  5716. let targs = null;
  5717. if (this.shouldParseTypes() && this.match(47)) {
  5718. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5719. }
  5720. node.typeArguments = targs;
  5721. }
  5722. parseAsyncArrowWithTypeParameters(startPos, startLoc) {
  5723. const node = this.startNodeAt(startPos, startLoc);
  5724. this.parseFunctionParams(node);
  5725. if (!this.parseArrow(node)) return;
  5726. return this.parseArrowExpression(node, undefined, true);
  5727. }
  5728. readToken_mult_modulo(code) {
  5729. const next = this.input.charCodeAt(this.state.pos + 1);
  5730. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5731. this.state.hasFlowComment = false;
  5732. this.state.pos += 2;
  5733. this.nextToken();
  5734. return;
  5735. }
  5736. super.readToken_mult_modulo(code);
  5737. }
  5738. readToken_pipe_amp(code) {
  5739. const next = this.input.charCodeAt(this.state.pos + 1);
  5740. if (code === 124 && next === 125) {
  5741. this.finishOp(9, 2);
  5742. return;
  5743. }
  5744. super.readToken_pipe_amp(code);
  5745. }
  5746. parseTopLevel(file, program) {
  5747. const fileNode = super.parseTopLevel(file, program);
  5748. if (this.state.hasFlowComment) {
  5749. this.raise(FlowErrors.UnterminatedFlowComment, {
  5750. at: this.state.curPosition()
  5751. });
  5752. }
  5753. return fileNode;
  5754. }
  5755. skipBlockComment() {
  5756. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5757. if (this.state.hasFlowComment) {
  5758. throw this.raise(FlowErrors.NestedFlowComment, {
  5759. at: this.state.startLoc
  5760. });
  5761. }
  5762. this.hasFlowCommentCompletion();
  5763. this.state.pos += this.skipFlowComment();
  5764. this.state.hasFlowComment = true;
  5765. return;
  5766. }
  5767. if (this.state.hasFlowComment) {
  5768. const end = this.input.indexOf("*-/", this.state.pos + 2);
  5769. if (end === -1) {
  5770. throw this.raise(Errors.UnterminatedComment, {
  5771. at: this.state.curPosition()
  5772. });
  5773. }
  5774. this.state.pos = end + 2 + 3;
  5775. return;
  5776. }
  5777. return super.skipBlockComment();
  5778. }
  5779. skipFlowComment() {
  5780. const {
  5781. pos
  5782. } = this.state;
  5783. let shiftToFirstNonWhiteSpace = 2;
  5784. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5785. shiftToFirstNonWhiteSpace++;
  5786. }
  5787. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5788. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5789. if (ch2 === 58 && ch3 === 58) {
  5790. return shiftToFirstNonWhiteSpace + 2;
  5791. }
  5792. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5793. return shiftToFirstNonWhiteSpace + 12;
  5794. }
  5795. if (ch2 === 58 && ch3 !== 58) {
  5796. return shiftToFirstNonWhiteSpace;
  5797. }
  5798. return false;
  5799. }
  5800. hasFlowCommentCompletion() {
  5801. const end = this.input.indexOf("*/", this.state.pos);
  5802. if (end === -1) {
  5803. throw this.raise(Errors.UnterminatedComment, {
  5804. at: this.state.curPosition()
  5805. });
  5806. }
  5807. }
  5808. flowEnumErrorBooleanMemberNotInitialized(loc, {
  5809. enumName,
  5810. memberName
  5811. }) {
  5812. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
  5813. at: loc,
  5814. memberName,
  5815. enumName
  5816. });
  5817. }
  5818. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  5819. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
  5820. at: loc
  5821. }, enumContext));
  5822. }
  5823. flowEnumErrorNumberMemberNotInitialized(loc, {
  5824. enumName,
  5825. memberName
  5826. }) {
  5827. this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
  5828. at: loc,
  5829. enumName,
  5830. memberName
  5831. });
  5832. }
  5833. flowEnumErrorStringMemberInconsistentlyInitailized(node, {
  5834. enumName
  5835. }) {
  5836. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitailized, {
  5837. at: node,
  5838. enumName
  5839. });
  5840. }
  5841. flowEnumMemberInit() {
  5842. const startLoc = this.state.startLoc;
  5843. const endOfInit = () => this.match(12) || this.match(8);
  5844. switch (this.state.type) {
  5845. case 130:
  5846. {
  5847. const literal = this.parseNumericLiteral(this.state.value);
  5848. if (endOfInit()) {
  5849. return {
  5850. type: "number",
  5851. loc: literal.loc.start,
  5852. value: literal
  5853. };
  5854. }
  5855. return {
  5856. type: "invalid",
  5857. loc: startLoc
  5858. };
  5859. }
  5860. case 129:
  5861. {
  5862. const literal = this.parseStringLiteral(this.state.value);
  5863. if (endOfInit()) {
  5864. return {
  5865. type: "string",
  5866. loc: literal.loc.start,
  5867. value: literal
  5868. };
  5869. }
  5870. return {
  5871. type: "invalid",
  5872. loc: startLoc
  5873. };
  5874. }
  5875. case 85:
  5876. case 86:
  5877. {
  5878. const literal = this.parseBooleanLiteral(this.match(85));
  5879. if (endOfInit()) {
  5880. return {
  5881. type: "boolean",
  5882. loc: literal.loc.start,
  5883. value: literal
  5884. };
  5885. }
  5886. return {
  5887. type: "invalid",
  5888. loc: startLoc
  5889. };
  5890. }
  5891. default:
  5892. return {
  5893. type: "invalid",
  5894. loc: startLoc
  5895. };
  5896. }
  5897. }
  5898. flowEnumMemberRaw() {
  5899. const loc = this.state.startLoc;
  5900. const id = this.parseIdentifier(true);
  5901. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  5902. type: "none",
  5903. loc
  5904. };
  5905. return {
  5906. id,
  5907. init
  5908. };
  5909. }
  5910. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  5911. const {
  5912. explicitType
  5913. } = context;
  5914. if (explicitType === null) {
  5915. return;
  5916. }
  5917. if (explicitType !== expectedType) {
  5918. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  5919. }
  5920. }
  5921. flowEnumMembers({
  5922. enumName,
  5923. explicitType
  5924. }) {
  5925. const seenNames = new Set();
  5926. const members = {
  5927. booleanMembers: [],
  5928. numberMembers: [],
  5929. stringMembers: [],
  5930. defaultedMembers: []
  5931. };
  5932. let hasUnknownMembers = false;
  5933. while (!this.match(8)) {
  5934. if (this.eat(21)) {
  5935. hasUnknownMembers = true;
  5936. break;
  5937. }
  5938. const memberNode = this.startNode();
  5939. const {
  5940. id,
  5941. init
  5942. } = this.flowEnumMemberRaw();
  5943. const memberName = id.name;
  5944. if (memberName === "") {
  5945. continue;
  5946. }
  5947. if (/^[a-z]/.test(memberName)) {
  5948. this.raise(FlowErrors.EnumInvalidMemberName, {
  5949. at: id,
  5950. memberName,
  5951. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  5952. enumName
  5953. });
  5954. }
  5955. if (seenNames.has(memberName)) {
  5956. this.raise(FlowErrors.EnumDuplicateMemberName, {
  5957. at: id,
  5958. memberName,
  5959. enumName
  5960. });
  5961. }
  5962. seenNames.add(memberName);
  5963. const context = {
  5964. enumName,
  5965. explicitType,
  5966. memberName
  5967. };
  5968. memberNode.id = id;
  5969. switch (init.type) {
  5970. case "boolean":
  5971. {
  5972. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  5973. memberNode.init = init.value;
  5974. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  5975. break;
  5976. }
  5977. case "number":
  5978. {
  5979. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  5980. memberNode.init = init.value;
  5981. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  5982. break;
  5983. }
  5984. case "string":
  5985. {
  5986. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  5987. memberNode.init = init.value;
  5988. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  5989. break;
  5990. }
  5991. case "invalid":
  5992. {
  5993. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  5994. }
  5995. case "none":
  5996. {
  5997. switch (explicitType) {
  5998. case "boolean":
  5999. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6000. break;
  6001. case "number":
  6002. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6003. break;
  6004. default:
  6005. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6006. }
  6007. }
  6008. }
  6009. if (!this.match(8)) {
  6010. this.expect(12);
  6011. }
  6012. }
  6013. return {
  6014. members,
  6015. hasUnknownMembers
  6016. };
  6017. }
  6018. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6019. enumName
  6020. }) {
  6021. if (initializedMembers.length === 0) {
  6022. return defaultedMembers;
  6023. } else if (defaultedMembers.length === 0) {
  6024. return initializedMembers;
  6025. } else if (defaultedMembers.length > initializedMembers.length) {
  6026. for (const member of initializedMembers) {
  6027. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6028. enumName
  6029. });
  6030. }
  6031. return defaultedMembers;
  6032. } else {
  6033. for (const member of defaultedMembers) {
  6034. this.flowEnumErrorStringMemberInconsistentlyInitailized(member, {
  6035. enumName
  6036. });
  6037. }
  6038. return initializedMembers;
  6039. }
  6040. }
  6041. flowEnumParseExplicitType({
  6042. enumName
  6043. }) {
  6044. if (!this.eatContextual(101)) return null;
  6045. if (!tokenIsIdentifier(this.state.type)) {
  6046. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
  6047. at: this.state.startLoc,
  6048. enumName
  6049. });
  6050. }
  6051. const {
  6052. value
  6053. } = this.state;
  6054. this.next();
  6055. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6056. this.raise(FlowErrors.EnumInvalidExplicitType, {
  6057. at: this.state.startLoc,
  6058. enumName,
  6059. invalidEnumType: value
  6060. });
  6061. }
  6062. return value;
  6063. }
  6064. flowEnumBody(node, id) {
  6065. const enumName = id.name;
  6066. const nameLoc = id.loc.start;
  6067. const explicitType = this.flowEnumParseExplicitType({
  6068. enumName
  6069. });
  6070. this.expect(5);
  6071. const {
  6072. members,
  6073. hasUnknownMembers
  6074. } = this.flowEnumMembers({
  6075. enumName,
  6076. explicitType
  6077. });
  6078. node.hasUnknownMembers = hasUnknownMembers;
  6079. switch (explicitType) {
  6080. case "boolean":
  6081. node.explicitType = true;
  6082. node.members = members.booleanMembers;
  6083. this.expect(8);
  6084. return this.finishNode(node, "EnumBooleanBody");
  6085. case "number":
  6086. node.explicitType = true;
  6087. node.members = members.numberMembers;
  6088. this.expect(8);
  6089. return this.finishNode(node, "EnumNumberBody");
  6090. case "string":
  6091. node.explicitType = true;
  6092. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6093. enumName
  6094. });
  6095. this.expect(8);
  6096. return this.finishNode(node, "EnumStringBody");
  6097. case "symbol":
  6098. node.members = members.defaultedMembers;
  6099. this.expect(8);
  6100. return this.finishNode(node, "EnumSymbolBody");
  6101. default:
  6102. {
  6103. const empty = () => {
  6104. node.members = [];
  6105. this.expect(8);
  6106. return this.finishNode(node, "EnumStringBody");
  6107. };
  6108. node.explicitType = false;
  6109. const boolsLen = members.booleanMembers.length;
  6110. const numsLen = members.numberMembers.length;
  6111. const strsLen = members.stringMembers.length;
  6112. const defaultedLen = members.defaultedMembers.length;
  6113. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6114. return empty();
  6115. } else if (!boolsLen && !numsLen) {
  6116. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6117. enumName
  6118. });
  6119. this.expect(8);
  6120. return this.finishNode(node, "EnumStringBody");
  6121. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6122. for (const member of members.defaultedMembers) {
  6123. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6124. enumName,
  6125. memberName: member.id.name
  6126. });
  6127. }
  6128. node.members = members.booleanMembers;
  6129. this.expect(8);
  6130. return this.finishNode(node, "EnumBooleanBody");
  6131. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6132. for (const member of members.defaultedMembers) {
  6133. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6134. enumName,
  6135. memberName: member.id.name
  6136. });
  6137. }
  6138. node.members = members.numberMembers;
  6139. this.expect(8);
  6140. return this.finishNode(node, "EnumNumberBody");
  6141. } else {
  6142. this.raise(FlowErrors.EnumInconsistentMemberValues, {
  6143. at: nameLoc,
  6144. enumName
  6145. });
  6146. return empty();
  6147. }
  6148. }
  6149. }
  6150. }
  6151. flowParseEnumDeclaration(node) {
  6152. const id = this.parseIdentifier();
  6153. node.id = id;
  6154. node.body = this.flowEnumBody(this.startNode(), id);
  6155. return this.finishNode(node, "EnumDeclaration");
  6156. }
  6157. isLookaheadToken_lt() {
  6158. const next = this.nextTokenStart();
  6159. if (this.input.charCodeAt(next) === 60) {
  6160. const afterNext = this.input.charCodeAt(next + 1);
  6161. return afterNext !== 60 && afterNext !== 61;
  6162. }
  6163. return false;
  6164. }
  6165. maybeUnwrapTypeCastExpression(node) {
  6166. return node.type === "TypeCastExpression" ? node.expression : node;
  6167. }
  6168. });
  6169. const entities = {
  6170. __proto__: null,
  6171. quot: "\u0022",
  6172. amp: "&",
  6173. apos: "\u0027",
  6174. lt: "<",
  6175. gt: ">",
  6176. nbsp: "\u00A0",
  6177. iexcl: "\u00A1",
  6178. cent: "\u00A2",
  6179. pound: "\u00A3",
  6180. curren: "\u00A4",
  6181. yen: "\u00A5",
  6182. brvbar: "\u00A6",
  6183. sect: "\u00A7",
  6184. uml: "\u00A8",
  6185. copy: "\u00A9",
  6186. ordf: "\u00AA",
  6187. laquo: "\u00AB",
  6188. not: "\u00AC",
  6189. shy: "\u00AD",
  6190. reg: "\u00AE",
  6191. macr: "\u00AF",
  6192. deg: "\u00B0",
  6193. plusmn: "\u00B1",
  6194. sup2: "\u00B2",
  6195. sup3: "\u00B3",
  6196. acute: "\u00B4",
  6197. micro: "\u00B5",
  6198. para: "\u00B6",
  6199. middot: "\u00B7",
  6200. cedil: "\u00B8",
  6201. sup1: "\u00B9",
  6202. ordm: "\u00BA",
  6203. raquo: "\u00BB",
  6204. frac14: "\u00BC",
  6205. frac12: "\u00BD",
  6206. frac34: "\u00BE",
  6207. iquest: "\u00BF",
  6208. Agrave: "\u00C0",
  6209. Aacute: "\u00C1",
  6210. Acirc: "\u00C2",
  6211. Atilde: "\u00C3",
  6212. Auml: "\u00C4",
  6213. Aring: "\u00C5",
  6214. AElig: "\u00C6",
  6215. Ccedil: "\u00C7",
  6216. Egrave: "\u00C8",
  6217. Eacute: "\u00C9",
  6218. Ecirc: "\u00CA",
  6219. Euml: "\u00CB",
  6220. Igrave: "\u00CC",
  6221. Iacute: "\u00CD",
  6222. Icirc: "\u00CE",
  6223. Iuml: "\u00CF",
  6224. ETH: "\u00D0",
  6225. Ntilde: "\u00D1",
  6226. Ograve: "\u00D2",
  6227. Oacute: "\u00D3",
  6228. Ocirc: "\u00D4",
  6229. Otilde: "\u00D5",
  6230. Ouml: "\u00D6",
  6231. times: "\u00D7",
  6232. Oslash: "\u00D8",
  6233. Ugrave: "\u00D9",
  6234. Uacute: "\u00DA",
  6235. Ucirc: "\u00DB",
  6236. Uuml: "\u00DC",
  6237. Yacute: "\u00DD",
  6238. THORN: "\u00DE",
  6239. szlig: "\u00DF",
  6240. agrave: "\u00E0",
  6241. aacute: "\u00E1",
  6242. acirc: "\u00E2",
  6243. atilde: "\u00E3",
  6244. auml: "\u00E4",
  6245. aring: "\u00E5",
  6246. aelig: "\u00E6",
  6247. ccedil: "\u00E7",
  6248. egrave: "\u00E8",
  6249. eacute: "\u00E9",
  6250. ecirc: "\u00EA",
  6251. euml: "\u00EB",
  6252. igrave: "\u00EC",
  6253. iacute: "\u00ED",
  6254. icirc: "\u00EE",
  6255. iuml: "\u00EF",
  6256. eth: "\u00F0",
  6257. ntilde: "\u00F1",
  6258. ograve: "\u00F2",
  6259. oacute: "\u00F3",
  6260. ocirc: "\u00F4",
  6261. otilde: "\u00F5",
  6262. ouml: "\u00F6",
  6263. divide: "\u00F7",
  6264. oslash: "\u00F8",
  6265. ugrave: "\u00F9",
  6266. uacute: "\u00FA",
  6267. ucirc: "\u00FB",
  6268. uuml: "\u00FC",
  6269. yacute: "\u00FD",
  6270. thorn: "\u00FE",
  6271. yuml: "\u00FF",
  6272. OElig: "\u0152",
  6273. oelig: "\u0153",
  6274. Scaron: "\u0160",
  6275. scaron: "\u0161",
  6276. Yuml: "\u0178",
  6277. fnof: "\u0192",
  6278. circ: "\u02C6",
  6279. tilde: "\u02DC",
  6280. Alpha: "\u0391",
  6281. Beta: "\u0392",
  6282. Gamma: "\u0393",
  6283. Delta: "\u0394",
  6284. Epsilon: "\u0395",
  6285. Zeta: "\u0396",
  6286. Eta: "\u0397",
  6287. Theta: "\u0398",
  6288. Iota: "\u0399",
  6289. Kappa: "\u039A",
  6290. Lambda: "\u039B",
  6291. Mu: "\u039C",
  6292. Nu: "\u039D",
  6293. Xi: "\u039E",
  6294. Omicron: "\u039F",
  6295. Pi: "\u03A0",
  6296. Rho: "\u03A1",
  6297. Sigma: "\u03A3",
  6298. Tau: "\u03A4",
  6299. Upsilon: "\u03A5",
  6300. Phi: "\u03A6",
  6301. Chi: "\u03A7",
  6302. Psi: "\u03A8",
  6303. Omega: "\u03A9",
  6304. alpha: "\u03B1",
  6305. beta: "\u03B2",
  6306. gamma: "\u03B3",
  6307. delta: "\u03B4",
  6308. epsilon: "\u03B5",
  6309. zeta: "\u03B6",
  6310. eta: "\u03B7",
  6311. theta: "\u03B8",
  6312. iota: "\u03B9",
  6313. kappa: "\u03BA",
  6314. lambda: "\u03BB",
  6315. mu: "\u03BC",
  6316. nu: "\u03BD",
  6317. xi: "\u03BE",
  6318. omicron: "\u03BF",
  6319. pi: "\u03C0",
  6320. rho: "\u03C1",
  6321. sigmaf: "\u03C2",
  6322. sigma: "\u03C3",
  6323. tau: "\u03C4",
  6324. upsilon: "\u03C5",
  6325. phi: "\u03C6",
  6326. chi: "\u03C7",
  6327. psi: "\u03C8",
  6328. omega: "\u03C9",
  6329. thetasym: "\u03D1",
  6330. upsih: "\u03D2",
  6331. piv: "\u03D6",
  6332. ensp: "\u2002",
  6333. emsp: "\u2003",
  6334. thinsp: "\u2009",
  6335. zwnj: "\u200C",
  6336. zwj: "\u200D",
  6337. lrm: "\u200E",
  6338. rlm: "\u200F",
  6339. ndash: "\u2013",
  6340. mdash: "\u2014",
  6341. lsquo: "\u2018",
  6342. rsquo: "\u2019",
  6343. sbquo: "\u201A",
  6344. ldquo: "\u201C",
  6345. rdquo: "\u201D",
  6346. bdquo: "\u201E",
  6347. dagger: "\u2020",
  6348. Dagger: "\u2021",
  6349. bull: "\u2022",
  6350. hellip: "\u2026",
  6351. permil: "\u2030",
  6352. prime: "\u2032",
  6353. Prime: "\u2033",
  6354. lsaquo: "\u2039",
  6355. rsaquo: "\u203A",
  6356. oline: "\u203E",
  6357. frasl: "\u2044",
  6358. euro: "\u20AC",
  6359. image: "\u2111",
  6360. weierp: "\u2118",
  6361. real: "\u211C",
  6362. trade: "\u2122",
  6363. alefsym: "\u2135",
  6364. larr: "\u2190",
  6365. uarr: "\u2191",
  6366. rarr: "\u2192",
  6367. darr: "\u2193",
  6368. harr: "\u2194",
  6369. crarr: "\u21B5",
  6370. lArr: "\u21D0",
  6371. uArr: "\u21D1",
  6372. rArr: "\u21D2",
  6373. dArr: "\u21D3",
  6374. hArr: "\u21D4",
  6375. forall: "\u2200",
  6376. part: "\u2202",
  6377. exist: "\u2203",
  6378. empty: "\u2205",
  6379. nabla: "\u2207",
  6380. isin: "\u2208",
  6381. notin: "\u2209",
  6382. ni: "\u220B",
  6383. prod: "\u220F",
  6384. sum: "\u2211",
  6385. minus: "\u2212",
  6386. lowast: "\u2217",
  6387. radic: "\u221A",
  6388. prop: "\u221D",
  6389. infin: "\u221E",
  6390. ang: "\u2220",
  6391. and: "\u2227",
  6392. or: "\u2228",
  6393. cap: "\u2229",
  6394. cup: "\u222A",
  6395. int: "\u222B",
  6396. there4: "\u2234",
  6397. sim: "\u223C",
  6398. cong: "\u2245",
  6399. asymp: "\u2248",
  6400. ne: "\u2260",
  6401. equiv: "\u2261",
  6402. le: "\u2264",
  6403. ge: "\u2265",
  6404. sub: "\u2282",
  6405. sup: "\u2283",
  6406. nsub: "\u2284",
  6407. sube: "\u2286",
  6408. supe: "\u2287",
  6409. oplus: "\u2295",
  6410. otimes: "\u2297",
  6411. perp: "\u22A5",
  6412. sdot: "\u22C5",
  6413. lceil: "\u2308",
  6414. rceil: "\u2309",
  6415. lfloor: "\u230A",
  6416. rfloor: "\u230B",
  6417. lang: "\u2329",
  6418. rang: "\u232A",
  6419. loz: "\u25CA",
  6420. spades: "\u2660",
  6421. clubs: "\u2663",
  6422. hearts: "\u2665",
  6423. diams: "\u2666"
  6424. };
  6425. const JsxErrors = ParseErrorEnum`jsx`(_ => ({
  6426. AttributeIsEmpty: _("JSX attributes must only be assigned a non-empty expression."),
  6427. MissingClosingTagElement: _(({
  6428. openingTagName
  6429. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`),
  6430. MissingClosingTagFragment: _("Expected corresponding JSX closing tag for <>."),
  6431. UnexpectedSequenceExpression: _("Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?"),
  6432. UnexpectedToken: _(({
  6433. unexpected,
  6434. HTMLEntity
  6435. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`),
  6436. UnsupportedJsxValue: _("JSX value should be either an expression or a quoted JSX text."),
  6437. UnterminatedJsxContent: _("Unterminated JSX contents."),
  6438. UnwrappedAdjacentJSXElements: _("Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?")
  6439. }));
  6440. function isFragment(object) {
  6441. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6442. }
  6443. function getQualifiedJSXName(object) {
  6444. if (object.type === "JSXIdentifier") {
  6445. return object.name;
  6446. }
  6447. if (object.type === "JSXNamespacedName") {
  6448. return object.namespace.name + ":" + object.name.name;
  6449. }
  6450. if (object.type === "JSXMemberExpression") {
  6451. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6452. }
  6453. throw new Error("Node had unexpected type: " + object.type);
  6454. }
  6455. var jsx = (superClass => class extends superClass {
  6456. jsxReadToken() {
  6457. let out = "";
  6458. let chunkStart = this.state.pos;
  6459. for (;;) {
  6460. if (this.state.pos >= this.length) {
  6461. throw this.raise(JsxErrors.UnterminatedJsxContent, {
  6462. at: this.state.startLoc
  6463. });
  6464. }
  6465. const ch = this.input.charCodeAt(this.state.pos);
  6466. switch (ch) {
  6467. case 60:
  6468. case 123:
  6469. if (this.state.pos === this.state.start) {
  6470. if (ch === 60 && this.state.canStartJSXElement) {
  6471. ++this.state.pos;
  6472. return this.finishToken(138);
  6473. }
  6474. return super.getTokenFromCode(ch);
  6475. }
  6476. out += this.input.slice(chunkStart, this.state.pos);
  6477. return this.finishToken(137, out);
  6478. case 38:
  6479. out += this.input.slice(chunkStart, this.state.pos);
  6480. out += this.jsxReadEntity();
  6481. chunkStart = this.state.pos;
  6482. break;
  6483. case 62:
  6484. case 125:
  6485. default:
  6486. if (isNewLine(ch)) {
  6487. out += this.input.slice(chunkStart, this.state.pos);
  6488. out += this.jsxReadNewLine(true);
  6489. chunkStart = this.state.pos;
  6490. } else {
  6491. ++this.state.pos;
  6492. }
  6493. }
  6494. }
  6495. }
  6496. jsxReadNewLine(normalizeCRLF) {
  6497. const ch = this.input.charCodeAt(this.state.pos);
  6498. let out;
  6499. ++this.state.pos;
  6500. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6501. ++this.state.pos;
  6502. out = normalizeCRLF ? "\n" : "\r\n";
  6503. } else {
  6504. out = String.fromCharCode(ch);
  6505. }
  6506. ++this.state.curLine;
  6507. this.state.lineStart = this.state.pos;
  6508. return out;
  6509. }
  6510. jsxReadString(quote) {
  6511. let out = "";
  6512. let chunkStart = ++this.state.pos;
  6513. for (;;) {
  6514. if (this.state.pos >= this.length) {
  6515. throw this.raise(Errors.UnterminatedString, {
  6516. at: this.state.startLoc
  6517. });
  6518. }
  6519. const ch = this.input.charCodeAt(this.state.pos);
  6520. if (ch === quote) break;
  6521. if (ch === 38) {
  6522. out += this.input.slice(chunkStart, this.state.pos);
  6523. out += this.jsxReadEntity();
  6524. chunkStart = this.state.pos;
  6525. } else if (isNewLine(ch)) {
  6526. out += this.input.slice(chunkStart, this.state.pos);
  6527. out += this.jsxReadNewLine(false);
  6528. chunkStart = this.state.pos;
  6529. } else {
  6530. ++this.state.pos;
  6531. }
  6532. }
  6533. out += this.input.slice(chunkStart, this.state.pos++);
  6534. return this.finishToken(129, out);
  6535. }
  6536. jsxReadEntity() {
  6537. const startPos = ++this.state.pos;
  6538. if (this.codePointAtPos(this.state.pos) === 35) {
  6539. ++this.state.pos;
  6540. let radix = 10;
  6541. if (this.codePointAtPos(this.state.pos) === 120) {
  6542. radix = 16;
  6543. ++this.state.pos;
  6544. }
  6545. const codePoint = this.readInt(radix, undefined, false, "bail");
  6546. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6547. ++this.state.pos;
  6548. return String.fromCodePoint(codePoint);
  6549. }
  6550. } else {
  6551. let count = 0;
  6552. let semi = false;
  6553. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
  6554. ++this.state.pos;
  6555. }
  6556. if (semi) {
  6557. const desc = this.input.slice(startPos, this.state.pos);
  6558. const entity = entities[desc];
  6559. ++this.state.pos;
  6560. if (entity) {
  6561. return entity;
  6562. }
  6563. }
  6564. }
  6565. this.state.pos = startPos;
  6566. return "&";
  6567. }
  6568. jsxReadWord() {
  6569. let ch;
  6570. const start = this.state.pos;
  6571. do {
  6572. ch = this.input.charCodeAt(++this.state.pos);
  6573. } while (isIdentifierChar(ch) || ch === 45);
  6574. return this.finishToken(136, this.input.slice(start, this.state.pos));
  6575. }
  6576. jsxParseIdentifier() {
  6577. const node = this.startNode();
  6578. if (this.match(136)) {
  6579. node.name = this.state.value;
  6580. } else if (tokenIsKeyword(this.state.type)) {
  6581. node.name = tokenLabelName(this.state.type);
  6582. } else {
  6583. this.unexpected();
  6584. }
  6585. this.next();
  6586. return this.finishNode(node, "JSXIdentifier");
  6587. }
  6588. jsxParseNamespacedName() {
  6589. const startPos = this.state.start;
  6590. const startLoc = this.state.startLoc;
  6591. const name = this.jsxParseIdentifier();
  6592. if (!this.eat(14)) return name;
  6593. const node = this.startNodeAt(startPos, startLoc);
  6594. node.namespace = name;
  6595. node.name = this.jsxParseIdentifier();
  6596. return this.finishNode(node, "JSXNamespacedName");
  6597. }
  6598. jsxParseElementName() {
  6599. const startPos = this.state.start;
  6600. const startLoc = this.state.startLoc;
  6601. let node = this.jsxParseNamespacedName();
  6602. if (node.type === "JSXNamespacedName") {
  6603. return node;
  6604. }
  6605. while (this.eat(16)) {
  6606. const newNode = this.startNodeAt(startPos, startLoc);
  6607. newNode.object = node;
  6608. newNode.property = this.jsxParseIdentifier();
  6609. node = this.finishNode(newNode, "JSXMemberExpression");
  6610. }
  6611. return node;
  6612. }
  6613. jsxParseAttributeValue() {
  6614. let node;
  6615. switch (this.state.type) {
  6616. case 5:
  6617. node = this.startNode();
  6618. this.setContext(types.brace);
  6619. this.next();
  6620. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6621. if (node.expression.type === "JSXEmptyExpression") {
  6622. this.raise(JsxErrors.AttributeIsEmpty, {
  6623. at: node
  6624. });
  6625. }
  6626. return node;
  6627. case 138:
  6628. case 129:
  6629. return this.parseExprAtom();
  6630. default:
  6631. throw this.raise(JsxErrors.UnsupportedJsxValue, {
  6632. at: this.state.startLoc
  6633. });
  6634. }
  6635. }
  6636. jsxParseEmptyExpression() {
  6637. const node = this.startNodeAt(this.state.lastTokEndLoc.index, this.state.lastTokEndLoc);
  6638. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6639. }
  6640. jsxParseSpreadChild(node) {
  6641. this.next();
  6642. node.expression = this.parseExpression();
  6643. this.setContext(types.j_oTag);
  6644. this.state.canStartJSXElement = true;
  6645. this.expect(8);
  6646. return this.finishNode(node, "JSXSpreadChild");
  6647. }
  6648. jsxParseExpressionContainer(node, previousContext) {
  6649. if (this.match(8)) {
  6650. node.expression = this.jsxParseEmptyExpression();
  6651. } else {
  6652. const expression = this.parseExpression();
  6653. node.expression = expression;
  6654. }
  6655. this.setContext(previousContext);
  6656. this.state.canStartJSXElement = true;
  6657. this.expect(8);
  6658. return this.finishNode(node, "JSXExpressionContainer");
  6659. }
  6660. jsxParseAttribute() {
  6661. const node = this.startNode();
  6662. if (this.match(5)) {
  6663. this.setContext(types.brace);
  6664. this.next();
  6665. this.expect(21);
  6666. node.argument = this.parseMaybeAssignAllowIn();
  6667. this.setContext(types.j_oTag);
  6668. this.state.canStartJSXElement = true;
  6669. this.expect(8);
  6670. return this.finishNode(node, "JSXSpreadAttribute");
  6671. }
  6672. node.name = this.jsxParseNamespacedName();
  6673. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6674. return this.finishNode(node, "JSXAttribute");
  6675. }
  6676. jsxParseOpeningElementAt(startPos, startLoc) {
  6677. const node = this.startNodeAt(startPos, startLoc);
  6678. if (this.eat(139)) {
  6679. return this.finishNode(node, "JSXOpeningFragment");
  6680. }
  6681. node.name = this.jsxParseElementName();
  6682. return this.jsxParseOpeningElementAfterName(node);
  6683. }
  6684. jsxParseOpeningElementAfterName(node) {
  6685. const attributes = [];
  6686. while (!this.match(56) && !this.match(139)) {
  6687. attributes.push(this.jsxParseAttribute());
  6688. }
  6689. node.attributes = attributes;
  6690. node.selfClosing = this.eat(56);
  6691. this.expect(139);
  6692. return this.finishNode(node, "JSXOpeningElement");
  6693. }
  6694. jsxParseClosingElementAt(startPos, startLoc) {
  6695. const node = this.startNodeAt(startPos, startLoc);
  6696. if (this.eat(139)) {
  6697. return this.finishNode(node, "JSXClosingFragment");
  6698. }
  6699. node.name = this.jsxParseElementName();
  6700. this.expect(139);
  6701. return this.finishNode(node, "JSXClosingElement");
  6702. }
  6703. jsxParseElementAt(startPos, startLoc) {
  6704. const node = this.startNodeAt(startPos, startLoc);
  6705. const children = [];
  6706. const openingElement = this.jsxParseOpeningElementAt(startPos, startLoc);
  6707. let closingElement = null;
  6708. if (!openingElement.selfClosing) {
  6709. contents: for (;;) {
  6710. switch (this.state.type) {
  6711. case 138:
  6712. startPos = this.state.start;
  6713. startLoc = this.state.startLoc;
  6714. this.next();
  6715. if (this.eat(56)) {
  6716. closingElement = this.jsxParseClosingElementAt(startPos, startLoc);
  6717. break contents;
  6718. }
  6719. children.push(this.jsxParseElementAt(startPos, startLoc));
  6720. break;
  6721. case 137:
  6722. children.push(this.parseExprAtom());
  6723. break;
  6724. case 5:
  6725. {
  6726. const node = this.startNode();
  6727. this.setContext(types.brace);
  6728. this.next();
  6729. if (this.match(21)) {
  6730. children.push(this.jsxParseSpreadChild(node));
  6731. } else {
  6732. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6733. }
  6734. break;
  6735. }
  6736. default:
  6737. throw this.unexpected();
  6738. }
  6739. }
  6740. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6741. this.raise(JsxErrors.MissingClosingTagFragment, {
  6742. at: closingElement
  6743. });
  6744. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6745. this.raise(JsxErrors.MissingClosingTagElement, {
  6746. at: closingElement,
  6747. openingTagName: getQualifiedJSXName(openingElement.name)
  6748. });
  6749. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6750. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6751. this.raise(JsxErrors.MissingClosingTagElement, {
  6752. at: closingElement,
  6753. openingTagName: getQualifiedJSXName(openingElement.name)
  6754. });
  6755. }
  6756. }
  6757. }
  6758. if (isFragment(openingElement)) {
  6759. node.openingFragment = openingElement;
  6760. node.closingFragment = closingElement;
  6761. } else {
  6762. node.openingElement = openingElement;
  6763. node.closingElement = closingElement;
  6764. }
  6765. node.children = children;
  6766. if (this.match(47)) {
  6767. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
  6768. at: this.state.startLoc
  6769. });
  6770. }
  6771. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6772. }
  6773. jsxParseElement() {
  6774. const startPos = this.state.start;
  6775. const startLoc = this.state.startLoc;
  6776. this.next();
  6777. return this.jsxParseElementAt(startPos, startLoc);
  6778. }
  6779. setContext(newContext) {
  6780. const {
  6781. context
  6782. } = this.state;
  6783. context[context.length - 1] = newContext;
  6784. }
  6785. parseExprAtom(refExpressionErrors) {
  6786. if (this.match(137)) {
  6787. return this.parseLiteral(this.state.value, "JSXText");
  6788. } else if (this.match(138)) {
  6789. return this.jsxParseElement();
  6790. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  6791. this.replaceToken(138);
  6792. return this.jsxParseElement();
  6793. } else {
  6794. return super.parseExprAtom(refExpressionErrors);
  6795. }
  6796. }
  6797. skipSpace() {
  6798. const curContext = this.curContext();
  6799. if (!curContext.preserveSpace) super.skipSpace();
  6800. }
  6801. getTokenFromCode(code) {
  6802. const context = this.curContext();
  6803. if (context === types.j_expr) {
  6804. return this.jsxReadToken();
  6805. }
  6806. if (context === types.j_oTag || context === types.j_cTag) {
  6807. if (isIdentifierStart(code)) {
  6808. return this.jsxReadWord();
  6809. }
  6810. if (code === 62) {
  6811. ++this.state.pos;
  6812. return this.finishToken(139);
  6813. }
  6814. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6815. return this.jsxReadString(code);
  6816. }
  6817. }
  6818. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  6819. ++this.state.pos;
  6820. return this.finishToken(138);
  6821. }
  6822. return super.getTokenFromCode(code);
  6823. }
  6824. updateContext(prevType) {
  6825. const {
  6826. context,
  6827. type
  6828. } = this.state;
  6829. if (type === 56 && prevType === 138) {
  6830. context.splice(-2, 2, types.j_cTag);
  6831. this.state.canStartJSXElement = false;
  6832. } else if (type === 138) {
  6833. context.push(types.j_oTag);
  6834. } else if (type === 139) {
  6835. const out = context[context.length - 1];
  6836. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  6837. context.pop();
  6838. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  6839. } else {
  6840. this.setContext(types.j_expr);
  6841. this.state.canStartJSXElement = true;
  6842. }
  6843. } else {
  6844. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  6845. }
  6846. }
  6847. });
  6848. class TypeScriptScope extends Scope {
  6849. constructor(...args) {
  6850. super(...args);
  6851. this.types = new Set();
  6852. this.enums = new Set();
  6853. this.constEnums = new Set();
  6854. this.classes = new Set();
  6855. this.exportOnlyBindings = new Set();
  6856. }
  6857. }
  6858. class TypeScriptScopeHandler extends ScopeHandler {
  6859. createScope(flags) {
  6860. return new TypeScriptScope(flags);
  6861. }
  6862. declareName(name, bindingType, loc) {
  6863. const scope = this.currentScope();
  6864. if (bindingType & BIND_FLAGS_TS_EXPORT_ONLY) {
  6865. this.maybeExportDefined(scope, name);
  6866. scope.exportOnlyBindings.add(name);
  6867. return;
  6868. }
  6869. super.declareName(...arguments);
  6870. if (bindingType & BIND_KIND_TYPE) {
  6871. if (!(bindingType & BIND_KIND_VALUE)) {
  6872. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  6873. this.maybeExportDefined(scope, name);
  6874. }
  6875. scope.types.add(name);
  6876. }
  6877. if (bindingType & BIND_FLAGS_TS_ENUM) scope.enums.add(name);
  6878. if (bindingType & BIND_FLAGS_TS_CONST_ENUM) scope.constEnums.add(name);
  6879. if (bindingType & BIND_FLAGS_CLASS) scope.classes.add(name);
  6880. }
  6881. isRedeclaredInScope(scope, name, bindingType) {
  6882. if (scope.enums.has(name)) {
  6883. if (bindingType & BIND_FLAGS_TS_ENUM) {
  6884. const isConst = !!(bindingType & BIND_FLAGS_TS_CONST_ENUM);
  6885. const wasConst = scope.constEnums.has(name);
  6886. return isConst !== wasConst;
  6887. }
  6888. return true;
  6889. }
  6890. if (bindingType & BIND_FLAGS_CLASS && scope.classes.has(name)) {
  6891. if (scope.lexical.has(name)) {
  6892. return !!(bindingType & BIND_KIND_VALUE);
  6893. } else {
  6894. return false;
  6895. }
  6896. }
  6897. if (bindingType & BIND_KIND_TYPE && scope.types.has(name)) {
  6898. return true;
  6899. }
  6900. return super.isRedeclaredInScope(...arguments);
  6901. }
  6902. checkLocalExport(id) {
  6903. const topLevelScope = this.scopeStack[0];
  6904. const {
  6905. name
  6906. } = id;
  6907. if (!topLevelScope.types.has(name) && !topLevelScope.exportOnlyBindings.has(name)) {
  6908. super.checkLocalExport(id);
  6909. }
  6910. }
  6911. }
  6912. const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  6913. function nonNull(x) {
  6914. if (x == null) {
  6915. throw new Error(`Unexpected ${x} value.`);
  6916. }
  6917. return x;
  6918. }
  6919. function assert(x) {
  6920. if (!x) {
  6921. throw new Error("Assert fail");
  6922. }
  6923. }
  6924. const TSErrors = ParseErrorEnum`typescript`(_ => ({
  6925. AbstractMethodHasImplementation: _(({
  6926. methodName
  6927. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`),
  6928. AbstractPropertyHasInitializer: _(({
  6929. propertyName
  6930. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`),
  6931. AccesorCannotDeclareThisParameter: _("'get' and 'set' accessors cannot declare 'this' parameters."),
  6932. AccesorCannotHaveTypeParameters: _("An accessor cannot have type parameters."),
  6933. CannotFindName: _(({
  6934. name
  6935. }) => `Cannot find name '${name}'.`),
  6936. ClassMethodHasDeclare: _("Class methods cannot have the 'declare' modifier."),
  6937. ClassMethodHasReadonly: _("Class methods cannot have the 'readonly' modifier."),
  6938. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: _("A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference."),
  6939. ConstructorHasTypeParameters: _("Type parameters cannot appear on a constructor declaration."),
  6940. DeclareAccessor: _(({
  6941. kind
  6942. }) => `'declare' is not allowed in ${kind}ters.`),
  6943. DeclareClassFieldHasInitializer: _("Initializers are not allowed in ambient contexts."),
  6944. DeclareFunctionHasImplementation: _("An implementation cannot be declared in ambient contexts."),
  6945. DuplicateAccessibilityModifier: _(({
  6946. modifier
  6947. }) => `Accessibility modifier already seen.`),
  6948. DuplicateModifier: _(({
  6949. modifier
  6950. }) => `Duplicate modifier: '${modifier}'.`),
  6951. EmptyHeritageClauseType: _(({
  6952. token
  6953. }) => `'${token}' list cannot be empty.`),
  6954. EmptyTypeArguments: _("Type argument list cannot be empty."),
  6955. EmptyTypeParameters: _("Type parameter list cannot be empty."),
  6956. ExpectedAmbientAfterExportDeclare: _("'export declare' must be followed by an ambient declaration."),
  6957. ImportAliasHasImportType: _("An import alias can not use 'import type'."),
  6958. IncompatibleModifiers: _(({
  6959. modifiers
  6960. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`),
  6961. IndexSignatureHasAbstract: _("Index signatures cannot have the 'abstract' modifier."),
  6962. IndexSignatureHasAccessibility: _(({
  6963. modifier
  6964. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`),
  6965. IndexSignatureHasDeclare: _("Index signatures cannot have the 'declare' modifier."),
  6966. IndexSignatureHasOverride: _("'override' modifier cannot appear on an index signature."),
  6967. IndexSignatureHasStatic: _("Index signatures cannot have the 'static' modifier."),
  6968. InitializerNotAllowedInAmbientContext: _("Initializers are not allowed in ambient contexts."),
  6969. InvalidModifierOnTypeMember: _(({
  6970. modifier
  6971. }) => `'${modifier}' modifier cannot appear on a type member.`),
  6972. InvalidModifierOnTypeParameter: _(({
  6973. modifier
  6974. }) => `'${modifier}' modifier cannot appear on a type parameter.`),
  6975. InvalidModifierOnTypeParameterPositions: _(({
  6976. modifier
  6977. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`),
  6978. InvalidModifiersOrder: _(({
  6979. orderedModifiers
  6980. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`),
  6981. InvalidPropertyAccessAfterInstantiationExpression: _("Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments."),
  6982. InvalidTupleMemberLabel: _("Tuple members must be labeled with a simple identifier."),
  6983. MissingInterfaceName: _("'interface' declarations must be followed by an identifier."),
  6984. MixedLabeledAndUnlabeledElements: _("Tuple members must all have names or all not have names."),
  6985. NonAbstractClassHasAbstractMethod: _("Abstract methods can only appear within an abstract class."),
  6986. NonClassMethodPropertyHasAbstractModifer: _("'abstract' modifier can only appear on a class, method, or property declaration."),
  6987. OptionalTypeBeforeRequired: _("A required element cannot follow an optional element."),
  6988. OverrideNotInSubClass: _("This member cannot have an 'override' modifier because its containing class does not extend another class."),
  6989. PatternIsOptional: _("A binding pattern parameter cannot be optional in an implementation signature."),
  6990. PrivateElementHasAbstract: _("Private elements cannot have the 'abstract' modifier."),
  6991. PrivateElementHasAccessibility: _(({
  6992. modifier
  6993. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`),
  6994. ReadonlyForMethodSignature: _("'readonly' modifier can only appear on a property declaration or index signature."),
  6995. ReservedArrowTypeParam: _("This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`."),
  6996. ReservedTypeAssertion: _("This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead."),
  6997. SetAccesorCannotHaveOptionalParameter: _("A 'set' accessor cannot have an optional parameter."),
  6998. SetAccesorCannotHaveRestParameter: _("A 'set' accessor cannot have rest parameter."),
  6999. SetAccesorCannotHaveReturnType: _("A 'set' accessor cannot have a return type annotation."),
  7000. SingleTypeParameterWithoutTrailingComma: _(({
  7001. typeParameterName
  7002. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`),
  7003. StaticBlockCannotHaveModifier: _("Static class blocks cannot have any modifier."),
  7004. TypeAnnotationAfterAssign: _("Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`."),
  7005. TypeImportCannotSpecifyDefaultAndNamed: _("A type-only import can specify a default import or named bindings, but not both."),
  7006. TypeModifierIsUsedInTypeExports: _("The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement."),
  7007. TypeModifierIsUsedInTypeImports: _("The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement."),
  7008. UnexpectedParameterModifier: _("A parameter property is only allowed in a constructor implementation."),
  7009. UnexpectedReadonly: _("'readonly' type modifier is only permitted on array and tuple literal types."),
  7010. UnexpectedTypeAnnotation: _("Did not expect a type annotation here."),
  7011. UnexpectedTypeCastInParameter: _("Unexpected type cast in parameter position."),
  7012. UnsupportedImportTypeArgument: _("Argument in a type import must be a string literal."),
  7013. UnsupportedParameterPropertyKind: _("A parameter property may not be declared using a binding pattern."),
  7014. UnsupportedSignatureParameterKind: _(({
  7015. type
  7016. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`)
  7017. }));
  7018. function keywordTypeFromName(value) {
  7019. switch (value) {
  7020. case "any":
  7021. return "TSAnyKeyword";
  7022. case "boolean":
  7023. return "TSBooleanKeyword";
  7024. case "bigint":
  7025. return "TSBigIntKeyword";
  7026. case "never":
  7027. return "TSNeverKeyword";
  7028. case "number":
  7029. return "TSNumberKeyword";
  7030. case "object":
  7031. return "TSObjectKeyword";
  7032. case "string":
  7033. return "TSStringKeyword";
  7034. case "symbol":
  7035. return "TSSymbolKeyword";
  7036. case "undefined":
  7037. return "TSUndefinedKeyword";
  7038. case "unknown":
  7039. return "TSUnknownKeyword";
  7040. default:
  7041. return undefined;
  7042. }
  7043. }
  7044. function tsIsAccessModifier(modifier) {
  7045. return modifier === "private" || modifier === "public" || modifier === "protected";
  7046. }
  7047. function tsIsVarianceAnnotations(modifier) {
  7048. return modifier === "in" || modifier === "out";
  7049. }
  7050. var typescript = (superClass => class extends superClass {
  7051. getScopeHandler() {
  7052. return TypeScriptScopeHandler;
  7053. }
  7054. tsIsIdentifier() {
  7055. return tokenIsIdentifier(this.state.type);
  7056. }
  7057. tsTokenCanFollowModifier() {
  7058. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(134) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  7059. }
  7060. tsNextTokenCanFollowModifier() {
  7061. this.next();
  7062. return this.tsTokenCanFollowModifier();
  7063. }
  7064. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7065. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58) {
  7066. return undefined;
  7067. }
  7068. const modifier = this.state.value;
  7069. if (allowedModifiers.indexOf(modifier) !== -1) {
  7070. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7071. return undefined;
  7072. }
  7073. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7074. return modifier;
  7075. }
  7076. }
  7077. return undefined;
  7078. }
  7079. tsParseModifiers({
  7080. modified,
  7081. allowedModifiers,
  7082. disallowedModifiers,
  7083. stopOnStartOfClassStaticBlock,
  7084. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7085. }) {
  7086. const enforceOrder = (loc, modifier, before, after) => {
  7087. if (modifier === before && modified[after]) {
  7088. this.raise(TSErrors.InvalidModifiersOrder, {
  7089. at: loc,
  7090. orderedModifiers: [before, after]
  7091. });
  7092. }
  7093. };
  7094. const incompatible = (loc, modifier, mod1, mod2) => {
  7095. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7096. this.raise(TSErrors.IncompatibleModifiers, {
  7097. at: loc,
  7098. modifiers: [mod1, mod2]
  7099. });
  7100. }
  7101. };
  7102. for (;;) {
  7103. const {
  7104. startLoc
  7105. } = this.state;
  7106. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7107. if (!modifier) break;
  7108. if (tsIsAccessModifier(modifier)) {
  7109. if (modified.accessibility) {
  7110. this.raise(TSErrors.DuplicateAccessibilityModifier, {
  7111. at: startLoc,
  7112. modifier
  7113. });
  7114. } else {
  7115. enforceOrder(startLoc, modifier, modifier, "override");
  7116. enforceOrder(startLoc, modifier, modifier, "static");
  7117. enforceOrder(startLoc, modifier, modifier, "readonly");
  7118. modified.accessibility = modifier;
  7119. }
  7120. } else if (tsIsVarianceAnnotations(modifier)) {
  7121. if (modified[modifier]) {
  7122. this.raise(TSErrors.DuplicateModifier, {
  7123. at: startLoc,
  7124. modifier
  7125. });
  7126. }
  7127. modified[modifier] = true;
  7128. enforceOrder(startLoc, modifier, "in", "out");
  7129. } else {
  7130. if (Object.hasOwnProperty.call(modified, modifier)) {
  7131. this.raise(TSErrors.DuplicateModifier, {
  7132. at: startLoc,
  7133. modifier
  7134. });
  7135. } else {
  7136. enforceOrder(startLoc, modifier, "static", "readonly");
  7137. enforceOrder(startLoc, modifier, "static", "override");
  7138. enforceOrder(startLoc, modifier, "override", "readonly");
  7139. enforceOrder(startLoc, modifier, "abstract", "override");
  7140. incompatible(startLoc, modifier, "declare", "override");
  7141. incompatible(startLoc, modifier, "static", "abstract");
  7142. }
  7143. modified[modifier] = true;
  7144. }
  7145. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7146. this.raise(errorTemplate, {
  7147. at: startLoc,
  7148. modifier
  7149. });
  7150. }
  7151. }
  7152. }
  7153. tsIsListTerminator(kind) {
  7154. switch (kind) {
  7155. case "EnumMembers":
  7156. case "TypeMembers":
  7157. return this.match(8);
  7158. case "HeritageClauseElement":
  7159. return this.match(5);
  7160. case "TupleElementTypes":
  7161. return this.match(3);
  7162. case "TypeParametersOrArguments":
  7163. return this.match(48);
  7164. }
  7165. throw new Error("Unreachable");
  7166. }
  7167. tsParseList(kind, parseElement) {
  7168. const result = [];
  7169. while (!this.tsIsListTerminator(kind)) {
  7170. result.push(parseElement());
  7171. }
  7172. return result;
  7173. }
  7174. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7175. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7176. }
  7177. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7178. const result = [];
  7179. let trailingCommaPos = -1;
  7180. for (;;) {
  7181. if (this.tsIsListTerminator(kind)) {
  7182. break;
  7183. }
  7184. trailingCommaPos = -1;
  7185. const element = parseElement();
  7186. if (element == null) {
  7187. return undefined;
  7188. }
  7189. result.push(element);
  7190. if (this.eat(12)) {
  7191. trailingCommaPos = this.state.lastTokStart;
  7192. continue;
  7193. }
  7194. if (this.tsIsListTerminator(kind)) {
  7195. break;
  7196. }
  7197. if (expectSuccess) {
  7198. this.expect(12);
  7199. }
  7200. return undefined;
  7201. }
  7202. if (refTrailingCommaPos) {
  7203. refTrailingCommaPos.value = trailingCommaPos;
  7204. }
  7205. return result;
  7206. }
  7207. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7208. if (!skipFirstToken) {
  7209. if (bracket) {
  7210. this.expect(0);
  7211. } else {
  7212. this.expect(47);
  7213. }
  7214. }
  7215. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7216. if (bracket) {
  7217. this.expect(3);
  7218. } else {
  7219. this.expect(48);
  7220. }
  7221. return result;
  7222. }
  7223. tsParseImportType() {
  7224. const node = this.startNode();
  7225. this.expect(83);
  7226. this.expect(10);
  7227. if (!this.match(129)) {
  7228. this.raise(TSErrors.UnsupportedImportTypeArgument, {
  7229. at: this.state.startLoc
  7230. });
  7231. }
  7232. node.argument = this.parseExprAtom();
  7233. this.expect(11);
  7234. if (this.eat(16)) {
  7235. node.qualifier = this.tsParseEntityName();
  7236. }
  7237. if (this.match(47)) {
  7238. node.typeParameters = this.tsParseTypeArguments();
  7239. }
  7240. return this.finishNode(node, "TSImportType");
  7241. }
  7242. tsParseEntityName(allowReservedWords = true) {
  7243. let entity = this.parseIdentifier(allowReservedWords);
  7244. while (this.eat(16)) {
  7245. const node = this.startNodeAtNode(entity);
  7246. node.left = entity;
  7247. node.right = this.parseIdentifier(allowReservedWords);
  7248. entity = this.finishNode(node, "TSQualifiedName");
  7249. }
  7250. return entity;
  7251. }
  7252. tsParseTypeReference() {
  7253. const node = this.startNode();
  7254. node.typeName = this.tsParseEntityName();
  7255. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7256. node.typeParameters = this.tsParseTypeArguments();
  7257. }
  7258. return this.finishNode(node, "TSTypeReference");
  7259. }
  7260. tsParseThisTypePredicate(lhs) {
  7261. this.next();
  7262. const node = this.startNodeAtNode(lhs);
  7263. node.parameterName = lhs;
  7264. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7265. node.asserts = false;
  7266. return this.finishNode(node, "TSTypePredicate");
  7267. }
  7268. tsParseThisTypeNode() {
  7269. const node = this.startNode();
  7270. this.next();
  7271. return this.finishNode(node, "TSThisType");
  7272. }
  7273. tsParseTypeQuery() {
  7274. const node = this.startNode();
  7275. this.expect(87);
  7276. if (this.match(83)) {
  7277. node.exprName = this.tsParseImportType();
  7278. } else {
  7279. node.exprName = this.tsParseEntityName();
  7280. }
  7281. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7282. node.typeParameters = this.tsParseTypeArguments();
  7283. }
  7284. return this.finishNode(node, "TSTypeQuery");
  7285. }
  7286. tsParseInOutModifiers(node) {
  7287. this.tsParseModifiers({
  7288. modified: node,
  7289. allowedModifiers: ["in", "out"],
  7290. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7291. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7292. });
  7293. }
  7294. tsParseNoneModifiers(node) {
  7295. this.tsParseModifiers({
  7296. modified: node,
  7297. allowedModifiers: [],
  7298. disallowedModifiers: ["in", "out"],
  7299. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7300. });
  7301. }
  7302. tsParseTypeParameter(parseModifiers = this.tsParseNoneModifiers.bind(this)) {
  7303. const node = this.startNode();
  7304. parseModifiers(node);
  7305. node.name = this.tsParseTypeParameterName();
  7306. node.constraint = this.tsEatThenParseType(81);
  7307. node.default = this.tsEatThenParseType(29);
  7308. return this.finishNode(node, "TSTypeParameter");
  7309. }
  7310. tsTryParseTypeParameters(parseModifiers) {
  7311. if (this.match(47)) {
  7312. return this.tsParseTypeParameters(parseModifiers);
  7313. }
  7314. }
  7315. tsParseTypeParameters(parseModifiers) {
  7316. const node = this.startNode();
  7317. if (this.match(47) || this.match(138)) {
  7318. this.next();
  7319. } else {
  7320. this.unexpected();
  7321. }
  7322. const refTrailingCommaPos = {
  7323. value: -1
  7324. };
  7325. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7326. if (node.params.length === 0) {
  7327. this.raise(TSErrors.EmptyTypeParameters, {
  7328. at: node
  7329. });
  7330. }
  7331. if (refTrailingCommaPos.value !== -1) {
  7332. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7333. }
  7334. return this.finishNode(node, "TSTypeParameterDeclaration");
  7335. }
  7336. tsTryNextParseConstantContext() {
  7337. if (this.lookahead().type !== 75) return null;
  7338. this.next();
  7339. const typeReference = this.tsParseTypeReference();
  7340. if (typeReference.typeParameters) {
  7341. this.raise(TSErrors.CannotFindName, {
  7342. at: typeReference.typeName,
  7343. name: "const"
  7344. });
  7345. }
  7346. return typeReference;
  7347. }
  7348. tsFillSignature(returnToken, signature) {
  7349. const returnTokenRequired = returnToken === 19;
  7350. const paramsKey = "parameters";
  7351. const returnTypeKey = "typeAnnotation";
  7352. signature.typeParameters = this.tsTryParseTypeParameters();
  7353. this.expect(10);
  7354. signature[paramsKey] = this.tsParseBindingListForSignature();
  7355. if (returnTokenRequired) {
  7356. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7357. } else if (this.match(returnToken)) {
  7358. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7359. }
  7360. }
  7361. tsParseBindingListForSignature() {
  7362. return this.parseBindingList(11, 41).map(pattern => {
  7363. if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") {
  7364. this.raise(TSErrors.UnsupportedSignatureParameterKind, {
  7365. at: pattern,
  7366. type: pattern.type
  7367. });
  7368. }
  7369. return pattern;
  7370. });
  7371. }
  7372. tsParseTypeMemberSemicolon() {
  7373. if (!this.eat(12) && !this.isLineTerminator()) {
  7374. this.expect(13);
  7375. }
  7376. }
  7377. tsParseSignatureMember(kind, node) {
  7378. this.tsFillSignature(14, node);
  7379. this.tsParseTypeMemberSemicolon();
  7380. return this.finishNode(node, kind);
  7381. }
  7382. tsIsUnambiguouslyIndexSignature() {
  7383. this.next();
  7384. if (tokenIsIdentifier(this.state.type)) {
  7385. this.next();
  7386. return this.match(14);
  7387. }
  7388. return false;
  7389. }
  7390. tsTryParseIndexSignature(node) {
  7391. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  7392. return undefined;
  7393. }
  7394. this.expect(0);
  7395. const id = this.parseIdentifier();
  7396. id.typeAnnotation = this.tsParseTypeAnnotation();
  7397. this.resetEndLocation(id);
  7398. this.expect(3);
  7399. node.parameters = [id];
  7400. const type = this.tsTryParseTypeAnnotation();
  7401. if (type) node.typeAnnotation = type;
  7402. this.tsParseTypeMemberSemicolon();
  7403. return this.finishNode(node, "TSIndexSignature");
  7404. }
  7405. tsParsePropertyOrMethodSignature(node, readonly) {
  7406. if (this.eat(17)) node.optional = true;
  7407. const nodeAny = node;
  7408. if (this.match(10) || this.match(47)) {
  7409. if (readonly) {
  7410. this.raise(TSErrors.ReadonlyForMethodSignature, {
  7411. at: node
  7412. });
  7413. }
  7414. const method = nodeAny;
  7415. if (method.kind && this.match(47)) {
  7416. this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
  7417. at: this.state.curPosition()
  7418. });
  7419. }
  7420. this.tsFillSignature(14, method);
  7421. this.tsParseTypeMemberSemicolon();
  7422. const paramsKey = "parameters";
  7423. const returnTypeKey = "typeAnnotation";
  7424. if (method.kind === "get") {
  7425. if (method[paramsKey].length > 0) {
  7426. this.raise(Errors.BadGetterArity, {
  7427. at: this.state.curPosition()
  7428. });
  7429. if (this.isThisParam(method[paramsKey][0])) {
  7430. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  7431. at: this.state.curPosition()
  7432. });
  7433. }
  7434. }
  7435. } else if (method.kind === "set") {
  7436. if (method[paramsKey].length !== 1) {
  7437. this.raise(Errors.BadSetterArity, {
  7438. at: this.state.curPosition()
  7439. });
  7440. } else {
  7441. const firstParameter = method[paramsKey][0];
  7442. if (this.isThisParam(firstParameter)) {
  7443. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  7444. at: this.state.curPosition()
  7445. });
  7446. }
  7447. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  7448. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
  7449. at: this.state.curPosition()
  7450. });
  7451. }
  7452. if (firstParameter.type === "RestElement") {
  7453. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
  7454. at: this.state.curPosition()
  7455. });
  7456. }
  7457. }
  7458. if (method[returnTypeKey]) {
  7459. this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
  7460. at: method[returnTypeKey]
  7461. });
  7462. }
  7463. } else {
  7464. method.kind = "method";
  7465. }
  7466. return this.finishNode(method, "TSMethodSignature");
  7467. } else {
  7468. const property = nodeAny;
  7469. if (readonly) property.readonly = true;
  7470. const type = this.tsTryParseTypeAnnotation();
  7471. if (type) property.typeAnnotation = type;
  7472. this.tsParseTypeMemberSemicolon();
  7473. return this.finishNode(property, "TSPropertySignature");
  7474. }
  7475. }
  7476. tsParseTypeMember() {
  7477. const node = this.startNode();
  7478. if (this.match(10) || this.match(47)) {
  7479. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  7480. }
  7481. if (this.match(77)) {
  7482. const id = this.startNode();
  7483. this.next();
  7484. if (this.match(10) || this.match(47)) {
  7485. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  7486. } else {
  7487. node.key = this.createIdentifier(id, "new");
  7488. return this.tsParsePropertyOrMethodSignature(node, false);
  7489. }
  7490. }
  7491. this.tsParseModifiers({
  7492. modified: node,
  7493. allowedModifiers: ["readonly"],
  7494. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  7495. });
  7496. const idx = this.tsTryParseIndexSignature(node);
  7497. if (idx) {
  7498. return idx;
  7499. }
  7500. this.parsePropertyName(node);
  7501. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  7502. node.kind = node.key.name;
  7503. this.parsePropertyName(node);
  7504. }
  7505. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  7506. }
  7507. tsParseTypeLiteral() {
  7508. const node = this.startNode();
  7509. node.members = this.tsParseObjectTypeMembers();
  7510. return this.finishNode(node, "TSTypeLiteral");
  7511. }
  7512. tsParseObjectTypeMembers() {
  7513. this.expect(5);
  7514. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  7515. this.expect(8);
  7516. return members;
  7517. }
  7518. tsIsStartOfMappedType() {
  7519. this.next();
  7520. if (this.eat(53)) {
  7521. return this.isContextual(118);
  7522. }
  7523. if (this.isContextual(118)) {
  7524. this.next();
  7525. }
  7526. if (!this.match(0)) {
  7527. return false;
  7528. }
  7529. this.next();
  7530. if (!this.tsIsIdentifier()) {
  7531. return false;
  7532. }
  7533. this.next();
  7534. return this.match(58);
  7535. }
  7536. tsParseMappedTypeParameter() {
  7537. const node = this.startNode();
  7538. node.name = this.tsParseTypeParameterName();
  7539. node.constraint = this.tsExpectThenParseType(58);
  7540. return this.finishNode(node, "TSTypeParameter");
  7541. }
  7542. tsParseMappedType() {
  7543. const node = this.startNode();
  7544. this.expect(5);
  7545. if (this.match(53)) {
  7546. node.readonly = this.state.value;
  7547. this.next();
  7548. this.expectContextual(118);
  7549. } else if (this.eatContextual(118)) {
  7550. node.readonly = true;
  7551. }
  7552. this.expect(0);
  7553. node.typeParameter = this.tsParseMappedTypeParameter();
  7554. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  7555. this.expect(3);
  7556. if (this.match(53)) {
  7557. node.optional = this.state.value;
  7558. this.next();
  7559. this.expect(17);
  7560. } else if (this.eat(17)) {
  7561. node.optional = true;
  7562. }
  7563. node.typeAnnotation = this.tsTryParseType();
  7564. this.semicolon();
  7565. this.expect(8);
  7566. return this.finishNode(node, "TSMappedType");
  7567. }
  7568. tsParseTupleType() {
  7569. const node = this.startNode();
  7570. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  7571. let seenOptionalElement = false;
  7572. let labeledElements = null;
  7573. node.elementTypes.forEach(elementNode => {
  7574. var _labeledElements;
  7575. let {
  7576. type
  7577. } = elementNode;
  7578. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  7579. this.raise(TSErrors.OptionalTypeBeforeRequired, {
  7580. at: elementNode
  7581. });
  7582. }
  7583. seenOptionalElement = seenOptionalElement || type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType";
  7584. if (type === "TSRestType") {
  7585. elementNode = elementNode.typeAnnotation;
  7586. type = elementNode.type;
  7587. }
  7588. const isLabeled = type === "TSNamedTupleMember";
  7589. labeledElements = (_labeledElements = labeledElements) != null ? _labeledElements : isLabeled;
  7590. if (labeledElements !== isLabeled) {
  7591. this.raise(TSErrors.MixedLabeledAndUnlabeledElements, {
  7592. at: elementNode
  7593. });
  7594. }
  7595. });
  7596. return this.finishNode(node, "TSTupleType");
  7597. }
  7598. tsParseTupleElementType() {
  7599. const {
  7600. start: startPos,
  7601. startLoc
  7602. } = this.state;
  7603. const rest = this.eat(21);
  7604. let type = this.tsParseType();
  7605. const optional = this.eat(17);
  7606. const labeled = this.eat(14);
  7607. if (labeled) {
  7608. const labeledNode = this.startNodeAtNode(type);
  7609. labeledNode.optional = optional;
  7610. if (type.type === "TSTypeReference" && !type.typeParameters && type.typeName.type === "Identifier") {
  7611. labeledNode.label = type.typeName;
  7612. } else {
  7613. this.raise(TSErrors.InvalidTupleMemberLabel, {
  7614. at: type
  7615. });
  7616. labeledNode.label = type;
  7617. }
  7618. labeledNode.elementType = this.tsParseType();
  7619. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  7620. } else if (optional) {
  7621. const optionalTypeNode = this.startNodeAtNode(type);
  7622. optionalTypeNode.typeAnnotation = type;
  7623. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  7624. }
  7625. if (rest) {
  7626. const restNode = this.startNodeAt(startPos, startLoc);
  7627. restNode.typeAnnotation = type;
  7628. type = this.finishNode(restNode, "TSRestType");
  7629. }
  7630. return type;
  7631. }
  7632. tsParseParenthesizedType() {
  7633. const node = this.startNode();
  7634. this.expect(10);
  7635. node.typeAnnotation = this.tsParseType();
  7636. this.expect(11);
  7637. return this.finishNode(node, "TSParenthesizedType");
  7638. }
  7639. tsParseFunctionOrConstructorType(type, abstract) {
  7640. const node = this.startNode();
  7641. if (type === "TSConstructorType") {
  7642. node.abstract = !!abstract;
  7643. if (abstract) this.next();
  7644. this.next();
  7645. }
  7646. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  7647. return this.finishNode(node, type);
  7648. }
  7649. tsParseLiteralTypeNode() {
  7650. const node = this.startNode();
  7651. node.literal = (() => {
  7652. switch (this.state.type) {
  7653. case 130:
  7654. case 131:
  7655. case 129:
  7656. case 85:
  7657. case 86:
  7658. return this.parseExprAtom();
  7659. default:
  7660. throw this.unexpected();
  7661. }
  7662. })();
  7663. return this.finishNode(node, "TSLiteralType");
  7664. }
  7665. tsParseTemplateLiteralType() {
  7666. const node = this.startNode();
  7667. node.literal = this.parseTemplate(false);
  7668. return this.finishNode(node, "TSLiteralType");
  7669. }
  7670. parseTemplateSubstitution() {
  7671. if (this.state.inType) return this.tsParseType();
  7672. return super.parseTemplateSubstitution();
  7673. }
  7674. tsParseThisTypeOrThisTypePredicate() {
  7675. const thisKeyword = this.tsParseThisTypeNode();
  7676. if (this.isContextual(113) && !this.hasPrecedingLineBreak()) {
  7677. return this.tsParseThisTypePredicate(thisKeyword);
  7678. } else {
  7679. return thisKeyword;
  7680. }
  7681. }
  7682. tsParseNonArrayType() {
  7683. switch (this.state.type) {
  7684. case 129:
  7685. case 130:
  7686. case 131:
  7687. case 85:
  7688. case 86:
  7689. return this.tsParseLiteralTypeNode();
  7690. case 53:
  7691. if (this.state.value === "-") {
  7692. const node = this.startNode();
  7693. const nextToken = this.lookahead();
  7694. if (nextToken.type !== 130 && nextToken.type !== 131) {
  7695. throw this.unexpected();
  7696. }
  7697. node.literal = this.parseMaybeUnary();
  7698. return this.finishNode(node, "TSLiteralType");
  7699. }
  7700. break;
  7701. case 78:
  7702. return this.tsParseThisTypeOrThisTypePredicate();
  7703. case 87:
  7704. return this.tsParseTypeQuery();
  7705. case 83:
  7706. return this.tsParseImportType();
  7707. case 5:
  7708. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  7709. case 0:
  7710. return this.tsParseTupleType();
  7711. case 10:
  7712. return this.tsParseParenthesizedType();
  7713. case 25:
  7714. case 24:
  7715. return this.tsParseTemplateLiteralType();
  7716. default:
  7717. {
  7718. const {
  7719. type
  7720. } = this.state;
  7721. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  7722. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  7723. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  7724. const node = this.startNode();
  7725. this.next();
  7726. return this.finishNode(node, nodeType);
  7727. }
  7728. return this.tsParseTypeReference();
  7729. }
  7730. }
  7731. }
  7732. throw this.unexpected();
  7733. }
  7734. tsParseArrayTypeOrHigher() {
  7735. let type = this.tsParseNonArrayType();
  7736. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  7737. if (this.match(3)) {
  7738. const node = this.startNodeAtNode(type);
  7739. node.elementType = type;
  7740. this.expect(3);
  7741. type = this.finishNode(node, "TSArrayType");
  7742. } else {
  7743. const node = this.startNodeAtNode(type);
  7744. node.objectType = type;
  7745. node.indexType = this.tsParseType();
  7746. this.expect(3);
  7747. type = this.finishNode(node, "TSIndexedAccessType");
  7748. }
  7749. }
  7750. return type;
  7751. }
  7752. tsParseTypeOperator() {
  7753. const node = this.startNode();
  7754. const operator = this.state.value;
  7755. this.next();
  7756. node.operator = operator;
  7757. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  7758. if (operator === "readonly") {
  7759. this.tsCheckTypeAnnotationForReadOnly(node);
  7760. }
  7761. return this.finishNode(node, "TSTypeOperator");
  7762. }
  7763. tsCheckTypeAnnotationForReadOnly(node) {
  7764. switch (node.typeAnnotation.type) {
  7765. case "TSTupleType":
  7766. case "TSArrayType":
  7767. return;
  7768. default:
  7769. this.raise(TSErrors.UnexpectedReadonly, {
  7770. at: node
  7771. });
  7772. }
  7773. }
  7774. tsParseInferType() {
  7775. const node = this.startNode();
  7776. this.expectContextual(112);
  7777. const typeParameter = this.startNode();
  7778. typeParameter.name = this.tsParseTypeParameterName();
  7779. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  7780. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  7781. return this.finishNode(node, "TSInferType");
  7782. }
  7783. tsParseConstraintForInferType() {
  7784. if (this.eat(81)) {
  7785. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  7786. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  7787. return constraint;
  7788. }
  7789. }
  7790. }
  7791. tsParseTypeOperatorOrHigher() {
  7792. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  7793. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(112) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  7794. }
  7795. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  7796. const node = this.startNode();
  7797. const hasLeadingOperator = this.eat(operator);
  7798. const types = [];
  7799. do {
  7800. types.push(parseConstituentType());
  7801. } while (this.eat(operator));
  7802. if (types.length === 1 && !hasLeadingOperator) {
  7803. return types[0];
  7804. }
  7805. node.types = types;
  7806. return this.finishNode(node, kind);
  7807. }
  7808. tsParseIntersectionTypeOrHigher() {
  7809. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  7810. }
  7811. tsParseUnionTypeOrHigher() {
  7812. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  7813. }
  7814. tsIsStartOfFunctionType() {
  7815. if (this.match(47)) {
  7816. return true;
  7817. }
  7818. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  7819. }
  7820. tsSkipParameterStart() {
  7821. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  7822. this.next();
  7823. return true;
  7824. }
  7825. if (this.match(5)) {
  7826. const {
  7827. errors
  7828. } = this.state;
  7829. const previousErrorCount = errors.length;
  7830. try {
  7831. this.parseObjectLike(8, true);
  7832. return errors.length === previousErrorCount;
  7833. } catch (_unused) {
  7834. return false;
  7835. }
  7836. }
  7837. if (this.match(0)) {
  7838. this.next();
  7839. const {
  7840. errors
  7841. } = this.state;
  7842. const previousErrorCount = errors.length;
  7843. try {
  7844. this.parseBindingList(3, 93, true);
  7845. return errors.length === previousErrorCount;
  7846. } catch (_unused2) {
  7847. return false;
  7848. }
  7849. }
  7850. return false;
  7851. }
  7852. tsIsUnambiguouslyStartOfFunctionType() {
  7853. this.next();
  7854. if (this.match(11) || this.match(21)) {
  7855. return true;
  7856. }
  7857. if (this.tsSkipParameterStart()) {
  7858. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  7859. return true;
  7860. }
  7861. if (this.match(11)) {
  7862. this.next();
  7863. if (this.match(19)) {
  7864. return true;
  7865. }
  7866. }
  7867. }
  7868. return false;
  7869. }
  7870. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  7871. return this.tsInType(() => {
  7872. const t = this.startNode();
  7873. this.expect(returnToken);
  7874. const node = this.startNode();
  7875. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  7876. if (asserts && this.match(78)) {
  7877. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  7878. if (thisTypePredicate.type === "TSThisType") {
  7879. node.parameterName = thisTypePredicate;
  7880. node.asserts = true;
  7881. node.typeAnnotation = null;
  7882. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  7883. } else {
  7884. this.resetStartLocationFromNode(thisTypePredicate, node);
  7885. thisTypePredicate.asserts = true;
  7886. }
  7887. t.typeAnnotation = thisTypePredicate;
  7888. return this.finishNode(t, "TSTypeAnnotation");
  7889. }
  7890. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  7891. if (!typePredicateVariable) {
  7892. if (!asserts) {
  7893. return this.tsParseTypeAnnotation(false, t);
  7894. }
  7895. node.parameterName = this.parseIdentifier();
  7896. node.asserts = asserts;
  7897. node.typeAnnotation = null;
  7898. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  7899. return this.finishNode(t, "TSTypeAnnotation");
  7900. }
  7901. const type = this.tsParseTypeAnnotation(false);
  7902. node.parameterName = typePredicateVariable;
  7903. node.typeAnnotation = type;
  7904. node.asserts = asserts;
  7905. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  7906. return this.finishNode(t, "TSTypeAnnotation");
  7907. });
  7908. }
  7909. tsTryParseTypeOrTypePredicateAnnotation() {
  7910. return this.match(14) ? this.tsParseTypeOrTypePredicateAnnotation(14) : undefined;
  7911. }
  7912. tsTryParseTypeAnnotation() {
  7913. return this.match(14) ? this.tsParseTypeAnnotation() : undefined;
  7914. }
  7915. tsTryParseType() {
  7916. return this.tsEatThenParseType(14);
  7917. }
  7918. tsParseTypePredicatePrefix() {
  7919. const id = this.parseIdentifier();
  7920. if (this.isContextual(113) && !this.hasPrecedingLineBreak()) {
  7921. this.next();
  7922. return id;
  7923. }
  7924. }
  7925. tsParseTypePredicateAsserts() {
  7926. if (this.state.type !== 106) {
  7927. return false;
  7928. }
  7929. const containsEsc = this.state.containsEsc;
  7930. this.next();
  7931. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  7932. return false;
  7933. }
  7934. if (containsEsc) {
  7935. this.raise(Errors.InvalidEscapedReservedWord, {
  7936. at: this.state.lastTokStartLoc,
  7937. reservedWord: "asserts"
  7938. });
  7939. }
  7940. return true;
  7941. }
  7942. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  7943. this.tsInType(() => {
  7944. if (eatColon) this.expect(14);
  7945. t.typeAnnotation = this.tsParseType();
  7946. });
  7947. return this.finishNode(t, "TSTypeAnnotation");
  7948. }
  7949. tsParseType() {
  7950. assert(this.state.inType);
  7951. const type = this.tsParseNonConditionalType();
  7952. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  7953. return type;
  7954. }
  7955. const node = this.startNodeAtNode(type);
  7956. node.checkType = type;
  7957. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  7958. this.expect(17);
  7959. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  7960. this.expect(14);
  7961. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  7962. return this.finishNode(node, "TSConditionalType");
  7963. }
  7964. isAbstractConstructorSignature() {
  7965. return this.isContextual(120) && this.lookahead().type === 77;
  7966. }
  7967. tsParseNonConditionalType() {
  7968. if (this.tsIsStartOfFunctionType()) {
  7969. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  7970. }
  7971. if (this.match(77)) {
  7972. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  7973. } else if (this.isAbstractConstructorSignature()) {
  7974. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  7975. }
  7976. return this.tsParseUnionTypeOrHigher();
  7977. }
  7978. tsParseTypeAssertion() {
  7979. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  7980. this.raise(TSErrors.ReservedTypeAssertion, {
  7981. at: this.state.startLoc
  7982. });
  7983. }
  7984. const node = this.startNode();
  7985. const _const = this.tsTryNextParseConstantContext();
  7986. node.typeAnnotation = _const || this.tsNextThenParseType();
  7987. this.expect(48);
  7988. node.expression = this.parseMaybeUnary();
  7989. return this.finishNode(node, "TSTypeAssertion");
  7990. }
  7991. tsParseHeritageClause(token) {
  7992. const originalStartLoc = this.state.startLoc;
  7993. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  7994. const node = this.startNode();
  7995. node.expression = this.tsParseEntityName();
  7996. if (this.match(47)) {
  7997. node.typeParameters = this.tsParseTypeArguments();
  7998. }
  7999. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8000. });
  8001. if (!delimitedList.length) {
  8002. this.raise(TSErrors.EmptyHeritageClauseType, {
  8003. at: originalStartLoc,
  8004. token
  8005. });
  8006. }
  8007. return delimitedList;
  8008. }
  8009. tsParseInterfaceDeclaration(node, properties = {}) {
  8010. if (this.hasFollowingLineBreak()) return null;
  8011. this.expectContextual(125);
  8012. if (properties.declare) node.declare = true;
  8013. if (tokenIsIdentifier(this.state.type)) {
  8014. node.id = this.parseIdentifier();
  8015. this.checkIdentifier(node.id, BIND_TS_INTERFACE);
  8016. } else {
  8017. node.id = null;
  8018. this.raise(TSErrors.MissingInterfaceName, {
  8019. at: this.state.startLoc
  8020. });
  8021. }
  8022. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers.bind(this));
  8023. if (this.eat(81)) {
  8024. node.extends = this.tsParseHeritageClause("extends");
  8025. }
  8026. const body = this.startNode();
  8027. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8028. node.body = this.finishNode(body, "TSInterfaceBody");
  8029. return this.finishNode(node, "TSInterfaceDeclaration");
  8030. }
  8031. tsParseTypeAliasDeclaration(node) {
  8032. node.id = this.parseIdentifier();
  8033. this.checkIdentifier(node.id, BIND_TS_TYPE);
  8034. node.typeAnnotation = this.tsInType(() => {
  8035. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers.bind(this));
  8036. this.expect(29);
  8037. if (this.isContextual(111) && this.lookahead().type !== 16) {
  8038. const node = this.startNode();
  8039. this.next();
  8040. return this.finishNode(node, "TSIntrinsicKeyword");
  8041. }
  8042. return this.tsParseType();
  8043. });
  8044. this.semicolon();
  8045. return this.finishNode(node, "TSTypeAliasDeclaration");
  8046. }
  8047. tsInNoContext(cb) {
  8048. const oldContext = this.state.context;
  8049. this.state.context = [oldContext[0]];
  8050. try {
  8051. return cb();
  8052. } finally {
  8053. this.state.context = oldContext;
  8054. }
  8055. }
  8056. tsInType(cb) {
  8057. const oldInType = this.state.inType;
  8058. this.state.inType = true;
  8059. try {
  8060. return cb();
  8061. } finally {
  8062. this.state.inType = oldInType;
  8063. }
  8064. }
  8065. tsInDisallowConditionalTypesContext(cb) {
  8066. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8067. this.state.inDisallowConditionalTypesContext = true;
  8068. try {
  8069. return cb();
  8070. } finally {
  8071. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8072. }
  8073. }
  8074. tsInAllowConditionalTypesContext(cb) {
  8075. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8076. this.state.inDisallowConditionalTypesContext = false;
  8077. try {
  8078. return cb();
  8079. } finally {
  8080. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8081. }
  8082. }
  8083. tsEatThenParseType(token) {
  8084. return !this.match(token) ? undefined : this.tsNextThenParseType();
  8085. }
  8086. tsExpectThenParseType(token) {
  8087. return this.tsDoThenParseType(() => this.expect(token));
  8088. }
  8089. tsNextThenParseType() {
  8090. return this.tsDoThenParseType(() => this.next());
  8091. }
  8092. tsDoThenParseType(cb) {
  8093. return this.tsInType(() => {
  8094. cb();
  8095. return this.tsParseType();
  8096. });
  8097. }
  8098. tsParseEnumMember() {
  8099. const node = this.startNode();
  8100. node.id = this.match(129) ? this.parseExprAtom() : this.parseIdentifier(true);
  8101. if (this.eat(29)) {
  8102. node.initializer = this.parseMaybeAssignAllowIn();
  8103. }
  8104. return this.finishNode(node, "TSEnumMember");
  8105. }
  8106. tsParseEnumDeclaration(node, properties = {}) {
  8107. if (properties.const) node.const = true;
  8108. if (properties.declare) node.declare = true;
  8109. this.expectContextual(122);
  8110. node.id = this.parseIdentifier();
  8111. this.checkIdentifier(node.id, node.const ? BIND_TS_CONST_ENUM : BIND_TS_ENUM);
  8112. this.expect(5);
  8113. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8114. this.expect(8);
  8115. return this.finishNode(node, "TSEnumDeclaration");
  8116. }
  8117. tsParseModuleBlock() {
  8118. const node = this.startNode();
  8119. this.scope.enter(SCOPE_OTHER);
  8120. this.expect(5);
  8121. this.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8122. this.scope.exit();
  8123. return this.finishNode(node, "TSModuleBlock");
  8124. }
  8125. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8126. node.id = this.parseIdentifier();
  8127. if (!nested) {
  8128. this.checkIdentifier(node.id, BIND_TS_NAMESPACE);
  8129. }
  8130. if (this.eat(16)) {
  8131. const inner = this.startNode();
  8132. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8133. node.body = inner;
  8134. } else {
  8135. this.scope.enter(SCOPE_TS_MODULE);
  8136. this.prodParam.enter(PARAM);
  8137. node.body = this.tsParseModuleBlock();
  8138. this.prodParam.exit();
  8139. this.scope.exit();
  8140. }
  8141. return this.finishNode(node, "TSModuleDeclaration");
  8142. }
  8143. tsParseAmbientExternalModuleDeclaration(node) {
  8144. if (this.isContextual(109)) {
  8145. node.global = true;
  8146. node.id = this.parseIdentifier();
  8147. } else if (this.match(129)) {
  8148. node.id = this.parseExprAtom();
  8149. } else {
  8150. this.unexpected();
  8151. }
  8152. if (this.match(5)) {
  8153. this.scope.enter(SCOPE_TS_MODULE);
  8154. this.prodParam.enter(PARAM);
  8155. node.body = this.tsParseModuleBlock();
  8156. this.prodParam.exit();
  8157. this.scope.exit();
  8158. } else {
  8159. this.semicolon();
  8160. }
  8161. return this.finishNode(node, "TSModuleDeclaration");
  8162. }
  8163. tsParseImportEqualsDeclaration(node, isExport) {
  8164. node.isExport = isExport || false;
  8165. node.id = this.parseIdentifier();
  8166. this.checkIdentifier(node.id, BIND_LEXICAL);
  8167. this.expect(29);
  8168. const moduleReference = this.tsParseModuleReference();
  8169. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8170. this.raise(TSErrors.ImportAliasHasImportType, {
  8171. at: moduleReference
  8172. });
  8173. }
  8174. node.moduleReference = moduleReference;
  8175. this.semicolon();
  8176. return this.finishNode(node, "TSImportEqualsDeclaration");
  8177. }
  8178. tsIsExternalModuleReference() {
  8179. return this.isContextual(116) && this.lookaheadCharCode() === 40;
  8180. }
  8181. tsParseModuleReference() {
  8182. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  8183. }
  8184. tsParseExternalModuleReference() {
  8185. const node = this.startNode();
  8186. this.expectContextual(116);
  8187. this.expect(10);
  8188. if (!this.match(129)) {
  8189. throw this.unexpected();
  8190. }
  8191. node.expression = this.parseExprAtom();
  8192. this.expect(11);
  8193. return this.finishNode(node, "TSExternalModuleReference");
  8194. }
  8195. tsLookAhead(f) {
  8196. const state = this.state.clone();
  8197. const res = f();
  8198. this.state = state;
  8199. return res;
  8200. }
  8201. tsTryParseAndCatch(f) {
  8202. const result = this.tryParse(abort => f() || abort());
  8203. if (result.aborted || !result.node) return undefined;
  8204. if (result.error) this.state = result.failState;
  8205. return result.node;
  8206. }
  8207. tsTryParse(f) {
  8208. const state = this.state.clone();
  8209. const result = f();
  8210. if (result !== undefined && result !== false) {
  8211. return result;
  8212. } else {
  8213. this.state = state;
  8214. return undefined;
  8215. }
  8216. }
  8217. tsTryParseDeclare(nany) {
  8218. if (this.isLineTerminator()) {
  8219. return;
  8220. }
  8221. let starttype = this.state.type;
  8222. let kind;
  8223. if (this.isContextual(99)) {
  8224. starttype = 74;
  8225. kind = "let";
  8226. }
  8227. return this.tsInAmbientContext(() => {
  8228. if (starttype === 68) {
  8229. nany.declare = true;
  8230. return this.parseFunctionStatement(nany, false, true);
  8231. }
  8232. if (starttype === 80) {
  8233. nany.declare = true;
  8234. return this.parseClass(nany, true, false);
  8235. }
  8236. if (starttype === 122) {
  8237. return this.tsParseEnumDeclaration(nany, {
  8238. declare: true
  8239. });
  8240. }
  8241. if (starttype === 109) {
  8242. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8243. }
  8244. if (starttype === 75 || starttype === 74) {
  8245. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8246. nany.declare = true;
  8247. return this.parseVarStatement(nany, kind || this.state.value, true);
  8248. }
  8249. this.expect(75);
  8250. return this.tsParseEnumDeclaration(nany, {
  8251. const: true,
  8252. declare: true
  8253. });
  8254. }
  8255. if (starttype === 125) {
  8256. const result = this.tsParseInterfaceDeclaration(nany, {
  8257. declare: true
  8258. });
  8259. if (result) return result;
  8260. }
  8261. if (tokenIsIdentifier(starttype)) {
  8262. return this.tsParseDeclaration(nany, this.state.value, true);
  8263. }
  8264. });
  8265. }
  8266. tsTryParseExportDeclaration() {
  8267. return this.tsParseDeclaration(this.startNode(), this.state.value, true);
  8268. }
  8269. tsParseExpressionStatement(node, expr) {
  8270. switch (expr.name) {
  8271. case "declare":
  8272. {
  8273. const declaration = this.tsTryParseDeclare(node);
  8274. if (declaration) {
  8275. declaration.declare = true;
  8276. return declaration;
  8277. }
  8278. break;
  8279. }
  8280. case "global":
  8281. if (this.match(5)) {
  8282. this.scope.enter(SCOPE_TS_MODULE);
  8283. this.prodParam.enter(PARAM);
  8284. const mod = node;
  8285. mod.global = true;
  8286. mod.id = expr;
  8287. mod.body = this.tsParseModuleBlock();
  8288. this.scope.exit();
  8289. this.prodParam.exit();
  8290. return this.finishNode(mod, "TSModuleDeclaration");
  8291. }
  8292. break;
  8293. default:
  8294. return this.tsParseDeclaration(node, expr.name, false);
  8295. }
  8296. }
  8297. tsParseDeclaration(node, value, next) {
  8298. switch (value) {
  8299. case "abstract":
  8300. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8301. return this.tsParseAbstractDeclaration(node);
  8302. }
  8303. break;
  8304. case "module":
  8305. if (this.tsCheckLineTerminator(next)) {
  8306. if (this.match(129)) {
  8307. return this.tsParseAmbientExternalModuleDeclaration(node);
  8308. } else if (tokenIsIdentifier(this.state.type)) {
  8309. return this.tsParseModuleOrNamespaceDeclaration(node);
  8310. }
  8311. }
  8312. break;
  8313. case "namespace":
  8314. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8315. return this.tsParseModuleOrNamespaceDeclaration(node);
  8316. }
  8317. break;
  8318. case "type":
  8319. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8320. return this.tsParseTypeAliasDeclaration(node);
  8321. }
  8322. break;
  8323. }
  8324. }
  8325. tsCheckLineTerminator(next) {
  8326. if (next) {
  8327. if (this.hasFollowingLineBreak()) return false;
  8328. this.next();
  8329. return true;
  8330. }
  8331. return !this.isLineTerminator();
  8332. }
  8333. tsTryParseGenericAsyncArrowFunction(startPos, startLoc) {
  8334. if (!this.match(47)) {
  8335. return undefined;
  8336. }
  8337. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8338. this.state.maybeInArrowParameters = true;
  8339. const res = this.tsTryParseAndCatch(() => {
  8340. const node = this.startNodeAt(startPos, startLoc);
  8341. node.typeParameters = this.tsParseTypeParameters();
  8342. super.parseFunctionParams(node);
  8343. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  8344. this.expect(19);
  8345. return node;
  8346. });
  8347. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  8348. if (!res) {
  8349. return undefined;
  8350. }
  8351. return this.parseArrowExpression(res, null, true);
  8352. }
  8353. tsParseTypeArgumentsInExpression() {
  8354. if (this.reScan_lt() !== 47) {
  8355. return undefined;
  8356. }
  8357. return this.tsParseTypeArguments();
  8358. }
  8359. tsParseTypeArguments() {
  8360. const node = this.startNode();
  8361. node.params = this.tsInType(() => this.tsInNoContext(() => {
  8362. this.expect(47);
  8363. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  8364. }));
  8365. if (node.params.length === 0) {
  8366. this.raise(TSErrors.EmptyTypeArguments, {
  8367. at: node
  8368. });
  8369. }
  8370. this.expect(48);
  8371. return this.finishNode(node, "TSTypeParameterInstantiation");
  8372. }
  8373. tsIsDeclarationStart() {
  8374. return tokenIsTSDeclarationStart(this.state.type);
  8375. }
  8376. isExportDefaultSpecifier() {
  8377. if (this.tsIsDeclarationStart()) return false;
  8378. return super.isExportDefaultSpecifier();
  8379. }
  8380. parseAssignableListItem(allowModifiers, decorators) {
  8381. const startPos = this.state.start;
  8382. const startLoc = this.state.startLoc;
  8383. let accessibility;
  8384. let readonly = false;
  8385. let override = false;
  8386. if (allowModifiers !== undefined) {
  8387. const modified = {};
  8388. this.tsParseModifiers({
  8389. modified,
  8390. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  8391. });
  8392. accessibility = modified.accessibility;
  8393. override = modified.override;
  8394. readonly = modified.readonly;
  8395. if (allowModifiers === false && (accessibility || readonly || override)) {
  8396. this.raise(TSErrors.UnexpectedParameterModifier, {
  8397. at: startLoc
  8398. });
  8399. }
  8400. }
  8401. const left = this.parseMaybeDefault();
  8402. this.parseAssignableListItemTypes(left);
  8403. const elt = this.parseMaybeDefault(left.start, left.loc.start, left);
  8404. if (accessibility || readonly || override) {
  8405. const pp = this.startNodeAt(startPos, startLoc);
  8406. if (decorators.length) {
  8407. pp.decorators = decorators;
  8408. }
  8409. if (accessibility) pp.accessibility = accessibility;
  8410. if (readonly) pp.readonly = readonly;
  8411. if (override) pp.override = override;
  8412. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  8413. this.raise(TSErrors.UnsupportedParameterPropertyKind, {
  8414. at: pp
  8415. });
  8416. }
  8417. pp.parameter = elt;
  8418. return this.finishNode(pp, "TSParameterProperty");
  8419. }
  8420. if (decorators.length) {
  8421. left.decorators = decorators;
  8422. }
  8423. return elt;
  8424. }
  8425. isSimpleParameter(node) {
  8426. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  8427. }
  8428. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  8429. if (this.match(14)) {
  8430. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  8431. }
  8432. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  8433. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  8434. this.finishNode(node, bodilessType);
  8435. return;
  8436. }
  8437. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  8438. this.raise(TSErrors.DeclareFunctionHasImplementation, {
  8439. at: node
  8440. });
  8441. if (node.declare) {
  8442. super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  8443. return;
  8444. }
  8445. }
  8446. super.parseFunctionBodyAndFinish(node, type, isMethod);
  8447. }
  8448. registerFunctionStatementId(node) {
  8449. if (!node.body && node.id) {
  8450. this.checkIdentifier(node.id, BIND_TS_AMBIENT);
  8451. } else {
  8452. super.registerFunctionStatementId(...arguments);
  8453. }
  8454. }
  8455. tsCheckForInvalidTypeCasts(items) {
  8456. items.forEach(node => {
  8457. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  8458. this.raise(TSErrors.UnexpectedTypeAnnotation, {
  8459. at: node.typeAnnotation
  8460. });
  8461. }
  8462. });
  8463. }
  8464. toReferencedList(exprList, isInParens) {
  8465. this.tsCheckForInvalidTypeCasts(exprList);
  8466. return exprList;
  8467. }
  8468. parseArrayLike(...args) {
  8469. const node = super.parseArrayLike(...args);
  8470. if (node.type === "ArrayExpression") {
  8471. this.tsCheckForInvalidTypeCasts(node.elements);
  8472. }
  8473. return node;
  8474. }
  8475. parseSubscript(base, startPos, startLoc, noCalls, state) {
  8476. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  8477. this.state.canStartJSXElement = false;
  8478. this.next();
  8479. const nonNullExpression = this.startNodeAt(startPos, startLoc);
  8480. nonNullExpression.expression = base;
  8481. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  8482. }
  8483. let isOptionalCall = false;
  8484. if (this.match(18) && this.lookaheadCharCode() === 60) {
  8485. if (noCalls) {
  8486. state.stop = true;
  8487. return base;
  8488. }
  8489. state.optionalChainMember = isOptionalCall = true;
  8490. this.next();
  8491. }
  8492. if (this.match(47) || this.match(51)) {
  8493. let missingParenErrorLoc;
  8494. const result = this.tsTryParseAndCatch(() => {
  8495. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  8496. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startPos, startLoc);
  8497. if (asyncArrowFn) {
  8498. return asyncArrowFn;
  8499. }
  8500. }
  8501. const typeArguments = this.tsParseTypeArgumentsInExpression();
  8502. if (!typeArguments) return;
  8503. if (isOptionalCall && !this.match(10)) {
  8504. missingParenErrorLoc = this.state.curPosition();
  8505. return;
  8506. }
  8507. if (tokenIsTemplate(this.state.type)) {
  8508. const result = this.parseTaggedTemplateExpression(base, startPos, startLoc, state);
  8509. result.typeParameters = typeArguments;
  8510. return result;
  8511. }
  8512. if (!noCalls && this.eat(10)) {
  8513. const node = this.startNodeAt(startPos, startLoc);
  8514. node.callee = base;
  8515. node.arguments = this.parseCallExpressionArguments(11, false);
  8516. this.tsCheckForInvalidTypeCasts(node.arguments);
  8517. node.typeParameters = typeArguments;
  8518. if (state.optionalChainMember) {
  8519. node.optional = isOptionalCall;
  8520. }
  8521. return this.finishCallExpression(node, state.optionalChainMember);
  8522. }
  8523. const tokenType = this.state.type;
  8524. if (tokenType === 48 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  8525. return;
  8526. }
  8527. const node = this.startNodeAt(startPos, startLoc);
  8528. node.expression = base;
  8529. node.typeParameters = typeArguments;
  8530. return this.finishNode(node, "TSInstantiationExpression");
  8531. });
  8532. if (missingParenErrorLoc) {
  8533. this.unexpected(missingParenErrorLoc, 10);
  8534. }
  8535. if (result) {
  8536. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  8537. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
  8538. at: this.state.startLoc
  8539. });
  8540. }
  8541. return result;
  8542. }
  8543. }
  8544. return super.parseSubscript(base, startPos, startLoc, noCalls, state);
  8545. }
  8546. parseNewCallee(node) {
  8547. var _callee$extra;
  8548. super.parseNewCallee(node);
  8549. const {
  8550. callee
  8551. } = node;
  8552. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  8553. node.typeParameters = callee.typeParameters;
  8554. node.callee = callee.expression;
  8555. }
  8556. }
  8557. parseExprOp(left, leftStartPos, leftStartLoc, minPrec) {
  8558. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && this.isContextual(93)) {
  8559. const node = this.startNodeAt(leftStartPos, leftStartLoc);
  8560. node.expression = left;
  8561. const _const = this.tsTryNextParseConstantContext();
  8562. if (_const) {
  8563. node.typeAnnotation = _const;
  8564. } else {
  8565. node.typeAnnotation = this.tsNextThenParseType();
  8566. }
  8567. this.finishNode(node, "TSAsExpression");
  8568. this.reScan_lt_gt();
  8569. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec);
  8570. }
  8571. return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec);
  8572. }
  8573. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  8574. if (!this.state.isAmbientContext) {
  8575. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  8576. }
  8577. }
  8578. checkDuplicateExports() {}
  8579. parseImport(node) {
  8580. node.importKind = "value";
  8581. if (tokenIsIdentifier(this.state.type) || this.match(55) || this.match(5)) {
  8582. let ahead = this.lookahead();
  8583. if (this.isContextual(126) && ahead.type !== 12 && ahead.type !== 97 && ahead.type !== 29) {
  8584. node.importKind = "type";
  8585. this.next();
  8586. ahead = this.lookahead();
  8587. }
  8588. if (tokenIsIdentifier(this.state.type) && ahead.type === 29) {
  8589. return this.tsParseImportEqualsDeclaration(node);
  8590. }
  8591. }
  8592. const importNode = super.parseImport(node);
  8593. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  8594. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
  8595. at: importNode
  8596. });
  8597. }
  8598. return importNode;
  8599. }
  8600. parseExport(node) {
  8601. if (this.match(83)) {
  8602. this.next();
  8603. if (this.isContextual(126) && this.lookaheadCharCode() !== 61) {
  8604. node.importKind = "type";
  8605. this.next();
  8606. } else {
  8607. node.importKind = "value";
  8608. }
  8609. return this.tsParseImportEqualsDeclaration(node, true);
  8610. } else if (this.eat(29)) {
  8611. const assign = node;
  8612. assign.expression = this.parseExpression();
  8613. this.semicolon();
  8614. return this.finishNode(assign, "TSExportAssignment");
  8615. } else if (this.eatContextual(93)) {
  8616. const decl = node;
  8617. this.expectContextual(124);
  8618. decl.id = this.parseIdentifier();
  8619. this.semicolon();
  8620. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  8621. } else {
  8622. if (this.isContextual(126) && this.lookahead().type === 5) {
  8623. this.next();
  8624. node.exportKind = "type";
  8625. } else {
  8626. node.exportKind = "value";
  8627. }
  8628. return super.parseExport(node);
  8629. }
  8630. }
  8631. isAbstractClass() {
  8632. return this.isContextual(120) && this.lookahead().type === 80;
  8633. }
  8634. parseExportDefaultExpression() {
  8635. if (this.isAbstractClass()) {
  8636. const cls = this.startNode();
  8637. this.next();
  8638. cls.abstract = true;
  8639. this.parseClass(cls, true, true);
  8640. return cls;
  8641. }
  8642. if (this.match(125)) {
  8643. const result = this.tsParseInterfaceDeclaration(this.startNode());
  8644. if (result) return result;
  8645. }
  8646. return super.parseExportDefaultExpression();
  8647. }
  8648. parseVarStatement(node, kind, allowMissingInitializer = false) {
  8649. const {
  8650. isAmbientContext
  8651. } = this.state;
  8652. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  8653. if (!isAmbientContext) return declaration;
  8654. for (const {
  8655. id,
  8656. init
  8657. } of declaration.declarations) {
  8658. if (!init) continue;
  8659. if (kind !== "const" || !!id.typeAnnotation) {
  8660. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
  8661. at: init
  8662. });
  8663. } else if (init.type !== "StringLiteral" && init.type !== "BooleanLiteral" && init.type !== "NumericLiteral" && init.type !== "BigIntLiteral" && (init.type !== "TemplateLiteral" || init.expressions.length > 0) && !isPossiblyLiteralEnum(init)) {
  8664. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
  8665. at: init
  8666. });
  8667. }
  8668. }
  8669. return declaration;
  8670. }
  8671. parseStatementContent(context, topLevel) {
  8672. if (this.match(75) && this.isLookaheadContextual("enum")) {
  8673. const node = this.startNode();
  8674. this.expect(75);
  8675. return this.tsParseEnumDeclaration(node, {
  8676. const: true
  8677. });
  8678. }
  8679. if (this.isContextual(122)) {
  8680. return this.tsParseEnumDeclaration(this.startNode());
  8681. }
  8682. if (this.isContextual(125)) {
  8683. const result = this.tsParseInterfaceDeclaration(this.startNode());
  8684. if (result) return result;
  8685. }
  8686. return super.parseStatementContent(context, topLevel);
  8687. }
  8688. parseAccessModifier() {
  8689. return this.tsParseModifier(["public", "protected", "private"]);
  8690. }
  8691. tsHasSomeModifiers(member, modifiers) {
  8692. return modifiers.some(modifier => {
  8693. if (tsIsAccessModifier(modifier)) {
  8694. return member.accessibility === modifier;
  8695. }
  8696. return !!member[modifier];
  8697. });
  8698. }
  8699. tsIsStartOfStaticBlocks() {
  8700. return this.isContextual(104) && this.lookaheadCharCode() === 123;
  8701. }
  8702. parseClassMember(classBody, member, state) {
  8703. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  8704. this.tsParseModifiers({
  8705. modified: member,
  8706. allowedModifiers: modifiers,
  8707. disallowedModifiers: ["in", "out"],
  8708. stopOnStartOfClassStaticBlock: true,
  8709. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  8710. });
  8711. const callParseClassMemberWithIsStatic = () => {
  8712. if (this.tsIsStartOfStaticBlocks()) {
  8713. this.next();
  8714. this.next();
  8715. if (this.tsHasSomeModifiers(member, modifiers)) {
  8716. this.raise(TSErrors.StaticBlockCannotHaveModifier, {
  8717. at: this.state.curPosition()
  8718. });
  8719. }
  8720. this.parseClassStaticBlock(classBody, member);
  8721. } else {
  8722. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  8723. }
  8724. };
  8725. if (member.declare) {
  8726. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  8727. } else {
  8728. callParseClassMemberWithIsStatic();
  8729. }
  8730. }
  8731. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  8732. const idx = this.tsTryParseIndexSignature(member);
  8733. if (idx) {
  8734. classBody.body.push(idx);
  8735. if (member.abstract) {
  8736. this.raise(TSErrors.IndexSignatureHasAbstract, {
  8737. at: member
  8738. });
  8739. }
  8740. if (member.accessibility) {
  8741. this.raise(TSErrors.IndexSignatureHasAccessibility, {
  8742. at: member,
  8743. modifier: member.accessibility
  8744. });
  8745. }
  8746. if (member.declare) {
  8747. this.raise(TSErrors.IndexSignatureHasDeclare, {
  8748. at: member
  8749. });
  8750. }
  8751. if (member.override) {
  8752. this.raise(TSErrors.IndexSignatureHasOverride, {
  8753. at: member
  8754. });
  8755. }
  8756. return;
  8757. }
  8758. if (!this.state.inAbstractClass && member.abstract) {
  8759. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
  8760. at: member
  8761. });
  8762. }
  8763. if (member.override) {
  8764. if (!state.hadSuperClass) {
  8765. this.raise(TSErrors.OverrideNotInSubClass, {
  8766. at: member
  8767. });
  8768. }
  8769. }
  8770. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  8771. }
  8772. parsePostMemberNameModifiers(methodOrProp) {
  8773. const optional = this.eat(17);
  8774. if (optional) methodOrProp.optional = true;
  8775. if (methodOrProp.readonly && this.match(10)) {
  8776. this.raise(TSErrors.ClassMethodHasReadonly, {
  8777. at: methodOrProp
  8778. });
  8779. }
  8780. if (methodOrProp.declare && this.match(10)) {
  8781. this.raise(TSErrors.ClassMethodHasDeclare, {
  8782. at: methodOrProp
  8783. });
  8784. }
  8785. }
  8786. parseExpressionStatement(node, expr) {
  8787. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr) : undefined;
  8788. return decl || super.parseExpressionStatement(node, expr);
  8789. }
  8790. shouldParseExportDeclaration() {
  8791. if (this.tsIsDeclarationStart()) return true;
  8792. return super.shouldParseExportDeclaration();
  8793. }
  8794. parseConditional(expr, startPos, startLoc, refExpressionErrors) {
  8795. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  8796. return super.parseConditional(expr, startPos, startLoc, refExpressionErrors);
  8797. }
  8798. const result = this.tryParse(() => super.parseConditional(expr, startPos, startLoc));
  8799. if (!result.node) {
  8800. if (result.error) {
  8801. super.setOptionalParametersError(refExpressionErrors, result.error);
  8802. }
  8803. return expr;
  8804. }
  8805. if (result.error) this.state = result.failState;
  8806. return result.node;
  8807. }
  8808. parseParenItem(node, startPos, startLoc) {
  8809. node = super.parseParenItem(node, startPos, startLoc);
  8810. if (this.eat(17)) {
  8811. node.optional = true;
  8812. this.resetEndLocation(node);
  8813. }
  8814. if (this.match(14)) {
  8815. const typeCastNode = this.startNodeAt(startPos, startLoc);
  8816. typeCastNode.expression = node;
  8817. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  8818. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  8819. }
  8820. return node;
  8821. }
  8822. parseExportDeclaration(node) {
  8823. if (!this.state.isAmbientContext && this.isContextual(121)) {
  8824. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  8825. }
  8826. const startPos = this.state.start;
  8827. const startLoc = this.state.startLoc;
  8828. const isDeclare = this.eatContextual(121);
  8829. if (isDeclare && (this.isContextual(121) || !this.shouldParseExportDeclaration())) {
  8830. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
  8831. at: this.state.startLoc
  8832. });
  8833. }
  8834. const isIdentifier = tokenIsIdentifier(this.state.type);
  8835. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  8836. if (!declaration) return null;
  8837. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  8838. node.exportKind = "type";
  8839. }
  8840. if (isDeclare) {
  8841. this.resetStartLocation(declaration, startPos, startLoc);
  8842. declaration.declare = true;
  8843. }
  8844. return declaration;
  8845. }
  8846. parseClassId(node, isStatement, optionalId) {
  8847. if ((!isStatement || optionalId) && this.isContextual(110)) {
  8848. return;
  8849. }
  8850. super.parseClassId(node, isStatement, optionalId, node.declare ? BIND_TS_AMBIENT : BIND_CLASS);
  8851. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers.bind(this));
  8852. if (typeParameters) node.typeParameters = typeParameters;
  8853. }
  8854. parseClassPropertyAnnotation(node) {
  8855. if (!node.optional && this.eat(35)) {
  8856. node.definite = true;
  8857. }
  8858. const type = this.tsTryParseTypeAnnotation();
  8859. if (type) node.typeAnnotation = type;
  8860. }
  8861. parseClassProperty(node) {
  8862. this.parseClassPropertyAnnotation(node);
  8863. if (this.state.isAmbientContext && this.match(29)) {
  8864. this.raise(TSErrors.DeclareClassFieldHasInitializer, {
  8865. at: this.state.startLoc
  8866. });
  8867. }
  8868. if (node.abstract && this.match(29)) {
  8869. const {
  8870. key
  8871. } = node;
  8872. this.raise(TSErrors.AbstractPropertyHasInitializer, {
  8873. at: this.state.startLoc,
  8874. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  8875. });
  8876. }
  8877. return super.parseClassProperty(node);
  8878. }
  8879. parseClassPrivateProperty(node) {
  8880. if (node.abstract) {
  8881. this.raise(TSErrors.PrivateElementHasAbstract, {
  8882. at: node
  8883. });
  8884. }
  8885. if (node.accessibility) {
  8886. this.raise(TSErrors.PrivateElementHasAccessibility, {
  8887. at: node,
  8888. modifier: node.accessibility
  8889. });
  8890. }
  8891. this.parseClassPropertyAnnotation(node);
  8892. return super.parseClassPrivateProperty(node);
  8893. }
  8894. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  8895. const typeParameters = this.tsTryParseTypeParameters();
  8896. if (typeParameters && isConstructor) {
  8897. this.raise(TSErrors.ConstructorHasTypeParameters, {
  8898. at: typeParameters
  8899. });
  8900. }
  8901. const {
  8902. declare = false,
  8903. kind
  8904. } = method;
  8905. if (declare && (kind === "get" || kind === "set")) {
  8906. this.raise(TSErrors.DeclareAccessor, {
  8907. at: method,
  8908. kind
  8909. });
  8910. }
  8911. if (typeParameters) method.typeParameters = typeParameters;
  8912. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  8913. }
  8914. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  8915. const typeParameters = this.tsTryParseTypeParameters();
  8916. if (typeParameters) method.typeParameters = typeParameters;
  8917. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  8918. }
  8919. declareClassPrivateMethodInScope(node, kind) {
  8920. if (node.type === "TSDeclareMethod") return;
  8921. if (node.type === "MethodDefinition" && !node.value.body) return;
  8922. super.declareClassPrivateMethodInScope(node, kind);
  8923. }
  8924. parseClassSuper(node) {
  8925. super.parseClassSuper(node);
  8926. if (node.superClass && (this.match(47) || this.match(51))) {
  8927. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  8928. }
  8929. if (this.eatContextual(110)) {
  8930. node.implements = this.tsParseHeritageClause("implements");
  8931. }
  8932. }
  8933. parseObjPropValue(prop, ...args) {
  8934. const typeParameters = this.tsTryParseTypeParameters();
  8935. if (typeParameters) prop.typeParameters = typeParameters;
  8936. super.parseObjPropValue(prop, ...args);
  8937. }
  8938. parseFunctionParams(node, allowModifiers) {
  8939. const typeParameters = this.tsTryParseTypeParameters();
  8940. if (typeParameters) node.typeParameters = typeParameters;
  8941. super.parseFunctionParams(node, allowModifiers);
  8942. }
  8943. parseVarId(decl, kind) {
  8944. super.parseVarId(decl, kind);
  8945. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  8946. decl.definite = true;
  8947. }
  8948. const type = this.tsTryParseTypeAnnotation();
  8949. if (type) {
  8950. decl.id.typeAnnotation = type;
  8951. this.resetEndLocation(decl.id);
  8952. }
  8953. }
  8954. parseAsyncArrowFromCallExpression(node, call) {
  8955. if (this.match(14)) {
  8956. node.returnType = this.tsParseTypeAnnotation();
  8957. }
  8958. return super.parseAsyncArrowFromCallExpression(node, call);
  8959. }
  8960. parseMaybeAssign(...args) {
  8961. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2, _jsx4, _typeCast3;
  8962. let state;
  8963. let jsx;
  8964. let typeCast;
  8965. if (this.hasPlugin("jsx") && (this.match(138) || this.match(47))) {
  8966. state = this.state.clone();
  8967. jsx = this.tryParse(() => super.parseMaybeAssign(...args), state);
  8968. if (!jsx.error) return jsx.node;
  8969. const {
  8970. context
  8971. } = this.state;
  8972. const currentContext = context[context.length - 1];
  8973. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  8974. context.pop();
  8975. }
  8976. }
  8977. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  8978. return super.parseMaybeAssign(...args);
  8979. }
  8980. if (!state || state === this.state) state = this.state.clone();
  8981. let typeParameters;
  8982. const arrow = this.tryParse(abort => {
  8983. var _expr$extra, _typeParameters;
  8984. typeParameters = this.tsParseTypeParameters();
  8985. const expr = super.parseMaybeAssign(...args);
  8986. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  8987. abort();
  8988. }
  8989. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  8990. this.resetStartLocationFromNode(expr, typeParameters);
  8991. }
  8992. expr.typeParameters = typeParameters;
  8993. return expr;
  8994. }, state);
  8995. if (!arrow.error && !arrow.aborted) {
  8996. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  8997. return arrow.node;
  8998. }
  8999. if (!jsx) {
  9000. assert(!this.hasPlugin("jsx"));
  9001. typeCast = this.tryParse(() => super.parseMaybeAssign(...args), state);
  9002. if (!typeCast.error) return typeCast.node;
  9003. }
  9004. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9005. this.state = jsx.failState;
  9006. return jsx.node;
  9007. }
  9008. if (arrow.node) {
  9009. this.state = arrow.failState;
  9010. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9011. return arrow.node;
  9012. }
  9013. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9014. this.state = typeCast.failState;
  9015. return typeCast.node;
  9016. }
  9017. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  9018. if (arrow.thrown) throw arrow.error;
  9019. if ((_typeCast2 = typeCast) != null && _typeCast2.thrown) throw typeCast.error;
  9020. throw ((_jsx4 = jsx) == null ? void 0 : _jsx4.error) || arrow.error || ((_typeCast3 = typeCast) == null ? void 0 : _typeCast3.error);
  9021. }
  9022. reportReservedArrowTypeParam(node) {
  9023. var _node$extra;
  9024. if (node.params.length === 1 && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9025. this.raise(TSErrors.ReservedArrowTypeParam, {
  9026. at: node
  9027. });
  9028. }
  9029. }
  9030. parseMaybeUnary(refExpressionErrors) {
  9031. if (!this.hasPlugin("jsx") && this.match(47)) {
  9032. return this.tsParseTypeAssertion();
  9033. } else {
  9034. return super.parseMaybeUnary(refExpressionErrors);
  9035. }
  9036. }
  9037. parseArrow(node) {
  9038. if (this.match(14)) {
  9039. const result = this.tryParse(abort => {
  9040. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9041. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9042. return returnType;
  9043. });
  9044. if (result.aborted) return;
  9045. if (!result.thrown) {
  9046. if (result.error) this.state = result.failState;
  9047. node.returnType = result.node;
  9048. }
  9049. }
  9050. return super.parseArrow(node);
  9051. }
  9052. parseAssignableListItemTypes(param) {
  9053. if (this.eat(17)) {
  9054. if (param.type !== "Identifier" && !this.state.isAmbientContext && !this.state.inType) {
  9055. this.raise(TSErrors.PatternIsOptional, {
  9056. at: param
  9057. });
  9058. }
  9059. param.optional = true;
  9060. }
  9061. const type = this.tsTryParseTypeAnnotation();
  9062. if (type) param.typeAnnotation = type;
  9063. this.resetEndLocation(param);
  9064. return param;
  9065. }
  9066. isAssignable(node, isBinding) {
  9067. switch (node.type) {
  9068. case "TSTypeCastExpression":
  9069. return this.isAssignable(node.expression, isBinding);
  9070. case "TSParameterProperty":
  9071. return true;
  9072. default:
  9073. return super.isAssignable(node, isBinding);
  9074. }
  9075. }
  9076. toAssignable(node, isLHS = false) {
  9077. switch (node.type) {
  9078. case "ParenthesizedExpression":
  9079. this.toAssignableParenthesizedExpression(node, isLHS);
  9080. break;
  9081. case "TSAsExpression":
  9082. case "TSNonNullExpression":
  9083. case "TSTypeAssertion":
  9084. if (isLHS) {
  9085. this.expressionScope.recordArrowParemeterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
  9086. at: node
  9087. });
  9088. } else {
  9089. this.raise(TSErrors.UnexpectedTypeCastInParameter, {
  9090. at: node
  9091. });
  9092. }
  9093. this.toAssignable(node.expression, isLHS);
  9094. break;
  9095. case "AssignmentExpression":
  9096. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9097. node.left = this.typeCastToParameter(node.left);
  9098. }
  9099. default:
  9100. super.toAssignable(node, isLHS);
  9101. }
  9102. }
  9103. toAssignableParenthesizedExpression(node, isLHS) {
  9104. switch (node.expression.type) {
  9105. case "TSAsExpression":
  9106. case "TSNonNullExpression":
  9107. case "TSTypeAssertion":
  9108. case "ParenthesizedExpression":
  9109. this.toAssignable(node.expression, isLHS);
  9110. break;
  9111. default:
  9112. super.toAssignable(node, isLHS);
  9113. }
  9114. }
  9115. checkToRestConversion(node, allowPattern) {
  9116. switch (node.type) {
  9117. case "TSAsExpression":
  9118. case "TSTypeAssertion":
  9119. case "TSNonNullExpression":
  9120. this.checkToRestConversion(node.expression, false);
  9121. break;
  9122. default:
  9123. super.checkToRestConversion(node, allowPattern);
  9124. }
  9125. }
  9126. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9127. return getOwn$1({
  9128. TSTypeCastExpression: true,
  9129. TSParameterProperty: "parameter",
  9130. TSNonNullExpression: "expression",
  9131. TSAsExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
  9132. TSTypeAssertion: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true]
  9133. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9134. }
  9135. parseBindingAtom() {
  9136. switch (this.state.type) {
  9137. case 78:
  9138. return this.parseIdentifier(true);
  9139. default:
  9140. return super.parseBindingAtom();
  9141. }
  9142. }
  9143. parseMaybeDecoratorArguments(expr) {
  9144. if (this.match(47) || this.match(51)) {
  9145. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9146. if (this.match(10)) {
  9147. const call = super.parseMaybeDecoratorArguments(expr);
  9148. call.typeParameters = typeArguments;
  9149. return call;
  9150. }
  9151. this.unexpected(null, 10);
  9152. }
  9153. return super.parseMaybeDecoratorArguments(expr);
  9154. }
  9155. checkCommaAfterRest(close) {
  9156. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9157. this.next();
  9158. return false;
  9159. } else {
  9160. return super.checkCommaAfterRest(close);
  9161. }
  9162. }
  9163. isClassMethod() {
  9164. return this.match(47) || super.isClassMethod();
  9165. }
  9166. isClassProperty() {
  9167. return this.match(35) || this.match(14) || super.isClassProperty();
  9168. }
  9169. parseMaybeDefault(...args) {
  9170. const node = super.parseMaybeDefault(...args);
  9171. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9172. this.raise(TSErrors.TypeAnnotationAfterAssign, {
  9173. at: node.typeAnnotation
  9174. });
  9175. }
  9176. return node;
  9177. }
  9178. getTokenFromCode(code) {
  9179. if (this.state.inType) {
  9180. if (code === 62) {
  9181. return this.finishOp(48, 1);
  9182. }
  9183. if (code === 60) {
  9184. return this.finishOp(47, 1);
  9185. }
  9186. }
  9187. return super.getTokenFromCode(code);
  9188. }
  9189. reScan_lt_gt() {
  9190. const {
  9191. type
  9192. } = this.state;
  9193. if (type === 47) {
  9194. this.state.pos -= 1;
  9195. this.readToken_lt();
  9196. } else if (type === 48) {
  9197. this.state.pos -= 1;
  9198. this.readToken_gt();
  9199. }
  9200. }
  9201. reScan_lt() {
  9202. const {
  9203. type
  9204. } = this.state;
  9205. if (type === 51) {
  9206. this.state.pos -= 2;
  9207. this.finishOp(47, 1);
  9208. return 47;
  9209. }
  9210. return type;
  9211. }
  9212. toAssignableList(exprList) {
  9213. for (let i = 0; i < exprList.length; i++) {
  9214. const expr = exprList[i];
  9215. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9216. exprList[i] = this.typeCastToParameter(expr);
  9217. }
  9218. }
  9219. super.toAssignableList(...arguments);
  9220. }
  9221. typeCastToParameter(node) {
  9222. node.expression.typeAnnotation = node.typeAnnotation;
  9223. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9224. return node.expression;
  9225. }
  9226. shouldParseArrow(params) {
  9227. if (this.match(14)) {
  9228. return params.every(expr => this.isAssignable(expr, true));
  9229. }
  9230. return super.shouldParseArrow(params);
  9231. }
  9232. shouldParseAsyncArrow() {
  9233. return this.match(14) || super.shouldParseAsyncArrow();
  9234. }
  9235. canHaveLeadingDecorator() {
  9236. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9237. }
  9238. jsxParseOpeningElementAfterName(node) {
  9239. if (this.match(47) || this.match(51)) {
  9240. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9241. if (typeArguments) node.typeParameters = typeArguments;
  9242. }
  9243. return super.jsxParseOpeningElementAfterName(node);
  9244. }
  9245. getGetterSetterExpectedParamCount(method) {
  9246. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9247. const params = this.getObjectOrClassMethodParams(method);
  9248. const firstParam = params[0];
  9249. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9250. return hasContextParam ? baseCount + 1 : baseCount;
  9251. }
  9252. parseCatchClauseParam() {
  9253. const param = super.parseCatchClauseParam();
  9254. const type = this.tsTryParseTypeAnnotation();
  9255. if (type) {
  9256. param.typeAnnotation = type;
  9257. this.resetEndLocation(param);
  9258. }
  9259. return param;
  9260. }
  9261. tsInAmbientContext(cb) {
  9262. const oldIsAmbientContext = this.state.isAmbientContext;
  9263. this.state.isAmbientContext = true;
  9264. try {
  9265. return cb();
  9266. } finally {
  9267. this.state.isAmbientContext = oldIsAmbientContext;
  9268. }
  9269. }
  9270. parseClass(node, ...args) {
  9271. const oldInAbstractClass = this.state.inAbstractClass;
  9272. this.state.inAbstractClass = !!node.abstract;
  9273. try {
  9274. return super.parseClass(node, ...args);
  9275. } finally {
  9276. this.state.inAbstractClass = oldInAbstractClass;
  9277. }
  9278. }
  9279. tsParseAbstractDeclaration(node) {
  9280. if (this.match(80)) {
  9281. node.abstract = true;
  9282. return this.parseClass(node, true, false);
  9283. } else if (this.isContextual(125)) {
  9284. if (!this.hasFollowingLineBreak()) {
  9285. node.abstract = true;
  9286. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
  9287. at: node
  9288. });
  9289. return this.tsParseInterfaceDeclaration(node);
  9290. }
  9291. } else {
  9292. this.unexpected(null, 80);
  9293. }
  9294. }
  9295. parseMethod(...args) {
  9296. const method = super.parseMethod(...args);
  9297. if (method.abstract) {
  9298. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  9299. if (hasBody) {
  9300. const {
  9301. key
  9302. } = method;
  9303. this.raise(TSErrors.AbstractMethodHasImplementation, {
  9304. at: method,
  9305. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9306. });
  9307. }
  9308. }
  9309. return method;
  9310. }
  9311. tsParseTypeParameterName() {
  9312. const typeName = this.parseIdentifier();
  9313. return typeName.name;
  9314. }
  9315. shouldParseAsAmbientContext() {
  9316. return !!this.getPluginOption("typescript", "dts");
  9317. }
  9318. parse() {
  9319. if (this.shouldParseAsAmbientContext()) {
  9320. this.state.isAmbientContext = true;
  9321. }
  9322. return super.parse();
  9323. }
  9324. getExpression() {
  9325. if (this.shouldParseAsAmbientContext()) {
  9326. this.state.isAmbientContext = true;
  9327. }
  9328. return super.getExpression();
  9329. }
  9330. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  9331. if (!isString && isMaybeTypeOnly) {
  9332. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  9333. return this.finishNode(node, "ExportSpecifier");
  9334. }
  9335. node.exportKind = "value";
  9336. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  9337. }
  9338. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly) {
  9339. if (!importedIsString && isMaybeTypeOnly) {
  9340. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  9341. return this.finishNode(specifier, "ImportSpecifier");
  9342. }
  9343. specifier.importKind = "value";
  9344. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly);
  9345. }
  9346. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  9347. const leftOfAsKey = isImport ? "imported" : "local";
  9348. const rightOfAsKey = isImport ? "local" : "exported";
  9349. let leftOfAs = node[leftOfAsKey];
  9350. let rightOfAs;
  9351. let hasTypeSpecifier = false;
  9352. let canParseAsKeyword = true;
  9353. const loc = leftOfAs.loc.start;
  9354. if (this.isContextual(93)) {
  9355. const firstAs = this.parseIdentifier();
  9356. if (this.isContextual(93)) {
  9357. const secondAs = this.parseIdentifier();
  9358. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9359. hasTypeSpecifier = true;
  9360. leftOfAs = firstAs;
  9361. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9362. canParseAsKeyword = false;
  9363. } else {
  9364. rightOfAs = secondAs;
  9365. canParseAsKeyword = false;
  9366. }
  9367. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9368. canParseAsKeyword = false;
  9369. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9370. } else {
  9371. hasTypeSpecifier = true;
  9372. leftOfAs = firstAs;
  9373. }
  9374. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9375. hasTypeSpecifier = true;
  9376. if (isImport) {
  9377. leftOfAs = this.parseIdentifier(true);
  9378. if (!this.isContextual(93)) {
  9379. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  9380. }
  9381. } else {
  9382. leftOfAs = this.parseModuleExportName();
  9383. }
  9384. }
  9385. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  9386. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
  9387. at: loc
  9388. });
  9389. }
  9390. node[leftOfAsKey] = leftOfAs;
  9391. node[rightOfAsKey] = rightOfAs;
  9392. const kindKey = isImport ? "importKind" : "exportKind";
  9393. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  9394. if (canParseAsKeyword && this.eatContextual(93)) {
  9395. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9396. }
  9397. if (!node[rightOfAsKey]) {
  9398. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  9399. }
  9400. if (isImport) {
  9401. this.checkIdentifier(node[rightOfAsKey], BIND_LEXICAL);
  9402. }
  9403. }
  9404. });
  9405. function isPossiblyLiteralEnum(expression) {
  9406. if (expression.type !== "MemberExpression") return false;
  9407. const {
  9408. computed,
  9409. property
  9410. } = expression;
  9411. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  9412. return false;
  9413. }
  9414. return isUncomputedMemberExpressionChain(expression.object);
  9415. }
  9416. function isUncomputedMemberExpressionChain(expression) {
  9417. if (expression.type === "Identifier") return true;
  9418. if (expression.type !== "MemberExpression") return false;
  9419. if (expression.computed) return false;
  9420. return isUncomputedMemberExpressionChain(expression.object);
  9421. }
  9422. const PlaceholderErrors = ParseErrorEnum`placeholders`(_ => ({
  9423. ClassNameIsRequired: _("A class name is required."),
  9424. UnexpectedSpace: _("Unexpected space in placeholder.")
  9425. }));
  9426. var placeholders = (superClass => class extends superClass {
  9427. parsePlaceholder(expectedNode) {
  9428. if (this.match(140)) {
  9429. const node = this.startNode();
  9430. this.next();
  9431. this.assertNoSpace();
  9432. node.name = super.parseIdentifier(true);
  9433. this.assertNoSpace();
  9434. this.expect(140);
  9435. return this.finishPlaceholder(node, expectedNode);
  9436. }
  9437. }
  9438. finishPlaceholder(node, expectedNode) {
  9439. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  9440. node.expectedNode = expectedNode;
  9441. return isFinished ? node : this.finishNode(node, "Placeholder");
  9442. }
  9443. getTokenFromCode(code) {
  9444. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  9445. return this.finishOp(140, 2);
  9446. }
  9447. return super.getTokenFromCode(...arguments);
  9448. }
  9449. parseExprAtom() {
  9450. return this.parsePlaceholder("Expression") || super.parseExprAtom(...arguments);
  9451. }
  9452. parseIdentifier() {
  9453. return this.parsePlaceholder("Identifier") || super.parseIdentifier(...arguments);
  9454. }
  9455. checkReservedWord(word) {
  9456. if (word !== undefined) super.checkReservedWord(...arguments);
  9457. }
  9458. parseBindingAtom() {
  9459. return this.parsePlaceholder("Pattern") || super.parseBindingAtom(...arguments);
  9460. }
  9461. isValidLVal(type, ...rest) {
  9462. return type === "Placeholder" || super.isValidLVal(type, ...rest);
  9463. }
  9464. toAssignable(node) {
  9465. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  9466. node.expectedNode = "Pattern";
  9467. } else {
  9468. super.toAssignable(...arguments);
  9469. }
  9470. }
  9471. isLet(context) {
  9472. if (super.isLet(context)) {
  9473. return true;
  9474. }
  9475. if (!this.isContextual(99)) {
  9476. return false;
  9477. }
  9478. if (context) return false;
  9479. const nextToken = this.lookahead();
  9480. if (nextToken.type === 140) {
  9481. return true;
  9482. }
  9483. return false;
  9484. }
  9485. verifyBreakContinue(node) {
  9486. if (node.label && node.label.type === "Placeholder") return;
  9487. super.verifyBreakContinue(...arguments);
  9488. }
  9489. parseExpressionStatement(node, expr) {
  9490. if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) {
  9491. return super.parseExpressionStatement(...arguments);
  9492. }
  9493. if (this.match(14)) {
  9494. const stmt = node;
  9495. stmt.label = this.finishPlaceholder(expr, "Identifier");
  9496. this.next();
  9497. stmt.body = this.parseStatement("label");
  9498. return this.finishNode(stmt, "LabeledStatement");
  9499. }
  9500. this.semicolon();
  9501. node.name = expr.name;
  9502. return this.finishPlaceholder(node, "Statement");
  9503. }
  9504. parseBlock() {
  9505. return this.parsePlaceholder("BlockStatement") || super.parseBlock(...arguments);
  9506. }
  9507. parseFunctionId() {
  9508. return this.parsePlaceholder("Identifier") || super.parseFunctionId(...arguments);
  9509. }
  9510. parseClass(node, isStatement, optionalId) {
  9511. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  9512. this.next();
  9513. this.takeDecorators(node);
  9514. const oldStrict = this.state.strict;
  9515. const placeholder = this.parsePlaceholder("Identifier");
  9516. if (placeholder) {
  9517. if (this.match(81) || this.match(140) || this.match(5)) {
  9518. node.id = placeholder;
  9519. } else if (optionalId || !isStatement) {
  9520. node.id = null;
  9521. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  9522. return this.finishNode(node, type);
  9523. } else {
  9524. throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
  9525. at: this.state.startLoc
  9526. });
  9527. }
  9528. } else {
  9529. this.parseClassId(node, isStatement, optionalId);
  9530. }
  9531. this.parseClassSuper(node);
  9532. node.body = this.parsePlaceholder("ClassBody") || this.parseClassBody(!!node.superClass, oldStrict);
  9533. return this.finishNode(node, type);
  9534. }
  9535. parseExport(node) {
  9536. const placeholder = this.parsePlaceholder("Identifier");
  9537. if (!placeholder) return super.parseExport(...arguments);
  9538. if (!this.isContextual(97) && !this.match(12)) {
  9539. node.specifiers = [];
  9540. node.source = null;
  9541. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  9542. return this.finishNode(node, "ExportNamedDeclaration");
  9543. }
  9544. this.expectPlugin("exportDefaultFrom");
  9545. const specifier = this.startNode();
  9546. specifier.exported = placeholder;
  9547. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  9548. return super.parseExport(node);
  9549. }
  9550. isExportDefaultSpecifier() {
  9551. if (this.match(65)) {
  9552. const next = this.nextTokenStart();
  9553. if (this.isUnparsedContextual(next, "from")) {
  9554. if (this.input.startsWith(tokenLabelName(140), this.nextTokenStartSince(next + 4))) {
  9555. return true;
  9556. }
  9557. }
  9558. }
  9559. return super.isExportDefaultSpecifier();
  9560. }
  9561. maybeParseExportDefaultSpecifier(node) {
  9562. if (node.specifiers && node.specifiers.length > 0) {
  9563. return true;
  9564. }
  9565. return super.maybeParseExportDefaultSpecifier(...arguments);
  9566. }
  9567. checkExport(node) {
  9568. const {
  9569. specifiers
  9570. } = node;
  9571. if (specifiers != null && specifiers.length) {
  9572. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  9573. }
  9574. super.checkExport(node);
  9575. node.specifiers = specifiers;
  9576. }
  9577. parseImport(node) {
  9578. const placeholder = this.parsePlaceholder("Identifier");
  9579. if (!placeholder) return super.parseImport(...arguments);
  9580. node.specifiers = [];
  9581. if (!this.isContextual(97) && !this.match(12)) {
  9582. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  9583. this.semicolon();
  9584. return this.finishNode(node, "ImportDeclaration");
  9585. }
  9586. const specifier = this.startNodeAtNode(placeholder);
  9587. specifier.local = placeholder;
  9588. this.finishNode(specifier, "ImportDefaultSpecifier");
  9589. node.specifiers.push(specifier);
  9590. if (this.eat(12)) {
  9591. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  9592. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  9593. }
  9594. this.expectContextual(97);
  9595. node.source = this.parseImportSource();
  9596. this.semicolon();
  9597. return this.finishNode(node, "ImportDeclaration");
  9598. }
  9599. parseImportSource() {
  9600. return this.parsePlaceholder("StringLiteral") || super.parseImportSource(...arguments);
  9601. }
  9602. assertNoSpace() {
  9603. if (this.state.start > this.state.lastTokEndLoc.index) {
  9604. this.raise(PlaceholderErrors.UnexpectedSpace, {
  9605. at: this.state.lastTokEndLoc
  9606. });
  9607. }
  9608. }
  9609. });
  9610. var v8intrinsic = (superClass => class extends superClass {
  9611. parseV8Intrinsic() {
  9612. if (this.match(54)) {
  9613. const v8IntrinsicStartLoc = this.state.startLoc;
  9614. const node = this.startNode();
  9615. this.next();
  9616. if (tokenIsIdentifier(this.state.type)) {
  9617. const name = this.parseIdentifierName(this.state.start);
  9618. const identifier = this.createIdentifier(node, name);
  9619. identifier.type = "V8IntrinsicIdentifier";
  9620. if (this.match(10)) {
  9621. return identifier;
  9622. }
  9623. }
  9624. this.unexpected(v8IntrinsicStartLoc);
  9625. }
  9626. }
  9627. parseExprAtom() {
  9628. return this.parseV8Intrinsic() || super.parseExprAtom(...arguments);
  9629. }
  9630. });
  9631. function hasPlugin(plugins, expectedConfig) {
  9632. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  9633. const expectedKeys = Object.keys(expectedOptions);
  9634. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  9635. return plugins.some(p => {
  9636. if (typeof p === "string") {
  9637. return expectedOptionsIsEmpty && p === expectedName;
  9638. } else {
  9639. const [pluginName, pluginOptions] = p;
  9640. if (pluginName !== expectedName) {
  9641. return false;
  9642. }
  9643. for (const key of expectedKeys) {
  9644. if (pluginOptions[key] !== expectedOptions[key]) {
  9645. return false;
  9646. }
  9647. }
  9648. return true;
  9649. }
  9650. });
  9651. }
  9652. function getPluginOption(plugins, name, option) {
  9653. const plugin = plugins.find(plugin => {
  9654. if (Array.isArray(plugin)) {
  9655. return plugin[0] === name;
  9656. } else {
  9657. return plugin === name;
  9658. }
  9659. });
  9660. if (plugin && Array.isArray(plugin)) {
  9661. return plugin[1][option];
  9662. }
  9663. return null;
  9664. }
  9665. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  9666. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  9667. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  9668. function validatePlugins(plugins) {
  9669. if (hasPlugin(plugins, "decorators")) {
  9670. if (hasPlugin(plugins, "decorators-legacy")) {
  9671. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  9672. }
  9673. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  9674. if (decoratorsBeforeExport == null) {
  9675. throw new Error("The 'decorators' plugin requires a 'decoratorsBeforeExport' option," + " whose value must be a boolean. If you are migrating from" + " Babylon/Babel 6 or want to use the old decorators proposal, you" + " should use the 'decorators-legacy' plugin instead of 'decorators'.");
  9676. } else if (typeof decoratorsBeforeExport !== "boolean") {
  9677. throw new Error("'decoratorsBeforeExport' must be a boolean.");
  9678. }
  9679. }
  9680. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  9681. throw new Error("Cannot combine flow and typescript plugins.");
  9682. }
  9683. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  9684. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  9685. }
  9686. if (hasPlugin(plugins, "pipelineOperator")) {
  9687. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  9688. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  9689. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  9690. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  9691. }
  9692. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  9693. syntaxType: "hash"
  9694. }]);
  9695. if (proposal === "hack") {
  9696. if (hasPlugin(plugins, "placeholders")) {
  9697. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  9698. }
  9699. if (hasPlugin(plugins, "v8intrinsic")) {
  9700. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  9701. }
  9702. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  9703. if (!TOPIC_TOKENS.includes(topicToken)) {
  9704. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  9705. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  9706. }
  9707. if (topicToken === "#" && tupleSyntaxIsHash) {
  9708. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  9709. }
  9710. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  9711. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  9712. }
  9713. }
  9714. if (hasPlugin(plugins, "moduleAttributes")) {
  9715. {
  9716. if (hasPlugin(plugins, "importAssertions")) {
  9717. throw new Error("Cannot combine importAssertions and moduleAttributes plugins.");
  9718. }
  9719. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  9720. if (moduleAttributesVersionPluginOption !== "may-2020") {
  9721. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  9722. }
  9723. }
  9724. }
  9725. if (hasPlugin(plugins, "recordAndTuple") && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  9726. throw new Error("'recordAndTuple' requires 'syntaxType' option whose value should be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  9727. }
  9728. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  9729. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  9730. error.missingPlugins = "doExpressions";
  9731. throw error;
  9732. }
  9733. }
  9734. const mixinPlugins = {
  9735. estree,
  9736. jsx,
  9737. flow,
  9738. typescript,
  9739. v8intrinsic,
  9740. placeholders
  9741. };
  9742. const mixinPluginNames = Object.keys(mixinPlugins);
  9743. const defaultOptions = {
  9744. sourceType: "script",
  9745. sourceFilename: undefined,
  9746. startColumn: 0,
  9747. startLine: 1,
  9748. allowAwaitOutsideFunction: false,
  9749. allowReturnOutsideFunction: false,
  9750. allowImportExportEverywhere: false,
  9751. allowSuperOutsideMethod: false,
  9752. allowUndeclaredExports: false,
  9753. plugins: [],
  9754. strictMode: null,
  9755. ranges: false,
  9756. tokens: false,
  9757. createParenthesizedExpressions: false,
  9758. errorRecovery: false,
  9759. attachComment: true
  9760. };
  9761. function getOptions(opts) {
  9762. const options = {};
  9763. for (const key of Object.keys(defaultOptions)) {
  9764. options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key];
  9765. }
  9766. return options;
  9767. }
  9768. const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  9769. const unwrapParenthesizedExpression = node => {
  9770. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  9771. };
  9772. class LValParser extends NodeUtils {
  9773. toAssignable(node, isLHS = false) {
  9774. var _node$extra, _node$extra3;
  9775. let parenthesized = undefined;
  9776. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  9777. parenthesized = unwrapParenthesizedExpression(node);
  9778. if (isLHS) {
  9779. if (parenthesized.type === "Identifier") {
  9780. this.expressionScope.recordArrowParemeterBindingError(Errors.InvalidParenthesizedAssignment, {
  9781. at: node
  9782. });
  9783. } else if (parenthesized.type !== "MemberExpression") {
  9784. this.raise(Errors.InvalidParenthesizedAssignment, {
  9785. at: node
  9786. });
  9787. }
  9788. } else {
  9789. this.raise(Errors.InvalidParenthesizedAssignment, {
  9790. at: node
  9791. });
  9792. }
  9793. }
  9794. switch (node.type) {
  9795. case "Identifier":
  9796. case "ObjectPattern":
  9797. case "ArrayPattern":
  9798. case "AssignmentPattern":
  9799. case "RestElement":
  9800. break;
  9801. case "ObjectExpression":
  9802. node.type = "ObjectPattern";
  9803. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  9804. var _node$extra2;
  9805. const prop = node.properties[i];
  9806. const isLast = i === last;
  9807. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  9808. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  9809. this.raise(Errors.RestTrailingComma, {
  9810. at: node.extra.trailingCommaLoc
  9811. });
  9812. }
  9813. }
  9814. break;
  9815. case "ObjectProperty":
  9816. {
  9817. const {
  9818. key,
  9819. value
  9820. } = node;
  9821. if (this.isPrivateName(key)) {
  9822. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  9823. }
  9824. this.toAssignable(value, isLHS);
  9825. break;
  9826. }
  9827. case "SpreadElement":
  9828. {
  9829. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  9830. }
  9831. case "ArrayExpression":
  9832. node.type = "ArrayPattern";
  9833. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  9834. break;
  9835. case "AssignmentExpression":
  9836. if (node.operator !== "=") {
  9837. this.raise(Errors.MissingEqInAssignment, {
  9838. at: node.left.loc.end
  9839. });
  9840. }
  9841. node.type = "AssignmentPattern";
  9842. delete node.operator;
  9843. this.toAssignable(node.left, isLHS);
  9844. break;
  9845. case "ParenthesizedExpression":
  9846. this.toAssignable(parenthesized, isLHS);
  9847. break;
  9848. }
  9849. }
  9850. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  9851. if (prop.type === "ObjectMethod") {
  9852. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
  9853. at: prop.key
  9854. });
  9855. } else if (prop.type === "SpreadElement") {
  9856. prop.type = "RestElement";
  9857. const arg = prop.argument;
  9858. this.checkToRestConversion(arg, false);
  9859. this.toAssignable(arg, isLHS);
  9860. if (!isLast) {
  9861. this.raise(Errors.RestTrailingComma, {
  9862. at: prop
  9863. });
  9864. }
  9865. } else {
  9866. this.toAssignable(prop, isLHS);
  9867. }
  9868. }
  9869. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9870. const end = exprList.length - 1;
  9871. for (let i = 0; i <= end; i++) {
  9872. const elt = exprList[i];
  9873. if (!elt) continue;
  9874. if (elt.type === "SpreadElement") {
  9875. elt.type = "RestElement";
  9876. const arg = elt.argument;
  9877. this.checkToRestConversion(arg, true);
  9878. this.toAssignable(arg, isLHS);
  9879. } else {
  9880. this.toAssignable(elt, isLHS);
  9881. }
  9882. if (elt.type === "RestElement") {
  9883. if (i < end) {
  9884. this.raise(Errors.RestTrailingComma, {
  9885. at: elt
  9886. });
  9887. } else if (trailingCommaLoc) {
  9888. this.raise(Errors.RestTrailingComma, {
  9889. at: trailingCommaLoc
  9890. });
  9891. }
  9892. }
  9893. }
  9894. }
  9895. isAssignable(node, isBinding) {
  9896. switch (node.type) {
  9897. case "Identifier":
  9898. case "ObjectPattern":
  9899. case "ArrayPattern":
  9900. case "AssignmentPattern":
  9901. case "RestElement":
  9902. return true;
  9903. case "ObjectExpression":
  9904. {
  9905. const last = node.properties.length - 1;
  9906. return node.properties.every((prop, i) => {
  9907. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  9908. });
  9909. }
  9910. case "ObjectProperty":
  9911. return this.isAssignable(node.value);
  9912. case "SpreadElement":
  9913. return this.isAssignable(node.argument);
  9914. case "ArrayExpression":
  9915. return node.elements.every(element => element === null || this.isAssignable(element));
  9916. case "AssignmentExpression":
  9917. return node.operator === "=";
  9918. case "ParenthesizedExpression":
  9919. return this.isAssignable(node.expression);
  9920. case "MemberExpression":
  9921. case "OptionalMemberExpression":
  9922. return !isBinding;
  9923. default:
  9924. return false;
  9925. }
  9926. }
  9927. toReferencedList(exprList, isParenthesizedExpr) {
  9928. return exprList;
  9929. }
  9930. toReferencedListDeep(exprList, isParenthesizedExpr) {
  9931. this.toReferencedList(exprList, isParenthesizedExpr);
  9932. for (const expr of exprList) {
  9933. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  9934. this.toReferencedListDeep(expr.elements);
  9935. }
  9936. }
  9937. }
  9938. parseSpread(refExpressionErrors, refNeedsArrowPos) {
  9939. const node = this.startNode();
  9940. this.next();
  9941. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined, refNeedsArrowPos);
  9942. return this.finishNode(node, "SpreadElement");
  9943. }
  9944. parseRestBinding() {
  9945. const node = this.startNode();
  9946. this.next();
  9947. node.argument = this.parseBindingAtom();
  9948. return this.finishNode(node, "RestElement");
  9949. }
  9950. parseBindingAtom() {
  9951. switch (this.state.type) {
  9952. case 0:
  9953. {
  9954. const node = this.startNode();
  9955. this.next();
  9956. node.elements = this.parseBindingList(3, 93, true);
  9957. return this.finishNode(node, "ArrayPattern");
  9958. }
  9959. case 5:
  9960. return this.parseObjectLike(8, true);
  9961. }
  9962. return this.parseIdentifier();
  9963. }
  9964. parseBindingList(close, closeCharCode, allowEmpty, allowModifiers) {
  9965. const elts = [];
  9966. let first = true;
  9967. while (!this.eat(close)) {
  9968. if (first) {
  9969. first = false;
  9970. } else {
  9971. this.expect(12);
  9972. }
  9973. if (allowEmpty && this.match(12)) {
  9974. elts.push(null);
  9975. } else if (this.eat(close)) {
  9976. break;
  9977. } else if (this.match(21)) {
  9978. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding()));
  9979. if (!this.checkCommaAfterRest(closeCharCode)) {
  9980. this.expect(close);
  9981. break;
  9982. }
  9983. } else {
  9984. const decorators = [];
  9985. if (this.match(26) && this.hasPlugin("decorators")) {
  9986. this.raise(Errors.UnsupportedParameterDecorator, {
  9987. at: this.state.startLoc
  9988. });
  9989. }
  9990. while (this.match(26)) {
  9991. decorators.push(this.parseDecorator());
  9992. }
  9993. elts.push(this.parseAssignableListItem(allowModifiers, decorators));
  9994. }
  9995. }
  9996. return elts;
  9997. }
  9998. parseBindingRestProperty(prop) {
  9999. this.next();
  10000. prop.argument = this.parseIdentifier();
  10001. this.checkCommaAfterRest(125);
  10002. return this.finishNode(prop, "RestElement");
  10003. }
  10004. parseBindingProperty() {
  10005. const prop = this.startNode();
  10006. const {
  10007. type,
  10008. start: startPos,
  10009. startLoc
  10010. } = this.state;
  10011. if (type === 21) {
  10012. return this.parseBindingRestProperty(prop);
  10013. } else if (type === 134) {
  10014. this.expectPlugin("destructuringPrivate", startLoc);
  10015. this.classScope.usePrivateName(this.state.value, startLoc);
  10016. prop.key = this.parsePrivateName();
  10017. } else {
  10018. this.parsePropertyName(prop);
  10019. }
  10020. prop.method = false;
  10021. this.parseObjPropValue(prop, startPos, startLoc, false, false, true, false);
  10022. return prop;
  10023. }
  10024. parseAssignableListItem(allowModifiers, decorators) {
  10025. const left = this.parseMaybeDefault();
  10026. this.parseAssignableListItemTypes(left);
  10027. const elt = this.parseMaybeDefault(left.start, left.loc.start, left);
  10028. if (decorators.length) {
  10029. left.decorators = decorators;
  10030. }
  10031. return elt;
  10032. }
  10033. parseAssignableListItemTypes(param) {
  10034. return param;
  10035. }
  10036. parseMaybeDefault(startPos, startLoc, left) {
  10037. var _startLoc, _startPos, _left;
  10038. startLoc = (_startLoc = startLoc) != null ? _startLoc : this.state.startLoc;
  10039. startPos = (_startPos = startPos) != null ? _startPos : this.state.start;
  10040. left = (_left = left) != null ? _left : this.parseBindingAtom();
  10041. if (!this.eat(29)) return left;
  10042. const node = this.startNodeAt(startPos, startLoc);
  10043. node.left = left;
  10044. node.right = this.parseMaybeAssignAllowIn();
  10045. return this.finishNode(node, "AssignmentPattern");
  10046. }
  10047. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  10048. return getOwn({
  10049. AssignmentPattern: "left",
  10050. RestElement: "argument",
  10051. ObjectProperty: "value",
  10052. ParenthesizedExpression: "expression",
  10053. ArrayPattern: "elements",
  10054. ObjectPattern: "properties"
  10055. }, type);
  10056. }
  10057. checkLVal(expression, {
  10058. in: ancestor,
  10059. binding = BIND_NONE,
  10060. checkClashes = false,
  10061. strictModeChanged = false,
  10062. allowingSloppyLetBinding = !(binding & BIND_SCOPE_LEXICAL),
  10063. hasParenthesizedAncestor = false
  10064. }) {
  10065. var _expression$extra;
  10066. const type = expression.type;
  10067. if (this.isObjectMethod(expression)) return;
  10068. if (type === "MemberExpression") {
  10069. if (binding !== BIND_NONE) {
  10070. this.raise(Errors.InvalidPropertyBindingPattern, {
  10071. at: expression
  10072. });
  10073. }
  10074. return;
  10075. }
  10076. if (expression.type === "Identifier") {
  10077. this.checkIdentifier(expression, binding, strictModeChanged, allowingSloppyLetBinding);
  10078. const {
  10079. name
  10080. } = expression;
  10081. if (checkClashes) {
  10082. if (checkClashes.has(name)) {
  10083. this.raise(Errors.ParamDupe, {
  10084. at: expression
  10085. });
  10086. } else {
  10087. checkClashes.add(name);
  10088. }
  10089. }
  10090. return;
  10091. }
  10092. const validity = this.isValidLVal(expression.type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  10093. if (validity === true) return;
  10094. if (validity === false) {
  10095. const ParseErrorClass = binding === BIND_NONE ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  10096. this.raise(ParseErrorClass, {
  10097. at: expression,
  10098. ancestor: ancestor.type === "UpdateExpression" ? {
  10099. type: "UpdateExpression",
  10100. prefix: ancestor.prefix
  10101. } : {
  10102. type: ancestor.type
  10103. }
  10104. });
  10105. return;
  10106. }
  10107. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  10108. const nextAncestor = expression.type === "ArrayPattern" || expression.type === "ObjectPattern" || expression.type === "ParenthesizedExpression" ? expression : ancestor;
  10109. for (const child of [].concat(expression[key])) {
  10110. if (child) {
  10111. this.checkLVal(child, {
  10112. in: nextAncestor,
  10113. binding,
  10114. checkClashes,
  10115. allowingSloppyLetBinding,
  10116. strictModeChanged,
  10117. hasParenthesizedAncestor: isParenthesizedExpression
  10118. });
  10119. }
  10120. }
  10121. }
  10122. checkIdentifier(at, bindingType, strictModeChanged = false, allowLetBinding = !(bindingType & BIND_SCOPE_LEXICAL)) {
  10123. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  10124. if (bindingType === BIND_NONE) {
  10125. this.raise(Errors.StrictEvalArguments, {
  10126. at,
  10127. referenceName: at.name
  10128. });
  10129. } else {
  10130. this.raise(Errors.StrictEvalArgumentsBinding, {
  10131. at,
  10132. bindingName: at.name
  10133. });
  10134. }
  10135. }
  10136. if (!allowLetBinding && at.name === "let") {
  10137. this.raise(Errors.LetInLexicalBinding, {
  10138. at
  10139. });
  10140. }
  10141. if (!(bindingType & BIND_NONE)) {
  10142. this.declareNameFromIdentifier(at, bindingType);
  10143. }
  10144. }
  10145. declareNameFromIdentifier(identifier, binding) {
  10146. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  10147. }
  10148. checkToRestConversion(node, allowPattern) {
  10149. switch (node.type) {
  10150. case "ParenthesizedExpression":
  10151. this.checkToRestConversion(node.expression, allowPattern);
  10152. break;
  10153. case "Identifier":
  10154. case "MemberExpression":
  10155. break;
  10156. case "ArrayExpression":
  10157. case "ObjectExpression":
  10158. if (allowPattern) break;
  10159. default:
  10160. this.raise(Errors.InvalidRestAssignmentPattern, {
  10161. at: node
  10162. });
  10163. }
  10164. }
  10165. checkCommaAfterRest(close) {
  10166. if (!this.match(12)) {
  10167. return false;
  10168. }
  10169. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
  10170. at: this.state.startLoc
  10171. });
  10172. return true;
  10173. }
  10174. }
  10175. class ExpressionParser extends LValParser {
  10176. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10177. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10178. return;
  10179. }
  10180. const key = prop.key;
  10181. const name = key.type === "Identifier" ? key.name : key.value;
  10182. if (name === "__proto__") {
  10183. if (isRecord) {
  10184. this.raise(Errors.RecordNoProto, {
  10185. at: key
  10186. });
  10187. return;
  10188. }
  10189. if (protoRef.used) {
  10190. if (refExpressionErrors) {
  10191. if (refExpressionErrors.doubleProtoLoc === null) {
  10192. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10193. }
  10194. } else {
  10195. this.raise(Errors.DuplicateProto, {
  10196. at: key
  10197. });
  10198. }
  10199. }
  10200. protoRef.used = true;
  10201. }
  10202. }
  10203. shouldExitDescending(expr, potentialArrowAt) {
  10204. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  10205. }
  10206. getExpression() {
  10207. this.enterInitialScopes();
  10208. this.nextToken();
  10209. const expr = this.parseExpression();
  10210. if (!this.match(135)) {
  10211. this.unexpected();
  10212. }
  10213. this.finalizeRemainingComments();
  10214. expr.comments = this.state.comments;
  10215. expr.errors = this.state.errors;
  10216. if (this.options.tokens) {
  10217. expr.tokens = this.tokens;
  10218. }
  10219. return expr;
  10220. }
  10221. parseExpression(disallowIn, refExpressionErrors) {
  10222. if (disallowIn) {
  10223. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10224. }
  10225. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10226. }
  10227. parseExpressionBase(refExpressionErrors) {
  10228. const startPos = this.state.start;
  10229. const startLoc = this.state.startLoc;
  10230. const expr = this.parseMaybeAssign(refExpressionErrors);
  10231. if (this.match(12)) {
  10232. const node = this.startNodeAt(startPos, startLoc);
  10233. node.expressions = [expr];
  10234. while (this.eat(12)) {
  10235. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10236. }
  10237. this.toReferencedList(node.expressions);
  10238. return this.finishNode(node, "SequenceExpression");
  10239. }
  10240. return expr;
  10241. }
  10242. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10243. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10244. }
  10245. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10246. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10247. }
  10248. setOptionalParametersError(refExpressionErrors, resultError) {
  10249. var _resultError$loc;
  10250. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10251. }
  10252. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10253. const startPos = this.state.start;
  10254. const startLoc = this.state.startLoc;
  10255. if (this.isContextual(105)) {
  10256. if (this.prodParam.hasYield) {
  10257. let left = this.parseYield();
  10258. if (afterLeftParse) {
  10259. left = afterLeftParse.call(this, left, startPos, startLoc);
  10260. }
  10261. return left;
  10262. }
  10263. }
  10264. let ownExpressionErrors;
  10265. if (refExpressionErrors) {
  10266. ownExpressionErrors = false;
  10267. } else {
  10268. refExpressionErrors = new ExpressionErrors();
  10269. ownExpressionErrors = true;
  10270. }
  10271. const {
  10272. type
  10273. } = this.state;
  10274. if (type === 10 || tokenIsIdentifier(type)) {
  10275. this.state.potentialArrowAt = this.state.start;
  10276. }
  10277. let left = this.parseMaybeConditional(refExpressionErrors);
  10278. if (afterLeftParse) {
  10279. left = afterLeftParse.call(this, left, startPos, startLoc);
  10280. }
  10281. if (tokenIsAssignment(this.state.type)) {
  10282. const node = this.startNodeAt(startPos, startLoc);
  10283. const operator = this.state.value;
  10284. node.operator = operator;
  10285. if (this.match(29)) {
  10286. this.toAssignable(left, true);
  10287. node.left = left;
  10288. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startPos) {
  10289. refExpressionErrors.doubleProtoLoc = null;
  10290. }
  10291. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startPos) {
  10292. refExpressionErrors.shorthandAssignLoc = null;
  10293. }
  10294. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startPos) {
  10295. this.checkDestructuringPrivate(refExpressionErrors);
  10296. refExpressionErrors.privateKeyLoc = null;
  10297. }
  10298. } else {
  10299. node.left = left;
  10300. }
  10301. this.next();
  10302. node.right = this.parseMaybeAssign();
  10303. this.checkLVal(left, {
  10304. in: this.finishNode(node, "AssignmentExpression")
  10305. });
  10306. return node;
  10307. } else if (ownExpressionErrors) {
  10308. this.checkExpressionErrors(refExpressionErrors, true);
  10309. }
  10310. return left;
  10311. }
  10312. parseMaybeConditional(refExpressionErrors) {
  10313. const startPos = this.state.start;
  10314. const startLoc = this.state.startLoc;
  10315. const potentialArrowAt = this.state.potentialArrowAt;
  10316. const expr = this.parseExprOps(refExpressionErrors);
  10317. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10318. return expr;
  10319. }
  10320. return this.parseConditional(expr, startPos, startLoc, refExpressionErrors);
  10321. }
  10322. parseConditional(expr, startPos, startLoc, refExpressionErrors) {
  10323. if (this.eat(17)) {
  10324. const node = this.startNodeAt(startPos, startLoc);
  10325. node.test = expr;
  10326. node.consequent = this.parseMaybeAssignAllowIn();
  10327. this.expect(14);
  10328. node.alternate = this.parseMaybeAssign();
  10329. return this.finishNode(node, "ConditionalExpression");
  10330. }
  10331. return expr;
  10332. }
  10333. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10334. return this.match(134) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10335. }
  10336. parseExprOps(refExpressionErrors) {
  10337. const startPos = this.state.start;
  10338. const startLoc = this.state.startLoc;
  10339. const potentialArrowAt = this.state.potentialArrowAt;
  10340. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10341. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10342. return expr;
  10343. }
  10344. return this.parseExprOp(expr, startPos, startLoc, -1);
  10345. }
  10346. parseExprOp(left, leftStartPos, leftStartLoc, minPrec) {
  10347. if (this.isPrivateName(left)) {
  10348. const value = this.getPrivateNameSV(left);
  10349. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10350. this.raise(Errors.PrivateInExpectedIn, {
  10351. at: left,
  10352. identifierName: value
  10353. });
  10354. }
  10355. this.classScope.usePrivateName(value, left.loc.start);
  10356. }
  10357. const op = this.state.type;
  10358. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10359. let prec = tokenOperatorPrecedence(op);
  10360. if (prec > minPrec) {
  10361. if (op === 39) {
  10362. this.expectPlugin("pipelineOperator");
  10363. if (this.state.inFSharpPipelineDirectBody) {
  10364. return left;
  10365. }
  10366. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10367. }
  10368. const node = this.startNodeAt(leftStartPos, leftStartLoc);
  10369. node.left = left;
  10370. node.operator = this.state.value;
  10371. const logical = op === 41 || op === 42;
  10372. const coalesce = op === 40;
  10373. if (coalesce) {
  10374. prec = tokenOperatorPrecedence(42);
  10375. }
  10376. this.next();
  10377. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10378. proposal: "minimal"
  10379. }])) {
  10380. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10381. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
  10382. at: this.state.startLoc
  10383. });
  10384. }
  10385. }
  10386. node.right = this.parseExprOpRightExpr(op, prec);
  10387. this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10388. const nextOp = this.state.type;
  10389. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10390. throw this.raise(Errors.MixingCoalesceWithLogical, {
  10391. at: this.state.startLoc
  10392. });
  10393. }
  10394. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec);
  10395. }
  10396. }
  10397. return left;
  10398. }
  10399. parseExprOpRightExpr(op, prec) {
  10400. const startPos = this.state.start;
  10401. const startLoc = this.state.startLoc;
  10402. switch (op) {
  10403. case 39:
  10404. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10405. case "hack":
  10406. return this.withTopicBindingContext(() => {
  10407. return this.parseHackPipeBody();
  10408. });
  10409. case "smart":
  10410. return this.withTopicBindingContext(() => {
  10411. if (this.prodParam.hasYield && this.isContextual(105)) {
  10412. throw this.raise(Errors.PipeBodyIsTighter, {
  10413. at: this.state.startLoc
  10414. });
  10415. }
  10416. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startPos, startLoc);
  10417. });
  10418. case "fsharp":
  10419. return this.withSoloAwaitPermittingContext(() => {
  10420. return this.parseFSharpPipelineBody(prec);
  10421. });
  10422. }
  10423. default:
  10424. return this.parseExprOpBaseRightExpr(op, prec);
  10425. }
  10426. }
  10427. parseExprOpBaseRightExpr(op, prec) {
  10428. const startPos = this.state.start;
  10429. const startLoc = this.state.startLoc;
  10430. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startPos, startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10431. }
  10432. parseHackPipeBody() {
  10433. var _body$extra;
  10434. const {
  10435. startLoc
  10436. } = this.state;
  10437. const body = this.parseMaybeAssign();
  10438. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10439. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10440. this.raise(Errors.PipeUnparenthesizedBody, {
  10441. at: startLoc,
  10442. type: body.type
  10443. });
  10444. }
  10445. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10446. this.raise(Errors.PipeTopicUnused, {
  10447. at: startLoc
  10448. });
  10449. }
  10450. return body;
  10451. }
  10452. checkExponentialAfterUnary(node) {
  10453. if (this.match(57)) {
  10454. this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
  10455. at: node.argument
  10456. });
  10457. }
  10458. }
  10459. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10460. const startPos = this.state.start;
  10461. const startLoc = this.state.startLoc;
  10462. const isAwait = this.isContextual(96);
  10463. if (isAwait && this.isAwaitAllowed()) {
  10464. this.next();
  10465. const expr = this.parseAwait(startPos, startLoc);
  10466. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10467. return expr;
  10468. }
  10469. const update = this.match(34);
  10470. const node = this.startNode();
  10471. if (tokenIsPrefix(this.state.type)) {
  10472. node.operator = this.state.value;
  10473. node.prefix = true;
  10474. if (this.match(72)) {
  10475. this.expectPlugin("throwExpressions");
  10476. }
  10477. const isDelete = this.match(89);
  10478. this.next();
  10479. node.argument = this.parseMaybeUnary(null, true);
  10480. this.checkExpressionErrors(refExpressionErrors, true);
  10481. if (this.state.strict && isDelete) {
  10482. const arg = node.argument;
  10483. if (arg.type === "Identifier") {
  10484. this.raise(Errors.StrictDelete, {
  10485. at: node
  10486. });
  10487. } else if (this.hasPropertyAsPrivateName(arg)) {
  10488. this.raise(Errors.DeletePrivateField, {
  10489. at: node
  10490. });
  10491. }
  10492. }
  10493. if (!update) {
  10494. if (!sawUnary) this.checkExponentialAfterUnary(node);
  10495. return this.finishNode(node, "UnaryExpression");
  10496. }
  10497. }
  10498. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10499. if (isAwait) {
  10500. const {
  10501. type
  10502. } = this.state;
  10503. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10504. if (startsExpr && !this.isAmbiguousAwait()) {
  10505. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
  10506. at: startLoc
  10507. });
  10508. return this.parseAwait(startPos, startLoc);
  10509. }
  10510. }
  10511. return expr;
  10512. }
  10513. parseUpdate(node, update, refExpressionErrors) {
  10514. if (update) {
  10515. this.checkLVal(node.argument, {
  10516. in: this.finishNode(node, "UpdateExpression")
  10517. });
  10518. return node;
  10519. }
  10520. const startPos = this.state.start;
  10521. const startLoc = this.state.startLoc;
  10522. let expr = this.parseExprSubscripts(refExpressionErrors);
  10523. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10524. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10525. const node = this.startNodeAt(startPos, startLoc);
  10526. node.operator = this.state.value;
  10527. node.prefix = false;
  10528. node.argument = expr;
  10529. this.next();
  10530. this.checkLVal(expr, {
  10531. in: expr = this.finishNode(node, "UpdateExpression")
  10532. });
  10533. }
  10534. return expr;
  10535. }
  10536. parseExprSubscripts(refExpressionErrors) {
  10537. const startPos = this.state.start;
  10538. const startLoc = this.state.startLoc;
  10539. const potentialArrowAt = this.state.potentialArrowAt;
  10540. const expr = this.parseExprAtom(refExpressionErrors);
  10541. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10542. return expr;
  10543. }
  10544. return this.parseSubscripts(expr, startPos, startLoc);
  10545. }
  10546. parseSubscripts(base, startPos, startLoc, noCalls) {
  10547. const state = {
  10548. optionalChainMember: false,
  10549. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10550. stop: false
  10551. };
  10552. do {
  10553. base = this.parseSubscript(base, startPos, startLoc, noCalls, state);
  10554. state.maybeAsyncArrow = false;
  10555. } while (!state.stop);
  10556. return base;
  10557. }
  10558. parseSubscript(base, startPos, startLoc, noCalls, state) {
  10559. const {
  10560. type
  10561. } = this.state;
  10562. if (!noCalls && type === 15) {
  10563. return this.parseBind(base, startPos, startLoc, noCalls, state);
  10564. } else if (tokenIsTemplate(type)) {
  10565. return this.parseTaggedTemplateExpression(base, startPos, startLoc, state);
  10566. }
  10567. let optional = false;
  10568. if (type === 18) {
  10569. if (noCalls && this.lookaheadCharCode() === 40) {
  10570. state.stop = true;
  10571. return base;
  10572. }
  10573. state.optionalChainMember = optional = true;
  10574. this.next();
  10575. }
  10576. if (!noCalls && this.match(10)) {
  10577. return this.parseCoverCallAndAsyncArrowHead(base, startPos, startLoc, state, optional);
  10578. } else {
  10579. const computed = this.eat(0);
  10580. if (computed || optional || this.eat(16)) {
  10581. return this.parseMember(base, startPos, startLoc, state, computed, optional);
  10582. } else {
  10583. state.stop = true;
  10584. return base;
  10585. }
  10586. }
  10587. }
  10588. parseMember(base, startPos, startLoc, state, computed, optional) {
  10589. const node = this.startNodeAt(startPos, startLoc);
  10590. node.object = base;
  10591. node.computed = computed;
  10592. if (computed) {
  10593. node.property = this.parseExpression();
  10594. this.expect(3);
  10595. } else if (this.match(134)) {
  10596. if (base.type === "Super") {
  10597. this.raise(Errors.SuperPrivateField, {
  10598. at: startLoc
  10599. });
  10600. }
  10601. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10602. node.property = this.parsePrivateName();
  10603. } else {
  10604. node.property = this.parseIdentifier(true);
  10605. }
  10606. if (state.optionalChainMember) {
  10607. node.optional = optional;
  10608. return this.finishNode(node, "OptionalMemberExpression");
  10609. } else {
  10610. return this.finishNode(node, "MemberExpression");
  10611. }
  10612. }
  10613. parseBind(base, startPos, startLoc, noCalls, state) {
  10614. const node = this.startNodeAt(startPos, startLoc);
  10615. node.object = base;
  10616. this.next();
  10617. node.callee = this.parseNoCallExpr();
  10618. state.stop = true;
  10619. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startPos, startLoc, noCalls);
  10620. }
  10621. parseCoverCallAndAsyncArrowHead(base, startPos, startLoc, state, optional) {
  10622. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10623. let refExpressionErrors = null;
  10624. this.state.maybeInArrowParameters = true;
  10625. this.next();
  10626. let node = this.startNodeAt(startPos, startLoc);
  10627. node.callee = base;
  10628. const {
  10629. maybeAsyncArrow,
  10630. optionalChainMember
  10631. } = state;
  10632. if (maybeAsyncArrow) {
  10633. this.expressionScope.enter(newAsyncArrowScope());
  10634. refExpressionErrors = new ExpressionErrors();
  10635. }
  10636. if (optionalChainMember) {
  10637. node.optional = optional;
  10638. }
  10639. if (optional) {
  10640. node.arguments = this.parseCallExpressionArguments(11);
  10641. } else {
  10642. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  10643. }
  10644. this.finishCallExpression(node, optionalChainMember);
  10645. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10646. state.stop = true;
  10647. this.checkDestructuringPrivate(refExpressionErrors);
  10648. this.expressionScope.validateAsPattern();
  10649. this.expressionScope.exit();
  10650. node = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node);
  10651. } else {
  10652. if (maybeAsyncArrow) {
  10653. this.checkExpressionErrors(refExpressionErrors, true);
  10654. this.expressionScope.exit();
  10655. }
  10656. this.toReferencedArguments(node);
  10657. }
  10658. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10659. return node;
  10660. }
  10661. toReferencedArguments(node, isParenthesizedExpr) {
  10662. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  10663. }
  10664. parseTaggedTemplateExpression(base, startPos, startLoc, state) {
  10665. const node = this.startNodeAt(startPos, startLoc);
  10666. node.tag = base;
  10667. node.quasi = this.parseTemplate(true);
  10668. if (state.optionalChainMember) {
  10669. this.raise(Errors.OptionalChainingNoTemplate, {
  10670. at: startLoc
  10671. });
  10672. }
  10673. return this.finishNode(node, "TaggedTemplateExpression");
  10674. }
  10675. atPossibleAsyncArrow(base) {
  10676. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.state.potentialArrowAt;
  10677. }
  10678. finishCallExpression(node, optional) {
  10679. if (node.callee.type === "Import") {
  10680. if (node.arguments.length === 2) {
  10681. {
  10682. if (!this.hasPlugin("moduleAttributes")) {
  10683. this.expectPlugin("importAssertions");
  10684. }
  10685. }
  10686. }
  10687. if (node.arguments.length === 0 || node.arguments.length > 2) {
  10688. this.raise(Errors.ImportCallArity, {
  10689. at: node,
  10690. maxArgumentCount: this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  10691. });
  10692. } else {
  10693. for (const arg of node.arguments) {
  10694. if (arg.type === "SpreadElement") {
  10695. this.raise(Errors.ImportCallSpreadArgument, {
  10696. at: arg
  10697. });
  10698. }
  10699. }
  10700. }
  10701. }
  10702. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  10703. }
  10704. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  10705. const elts = [];
  10706. let first = true;
  10707. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10708. this.state.inFSharpPipelineDirectBody = false;
  10709. while (!this.eat(close)) {
  10710. if (first) {
  10711. first = false;
  10712. } else {
  10713. this.expect(12);
  10714. if (this.match(close)) {
  10715. if (dynamicImport && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  10716. this.raise(Errors.ImportCallArgumentTrailingComma, {
  10717. at: this.state.lastTokStartLoc
  10718. });
  10719. }
  10720. if (nodeForExtra) {
  10721. this.addTrailingCommaExtraToNode(nodeForExtra);
  10722. }
  10723. this.next();
  10724. break;
  10725. }
  10726. }
  10727. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  10728. }
  10729. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  10730. return elts;
  10731. }
  10732. shouldParseAsyncArrow() {
  10733. return this.match(19) && !this.canInsertSemicolon();
  10734. }
  10735. parseAsyncArrowFromCallExpression(node, call) {
  10736. var _call$extra;
  10737. this.resetPreviousNodeTrailingComments(call);
  10738. this.expect(19);
  10739. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  10740. if (call.innerComments) {
  10741. setInnerComments(node, call.innerComments);
  10742. }
  10743. if (call.callee.trailingComments) {
  10744. setInnerComments(node, call.callee.trailingComments);
  10745. }
  10746. return node;
  10747. }
  10748. parseNoCallExpr() {
  10749. const startPos = this.state.start;
  10750. const startLoc = this.state.startLoc;
  10751. return this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  10752. }
  10753. parseExprAtom(refExpressionErrors) {
  10754. let node;
  10755. const {
  10756. type
  10757. } = this.state;
  10758. switch (type) {
  10759. case 79:
  10760. return this.parseSuper();
  10761. case 83:
  10762. node = this.startNode();
  10763. this.next();
  10764. if (this.match(16)) {
  10765. return this.parseImportMetaProperty(node);
  10766. }
  10767. if (!this.match(10)) {
  10768. this.raise(Errors.UnsupportedImport, {
  10769. at: this.state.lastTokStartLoc
  10770. });
  10771. }
  10772. return this.finishNode(node, "Import");
  10773. case 78:
  10774. node = this.startNode();
  10775. this.next();
  10776. return this.finishNode(node, "ThisExpression");
  10777. case 90:
  10778. {
  10779. return this.parseDo(this.startNode(), false);
  10780. }
  10781. case 56:
  10782. case 31:
  10783. {
  10784. this.readRegexp();
  10785. return this.parseRegExpLiteral(this.state.value);
  10786. }
  10787. case 130:
  10788. return this.parseNumericLiteral(this.state.value);
  10789. case 131:
  10790. return this.parseBigIntLiteral(this.state.value);
  10791. case 132:
  10792. return this.parseDecimalLiteral(this.state.value);
  10793. case 129:
  10794. return this.parseStringLiteral(this.state.value);
  10795. case 84:
  10796. return this.parseNullLiteral();
  10797. case 85:
  10798. return this.parseBooleanLiteral(true);
  10799. case 86:
  10800. return this.parseBooleanLiteral(false);
  10801. case 10:
  10802. {
  10803. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  10804. return this.parseParenAndDistinguishExpression(canBeArrow);
  10805. }
  10806. case 2:
  10807. case 1:
  10808. {
  10809. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  10810. }
  10811. case 0:
  10812. {
  10813. return this.parseArrayLike(3, true, false, refExpressionErrors);
  10814. }
  10815. case 6:
  10816. case 7:
  10817. {
  10818. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  10819. }
  10820. case 5:
  10821. {
  10822. return this.parseObjectLike(8, false, false, refExpressionErrors);
  10823. }
  10824. case 68:
  10825. return this.parseFunctionOrFunctionSent();
  10826. case 26:
  10827. this.parseDecorators();
  10828. case 80:
  10829. node = this.startNode();
  10830. this.takeDecorators(node);
  10831. return this.parseClass(node, false);
  10832. case 77:
  10833. return this.parseNewOrNewTarget();
  10834. case 25:
  10835. case 24:
  10836. return this.parseTemplate(false);
  10837. case 15:
  10838. {
  10839. node = this.startNode();
  10840. this.next();
  10841. node.object = null;
  10842. const callee = node.callee = this.parseNoCallExpr();
  10843. if (callee.type === "MemberExpression") {
  10844. return this.finishNode(node, "BindExpression");
  10845. } else {
  10846. throw this.raise(Errors.UnsupportedBind, {
  10847. at: callee
  10848. });
  10849. }
  10850. }
  10851. case 134:
  10852. {
  10853. this.raise(Errors.PrivateInExpectedIn, {
  10854. at: this.state.startLoc,
  10855. identifierName: this.state.value
  10856. });
  10857. return this.parsePrivateName();
  10858. }
  10859. case 33:
  10860. {
  10861. return this.parseTopicReferenceThenEqualsSign(54, "%");
  10862. }
  10863. case 32:
  10864. {
  10865. return this.parseTopicReferenceThenEqualsSign(44, "^");
  10866. }
  10867. case 37:
  10868. case 38:
  10869. {
  10870. return this.parseTopicReference("hack");
  10871. }
  10872. case 44:
  10873. case 54:
  10874. case 27:
  10875. {
  10876. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  10877. if (pipeProposal) {
  10878. return this.parseTopicReference(pipeProposal);
  10879. } else {
  10880. throw this.unexpected();
  10881. }
  10882. }
  10883. case 47:
  10884. {
  10885. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  10886. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  10887. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  10888. break;
  10889. } else {
  10890. throw this.unexpected();
  10891. }
  10892. }
  10893. default:
  10894. if (tokenIsIdentifier(type)) {
  10895. if (this.isContextual(123) && this.lookaheadCharCode() === 123 && !this.hasFollowingLineBreak()) {
  10896. return this.parseModuleExpression();
  10897. }
  10898. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  10899. const containsEsc = this.state.containsEsc;
  10900. const id = this.parseIdentifier();
  10901. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  10902. const {
  10903. type
  10904. } = this.state;
  10905. if (type === 68) {
  10906. this.resetPreviousNodeTrailingComments(id);
  10907. this.next();
  10908. return this.parseFunction(this.startNodeAtNode(id), undefined, true);
  10909. } else if (tokenIsIdentifier(type)) {
  10910. if (this.lookaheadCharCode() === 61) {
  10911. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  10912. } else {
  10913. return id;
  10914. }
  10915. } else if (type === 90) {
  10916. this.resetPreviousNodeTrailingComments(id);
  10917. return this.parseDo(this.startNodeAtNode(id), true);
  10918. }
  10919. }
  10920. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  10921. this.next();
  10922. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  10923. }
  10924. return id;
  10925. } else {
  10926. throw this.unexpected();
  10927. }
  10928. }
  10929. }
  10930. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  10931. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  10932. if (pipeProposal) {
  10933. this.state.type = topicTokenType;
  10934. this.state.value = topicTokenValue;
  10935. this.state.pos--;
  10936. this.state.end--;
  10937. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  10938. return this.parseTopicReference(pipeProposal);
  10939. } else {
  10940. throw this.unexpected();
  10941. }
  10942. }
  10943. parseTopicReference(pipeProposal) {
  10944. const node = this.startNode();
  10945. const startLoc = this.state.startLoc;
  10946. const tokenType = this.state.type;
  10947. this.next();
  10948. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  10949. }
  10950. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  10951. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  10952. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  10953. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  10954. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, {
  10955. at: startLoc
  10956. });
  10957. }
  10958. this.registerTopicReference();
  10959. return this.finishNode(node, nodeType);
  10960. } else {
  10961. throw this.raise(Errors.PipeTopicUnconfiguredToken, {
  10962. at: startLoc,
  10963. token: tokenLabelName(tokenType)
  10964. });
  10965. }
  10966. }
  10967. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  10968. switch (pipeProposal) {
  10969. case "hack":
  10970. {
  10971. return this.hasPlugin(["pipelineOperator", {
  10972. topicToken: tokenLabelName(tokenType)
  10973. }]);
  10974. }
  10975. case "smart":
  10976. return tokenType === 27;
  10977. default:
  10978. throw this.raise(Errors.PipeTopicRequiresHackPipes, {
  10979. at: startLoc
  10980. });
  10981. }
  10982. }
  10983. parseAsyncArrowUnaryFunction(node) {
  10984. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  10985. const params = [this.parseIdentifier()];
  10986. this.prodParam.exit();
  10987. if (this.hasPrecedingLineBreak()) {
  10988. this.raise(Errors.LineTerminatorBeforeArrow, {
  10989. at: this.state.curPosition()
  10990. });
  10991. }
  10992. this.expect(19);
  10993. this.parseArrowExpression(node, params, true);
  10994. return node;
  10995. }
  10996. parseDo(node, isAsync) {
  10997. this.expectPlugin("doExpressions");
  10998. if (isAsync) {
  10999. this.expectPlugin("asyncDoExpressions");
  11000. }
  11001. node.async = isAsync;
  11002. this.next();
  11003. const oldLabels = this.state.labels;
  11004. this.state.labels = [];
  11005. if (isAsync) {
  11006. this.prodParam.enter(PARAM_AWAIT);
  11007. node.body = this.parseBlock();
  11008. this.prodParam.exit();
  11009. } else {
  11010. node.body = this.parseBlock();
  11011. }
  11012. this.state.labels = oldLabels;
  11013. return this.finishNode(node, "DoExpression");
  11014. }
  11015. parseSuper() {
  11016. const node = this.startNode();
  11017. this.next();
  11018. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  11019. this.raise(Errors.SuperNotAllowed, {
  11020. at: node
  11021. });
  11022. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  11023. this.raise(Errors.UnexpectedSuper, {
  11024. at: node
  11025. });
  11026. }
  11027. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11028. this.raise(Errors.UnsupportedSuper, {
  11029. at: node
  11030. });
  11031. }
  11032. return this.finishNode(node, "Super");
  11033. }
  11034. parsePrivateName() {
  11035. const node = this.startNode();
  11036. const id = this.startNodeAt(this.state.start + 1, new Position(this.state.curLine, this.state.start + 1 - this.state.lineStart, this.state.start + 1));
  11037. const name = this.state.value;
  11038. this.next();
  11039. node.id = this.createIdentifier(id, name);
  11040. return this.finishNode(node, "PrivateName");
  11041. }
  11042. parseFunctionOrFunctionSent() {
  11043. const node = this.startNode();
  11044. this.next();
  11045. if (this.prodParam.hasYield && this.match(16)) {
  11046. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11047. this.next();
  11048. if (this.match(102)) {
  11049. this.expectPlugin("functionSent");
  11050. } else if (!this.hasPlugin("functionSent")) {
  11051. this.unexpected();
  11052. }
  11053. return this.parseMetaProperty(node, meta, "sent");
  11054. }
  11055. return this.parseFunction(node);
  11056. }
  11057. parseMetaProperty(node, meta, propertyName) {
  11058. node.meta = meta;
  11059. const containsEsc = this.state.containsEsc;
  11060. node.property = this.parseIdentifier(true);
  11061. if (node.property.name !== propertyName || containsEsc) {
  11062. this.raise(Errors.UnsupportedMetaProperty, {
  11063. at: node.property,
  11064. target: meta.name,
  11065. onlyValidPropertyName: propertyName
  11066. });
  11067. }
  11068. return this.finishNode(node, "MetaProperty");
  11069. }
  11070. parseImportMetaProperty(node) {
  11071. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11072. this.next();
  11073. if (this.isContextual(100)) {
  11074. if (!this.inModule) {
  11075. this.raise(Errors.ImportMetaOutsideModule, {
  11076. at: id
  11077. });
  11078. }
  11079. this.sawUnambiguousESM = true;
  11080. }
  11081. return this.parseMetaProperty(node, id, "meta");
  11082. }
  11083. parseLiteralAtNode(value, type, node) {
  11084. this.addExtra(node, "rawValue", value);
  11085. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  11086. node.value = value;
  11087. this.next();
  11088. return this.finishNode(node, type);
  11089. }
  11090. parseLiteral(value, type) {
  11091. const node = this.startNode();
  11092. return this.parseLiteralAtNode(value, type, node);
  11093. }
  11094. parseStringLiteral(value) {
  11095. return this.parseLiteral(value, "StringLiteral");
  11096. }
  11097. parseNumericLiteral(value) {
  11098. return this.parseLiteral(value, "NumericLiteral");
  11099. }
  11100. parseBigIntLiteral(value) {
  11101. return this.parseLiteral(value, "BigIntLiteral");
  11102. }
  11103. parseDecimalLiteral(value) {
  11104. return this.parseLiteral(value, "DecimalLiteral");
  11105. }
  11106. parseRegExpLiteral(value) {
  11107. const node = this.parseLiteral(value.value, "RegExpLiteral");
  11108. node.pattern = value.pattern;
  11109. node.flags = value.flags;
  11110. return node;
  11111. }
  11112. parseBooleanLiteral(value) {
  11113. const node = this.startNode();
  11114. node.value = value;
  11115. this.next();
  11116. return this.finishNode(node, "BooleanLiteral");
  11117. }
  11118. parseNullLiteral() {
  11119. const node = this.startNode();
  11120. this.next();
  11121. return this.finishNode(node, "NullLiteral");
  11122. }
  11123. parseParenAndDistinguishExpression(canBeArrow) {
  11124. const startPos = this.state.start;
  11125. const startLoc = this.state.startLoc;
  11126. let val;
  11127. this.next();
  11128. this.expressionScope.enter(newArrowHeadScope());
  11129. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11130. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11131. this.state.maybeInArrowParameters = true;
  11132. this.state.inFSharpPipelineDirectBody = false;
  11133. const innerStartPos = this.state.start;
  11134. const innerStartLoc = this.state.startLoc;
  11135. const exprList = [];
  11136. const refExpressionErrors = new ExpressionErrors();
  11137. let first = true;
  11138. let spreadStartLoc;
  11139. let optionalCommaStartLoc;
  11140. while (!this.match(11)) {
  11141. if (first) {
  11142. first = false;
  11143. } else {
  11144. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11145. if (this.match(11)) {
  11146. optionalCommaStartLoc = this.state.startLoc;
  11147. break;
  11148. }
  11149. }
  11150. if (this.match(21)) {
  11151. const spreadNodeStartPos = this.state.start;
  11152. const spreadNodeStartLoc = this.state.startLoc;
  11153. spreadStartLoc = this.state.startLoc;
  11154. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartPos, spreadNodeStartLoc));
  11155. if (!this.checkCommaAfterRest(41)) {
  11156. break;
  11157. }
  11158. } else {
  11159. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11160. }
  11161. }
  11162. const innerEndLoc = this.state.lastTokEndLoc;
  11163. this.expect(11);
  11164. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11165. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11166. let arrowNode = this.startNodeAt(startPos, startLoc);
  11167. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11168. this.checkDestructuringPrivate(refExpressionErrors);
  11169. this.expressionScope.validateAsPattern();
  11170. this.expressionScope.exit();
  11171. this.parseArrowExpression(arrowNode, exprList, false);
  11172. return arrowNode;
  11173. }
  11174. this.expressionScope.exit();
  11175. if (!exprList.length) {
  11176. this.unexpected(this.state.lastTokStartLoc);
  11177. }
  11178. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11179. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11180. this.checkExpressionErrors(refExpressionErrors, true);
  11181. this.toReferencedListDeep(exprList, true);
  11182. if (exprList.length > 1) {
  11183. val = this.startNodeAt(innerStartPos, innerStartLoc);
  11184. val.expressions = exprList;
  11185. this.finishNode(val, "SequenceExpression");
  11186. this.resetEndLocation(val, innerEndLoc);
  11187. } else {
  11188. val = exprList[0];
  11189. }
  11190. return this.wrapParenthesis(startPos, startLoc, val);
  11191. }
  11192. wrapParenthesis(startPos, startLoc, expression) {
  11193. if (!this.options.createParenthesizedExpressions) {
  11194. this.addExtra(expression, "parenthesized", true);
  11195. this.addExtra(expression, "parenStart", startPos);
  11196. this.takeSurroundingComments(expression, startPos, this.state.lastTokEndLoc.index);
  11197. return expression;
  11198. }
  11199. const parenExpression = this.startNodeAt(startPos, startLoc);
  11200. parenExpression.expression = expression;
  11201. this.finishNode(parenExpression, "ParenthesizedExpression");
  11202. return parenExpression;
  11203. }
  11204. shouldParseArrow(params) {
  11205. return !this.canInsertSemicolon();
  11206. }
  11207. parseArrow(node) {
  11208. if (this.eat(19)) {
  11209. return node;
  11210. }
  11211. }
  11212. parseParenItem(node, startPos, startLoc) {
  11213. return node;
  11214. }
  11215. parseNewOrNewTarget() {
  11216. const node = this.startNode();
  11217. this.next();
  11218. if (this.match(16)) {
  11219. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11220. this.next();
  11221. const metaProp = this.parseMetaProperty(node, meta, "target");
  11222. if (!this.scope.inNonArrowFunction && !this.scope.inClass) {
  11223. this.raise(Errors.UnexpectedNewTarget, {
  11224. at: metaProp
  11225. });
  11226. }
  11227. return metaProp;
  11228. }
  11229. return this.parseNew(node);
  11230. }
  11231. parseNew(node) {
  11232. this.parseNewCallee(node);
  11233. if (this.eat(10)) {
  11234. const args = this.parseExprList(11);
  11235. this.toReferencedList(args);
  11236. node.arguments = args;
  11237. } else {
  11238. node.arguments = [];
  11239. }
  11240. return this.finishNode(node, "NewExpression");
  11241. }
  11242. parseNewCallee(node) {
  11243. node.callee = this.parseNoCallExpr();
  11244. if (node.callee.type === "Import") {
  11245. this.raise(Errors.ImportCallNotNewExpression, {
  11246. at: node.callee
  11247. });
  11248. } else if (this.isOptionalChain(node.callee)) {
  11249. this.raise(Errors.OptionalChainingNoNew, {
  11250. at: this.state.lastTokEndLoc
  11251. });
  11252. } else if (this.eat(18)) {
  11253. this.raise(Errors.OptionalChainingNoNew, {
  11254. at: this.state.startLoc
  11255. });
  11256. }
  11257. }
  11258. parseTemplateElement(isTagged) {
  11259. const {
  11260. start,
  11261. startLoc,
  11262. end,
  11263. value
  11264. } = this.state;
  11265. const elemStart = start + 1;
  11266. const elem = this.startNodeAt(elemStart, createPositionWithColumnOffset(startLoc, 1));
  11267. if (value === null) {
  11268. if (!isTagged) {
  11269. this.raise(Errors.InvalidEscapeSequenceTemplate, {
  11270. at: createPositionWithColumnOffset(startLoc, 2)
  11271. });
  11272. }
  11273. }
  11274. const isTail = this.match(24);
  11275. const endOffset = isTail ? -1 : -2;
  11276. const elemEnd = end + endOffset;
  11277. elem.value = {
  11278. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11279. cooked: value === null ? null : value.slice(1, endOffset)
  11280. };
  11281. elem.tail = isTail;
  11282. this.next();
  11283. this.finishNode(elem, "TemplateElement");
  11284. this.resetEndLocation(elem, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11285. return elem;
  11286. }
  11287. parseTemplate(isTagged) {
  11288. const node = this.startNode();
  11289. node.expressions = [];
  11290. let curElt = this.parseTemplateElement(isTagged);
  11291. node.quasis = [curElt];
  11292. while (!curElt.tail) {
  11293. node.expressions.push(this.parseTemplateSubstitution());
  11294. this.readTemplateContinuation();
  11295. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  11296. }
  11297. return this.finishNode(node, "TemplateLiteral");
  11298. }
  11299. parseTemplateSubstitution() {
  11300. return this.parseExpression();
  11301. }
  11302. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11303. if (isRecord) {
  11304. this.expectPlugin("recordAndTuple");
  11305. }
  11306. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11307. this.state.inFSharpPipelineDirectBody = false;
  11308. const propHash = Object.create(null);
  11309. let first = true;
  11310. const node = this.startNode();
  11311. node.properties = [];
  11312. this.next();
  11313. while (!this.match(close)) {
  11314. if (first) {
  11315. first = false;
  11316. } else {
  11317. this.expect(12);
  11318. if (this.match(close)) {
  11319. this.addTrailingCommaExtraToNode(node);
  11320. break;
  11321. }
  11322. }
  11323. let prop;
  11324. if (isPattern) {
  11325. prop = this.parseBindingProperty();
  11326. } else {
  11327. prop = this.parsePropertyDefinition(refExpressionErrors);
  11328. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11329. }
  11330. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11331. this.raise(Errors.InvalidRecordProperty, {
  11332. at: prop
  11333. });
  11334. }
  11335. if (prop.shorthand) {
  11336. this.addExtra(prop, "shorthand", true);
  11337. }
  11338. node.properties.push(prop);
  11339. }
  11340. this.next();
  11341. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11342. let type = "ObjectExpression";
  11343. if (isPattern) {
  11344. type = "ObjectPattern";
  11345. } else if (isRecord) {
  11346. type = "RecordExpression";
  11347. }
  11348. return this.finishNode(node, type);
  11349. }
  11350. addTrailingCommaExtraToNode(node) {
  11351. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  11352. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11353. }
  11354. maybeAsyncOrAccessorProp(prop) {
  11355. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11356. }
  11357. parsePropertyDefinition(refExpressionErrors) {
  11358. let decorators = [];
  11359. if (this.match(26)) {
  11360. if (this.hasPlugin("decorators")) {
  11361. this.raise(Errors.UnsupportedPropertyDecorator, {
  11362. at: this.state.startLoc
  11363. });
  11364. }
  11365. while (this.match(26)) {
  11366. decorators.push(this.parseDecorator());
  11367. }
  11368. }
  11369. const prop = this.startNode();
  11370. let isAsync = false;
  11371. let isAccessor = false;
  11372. let startPos;
  11373. let startLoc;
  11374. if (this.match(21)) {
  11375. if (decorators.length) this.unexpected();
  11376. return this.parseSpread();
  11377. }
  11378. if (decorators.length) {
  11379. prop.decorators = decorators;
  11380. decorators = [];
  11381. }
  11382. prop.method = false;
  11383. if (refExpressionErrors) {
  11384. startPos = this.state.start;
  11385. startLoc = this.state.startLoc;
  11386. }
  11387. let isGenerator = this.eat(55);
  11388. this.parsePropertyNamePrefixOperator(prop);
  11389. const containsEsc = this.state.containsEsc;
  11390. const key = this.parsePropertyName(prop, refExpressionErrors);
  11391. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11392. const keyName = key.name;
  11393. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11394. isAsync = true;
  11395. this.resetPreviousNodeTrailingComments(key);
  11396. isGenerator = this.eat(55);
  11397. this.parsePropertyName(prop);
  11398. }
  11399. if (keyName === "get" || keyName === "set") {
  11400. isAccessor = true;
  11401. this.resetPreviousNodeTrailingComments(key);
  11402. prop.kind = keyName;
  11403. if (this.match(55)) {
  11404. isGenerator = true;
  11405. this.raise(Errors.AccessorIsGenerator, {
  11406. at: this.state.curPosition(),
  11407. kind: keyName
  11408. });
  11409. this.next();
  11410. }
  11411. this.parsePropertyName(prop);
  11412. }
  11413. }
  11414. this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11415. return prop;
  11416. }
  11417. getGetterSetterExpectedParamCount(method) {
  11418. return method.kind === "get" ? 0 : 1;
  11419. }
  11420. getObjectOrClassMethodParams(method) {
  11421. return method.params;
  11422. }
  11423. checkGetterSetterParams(method) {
  11424. var _params;
  11425. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11426. const params = this.getObjectOrClassMethodParams(method);
  11427. if (params.length !== paramCount) {
  11428. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  11429. at: method
  11430. });
  11431. }
  11432. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11433. this.raise(Errors.BadSetterRestParameter, {
  11434. at: method
  11435. });
  11436. }
  11437. }
  11438. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11439. if (isAccessor) {
  11440. this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11441. this.checkGetterSetterParams(prop);
  11442. return prop;
  11443. }
  11444. if (isAsync || isGenerator || this.match(10)) {
  11445. if (isPattern) this.unexpected();
  11446. prop.kind = "method";
  11447. prop.method = true;
  11448. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11449. }
  11450. }
  11451. parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors) {
  11452. prop.shorthand = false;
  11453. if (this.eat(14)) {
  11454. prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11455. return this.finishNode(prop, "ObjectProperty");
  11456. }
  11457. if (!prop.computed && prop.key.type === "Identifier") {
  11458. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11459. if (isPattern) {
  11460. prop.value = this.parseMaybeDefault(startPos, startLoc, cloneIdentifier(prop.key));
  11461. } else if (this.match(29)) {
  11462. const shorthandAssignLoc = this.state.startLoc;
  11463. if (refExpressionErrors != null) {
  11464. if (refExpressionErrors.shorthandAssignLoc === null) {
  11465. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11466. }
  11467. } else {
  11468. this.raise(Errors.InvalidCoverInitializedName, {
  11469. at: shorthandAssignLoc
  11470. });
  11471. }
  11472. prop.value = this.parseMaybeDefault(startPos, startLoc, cloneIdentifier(prop.key));
  11473. } else {
  11474. prop.value = cloneIdentifier(prop.key);
  11475. }
  11476. prop.shorthand = true;
  11477. return this.finishNode(prop, "ObjectProperty");
  11478. }
  11479. }
  11480. parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11481. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors);
  11482. if (!node) this.unexpected();
  11483. return node;
  11484. }
  11485. parsePropertyName(prop, refExpressionErrors) {
  11486. if (this.eat(0)) {
  11487. prop.computed = true;
  11488. prop.key = this.parseMaybeAssignAllowIn();
  11489. this.expect(3);
  11490. } else {
  11491. const {
  11492. type,
  11493. value
  11494. } = this.state;
  11495. let key;
  11496. if (tokenIsKeywordOrIdentifier(type)) {
  11497. key = this.parseIdentifier(true);
  11498. } else {
  11499. switch (type) {
  11500. case 130:
  11501. key = this.parseNumericLiteral(value);
  11502. break;
  11503. case 129:
  11504. key = this.parseStringLiteral(value);
  11505. break;
  11506. case 131:
  11507. key = this.parseBigIntLiteral(value);
  11508. break;
  11509. case 132:
  11510. key = this.parseDecimalLiteral(value);
  11511. break;
  11512. case 134:
  11513. {
  11514. const privateKeyLoc = this.state.startLoc;
  11515. if (refExpressionErrors != null) {
  11516. if (refExpressionErrors.privateKeyLoc === null) {
  11517. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11518. }
  11519. } else {
  11520. this.raise(Errors.UnexpectedPrivateField, {
  11521. at: privateKeyLoc
  11522. });
  11523. }
  11524. key = this.parsePrivateName();
  11525. break;
  11526. }
  11527. default:
  11528. throw this.unexpected();
  11529. }
  11530. }
  11531. prop.key = key;
  11532. if (type !== 134) {
  11533. prop.computed = false;
  11534. }
  11535. }
  11536. return prop.key;
  11537. }
  11538. initFunction(node, isAsync) {
  11539. node.id = null;
  11540. node.generator = false;
  11541. node.async = !!isAsync;
  11542. }
  11543. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11544. this.initFunction(node, isAsync);
  11545. node.generator = !!isGenerator;
  11546. const allowModifiers = isConstructor;
  11547. this.scope.enter(SCOPE_FUNCTION | SCOPE_SUPER | (inClassScope ? SCOPE_CLASS : 0) | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  11548. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11549. this.parseFunctionParams(node, allowModifiers);
  11550. this.parseFunctionBodyAndFinish(node, type, true);
  11551. this.prodParam.exit();
  11552. this.scope.exit();
  11553. return node;
  11554. }
  11555. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11556. if (isTuple) {
  11557. this.expectPlugin("recordAndTuple");
  11558. }
  11559. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11560. this.state.inFSharpPipelineDirectBody = false;
  11561. const node = this.startNode();
  11562. this.next();
  11563. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11564. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11565. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11566. }
  11567. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11568. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  11569. let flags = functionFlags(isAsync, false);
  11570. if (!this.match(5) && this.prodParam.hasIn) {
  11571. flags |= PARAM_IN;
  11572. }
  11573. this.prodParam.enter(flags);
  11574. this.initFunction(node, isAsync);
  11575. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11576. if (params) {
  11577. this.state.maybeInArrowParameters = true;
  11578. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11579. }
  11580. this.state.maybeInArrowParameters = false;
  11581. this.parseFunctionBody(node, true);
  11582. this.prodParam.exit();
  11583. this.scope.exit();
  11584. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11585. return this.finishNode(node, "ArrowFunctionExpression");
  11586. }
  11587. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11588. this.toAssignableList(params, trailingCommaLoc, false);
  11589. node.params = params;
  11590. }
  11591. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11592. this.parseFunctionBody(node, false, isMethod);
  11593. this.finishNode(node, type);
  11594. }
  11595. parseFunctionBody(node, allowExpression, isMethod = false) {
  11596. const isExpression = allowExpression && !this.match(5);
  11597. this.expressionScope.enter(newExpressionScope());
  11598. if (isExpression) {
  11599. node.body = this.parseMaybeAssign();
  11600. this.checkParams(node, false, allowExpression, false);
  11601. } else {
  11602. const oldStrict = this.state.strict;
  11603. const oldLabels = this.state.labels;
  11604. this.state.labels = [];
  11605. this.prodParam.enter(this.prodParam.currentFlags() | PARAM_RETURN);
  11606. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11607. const nonSimple = !this.isSimpleParamList(node.params);
  11608. if (hasStrictModeDirective && nonSimple) {
  11609. this.raise(Errors.IllegalLanguageModeDirective, {
  11610. at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node
  11611. });
  11612. }
  11613. const strictModeChanged = !oldStrict && this.state.strict;
  11614. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11615. if (this.state.strict && node.id) {
  11616. this.checkIdentifier(node.id, BIND_OUTSIDE, strictModeChanged);
  11617. }
  11618. });
  11619. this.prodParam.exit();
  11620. this.state.labels = oldLabels;
  11621. }
  11622. this.expressionScope.exit();
  11623. }
  11624. isSimpleParameter(node) {
  11625. return node.type === "Identifier";
  11626. }
  11627. isSimpleParamList(params) {
  11628. for (let i = 0, len = params.length; i < len; i++) {
  11629. if (!this.isSimpleParameter(params[i])) return false;
  11630. }
  11631. return true;
  11632. }
  11633. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11634. const checkClashes = !allowDuplicates && new Set();
  11635. const formalParameters = {
  11636. type: "FormalParameters"
  11637. };
  11638. for (const param of node.params) {
  11639. this.checkLVal(param, {
  11640. in: formalParameters,
  11641. binding: BIND_VAR,
  11642. checkClashes,
  11643. strictModeChanged
  11644. });
  11645. }
  11646. }
  11647. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11648. const elts = [];
  11649. let first = true;
  11650. while (!this.eat(close)) {
  11651. if (first) {
  11652. first = false;
  11653. } else {
  11654. this.expect(12);
  11655. if (this.match(close)) {
  11656. if (nodeForExtra) {
  11657. this.addTrailingCommaExtraToNode(nodeForExtra);
  11658. }
  11659. this.next();
  11660. break;
  11661. }
  11662. }
  11663. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11664. }
  11665. return elts;
  11666. }
  11667. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  11668. let elt;
  11669. if (this.match(12)) {
  11670. if (!allowEmpty) {
  11671. this.raise(Errors.UnexpectedToken, {
  11672. at: this.state.curPosition(),
  11673. unexpected: ","
  11674. });
  11675. }
  11676. elt = null;
  11677. } else if (this.match(21)) {
  11678. const spreadNodeStartPos = this.state.start;
  11679. const spreadNodeStartLoc = this.state.startLoc;
  11680. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartPos, spreadNodeStartLoc);
  11681. } else if (this.match(17)) {
  11682. this.expectPlugin("partialApplication");
  11683. if (!allowPlaceholder) {
  11684. this.raise(Errors.UnexpectedArgumentPlaceholder, {
  11685. at: this.state.startLoc
  11686. });
  11687. }
  11688. const node = this.startNode();
  11689. this.next();
  11690. elt = this.finishNode(node, "ArgumentPlaceholder");
  11691. } else {
  11692. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  11693. }
  11694. return elt;
  11695. }
  11696. parseIdentifier(liberal) {
  11697. const node = this.startNode();
  11698. const name = this.parseIdentifierName(node.start, liberal);
  11699. return this.createIdentifier(node, name);
  11700. }
  11701. createIdentifier(node, name) {
  11702. node.name = name;
  11703. node.loc.identifierName = name;
  11704. return this.finishNode(node, "Identifier");
  11705. }
  11706. parseIdentifierName(pos, liberal) {
  11707. let name;
  11708. const {
  11709. startLoc,
  11710. type
  11711. } = this.state;
  11712. if (tokenIsKeywordOrIdentifier(type)) {
  11713. name = this.state.value;
  11714. } else {
  11715. throw this.unexpected();
  11716. }
  11717. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  11718. if (liberal) {
  11719. if (tokenIsKeyword) {
  11720. this.replaceToken(128);
  11721. }
  11722. } else {
  11723. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  11724. }
  11725. this.next();
  11726. return name;
  11727. }
  11728. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  11729. if (word.length > 10) {
  11730. return;
  11731. }
  11732. if (!canBeReservedWord(word)) {
  11733. return;
  11734. }
  11735. if (word === "yield") {
  11736. if (this.prodParam.hasYield) {
  11737. this.raise(Errors.YieldBindingIdentifier, {
  11738. at: startLoc
  11739. });
  11740. return;
  11741. }
  11742. } else if (word === "await") {
  11743. if (this.prodParam.hasAwait) {
  11744. this.raise(Errors.AwaitBindingIdentifier, {
  11745. at: startLoc
  11746. });
  11747. return;
  11748. }
  11749. if (this.scope.inStaticBlock) {
  11750. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
  11751. at: startLoc
  11752. });
  11753. return;
  11754. }
  11755. this.expressionScope.recordAsyncArrowParametersError({
  11756. at: startLoc
  11757. });
  11758. } else if (word === "arguments") {
  11759. if (this.scope.inClassAndNotInNonArrowFunction) {
  11760. this.raise(Errors.ArgumentsInClass, {
  11761. at: startLoc
  11762. });
  11763. return;
  11764. }
  11765. }
  11766. if (checkKeywords && isKeyword(word)) {
  11767. this.raise(Errors.UnexpectedKeyword, {
  11768. at: startLoc,
  11769. keyword: word
  11770. });
  11771. return;
  11772. }
  11773. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  11774. if (reservedTest(word, this.inModule)) {
  11775. this.raise(Errors.UnexpectedReservedWord, {
  11776. at: startLoc,
  11777. reservedWord: word
  11778. });
  11779. }
  11780. }
  11781. isAwaitAllowed() {
  11782. if (this.prodParam.hasAwait) return true;
  11783. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  11784. return true;
  11785. }
  11786. return false;
  11787. }
  11788. parseAwait(startPos, startLoc) {
  11789. const node = this.startNodeAt(startPos, startLoc);
  11790. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
  11791. at: node
  11792. });
  11793. if (this.eat(55)) {
  11794. this.raise(Errors.ObsoleteAwaitStar, {
  11795. at: node
  11796. });
  11797. }
  11798. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  11799. if (this.isAmbiguousAwait()) {
  11800. this.ambiguousScriptDifferentAst = true;
  11801. } else {
  11802. this.sawUnambiguousESM = true;
  11803. }
  11804. }
  11805. if (!this.state.soloAwait) {
  11806. node.argument = this.parseMaybeUnary(null, true);
  11807. }
  11808. return this.finishNode(node, "AwaitExpression");
  11809. }
  11810. isAmbiguousAwait() {
  11811. if (this.hasPrecedingLineBreak()) return true;
  11812. const {
  11813. type
  11814. } = this.state;
  11815. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 133 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  11816. }
  11817. parseYield() {
  11818. const node = this.startNode();
  11819. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
  11820. at: node
  11821. });
  11822. this.next();
  11823. let delegating = false;
  11824. let argument = null;
  11825. if (!this.hasPrecedingLineBreak()) {
  11826. delegating = this.eat(55);
  11827. switch (this.state.type) {
  11828. case 13:
  11829. case 135:
  11830. case 8:
  11831. case 11:
  11832. case 3:
  11833. case 9:
  11834. case 14:
  11835. case 12:
  11836. if (!delegating) break;
  11837. default:
  11838. argument = this.parseMaybeAssign();
  11839. }
  11840. }
  11841. node.delegate = delegating;
  11842. node.argument = argument;
  11843. return this.finishNode(node, "YieldExpression");
  11844. }
  11845. checkPipelineAtInfixOperator(left, leftStartLoc) {
  11846. if (this.hasPlugin(["pipelineOperator", {
  11847. proposal: "smart"
  11848. }])) {
  11849. if (left.type === "SequenceExpression") {
  11850. this.raise(Errors.PipelineHeadSequenceExpression, {
  11851. at: leftStartLoc
  11852. });
  11853. }
  11854. }
  11855. }
  11856. parseSmartPipelineBodyInStyle(childExpr, startPos, startLoc) {
  11857. const bodyNode = this.startNodeAt(startPos, startLoc);
  11858. if (this.isSimpleReference(childExpr)) {
  11859. bodyNode.callee = childExpr;
  11860. return this.finishNode(bodyNode, "PipelineBareFunction");
  11861. } else {
  11862. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  11863. bodyNode.expression = childExpr;
  11864. return this.finishNode(bodyNode, "PipelineTopicExpression");
  11865. }
  11866. }
  11867. isSimpleReference(expression) {
  11868. switch (expression.type) {
  11869. case "MemberExpression":
  11870. return !expression.computed && this.isSimpleReference(expression.object);
  11871. case "Identifier":
  11872. return true;
  11873. default:
  11874. return false;
  11875. }
  11876. }
  11877. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  11878. if (this.match(19)) {
  11879. throw this.raise(Errors.PipelineBodyNoArrow, {
  11880. at: this.state.startLoc
  11881. });
  11882. }
  11883. if (!this.topicReferenceWasUsedInCurrentContext()) {
  11884. this.raise(Errors.PipelineTopicUnused, {
  11885. at: startLoc
  11886. });
  11887. }
  11888. }
  11889. withTopicBindingContext(callback) {
  11890. const outerContextTopicState = this.state.topicContext;
  11891. this.state.topicContext = {
  11892. maxNumOfResolvableTopics: 1,
  11893. maxTopicIndex: null
  11894. };
  11895. try {
  11896. return callback();
  11897. } finally {
  11898. this.state.topicContext = outerContextTopicState;
  11899. }
  11900. }
  11901. withSmartMixTopicForbiddingContext(callback) {
  11902. if (this.hasPlugin(["pipelineOperator", {
  11903. proposal: "smart"
  11904. }])) {
  11905. const outerContextTopicState = this.state.topicContext;
  11906. this.state.topicContext = {
  11907. maxNumOfResolvableTopics: 0,
  11908. maxTopicIndex: null
  11909. };
  11910. try {
  11911. return callback();
  11912. } finally {
  11913. this.state.topicContext = outerContextTopicState;
  11914. }
  11915. } else {
  11916. return callback();
  11917. }
  11918. }
  11919. withSoloAwaitPermittingContext(callback) {
  11920. const outerContextSoloAwaitState = this.state.soloAwait;
  11921. this.state.soloAwait = true;
  11922. try {
  11923. return callback();
  11924. } finally {
  11925. this.state.soloAwait = outerContextSoloAwaitState;
  11926. }
  11927. }
  11928. allowInAnd(callback) {
  11929. const flags = this.prodParam.currentFlags();
  11930. const prodParamToSet = PARAM_IN & ~flags;
  11931. if (prodParamToSet) {
  11932. this.prodParam.enter(flags | PARAM_IN);
  11933. try {
  11934. return callback();
  11935. } finally {
  11936. this.prodParam.exit();
  11937. }
  11938. }
  11939. return callback();
  11940. }
  11941. disallowInAnd(callback) {
  11942. const flags = this.prodParam.currentFlags();
  11943. const prodParamToClear = PARAM_IN & flags;
  11944. if (prodParamToClear) {
  11945. this.prodParam.enter(flags & ~PARAM_IN);
  11946. try {
  11947. return callback();
  11948. } finally {
  11949. this.prodParam.exit();
  11950. }
  11951. }
  11952. return callback();
  11953. }
  11954. registerTopicReference() {
  11955. this.state.topicContext.maxTopicIndex = 0;
  11956. }
  11957. topicReferenceIsAllowedInCurrentContext() {
  11958. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  11959. }
  11960. topicReferenceWasUsedInCurrentContext() {
  11961. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  11962. }
  11963. parseFSharpPipelineBody(prec) {
  11964. const startPos = this.state.start;
  11965. const startLoc = this.state.startLoc;
  11966. this.state.potentialArrowAt = this.state.start;
  11967. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11968. this.state.inFSharpPipelineDirectBody = true;
  11969. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startPos, startLoc, prec);
  11970. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11971. return ret;
  11972. }
  11973. parseModuleExpression() {
  11974. this.expectPlugin("moduleBlocks");
  11975. const node = this.startNode();
  11976. this.next();
  11977. this.eat(5);
  11978. const revertScopes = this.initializeScopes(true);
  11979. this.enterInitialScopes();
  11980. const program = this.startNode();
  11981. try {
  11982. node.body = this.parseProgram(program, 8, "module");
  11983. } finally {
  11984. revertScopes();
  11985. }
  11986. this.eat(8);
  11987. return this.finishNode(node, "ModuleExpression");
  11988. }
  11989. parsePropertyNamePrefixOperator(prop) {}
  11990. }
  11991. const loopLabel = {
  11992. kind: "loop"
  11993. },
  11994. switchLabel = {
  11995. kind: "switch"
  11996. };
  11997. const FUNC_NO_FLAGS = 0b000,
  11998. FUNC_STATEMENT = 0b001,
  11999. FUNC_HANGING_STATEMENT = 0b010,
  12000. FUNC_NULLABLE_ID = 0b100;
  12001. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12002. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12003. function babel7CompatTokens(tokens, input) {
  12004. for (let i = 0; i < tokens.length; i++) {
  12005. const token = tokens[i];
  12006. const {
  12007. type
  12008. } = token;
  12009. if (typeof type === "number") {
  12010. {
  12011. if (type === 134) {
  12012. const {
  12013. loc,
  12014. start,
  12015. value,
  12016. end
  12017. } = token;
  12018. const hashEndPos = start + 1;
  12019. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12020. tokens.splice(i, 1, new Token({
  12021. type: getExportedToken(27),
  12022. value: "#",
  12023. start: start,
  12024. end: hashEndPos,
  12025. startLoc: loc.start,
  12026. endLoc: hashEndLoc
  12027. }), new Token({
  12028. type: getExportedToken(128),
  12029. value: value,
  12030. start: hashEndPos,
  12031. end: end,
  12032. startLoc: hashEndLoc,
  12033. endLoc: loc.end
  12034. }));
  12035. i++;
  12036. continue;
  12037. }
  12038. if (tokenIsTemplate(type)) {
  12039. const {
  12040. loc,
  12041. start,
  12042. value,
  12043. end
  12044. } = token;
  12045. const backquoteEnd = start + 1;
  12046. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12047. let startToken;
  12048. if (input.charCodeAt(start) === 96) {
  12049. startToken = new Token({
  12050. type: getExportedToken(22),
  12051. value: "`",
  12052. start: start,
  12053. end: backquoteEnd,
  12054. startLoc: loc.start,
  12055. endLoc: backquoteEndLoc
  12056. });
  12057. } else {
  12058. startToken = new Token({
  12059. type: getExportedToken(8),
  12060. value: "}",
  12061. start: start,
  12062. end: backquoteEnd,
  12063. startLoc: loc.start,
  12064. endLoc: backquoteEndLoc
  12065. });
  12066. }
  12067. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12068. if (type === 24) {
  12069. templateElementEnd = end - 1;
  12070. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12071. templateValue = value === null ? null : value.slice(1, -1);
  12072. endToken = new Token({
  12073. type: getExportedToken(22),
  12074. value: "`",
  12075. start: templateElementEnd,
  12076. end: end,
  12077. startLoc: templateElementEndLoc,
  12078. endLoc: loc.end
  12079. });
  12080. } else {
  12081. templateElementEnd = end - 2;
  12082. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12083. templateValue = value === null ? null : value.slice(1, -2);
  12084. endToken = new Token({
  12085. type: getExportedToken(23),
  12086. value: "${",
  12087. start: templateElementEnd,
  12088. end: end,
  12089. startLoc: templateElementEndLoc,
  12090. endLoc: loc.end
  12091. });
  12092. }
  12093. tokens.splice(i, 1, startToken, new Token({
  12094. type: getExportedToken(20),
  12095. value: templateValue,
  12096. start: backquoteEnd,
  12097. end: templateElementEnd,
  12098. startLoc: backquoteEndLoc,
  12099. endLoc: templateElementEndLoc
  12100. }), endToken);
  12101. i += 2;
  12102. continue;
  12103. }
  12104. }
  12105. token.type = getExportedToken(type);
  12106. }
  12107. }
  12108. return tokens;
  12109. }
  12110. class StatementParser extends ExpressionParser {
  12111. parseTopLevel(file, program) {
  12112. file.program = this.parseProgram(program);
  12113. file.comments = this.state.comments;
  12114. if (this.options.tokens) {
  12115. file.tokens = babel7CompatTokens(this.tokens, this.input);
  12116. }
  12117. return this.finishNode(file, "File");
  12118. }
  12119. parseProgram(program, end = 135, sourceType = this.options.sourceType) {
  12120. program.sourceType = sourceType;
  12121. program.interpreter = this.parseInterpreterDirective();
  12122. this.parseBlockBody(program, true, true, end);
  12123. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  12124. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12125. this.raise(Errors.ModuleExportUndefined, {
  12126. at,
  12127. localName
  12128. });
  12129. }
  12130. }
  12131. return this.finishNode(program, "Program");
  12132. }
  12133. stmtToDirective(stmt) {
  12134. const directive = stmt;
  12135. directive.type = "Directive";
  12136. directive.value = directive.expression;
  12137. delete directive.expression;
  12138. const directiveLiteral = directive.value;
  12139. const expressionValue = directiveLiteral.value;
  12140. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  12141. const val = directiveLiteral.value = raw.slice(1, -1);
  12142. this.addExtra(directiveLiteral, "raw", raw);
  12143. this.addExtra(directiveLiteral, "rawValue", val);
  12144. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12145. directiveLiteral.type = "DirectiveLiteral";
  12146. return directive;
  12147. }
  12148. parseInterpreterDirective() {
  12149. if (!this.match(28)) {
  12150. return null;
  12151. }
  12152. const node = this.startNode();
  12153. node.value = this.state.value;
  12154. this.next();
  12155. return this.finishNode(node, "InterpreterDirective");
  12156. }
  12157. isLet(context) {
  12158. if (!this.isContextual(99)) {
  12159. return false;
  12160. }
  12161. return this.isLetKeyword(context);
  12162. }
  12163. isLetKeyword(context) {
  12164. const next = this.nextTokenStart();
  12165. const nextCh = this.codePointAtPos(next);
  12166. if (nextCh === 92 || nextCh === 91) {
  12167. return true;
  12168. }
  12169. if (context) return false;
  12170. if (nextCh === 123) return true;
  12171. if (isIdentifierStart(nextCh)) {
  12172. keywordRelationalOperator.lastIndex = next;
  12173. if (keywordRelationalOperator.test(this.input)) {
  12174. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12175. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12176. return false;
  12177. }
  12178. }
  12179. return true;
  12180. }
  12181. return false;
  12182. }
  12183. parseStatement(context, topLevel) {
  12184. if (this.match(26)) {
  12185. this.parseDecorators(true);
  12186. }
  12187. return this.parseStatementContent(context, topLevel);
  12188. }
  12189. parseStatementContent(context, topLevel) {
  12190. let starttype = this.state.type;
  12191. const node = this.startNode();
  12192. let kind;
  12193. if (this.isLet(context)) {
  12194. starttype = 74;
  12195. kind = "let";
  12196. }
  12197. switch (starttype) {
  12198. case 60:
  12199. return this.parseBreakContinueStatement(node, true);
  12200. case 63:
  12201. return this.parseBreakContinueStatement(node, false);
  12202. case 64:
  12203. return this.parseDebuggerStatement(node);
  12204. case 90:
  12205. return this.parseDoStatement(node);
  12206. case 91:
  12207. return this.parseForStatement(node);
  12208. case 68:
  12209. if (this.lookaheadCharCode() === 46) break;
  12210. if (context) {
  12211. if (this.state.strict) {
  12212. this.raise(Errors.StrictFunction, {
  12213. at: this.state.startLoc
  12214. });
  12215. } else if (context !== "if" && context !== "label") {
  12216. this.raise(Errors.SloppyFunction, {
  12217. at: this.state.startLoc
  12218. });
  12219. }
  12220. }
  12221. return this.parseFunctionStatement(node, false, !context);
  12222. case 80:
  12223. if (context) this.unexpected();
  12224. return this.parseClass(node, true);
  12225. case 69:
  12226. return this.parseIfStatement(node);
  12227. case 70:
  12228. return this.parseReturnStatement(node);
  12229. case 71:
  12230. return this.parseSwitchStatement(node);
  12231. case 72:
  12232. return this.parseThrowStatement(node);
  12233. case 73:
  12234. return this.parseTryStatement(node);
  12235. case 75:
  12236. case 74:
  12237. kind = kind || this.state.value;
  12238. if (context && kind !== "var") {
  12239. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12240. at: this.state.startLoc
  12241. });
  12242. }
  12243. return this.parseVarStatement(node, kind);
  12244. case 92:
  12245. return this.parseWhileStatement(node);
  12246. case 76:
  12247. return this.parseWithStatement(node);
  12248. case 5:
  12249. return this.parseBlock();
  12250. case 13:
  12251. return this.parseEmptyStatement(node);
  12252. case 83:
  12253. {
  12254. const nextTokenCharCode = this.lookaheadCharCode();
  12255. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12256. break;
  12257. }
  12258. }
  12259. case 82:
  12260. {
  12261. if (!this.options.allowImportExportEverywhere && !topLevel) {
  12262. this.raise(Errors.UnexpectedImportExport, {
  12263. at: this.state.startLoc
  12264. });
  12265. }
  12266. this.next();
  12267. let result;
  12268. if (starttype === 83) {
  12269. result = this.parseImport(node);
  12270. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12271. this.sawUnambiguousESM = true;
  12272. }
  12273. } else {
  12274. result = this.parseExport(node);
  12275. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12276. this.sawUnambiguousESM = true;
  12277. }
  12278. }
  12279. this.assertModuleNodeAllowed(node);
  12280. return result;
  12281. }
  12282. default:
  12283. {
  12284. if (this.isAsyncFunction()) {
  12285. if (context) {
  12286. this.raise(Errors.AsyncFunctionInSingleStatementContext, {
  12287. at: this.state.startLoc
  12288. });
  12289. }
  12290. this.next();
  12291. return this.parseFunctionStatement(node, true, !context);
  12292. }
  12293. }
  12294. }
  12295. const maybeName = this.state.value;
  12296. const expr = this.parseExpression();
  12297. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  12298. return this.parseLabeledStatement(node, maybeName, expr, context);
  12299. } else {
  12300. return this.parseExpressionStatement(node, expr);
  12301. }
  12302. }
  12303. assertModuleNodeAllowed(node) {
  12304. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  12305. this.raise(Errors.ImportOutsideModule, {
  12306. at: node
  12307. });
  12308. }
  12309. }
  12310. takeDecorators(node) {
  12311. const decorators = this.state.decoratorStack[this.state.decoratorStack.length - 1];
  12312. if (decorators.length) {
  12313. node.decorators = decorators;
  12314. this.resetStartLocationFromNode(node, decorators[0]);
  12315. this.state.decoratorStack[this.state.decoratorStack.length - 1] = [];
  12316. }
  12317. }
  12318. canHaveLeadingDecorator() {
  12319. return this.match(80);
  12320. }
  12321. parseDecorators(allowExport) {
  12322. const currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1];
  12323. while (this.match(26)) {
  12324. const decorator = this.parseDecorator();
  12325. currentContextDecorators.push(decorator);
  12326. }
  12327. if (this.match(82)) {
  12328. if (!allowExport) {
  12329. this.unexpected();
  12330. }
  12331. if (this.hasPlugin("decorators") && !this.getPluginOption("decorators", "decoratorsBeforeExport")) {
  12332. this.raise(Errors.DecoratorExportClass, {
  12333. at: this.state.startLoc
  12334. });
  12335. }
  12336. } else if (!this.canHaveLeadingDecorator()) {
  12337. throw this.raise(Errors.UnexpectedLeadingDecorator, {
  12338. at: this.state.startLoc
  12339. });
  12340. }
  12341. }
  12342. parseDecorator() {
  12343. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12344. const node = this.startNode();
  12345. this.next();
  12346. if (this.hasPlugin("decorators")) {
  12347. this.state.decoratorStack.push([]);
  12348. const startPos = this.state.start;
  12349. const startLoc = this.state.startLoc;
  12350. let expr;
  12351. if (this.match(10)) {
  12352. const startPos = this.state.start;
  12353. const startLoc = this.state.startLoc;
  12354. this.next();
  12355. expr = this.parseExpression();
  12356. this.expect(11);
  12357. expr = this.wrapParenthesis(startPos, startLoc, expr);
  12358. } else {
  12359. expr = this.parseIdentifier(false);
  12360. while (this.eat(16)) {
  12361. const node = this.startNodeAt(startPos, startLoc);
  12362. node.object = expr;
  12363. node.property = this.parseIdentifier(true);
  12364. node.computed = false;
  12365. expr = this.finishNode(node, "MemberExpression");
  12366. }
  12367. }
  12368. node.expression = this.parseMaybeDecoratorArguments(expr);
  12369. this.state.decoratorStack.pop();
  12370. } else {
  12371. node.expression = this.parseExprSubscripts();
  12372. }
  12373. return this.finishNode(node, "Decorator");
  12374. }
  12375. parseMaybeDecoratorArguments(expr) {
  12376. if (this.eat(10)) {
  12377. const node = this.startNodeAtNode(expr);
  12378. node.callee = expr;
  12379. node.arguments = this.parseCallExpressionArguments(11, false);
  12380. this.toReferencedList(node.arguments);
  12381. return this.finishNode(node, "CallExpression");
  12382. }
  12383. return expr;
  12384. }
  12385. parseBreakContinueStatement(node, isBreak) {
  12386. this.next();
  12387. if (this.isLineTerminator()) {
  12388. node.label = null;
  12389. } else {
  12390. node.label = this.parseIdentifier();
  12391. this.semicolon();
  12392. }
  12393. this.verifyBreakContinue(node, isBreak);
  12394. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12395. }
  12396. verifyBreakContinue(node, isBreak) {
  12397. let i;
  12398. for (i = 0; i < this.state.labels.length; ++i) {
  12399. const lab = this.state.labels[i];
  12400. if (node.label == null || lab.name === node.label.name) {
  12401. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  12402. if (node.label && isBreak) break;
  12403. }
  12404. }
  12405. if (i === this.state.labels.length) {
  12406. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12407. this.raise(Errors.IllegalBreakContinue, {
  12408. at: node,
  12409. type
  12410. });
  12411. }
  12412. }
  12413. parseDebuggerStatement(node) {
  12414. this.next();
  12415. this.semicolon();
  12416. return this.finishNode(node, "DebuggerStatement");
  12417. }
  12418. parseHeaderExpression() {
  12419. this.expect(10);
  12420. const val = this.parseExpression();
  12421. this.expect(11);
  12422. return val;
  12423. }
  12424. parseDoStatement(node) {
  12425. this.next();
  12426. this.state.labels.push(loopLabel);
  12427. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("do"));
  12428. this.state.labels.pop();
  12429. this.expect(92);
  12430. node.test = this.parseHeaderExpression();
  12431. this.eat(13);
  12432. return this.finishNode(node, "DoWhileStatement");
  12433. }
  12434. parseForStatement(node) {
  12435. this.next();
  12436. this.state.labels.push(loopLabel);
  12437. let awaitAt = null;
  12438. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  12439. awaitAt = this.state.lastTokStartLoc;
  12440. }
  12441. this.scope.enter(SCOPE_OTHER);
  12442. this.expect(10);
  12443. if (this.match(13)) {
  12444. if (awaitAt !== null) {
  12445. this.unexpected(awaitAt);
  12446. }
  12447. return this.parseFor(node, null);
  12448. }
  12449. const startsWithLet = this.isContextual(99);
  12450. const isLet = startsWithLet && this.isLetKeyword();
  12451. if (this.match(74) || this.match(75) || isLet) {
  12452. const init = this.startNode();
  12453. const kind = isLet ? "let" : this.state.value;
  12454. this.next();
  12455. this.parseVar(init, true, kind);
  12456. this.finishNode(init, "VariableDeclaration");
  12457. if ((this.match(58) || this.isContextual(101)) && init.declarations.length === 1) {
  12458. return this.parseForIn(node, init, awaitAt);
  12459. }
  12460. if (awaitAt !== null) {
  12461. this.unexpected(awaitAt);
  12462. }
  12463. return this.parseFor(node, init);
  12464. }
  12465. const startsWithAsync = this.isContextual(95);
  12466. const refExpressionErrors = new ExpressionErrors();
  12467. const init = this.parseExpression(true, refExpressionErrors);
  12468. const isForOf = this.isContextual(101);
  12469. if (isForOf) {
  12470. if (startsWithLet) {
  12471. this.raise(Errors.ForOfLet, {
  12472. at: init
  12473. });
  12474. }
  12475. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12476. this.raise(Errors.ForOfAsync, {
  12477. at: init
  12478. });
  12479. }
  12480. }
  12481. if (isForOf || this.match(58)) {
  12482. this.checkDestructuringPrivate(refExpressionErrors);
  12483. this.toAssignable(init, true);
  12484. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12485. this.checkLVal(init, {
  12486. in: {
  12487. type
  12488. }
  12489. });
  12490. return this.parseForIn(node, init, awaitAt);
  12491. } else {
  12492. this.checkExpressionErrors(refExpressionErrors, true);
  12493. }
  12494. if (awaitAt !== null) {
  12495. this.unexpected(awaitAt);
  12496. }
  12497. return this.parseFor(node, init);
  12498. }
  12499. parseFunctionStatement(node, isAsync, declarationPosition) {
  12500. this.next();
  12501. return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), isAsync);
  12502. }
  12503. parseIfStatement(node) {
  12504. this.next();
  12505. node.test = this.parseHeaderExpression();
  12506. node.consequent = this.parseStatement("if");
  12507. node.alternate = this.eat(66) ? this.parseStatement("if") : null;
  12508. return this.finishNode(node, "IfStatement");
  12509. }
  12510. parseReturnStatement(node) {
  12511. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  12512. this.raise(Errors.IllegalReturn, {
  12513. at: this.state.startLoc
  12514. });
  12515. }
  12516. this.next();
  12517. if (this.isLineTerminator()) {
  12518. node.argument = null;
  12519. } else {
  12520. node.argument = this.parseExpression();
  12521. this.semicolon();
  12522. }
  12523. return this.finishNode(node, "ReturnStatement");
  12524. }
  12525. parseSwitchStatement(node) {
  12526. this.next();
  12527. node.discriminant = this.parseHeaderExpression();
  12528. const cases = node.cases = [];
  12529. this.expect(5);
  12530. this.state.labels.push(switchLabel);
  12531. this.scope.enter(SCOPE_OTHER);
  12532. let cur;
  12533. for (let sawDefault; !this.match(8);) {
  12534. if (this.match(61) || this.match(65)) {
  12535. const isCase = this.match(61);
  12536. if (cur) this.finishNode(cur, "SwitchCase");
  12537. cases.push(cur = this.startNode());
  12538. cur.consequent = [];
  12539. this.next();
  12540. if (isCase) {
  12541. cur.test = this.parseExpression();
  12542. } else {
  12543. if (sawDefault) {
  12544. this.raise(Errors.MultipleDefaultsInSwitch, {
  12545. at: this.state.lastTokStartLoc
  12546. });
  12547. }
  12548. sawDefault = true;
  12549. cur.test = null;
  12550. }
  12551. this.expect(14);
  12552. } else {
  12553. if (cur) {
  12554. cur.consequent.push(this.parseStatement(null));
  12555. } else {
  12556. this.unexpected();
  12557. }
  12558. }
  12559. }
  12560. this.scope.exit();
  12561. if (cur) this.finishNode(cur, "SwitchCase");
  12562. this.next();
  12563. this.state.labels.pop();
  12564. return this.finishNode(node, "SwitchStatement");
  12565. }
  12566. parseThrowStatement(node) {
  12567. this.next();
  12568. if (this.hasPrecedingLineBreak()) {
  12569. this.raise(Errors.NewlineAfterThrow, {
  12570. at: this.state.lastTokEndLoc
  12571. });
  12572. }
  12573. node.argument = this.parseExpression();
  12574. this.semicolon();
  12575. return this.finishNode(node, "ThrowStatement");
  12576. }
  12577. parseCatchClauseParam() {
  12578. const param = this.parseBindingAtom();
  12579. const simple = param.type === "Identifier";
  12580. this.scope.enter(simple ? SCOPE_SIMPLE_CATCH : 0);
  12581. this.checkLVal(param, {
  12582. in: {
  12583. type: "CatchClause"
  12584. },
  12585. binding: BIND_LEXICAL,
  12586. allowingSloppyLetBinding: true
  12587. });
  12588. return param;
  12589. }
  12590. parseTryStatement(node) {
  12591. this.next();
  12592. node.block = this.parseBlock();
  12593. node.handler = null;
  12594. if (this.match(62)) {
  12595. const clause = this.startNode();
  12596. this.next();
  12597. if (this.match(10)) {
  12598. this.expect(10);
  12599. clause.param = this.parseCatchClauseParam();
  12600. this.expect(11);
  12601. } else {
  12602. clause.param = null;
  12603. this.scope.enter(SCOPE_OTHER);
  12604. }
  12605. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  12606. this.scope.exit();
  12607. node.handler = this.finishNode(clause, "CatchClause");
  12608. }
  12609. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  12610. if (!node.handler && !node.finalizer) {
  12611. this.raise(Errors.NoCatchOrFinally, {
  12612. at: node
  12613. });
  12614. }
  12615. return this.finishNode(node, "TryStatement");
  12616. }
  12617. parseVarStatement(node, kind, allowMissingInitializer = false) {
  12618. this.next();
  12619. this.parseVar(node, false, kind, allowMissingInitializer);
  12620. this.semicolon();
  12621. return this.finishNode(node, "VariableDeclaration");
  12622. }
  12623. parseWhileStatement(node) {
  12624. this.next();
  12625. node.test = this.parseHeaderExpression();
  12626. this.state.labels.push(loopLabel);
  12627. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("while"));
  12628. this.state.labels.pop();
  12629. return this.finishNode(node, "WhileStatement");
  12630. }
  12631. parseWithStatement(node) {
  12632. if (this.state.strict) {
  12633. this.raise(Errors.StrictWith, {
  12634. at: this.state.startLoc
  12635. });
  12636. }
  12637. this.next();
  12638. node.object = this.parseHeaderExpression();
  12639. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("with"));
  12640. return this.finishNode(node, "WithStatement");
  12641. }
  12642. parseEmptyStatement(node) {
  12643. this.next();
  12644. return this.finishNode(node, "EmptyStatement");
  12645. }
  12646. parseLabeledStatement(node, maybeName, expr, context) {
  12647. for (const label of this.state.labels) {
  12648. if (label.name === maybeName) {
  12649. this.raise(Errors.LabelRedeclaration, {
  12650. at: expr,
  12651. labelName: maybeName
  12652. });
  12653. }
  12654. }
  12655. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
  12656. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  12657. const label = this.state.labels[i];
  12658. if (label.statementStart === node.start) {
  12659. label.statementStart = this.state.start;
  12660. label.kind = kind;
  12661. } else {
  12662. break;
  12663. }
  12664. }
  12665. this.state.labels.push({
  12666. name: maybeName,
  12667. kind: kind,
  12668. statementStart: this.state.start
  12669. });
  12670. node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
  12671. this.state.labels.pop();
  12672. node.label = expr;
  12673. return this.finishNode(node, "LabeledStatement");
  12674. }
  12675. parseExpressionStatement(node, expr) {
  12676. node.expression = expr;
  12677. this.semicolon();
  12678. return this.finishNode(node, "ExpressionStatement");
  12679. }
  12680. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  12681. const node = this.startNode();
  12682. if (allowDirectives) {
  12683. this.state.strictErrors.clear();
  12684. }
  12685. this.expect(5);
  12686. if (createNewLexicalScope) {
  12687. this.scope.enter(SCOPE_OTHER);
  12688. }
  12689. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  12690. if (createNewLexicalScope) {
  12691. this.scope.exit();
  12692. }
  12693. return this.finishNode(node, "BlockStatement");
  12694. }
  12695. isValidDirective(stmt) {
  12696. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  12697. }
  12698. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  12699. const body = node.body = [];
  12700. const directives = node.directives = [];
  12701. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  12702. }
  12703. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  12704. const oldStrict = this.state.strict;
  12705. let hasStrictModeDirective = false;
  12706. let parsedNonDirective = false;
  12707. while (!this.match(end)) {
  12708. const stmt = this.parseStatement(null, topLevel);
  12709. if (directives && !parsedNonDirective) {
  12710. if (this.isValidDirective(stmt)) {
  12711. const directive = this.stmtToDirective(stmt);
  12712. directives.push(directive);
  12713. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  12714. hasStrictModeDirective = true;
  12715. this.setStrict(true);
  12716. }
  12717. continue;
  12718. }
  12719. parsedNonDirective = true;
  12720. this.state.strictErrors.clear();
  12721. }
  12722. body.push(stmt);
  12723. }
  12724. if (afterBlockParse) {
  12725. afterBlockParse.call(this, hasStrictModeDirective);
  12726. }
  12727. if (!oldStrict) {
  12728. this.setStrict(false);
  12729. }
  12730. this.next();
  12731. }
  12732. parseFor(node, init) {
  12733. node.init = init;
  12734. this.semicolon(false);
  12735. node.test = this.match(13) ? null : this.parseExpression();
  12736. this.semicolon(false);
  12737. node.update = this.match(11) ? null : this.parseExpression();
  12738. this.expect(11);
  12739. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("for"));
  12740. this.scope.exit();
  12741. this.state.labels.pop();
  12742. return this.finishNode(node, "ForStatement");
  12743. }
  12744. parseForIn(node, init, awaitAt) {
  12745. const isForIn = this.match(58);
  12746. this.next();
  12747. if (isForIn) {
  12748. if (awaitAt !== null) this.unexpected(awaitAt);
  12749. } else {
  12750. node.await = awaitAt !== null;
  12751. }
  12752. if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) {
  12753. this.raise(Errors.ForInOfLoopInitializer, {
  12754. at: init,
  12755. type: isForIn ? "ForInStatement" : "ForOfStatement"
  12756. });
  12757. }
  12758. if (init.type === "AssignmentPattern") {
  12759. this.raise(Errors.InvalidLhs, {
  12760. at: init,
  12761. ancestor: {
  12762. type: "ForStatement"
  12763. }
  12764. });
  12765. }
  12766. node.left = init;
  12767. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  12768. this.expect(11);
  12769. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("for"));
  12770. this.scope.exit();
  12771. this.state.labels.pop();
  12772. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  12773. }
  12774. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  12775. const declarations = node.declarations = [];
  12776. node.kind = kind;
  12777. for (;;) {
  12778. const decl = this.startNode();
  12779. this.parseVarId(decl, kind);
  12780. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  12781. if (decl.init === null && !allowMissingInitializer) {
  12782. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(101)))) {
  12783. this.raise(Errors.DeclarationMissingInitializer, {
  12784. at: this.state.lastTokEndLoc,
  12785. kind: "destructuring"
  12786. });
  12787. } else if (kind === "const" && !(this.match(58) || this.isContextual(101))) {
  12788. this.raise(Errors.DeclarationMissingInitializer, {
  12789. at: this.state.lastTokEndLoc,
  12790. kind: "const"
  12791. });
  12792. }
  12793. }
  12794. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  12795. if (!this.eat(12)) break;
  12796. }
  12797. return node;
  12798. }
  12799. parseVarId(decl, kind) {
  12800. decl.id = this.parseBindingAtom();
  12801. this.checkLVal(decl.id, {
  12802. in: {
  12803. type: "VariableDeclarator"
  12804. },
  12805. binding: kind === "var" ? BIND_VAR : BIND_LEXICAL
  12806. });
  12807. }
  12808. parseFunction(node, statement = FUNC_NO_FLAGS, isAsync = false) {
  12809. const isStatement = statement & FUNC_STATEMENT;
  12810. const isHangingStatement = statement & FUNC_HANGING_STATEMENT;
  12811. const requireId = !!isStatement && !(statement & FUNC_NULLABLE_ID);
  12812. this.initFunction(node, isAsync);
  12813. if (this.match(55) && isHangingStatement) {
  12814. this.raise(Errors.GeneratorInSingleStatementContext, {
  12815. at: this.state.startLoc
  12816. });
  12817. }
  12818. node.generator = this.eat(55);
  12819. if (isStatement) {
  12820. node.id = this.parseFunctionId(requireId);
  12821. }
  12822. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12823. this.state.maybeInArrowParameters = false;
  12824. this.scope.enter(SCOPE_FUNCTION);
  12825. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12826. if (!isStatement) {
  12827. node.id = this.parseFunctionId();
  12828. }
  12829. this.parseFunctionParams(node, false);
  12830. this.withSmartMixTopicForbiddingContext(() => {
  12831. this.parseFunctionBodyAndFinish(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
  12832. });
  12833. this.prodParam.exit();
  12834. this.scope.exit();
  12835. if (isStatement && !isHangingStatement) {
  12836. this.registerFunctionStatementId(node);
  12837. }
  12838. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12839. return node;
  12840. }
  12841. parseFunctionId(requireId) {
  12842. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  12843. }
  12844. parseFunctionParams(node, allowModifiers) {
  12845. this.expect(10);
  12846. this.expressionScope.enter(newParameterDeclarationScope());
  12847. node.params = this.parseBindingList(11, 41, false, allowModifiers);
  12848. this.expressionScope.exit();
  12849. }
  12850. registerFunctionStatementId(node) {
  12851. if (!node.id) return;
  12852. 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);
  12853. }
  12854. parseClass(node, isStatement, optionalId) {
  12855. this.next();
  12856. this.takeDecorators(node);
  12857. const oldStrict = this.state.strict;
  12858. this.state.strict = true;
  12859. this.parseClassId(node, isStatement, optionalId);
  12860. this.parseClassSuper(node);
  12861. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  12862. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  12863. }
  12864. isClassProperty() {
  12865. return this.match(29) || this.match(13) || this.match(8);
  12866. }
  12867. isClassMethod() {
  12868. return this.match(10);
  12869. }
  12870. isNonstaticConstructor(method) {
  12871. return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
  12872. }
  12873. parseClassBody(hadSuperClass, oldStrict) {
  12874. this.classScope.enter();
  12875. const state = {
  12876. hadConstructor: false,
  12877. hadSuperClass
  12878. };
  12879. let decorators = [];
  12880. const classBody = this.startNode();
  12881. classBody.body = [];
  12882. this.expect(5);
  12883. this.withSmartMixTopicForbiddingContext(() => {
  12884. while (!this.match(8)) {
  12885. if (this.eat(13)) {
  12886. if (decorators.length > 0) {
  12887. throw this.raise(Errors.DecoratorSemicolon, {
  12888. at: this.state.lastTokEndLoc
  12889. });
  12890. }
  12891. continue;
  12892. }
  12893. if (this.match(26)) {
  12894. decorators.push(this.parseDecorator());
  12895. continue;
  12896. }
  12897. const member = this.startNode();
  12898. if (decorators.length) {
  12899. member.decorators = decorators;
  12900. this.resetStartLocationFromNode(member, decorators[0]);
  12901. decorators = [];
  12902. }
  12903. this.parseClassMember(classBody, member, state);
  12904. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  12905. this.raise(Errors.DecoratorConstructor, {
  12906. at: member
  12907. });
  12908. }
  12909. }
  12910. });
  12911. this.state.strict = oldStrict;
  12912. this.next();
  12913. if (decorators.length) {
  12914. throw this.raise(Errors.TrailingDecorator, {
  12915. at: this.state.startLoc
  12916. });
  12917. }
  12918. this.classScope.exit();
  12919. return this.finishNode(classBody, "ClassBody");
  12920. }
  12921. parseClassMemberFromModifier(classBody, member) {
  12922. const key = this.parseIdentifier(true);
  12923. if (this.isClassMethod()) {
  12924. const method = member;
  12925. method.kind = "method";
  12926. method.computed = false;
  12927. method.key = key;
  12928. method.static = false;
  12929. this.pushClassMethod(classBody, method, false, false, false, false);
  12930. return true;
  12931. } else if (this.isClassProperty()) {
  12932. const prop = member;
  12933. prop.computed = false;
  12934. prop.key = key;
  12935. prop.static = false;
  12936. classBody.body.push(this.parseClassProperty(prop));
  12937. return true;
  12938. }
  12939. this.resetPreviousNodeTrailingComments(key);
  12940. return false;
  12941. }
  12942. parseClassMember(classBody, member, state) {
  12943. const isStatic = this.isContextual(104);
  12944. if (isStatic) {
  12945. if (this.parseClassMemberFromModifier(classBody, member)) {
  12946. return;
  12947. }
  12948. if (this.eat(5)) {
  12949. this.parseClassStaticBlock(classBody, member);
  12950. return;
  12951. }
  12952. }
  12953. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  12954. }
  12955. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  12956. const publicMethod = member;
  12957. const privateMethod = member;
  12958. const publicProp = member;
  12959. const privateProp = member;
  12960. const accessorProp = member;
  12961. const method = publicMethod;
  12962. const publicMember = publicMethod;
  12963. member.static = isStatic;
  12964. this.parsePropertyNamePrefixOperator(member);
  12965. if (this.eat(55)) {
  12966. method.kind = "method";
  12967. const isPrivateName = this.match(134);
  12968. this.parseClassElementName(method);
  12969. if (isPrivateName) {
  12970. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  12971. return;
  12972. }
  12973. if (this.isNonstaticConstructor(publicMethod)) {
  12974. this.raise(Errors.ConstructorIsGenerator, {
  12975. at: publicMethod.key
  12976. });
  12977. }
  12978. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  12979. return;
  12980. }
  12981. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  12982. const isPrivate = this.match(134);
  12983. const key = this.parseClassElementName(member);
  12984. const maybeQuestionTokenStartLoc = this.state.startLoc;
  12985. this.parsePostMemberNameModifiers(publicMember);
  12986. if (this.isClassMethod()) {
  12987. method.kind = "method";
  12988. if (isPrivate) {
  12989. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  12990. return;
  12991. }
  12992. const isConstructor = this.isNonstaticConstructor(publicMethod);
  12993. let allowsDirectSuper = false;
  12994. if (isConstructor) {
  12995. publicMethod.kind = "constructor";
  12996. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  12997. this.raise(Errors.DuplicateConstructor, {
  12998. at: key
  12999. });
  13000. }
  13001. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13002. this.raise(Errors.OverrideOnConstructor, {
  13003. at: key
  13004. });
  13005. }
  13006. state.hadConstructor = true;
  13007. allowsDirectSuper = state.hadSuperClass;
  13008. }
  13009. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13010. } else if (this.isClassProperty()) {
  13011. if (isPrivate) {
  13012. this.pushClassPrivateProperty(classBody, privateProp);
  13013. } else {
  13014. this.pushClassProperty(classBody, publicProp);
  13015. }
  13016. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  13017. this.resetPreviousNodeTrailingComments(key);
  13018. const isGenerator = this.eat(55);
  13019. if (publicMember.optional) {
  13020. this.unexpected(maybeQuestionTokenStartLoc);
  13021. }
  13022. method.kind = "method";
  13023. const isPrivate = this.match(134);
  13024. this.parseClassElementName(method);
  13025. this.parsePostMemberNameModifiers(publicMember);
  13026. if (isPrivate) {
  13027. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13028. } else {
  13029. if (this.isNonstaticConstructor(publicMethod)) {
  13030. this.raise(Errors.ConstructorIsAsync, {
  13031. at: publicMethod.key
  13032. });
  13033. }
  13034. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13035. }
  13036. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
  13037. this.resetPreviousNodeTrailingComments(key);
  13038. method.kind = key.name;
  13039. const isPrivate = this.match(134);
  13040. this.parseClassElementName(publicMethod);
  13041. if (isPrivate) {
  13042. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13043. } else {
  13044. if (this.isNonstaticConstructor(publicMethod)) {
  13045. this.raise(Errors.ConstructorIsAccessor, {
  13046. at: publicMethod.key
  13047. });
  13048. }
  13049. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13050. }
  13051. this.checkGetterSetterParams(publicMethod);
  13052. } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
  13053. this.expectPlugin("decoratorAutoAccessors");
  13054. this.resetPreviousNodeTrailingComments(key);
  13055. const isPrivate = this.match(134);
  13056. this.parseClassElementName(publicProp);
  13057. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13058. } else if (this.isLineTerminator()) {
  13059. if (isPrivate) {
  13060. this.pushClassPrivateProperty(classBody, privateProp);
  13061. } else {
  13062. this.pushClassProperty(classBody, publicProp);
  13063. }
  13064. } else {
  13065. this.unexpected();
  13066. }
  13067. }
  13068. parseClassElementName(member) {
  13069. const {
  13070. type,
  13071. value
  13072. } = this.state;
  13073. if ((type === 128 || type === 129) && member.static && value === "prototype") {
  13074. this.raise(Errors.StaticPrototype, {
  13075. at: this.state.startLoc
  13076. });
  13077. }
  13078. if (type === 134) {
  13079. if (value === "constructor") {
  13080. this.raise(Errors.ConstructorClassPrivateField, {
  13081. at: this.state.startLoc
  13082. });
  13083. }
  13084. const key = this.parsePrivateName();
  13085. member.key = key;
  13086. return key;
  13087. }
  13088. return this.parsePropertyName(member);
  13089. }
  13090. parseClassStaticBlock(classBody, member) {
  13091. var _member$decorators;
  13092. this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER);
  13093. const oldLabels = this.state.labels;
  13094. this.state.labels = [];
  13095. this.prodParam.enter(PARAM);
  13096. const body = member.body = [];
  13097. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13098. this.prodParam.exit();
  13099. this.scope.exit();
  13100. this.state.labels = oldLabels;
  13101. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13102. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13103. this.raise(Errors.DecoratorStaticBlock, {
  13104. at: member
  13105. });
  13106. }
  13107. }
  13108. pushClassProperty(classBody, prop) {
  13109. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  13110. this.raise(Errors.ConstructorClassField, {
  13111. at: prop.key
  13112. });
  13113. }
  13114. classBody.body.push(this.parseClassProperty(prop));
  13115. }
  13116. pushClassPrivateProperty(classBody, prop) {
  13117. const node = this.parseClassPrivateProperty(prop);
  13118. classBody.body.push(node);
  13119. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  13120. }
  13121. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13122. if (!isPrivate && !prop.computed) {
  13123. const key = prop.key;
  13124. if (key.name === "constructor" || key.value === "constructor") {
  13125. this.raise(Errors.ConstructorClassField, {
  13126. at: key
  13127. });
  13128. }
  13129. }
  13130. const node = this.parseClassAccessorProperty(prop);
  13131. classBody.body.push(node);
  13132. if (isPrivate) {
  13133. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.loc.start);
  13134. }
  13135. }
  13136. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13137. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13138. }
  13139. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13140. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13141. classBody.body.push(node);
  13142. 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;
  13143. this.declareClassPrivateMethodInScope(node, kind);
  13144. }
  13145. declareClassPrivateMethodInScope(node, kind) {
  13146. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13147. }
  13148. parsePostMemberNameModifiers(methodOrProp) {}
  13149. parseClassPrivateProperty(node) {
  13150. this.parseInitializer(node);
  13151. this.semicolon();
  13152. return this.finishNode(node, "ClassPrivateProperty");
  13153. }
  13154. parseClassProperty(node) {
  13155. this.parseInitializer(node);
  13156. this.semicolon();
  13157. return this.finishNode(node, "ClassProperty");
  13158. }
  13159. parseClassAccessorProperty(node) {
  13160. this.parseInitializer(node);
  13161. this.semicolon();
  13162. return this.finishNode(node, "ClassAccessorProperty");
  13163. }
  13164. parseInitializer(node) {
  13165. this.scope.enter(SCOPE_CLASS | SCOPE_SUPER);
  13166. this.expressionScope.enter(newExpressionScope());
  13167. this.prodParam.enter(PARAM);
  13168. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13169. this.expressionScope.exit();
  13170. this.prodParam.exit();
  13171. this.scope.exit();
  13172. }
  13173. parseClassId(node, isStatement, optionalId, bindingType = BIND_CLASS) {
  13174. if (tokenIsIdentifier(this.state.type)) {
  13175. node.id = this.parseIdentifier();
  13176. if (isStatement) {
  13177. this.declareNameFromIdentifier(node.id, bindingType);
  13178. }
  13179. } else {
  13180. if (optionalId || !isStatement) {
  13181. node.id = null;
  13182. } else {
  13183. throw this.raise(Errors.MissingClassName, {
  13184. at: this.state.startLoc
  13185. });
  13186. }
  13187. }
  13188. }
  13189. parseClassSuper(node) {
  13190. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13191. }
  13192. parseExport(node) {
  13193. const hasDefault = this.maybeParseExportDefaultSpecifier(node);
  13194. const parseAfterDefault = !hasDefault || this.eat(12);
  13195. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13196. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13197. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13198. const isFromRequired = hasDefault || hasStar;
  13199. if (hasStar && !hasNamespace) {
  13200. if (hasDefault) this.unexpected();
  13201. this.parseExportFrom(node, true);
  13202. return this.finishNode(node, "ExportAllDeclaration");
  13203. }
  13204. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13205. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers || hasNamespace && parseAfterNamespace && !hasSpecifiers) {
  13206. throw this.unexpected(null, 5);
  13207. }
  13208. let hasDeclaration;
  13209. if (isFromRequired || hasSpecifiers) {
  13210. hasDeclaration = false;
  13211. this.parseExportFrom(node, isFromRequired);
  13212. } else {
  13213. hasDeclaration = this.maybeParseExportDeclaration(node);
  13214. }
  13215. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13216. this.checkExport(node, true, false, !!node.source);
  13217. return this.finishNode(node, "ExportNamedDeclaration");
  13218. }
  13219. if (this.eat(65)) {
  13220. node.declaration = this.parseExportDefaultExpression();
  13221. this.checkExport(node, true, true);
  13222. return this.finishNode(node, "ExportDefaultDeclaration");
  13223. }
  13224. throw this.unexpected(null, 5);
  13225. }
  13226. eatExportStar(node) {
  13227. return this.eat(55);
  13228. }
  13229. maybeParseExportDefaultSpecifier(node) {
  13230. if (this.isExportDefaultSpecifier()) {
  13231. this.expectPlugin("exportDefaultFrom");
  13232. const specifier = this.startNode();
  13233. specifier.exported = this.parseIdentifier(true);
  13234. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13235. return true;
  13236. }
  13237. return false;
  13238. }
  13239. maybeParseExportNamespaceSpecifier(node) {
  13240. if (this.isContextual(93)) {
  13241. if (!node.specifiers) node.specifiers = [];
  13242. const specifier = this.startNodeAt(this.state.lastTokStart, this.state.lastTokStartLoc);
  13243. this.next();
  13244. specifier.exported = this.parseModuleExportName();
  13245. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13246. return true;
  13247. }
  13248. return false;
  13249. }
  13250. maybeParseExportNamedSpecifiers(node) {
  13251. if (this.match(5)) {
  13252. if (!node.specifiers) node.specifiers = [];
  13253. const isTypeExport = node.exportKind === "type";
  13254. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13255. node.source = null;
  13256. node.declaration = null;
  13257. if (this.hasPlugin("importAssertions")) {
  13258. node.assertions = [];
  13259. }
  13260. return true;
  13261. }
  13262. return false;
  13263. }
  13264. maybeParseExportDeclaration(node) {
  13265. if (this.shouldParseExportDeclaration()) {
  13266. node.specifiers = [];
  13267. node.source = null;
  13268. if (this.hasPlugin("importAssertions")) {
  13269. node.assertions = [];
  13270. }
  13271. node.declaration = this.parseExportDeclaration(node);
  13272. return true;
  13273. }
  13274. return false;
  13275. }
  13276. isAsyncFunction() {
  13277. if (!this.isContextual(95)) return false;
  13278. const next = this.nextTokenStart();
  13279. return !lineBreak.test(this.input.slice(this.state.pos, next)) && this.isUnparsedContextual(next, "function");
  13280. }
  13281. parseExportDefaultExpression() {
  13282. const expr = this.startNode();
  13283. const isAsync = this.isAsyncFunction();
  13284. if (this.match(68) || isAsync) {
  13285. this.next();
  13286. if (isAsync) {
  13287. this.next();
  13288. }
  13289. return this.parseFunction(expr, FUNC_STATEMENT | FUNC_NULLABLE_ID, isAsync);
  13290. }
  13291. if (this.match(80)) {
  13292. return this.parseClass(expr, true, true);
  13293. }
  13294. if (this.match(26)) {
  13295. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport")) {
  13296. this.raise(Errors.DecoratorBeforeExport, {
  13297. at: this.state.startLoc
  13298. });
  13299. }
  13300. this.parseDecorators(false);
  13301. return this.parseClass(expr, true, true);
  13302. }
  13303. if (this.match(75) || this.match(74) || this.isLet()) {
  13304. throw this.raise(Errors.UnsupportedDefaultExport, {
  13305. at: this.state.startLoc
  13306. });
  13307. }
  13308. const res = this.parseMaybeAssignAllowIn();
  13309. this.semicolon();
  13310. return res;
  13311. }
  13312. parseExportDeclaration(node) {
  13313. return this.parseStatement(null);
  13314. }
  13315. isExportDefaultSpecifier() {
  13316. const {
  13317. type
  13318. } = this.state;
  13319. if (tokenIsIdentifier(type)) {
  13320. if (type === 95 && !this.state.containsEsc || type === 99) {
  13321. return false;
  13322. }
  13323. if ((type === 126 || type === 125) && !this.state.containsEsc) {
  13324. const {
  13325. type: nextType
  13326. } = this.lookahead();
  13327. if (tokenIsIdentifier(nextType) && nextType !== 97 || nextType === 5) {
  13328. this.expectOnePlugin(["flow", "typescript"]);
  13329. return false;
  13330. }
  13331. }
  13332. } else if (!this.match(65)) {
  13333. return false;
  13334. }
  13335. const next = this.nextTokenStart();
  13336. const hasFrom = this.isUnparsedContextual(next, "from");
  13337. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13338. return true;
  13339. }
  13340. if (this.match(65) && hasFrom) {
  13341. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13342. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13343. }
  13344. return false;
  13345. }
  13346. parseExportFrom(node, expect) {
  13347. if (this.eatContextual(97)) {
  13348. node.source = this.parseImportSource();
  13349. this.checkExport(node);
  13350. const assertions = this.maybeParseImportAssertions();
  13351. if (assertions) {
  13352. node.assertions = assertions;
  13353. this.checkJSONModuleImport(node);
  13354. }
  13355. } else if (expect) {
  13356. this.unexpected();
  13357. }
  13358. this.semicolon();
  13359. }
  13360. shouldParseExportDeclaration() {
  13361. const {
  13362. type
  13363. } = this.state;
  13364. if (type === 26) {
  13365. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13366. if (this.hasPlugin("decorators")) {
  13367. if (this.getPluginOption("decorators", "decoratorsBeforeExport")) {
  13368. throw this.raise(Errors.DecoratorBeforeExport, {
  13369. at: this.state.startLoc
  13370. });
  13371. }
  13372. return true;
  13373. }
  13374. }
  13375. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13376. }
  13377. checkExport(node, checkNames, isDefault, isFrom) {
  13378. if (checkNames) {
  13379. if (isDefault) {
  13380. this.checkDuplicateExports(node, "default");
  13381. if (this.hasPlugin("exportDefaultFrom")) {
  13382. var _declaration$extra;
  13383. const declaration = node.declaration;
  13384. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13385. this.raise(Errors.ExportDefaultFromAsIdentifier, {
  13386. at: declaration
  13387. });
  13388. }
  13389. }
  13390. } else if (node.specifiers && node.specifiers.length) {
  13391. for (const specifier of node.specifiers) {
  13392. const {
  13393. exported
  13394. } = specifier;
  13395. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13396. this.checkDuplicateExports(specifier, exportName);
  13397. if (!isFrom && specifier.local) {
  13398. const {
  13399. local
  13400. } = specifier;
  13401. if (local.type !== "Identifier") {
  13402. this.raise(Errors.ExportBindingIsString, {
  13403. at: specifier,
  13404. localName: local.value,
  13405. exportName
  13406. });
  13407. } else {
  13408. this.checkReservedWord(local.name, local.loc.start, true, false);
  13409. this.scope.checkLocalExport(local);
  13410. }
  13411. }
  13412. }
  13413. } else if (node.declaration) {
  13414. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  13415. const id = node.declaration.id;
  13416. if (!id) throw new Error("Assertion failure");
  13417. this.checkDuplicateExports(node, id.name);
  13418. } else if (node.declaration.type === "VariableDeclaration") {
  13419. for (const declaration of node.declaration.declarations) {
  13420. this.checkDeclaration(declaration.id);
  13421. }
  13422. }
  13423. }
  13424. }
  13425. const currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1];
  13426. if (currentContextDecorators.length) {
  13427. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13428. at: node
  13429. });
  13430. }
  13431. }
  13432. checkDeclaration(node) {
  13433. if (node.type === "Identifier") {
  13434. this.checkDuplicateExports(node, node.name);
  13435. } else if (node.type === "ObjectPattern") {
  13436. for (const prop of node.properties) {
  13437. this.checkDeclaration(prop);
  13438. }
  13439. } else if (node.type === "ArrayPattern") {
  13440. for (const elem of node.elements) {
  13441. if (elem) {
  13442. this.checkDeclaration(elem);
  13443. }
  13444. }
  13445. } else if (node.type === "ObjectProperty") {
  13446. this.checkDeclaration(node.value);
  13447. } else if (node.type === "RestElement") {
  13448. this.checkDeclaration(node.argument);
  13449. } else if (node.type === "AssignmentPattern") {
  13450. this.checkDeclaration(node.left);
  13451. }
  13452. }
  13453. checkDuplicateExports(node, exportName) {
  13454. if (this.exportedIdentifiers.has(exportName)) {
  13455. if (exportName === "default") {
  13456. this.raise(Errors.DuplicateDefaultExport, {
  13457. at: node
  13458. });
  13459. } else {
  13460. this.raise(Errors.DuplicateExport, {
  13461. at: node,
  13462. exportName
  13463. });
  13464. }
  13465. }
  13466. this.exportedIdentifiers.add(exportName);
  13467. }
  13468. parseExportSpecifiers(isInTypeExport) {
  13469. const nodes = [];
  13470. let first = true;
  13471. this.expect(5);
  13472. while (!this.eat(8)) {
  13473. if (first) {
  13474. first = false;
  13475. } else {
  13476. this.expect(12);
  13477. if (this.eat(8)) break;
  13478. }
  13479. const isMaybeTypeOnly = this.isContextual(126);
  13480. const isString = this.match(129);
  13481. const node = this.startNode();
  13482. node.local = this.parseModuleExportName();
  13483. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13484. }
  13485. return nodes;
  13486. }
  13487. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  13488. if (this.eatContextual(93)) {
  13489. node.exported = this.parseModuleExportName();
  13490. } else if (isString) {
  13491. node.exported = cloneStringLiteral(node.local);
  13492. } else if (!node.exported) {
  13493. node.exported = cloneIdentifier(node.local);
  13494. }
  13495. return this.finishNode(node, "ExportSpecifier");
  13496. }
  13497. parseModuleExportName() {
  13498. if (this.match(129)) {
  13499. const result = this.parseStringLiteral(this.state.value);
  13500. const surrogate = result.value.match(loneSurrogate);
  13501. if (surrogate) {
  13502. this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
  13503. at: result,
  13504. surrogateCharCode: surrogate[0].charCodeAt(0)
  13505. });
  13506. }
  13507. return result;
  13508. }
  13509. return this.parseIdentifier(true);
  13510. }
  13511. isJSONModuleImport(node) {
  13512. if (node.assertions != null) {
  13513. return node.assertions.some(({
  13514. key,
  13515. value
  13516. }) => {
  13517. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  13518. });
  13519. }
  13520. return false;
  13521. }
  13522. checkJSONModuleImport(node) {
  13523. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  13524. const {
  13525. specifiers
  13526. } = node;
  13527. if (node.specifiers != null) {
  13528. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  13529. let imported;
  13530. if (specifier.type === "ExportSpecifier") {
  13531. imported = specifier.local;
  13532. } else if (specifier.type === "ImportSpecifier") {
  13533. imported = specifier.imported;
  13534. }
  13535. if (imported !== undefined) {
  13536. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  13537. }
  13538. });
  13539. if (nonDefaultNamedSpecifier !== undefined) {
  13540. this.raise(Errors.ImportJSONBindingNotDefault, {
  13541. at: nonDefaultNamedSpecifier.loc.start
  13542. });
  13543. }
  13544. }
  13545. }
  13546. }
  13547. parseImport(node) {
  13548. node.specifiers = [];
  13549. if (!this.match(129)) {
  13550. const hasDefault = this.maybeParseDefaultImportSpecifier(node);
  13551. const parseNext = !hasDefault || this.eat(12);
  13552. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  13553. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  13554. this.expectContextual(97);
  13555. }
  13556. node.source = this.parseImportSource();
  13557. const assertions = this.maybeParseImportAssertions();
  13558. if (assertions) {
  13559. node.assertions = assertions;
  13560. } else {
  13561. const attributes = this.maybeParseModuleAttributes();
  13562. if (attributes) {
  13563. node.attributes = attributes;
  13564. }
  13565. }
  13566. this.checkJSONModuleImport(node);
  13567. this.semicolon();
  13568. return this.finishNode(node, "ImportDeclaration");
  13569. }
  13570. parseImportSource() {
  13571. if (!this.match(129)) this.unexpected();
  13572. return this.parseExprAtom();
  13573. }
  13574. shouldParseDefaultImport(node) {
  13575. return tokenIsIdentifier(this.state.type);
  13576. }
  13577. parseImportSpecifierLocal(node, specifier, type) {
  13578. specifier.local = this.parseIdentifier();
  13579. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  13580. }
  13581. finishImportSpecifier(specifier, type) {
  13582. this.checkLVal(specifier.local, {
  13583. in: specifier,
  13584. binding: BIND_LEXICAL
  13585. });
  13586. return this.finishNode(specifier, type);
  13587. }
  13588. parseAssertEntries() {
  13589. const attrs = [];
  13590. const attrNames = new Set();
  13591. do {
  13592. if (this.match(8)) {
  13593. break;
  13594. }
  13595. const node = this.startNode();
  13596. const keyName = this.state.value;
  13597. if (attrNames.has(keyName)) {
  13598. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  13599. at: this.state.startLoc,
  13600. key: keyName
  13601. });
  13602. }
  13603. attrNames.add(keyName);
  13604. if (this.match(129)) {
  13605. node.key = this.parseStringLiteral(keyName);
  13606. } else {
  13607. node.key = this.parseIdentifier(true);
  13608. }
  13609. this.expect(14);
  13610. if (!this.match(129)) {
  13611. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  13612. at: this.state.startLoc
  13613. });
  13614. }
  13615. node.value = this.parseStringLiteral(this.state.value);
  13616. this.finishNode(node, "ImportAttribute");
  13617. attrs.push(node);
  13618. } while (this.eat(12));
  13619. return attrs;
  13620. }
  13621. maybeParseModuleAttributes() {
  13622. if (this.match(76) && !this.hasPrecedingLineBreak()) {
  13623. this.expectPlugin("moduleAttributes");
  13624. this.next();
  13625. } else {
  13626. if (this.hasPlugin("moduleAttributes")) return [];
  13627. return null;
  13628. }
  13629. const attrs = [];
  13630. const attributes = new Set();
  13631. do {
  13632. const node = this.startNode();
  13633. node.key = this.parseIdentifier(true);
  13634. if (node.key.name !== "type") {
  13635. this.raise(Errors.ModuleAttributeDifferentFromType, {
  13636. at: node.key
  13637. });
  13638. }
  13639. if (attributes.has(node.key.name)) {
  13640. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  13641. at: node.key,
  13642. key: node.key.name
  13643. });
  13644. }
  13645. attributes.add(node.key.name);
  13646. this.expect(14);
  13647. if (!this.match(129)) {
  13648. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  13649. at: this.state.startLoc
  13650. });
  13651. }
  13652. node.value = this.parseStringLiteral(this.state.value);
  13653. this.finishNode(node, "ImportAttribute");
  13654. attrs.push(node);
  13655. } while (this.eat(12));
  13656. return attrs;
  13657. }
  13658. maybeParseImportAssertions() {
  13659. if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  13660. this.expectPlugin("importAssertions");
  13661. this.next();
  13662. } else {
  13663. if (this.hasPlugin("importAssertions")) return [];
  13664. return null;
  13665. }
  13666. this.eat(5);
  13667. const attrs = this.parseAssertEntries();
  13668. this.eat(8);
  13669. return attrs;
  13670. }
  13671. maybeParseDefaultImportSpecifier(node) {
  13672. if (this.shouldParseDefaultImport(node)) {
  13673. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  13674. return true;
  13675. }
  13676. return false;
  13677. }
  13678. maybeParseStarImportSpecifier(node) {
  13679. if (this.match(55)) {
  13680. const specifier = this.startNode();
  13681. this.next();
  13682. this.expectContextual(93);
  13683. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  13684. return true;
  13685. }
  13686. return false;
  13687. }
  13688. parseNamedImportSpecifiers(node) {
  13689. let first = true;
  13690. this.expect(5);
  13691. while (!this.eat(8)) {
  13692. if (first) {
  13693. first = false;
  13694. } else {
  13695. if (this.eat(14)) {
  13696. throw this.raise(Errors.DestructureNamedImport, {
  13697. at: this.state.startLoc
  13698. });
  13699. }
  13700. this.expect(12);
  13701. if (this.eat(8)) break;
  13702. }
  13703. const specifier = this.startNode();
  13704. const importedIsString = this.match(129);
  13705. const isMaybeTypeOnly = this.isContextual(126);
  13706. specifier.imported = this.parseModuleExportName();
  13707. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly);
  13708. node.specifiers.push(importSpecifier);
  13709. }
  13710. }
  13711. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly) {
  13712. if (this.eatContextual(93)) {
  13713. specifier.local = this.parseIdentifier();
  13714. } else {
  13715. const {
  13716. imported
  13717. } = specifier;
  13718. if (importedIsString) {
  13719. throw this.raise(Errors.ImportBindingIsString, {
  13720. at: specifier,
  13721. importName: imported.value
  13722. });
  13723. }
  13724. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  13725. if (!specifier.local) {
  13726. specifier.local = cloneIdentifier(imported);
  13727. }
  13728. }
  13729. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  13730. }
  13731. isThisParam(param) {
  13732. return param.type === "Identifier" && param.name === "this";
  13733. }
  13734. }
  13735. class Parser extends StatementParser {
  13736. constructor(options, input) {
  13737. options = getOptions(options);
  13738. super(options, input);
  13739. this.options = options;
  13740. this.initializeScopes();
  13741. this.plugins = pluginsMap(this.options.plugins);
  13742. this.filename = options.sourceFilename;
  13743. }
  13744. getScopeHandler() {
  13745. return ScopeHandler;
  13746. }
  13747. parse() {
  13748. this.enterInitialScopes();
  13749. const file = this.startNode();
  13750. const program = this.startNode();
  13751. this.nextToken();
  13752. file.errors = null;
  13753. this.parseTopLevel(file, program);
  13754. file.errors = this.state.errors;
  13755. return file;
  13756. }
  13757. }
  13758. function pluginsMap(plugins) {
  13759. const pluginMap = new Map();
  13760. for (const plugin of plugins) {
  13761. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  13762. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  13763. }
  13764. return pluginMap;
  13765. }
  13766. function parse(input, options) {
  13767. var _options;
  13768. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  13769. options = Object.assign({}, options);
  13770. try {
  13771. options.sourceType = "module";
  13772. const parser = getParser(options, input);
  13773. const ast = parser.parse();
  13774. if (parser.sawUnambiguousESM) {
  13775. return ast;
  13776. }
  13777. if (parser.ambiguousScriptDifferentAst) {
  13778. try {
  13779. options.sourceType = "script";
  13780. return getParser(options, input).parse();
  13781. } catch (_unused) {}
  13782. } else {
  13783. ast.program.sourceType = "script";
  13784. }
  13785. return ast;
  13786. } catch (moduleError) {
  13787. try {
  13788. options.sourceType = "script";
  13789. return getParser(options, input).parse();
  13790. } catch (_unused2) {}
  13791. throw moduleError;
  13792. }
  13793. } else {
  13794. return getParser(options, input).parse();
  13795. }
  13796. }
  13797. function parseExpression(input, options) {
  13798. const parser = getParser(options, input);
  13799. if (parser.options.strictMode) {
  13800. parser.state.strict = true;
  13801. }
  13802. return parser.getExpression();
  13803. }
  13804. function generateExportedTokenTypes(internalTokenTypes) {
  13805. const tokenTypes = {};
  13806. for (const typeName of Object.keys(internalTokenTypes)) {
  13807. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  13808. }
  13809. return tokenTypes;
  13810. }
  13811. const tokTypes = generateExportedTokenTypes(tt);
  13812. function getParser(options, input) {
  13813. let cls = Parser;
  13814. if (options != null && options.plugins) {
  13815. validatePlugins(options.plugins);
  13816. cls = getParserClass(options.plugins);
  13817. }
  13818. return new cls(options, input);
  13819. }
  13820. const parserClassCache = {};
  13821. function getParserClass(pluginsFromOptions) {
  13822. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  13823. const key = pluginList.join("/");
  13824. let cls = parserClassCache[key];
  13825. if (!cls) {
  13826. cls = Parser;
  13827. for (const plugin of pluginList) {
  13828. cls = mixinPlugins[plugin](cls);
  13829. }
  13830. parserClassCache[key] = cls;
  13831. }
  13832. return cls;
  13833. }
  13834. exports.parse = parse;
  13835. exports.parseExpression = parseExpression;
  13836. exports.tokTypes = tokTypes;
  13837. //# sourceMappingURL=index.js.map