index.js 430 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  4. const lineBreakG = new RegExp(lineBreak.source, "g");
  5. function isNewLine(code) {
  6. switch (code) {
  7. case 10:
  8. case 13:
  9. case 8232:
  10. case 8233:
  11. return true;
  12. default:
  13. return false;
  14. }
  15. }
  16. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  17. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/y;
  18. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  19. function isWhitespace(code) {
  20. switch (code) {
  21. case 0x0009:
  22. case 0x000b:
  23. case 0x000c:
  24. case 32:
  25. case 160:
  26. case 5760:
  27. case 0x2000:
  28. case 0x2001:
  29. case 0x2002:
  30. case 0x2003:
  31. case 0x2004:
  32. case 0x2005:
  33. case 0x2006:
  34. case 0x2007:
  35. case 0x2008:
  36. case 0x2009:
  37. case 0x200a:
  38. case 0x202f:
  39. case 0x205f:
  40. case 0x3000:
  41. case 0xfeff:
  42. return true;
  43. default:
  44. return false;
  45. }
  46. }
  47. class Position {
  48. constructor(line, col) {
  49. this.line = void 0;
  50. this.column = void 0;
  51. this.line = line;
  52. this.column = col;
  53. }
  54. }
  55. class SourceLocation {
  56. constructor(start, end) {
  57. this.start = void 0;
  58. this.end = void 0;
  59. this.filename = void 0;
  60. this.identifierName = void 0;
  61. this.start = start;
  62. this.end = end;
  63. }
  64. }
  65. function getLineInfo(input, offset) {
  66. let line = 1;
  67. let lineStart = 0;
  68. let match;
  69. lineBreakG.lastIndex = 0;
  70. while ((match = lineBreakG.exec(input)) && match.index < offset) {
  71. line++;
  72. lineStart = lineBreakG.lastIndex;
  73. }
  74. return new Position(line, offset - lineStart);
  75. }
  76. class BaseParser {
  77. constructor() {
  78. this.sawUnambiguousESM = false;
  79. this.ambiguousScriptDifferentAst = false;
  80. }
  81. hasPlugin(name) {
  82. return this.plugins.has(name);
  83. }
  84. getPluginOption(plugin, name) {
  85. if (this.hasPlugin(plugin)) return this.plugins.get(plugin)[name];
  86. }
  87. }
  88. function setTrailingComments(node, comments) {
  89. if (node.trailingComments === undefined) {
  90. node.trailingComments = comments;
  91. } else {
  92. node.trailingComments.unshift(...comments);
  93. }
  94. }
  95. function setLeadingComments(node, comments) {
  96. if (node.leadingComments === undefined) {
  97. node.leadingComments = comments;
  98. } else {
  99. node.leadingComments.unshift(...comments);
  100. }
  101. }
  102. function setInnerComments(node, comments) {
  103. if (node.innerComments === undefined) {
  104. node.innerComments = comments;
  105. } else {
  106. node.innerComments.unshift(...comments);
  107. }
  108. }
  109. function adjustInnerComments(node, elements, commentWS) {
  110. let lastElement = null;
  111. let i = elements.length;
  112. while (lastElement === null && i > 0) {
  113. lastElement = elements[--i];
  114. }
  115. if (lastElement === null || lastElement.start > commentWS.start) {
  116. setInnerComments(node, commentWS.comments);
  117. } else {
  118. setTrailingComments(lastElement, commentWS.comments);
  119. }
  120. }
  121. class CommentsParser extends BaseParser {
  122. addComment(comment) {
  123. if (this.filename) comment.loc.filename = this.filename;
  124. this.state.comments.push(comment);
  125. }
  126. processComment(node) {
  127. const {
  128. commentStack
  129. } = this.state;
  130. const commentStackLength = commentStack.length;
  131. if (commentStackLength === 0) return;
  132. let i = commentStackLength - 1;
  133. const lastCommentWS = commentStack[i];
  134. if (lastCommentWS.start === node.end) {
  135. lastCommentWS.leadingNode = node;
  136. i--;
  137. }
  138. const {
  139. start: nodeStart
  140. } = node;
  141. for (; i >= 0; i--) {
  142. const commentWS = commentStack[i];
  143. const commentEnd = commentWS.end;
  144. if (commentEnd > nodeStart) {
  145. commentWS.containingNode = node;
  146. this.finalizeComment(commentWS);
  147. commentStack.splice(i, 1);
  148. } else {
  149. if (commentEnd === nodeStart) {
  150. commentWS.trailingNode = node;
  151. }
  152. break;
  153. }
  154. }
  155. }
  156. finalizeComment(commentWS) {
  157. const {
  158. comments
  159. } = commentWS;
  160. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  161. if (commentWS.leadingNode !== null) {
  162. setTrailingComments(commentWS.leadingNode, comments);
  163. }
  164. if (commentWS.trailingNode !== null) {
  165. setLeadingComments(commentWS.trailingNode, comments);
  166. }
  167. } else {
  168. const {
  169. containingNode: node,
  170. start: commentStart
  171. } = commentWS;
  172. if (this.input.charCodeAt(commentStart - 1) === 44) {
  173. switch (node.type) {
  174. case "ObjectExpression":
  175. case "ObjectPattern":
  176. case "RecordExpression":
  177. adjustInnerComments(node, node.properties, commentWS);
  178. break;
  179. case "CallExpression":
  180. case "OptionalCallExpression":
  181. adjustInnerComments(node, node.arguments, commentWS);
  182. break;
  183. case "FunctionDeclaration":
  184. case "FunctionExpression":
  185. case "ArrowFunctionExpression":
  186. case "ObjectMethod":
  187. case "ClassMethod":
  188. case "ClassPrivateMethod":
  189. adjustInnerComments(node, node.params, commentWS);
  190. break;
  191. case "ArrayExpression":
  192. case "ArrayPattern":
  193. case "TupleExpression":
  194. adjustInnerComments(node, node.elements, commentWS);
  195. break;
  196. case "ExportNamedDeclaration":
  197. case "ImportDeclaration":
  198. adjustInnerComments(node, node.specifiers, commentWS);
  199. break;
  200. default:
  201. {
  202. setInnerComments(node, comments);
  203. }
  204. }
  205. } else {
  206. setInnerComments(node, comments);
  207. }
  208. }
  209. }
  210. finalizeRemainingComments() {
  211. const {
  212. commentStack
  213. } = this.state;
  214. for (let i = commentStack.length - 1; i >= 0; i--) {
  215. this.finalizeComment(commentStack[i]);
  216. }
  217. this.state.commentStack = [];
  218. }
  219. resetPreviousNodeTrailingComments(node) {
  220. const {
  221. commentStack
  222. } = this.state;
  223. const {
  224. length
  225. } = commentStack;
  226. if (length === 0) return;
  227. const commentWS = commentStack[length - 1];
  228. if (commentWS.leadingNode === node) {
  229. commentWS.leadingNode = null;
  230. }
  231. }
  232. takeSurroundingComments(node, start, end) {
  233. const {
  234. commentStack
  235. } = this.state;
  236. const commentStackLength = commentStack.length;
  237. if (commentStackLength === 0) return;
  238. let i = commentStackLength - 1;
  239. for (; i >= 0; i--) {
  240. const commentWS = commentStack[i];
  241. const commentEnd = commentWS.end;
  242. const commentStart = commentWS.start;
  243. if (commentStart === end) {
  244. commentWS.leadingNode = node;
  245. } else if (commentEnd === start) {
  246. commentWS.trailingNode = node;
  247. } else if (commentEnd < start) {
  248. break;
  249. }
  250. }
  251. }
  252. }
  253. const ErrorCodes = Object.freeze({
  254. SyntaxError: "BABEL_PARSER_SYNTAX_ERROR",
  255. SourceTypeModuleError: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"
  256. });
  257. const ErrorMessages = makeErrorTemplates({
  258. AccessorIsGenerator: "A %0ter cannot be a generator.",
  259. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  260. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  261. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  262. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  263. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  264. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  265. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  266. BadGetterArity: "A 'get' accesor must not have any formal parameters.",
  267. BadSetterArity: "A 'set' accesor must have exactly one formal parameter.",
  268. BadSetterRestParameter: "A 'set' accesor function argument must not be a rest parameter.",
  269. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  270. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  271. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  272. ConstructorIsAsync: "Constructor can't be an async function.",
  273. ConstructorIsGenerator: "Constructor can't be a generator.",
  274. DeclarationMissingInitializer: "'%0' require an initialization value.",
  275. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. You can set the 'decoratorsBeforeExport' option to false to use the 'export @decorator class {}' syntax.",
  276. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  277. DecoratorExportClass: "Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead.",
  278. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  279. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  280. DeletePrivateField: "Deleting a private field is not allowed.",
  281. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  282. DuplicateConstructor: "Duplicate constructor in the same class.",
  283. DuplicateDefaultExport: "Only one default export allowed per module.",
  284. DuplicateExport: "`%0` has already been exported. Exported identifiers must be unique.",
  285. DuplicateProto: "Redefinition of __proto__ property.",
  286. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  287. ElementAfterRest: "Rest element must be last element.",
  288. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  289. ExportBindingIsString: "A string literal cannot be used as an exported binding without `from`.\n- Did you mean `export { '%0' as '%1' } from 'some-module'`?",
  290. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  291. ForInOfLoopInitializer: "'%0' loop variable declaration may not have an initializer.",
  292. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  293. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  294. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  295. IllegalBreakContinue: "Unsyntactic %0.",
  296. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  297. IllegalReturn: "'return' outside of function.",
  298. ImportBindingIsString: 'A string literal cannot be used as an imported binding.\n- Did you mean `import { "%0" as foo }`?',
  299. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  300. ImportCallArity: "`import()` requires exactly %0.",
  301. ImportCallNotNewExpression: "Cannot use new with import(...).",
  302. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  303. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  304. InvalidCodePoint: "Code point out of bounds.",
  305. InvalidDecimal: "Invalid decimal.",
  306. InvalidDigit: "Expected number in radix %0.",
  307. InvalidEscapeSequence: "Bad character escape sequence.",
  308. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  309. InvalidEscapedReservedWord: "Escape sequence in keyword %0.",
  310. InvalidIdentifier: "Invalid identifier %0.",
  311. InvalidLhs: "Invalid left-hand side in %0.",
  312. InvalidLhsBinding: "Binding invalid left-hand side in %0.",
  313. InvalidNumber: "Invalid number.",
  314. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  315. InvalidOrUnexpectedToken: "Unexpected character '%0'.",
  316. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  317. InvalidPrivateFieldResolution: "Private name #%0 is not defined.",
  318. InvalidPropertyBindingPattern: "Binding member expression.",
  319. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  320. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  321. LabelRedeclaration: "Label '%0' is already declared.",
  322. LetInLexicalBinding: "'let' is not allowed to be used as a name in 'let' or 'const' declarations.",
  323. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  324. MalformedRegExpFlags: "Invalid regular expression flag.",
  325. MissingClassName: "A class name is required.",
  326. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  327. MissingSemicolon: "Missing semicolon.",
  328. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  329. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  330. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  331. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  332. ModuleAttributesWithDuplicateKeys: 'Duplicate key "%0" is not allowed in module attributes.',
  333. ModuleExportNameHasLoneSurrogate: "An export name cannot include a lone surrogate, found '\\u%0'.",
  334. ModuleExportUndefined: "Export '%0' is not defined.",
  335. MultipleDefaultsInSwitch: "Multiple default clauses.",
  336. NewlineAfterThrow: "Illegal newline after throw.",
  337. NoCatchOrFinally: "Missing catch or finally clause.",
  338. NumberIdentifier: "Identifier directly after number.",
  339. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  340. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  341. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  342. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  343. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  344. ParamDupe: "Argument name clash.",
  345. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  346. PatternHasMethod: "Object pattern can't contain methods.",
  347. PipeBodyIsTighter: "Unexpected %0 after pipeline body; any %0 expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  348. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  349. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  350. PipeTopicUnconfiguredToken: 'Invalid topic token %0. In order to use %0 as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "%0" }.',
  351. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  352. PipeUnparenthesizedBody: "Hack-style pipe body cannot be an unparenthesized %0 expression; please wrap it in parentheses.",
  353. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  354. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  355. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  356. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  357. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  358. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  359. PrivateInExpectedIn: "Private names are only allowed in property accesses (`obj.#%0`) or in `in` expressions (`#%0 in obj`).",
  360. PrivateNameRedeclaration: "Duplicate private name #%0.",
  361. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  362. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  363. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  364. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  365. RestTrailingComma: "Unexpected trailing comma after rest element.",
  366. 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.",
  367. StaticPrototype: "Classes may not have static property named prototype.",
  368. StrictDelete: "Deleting local variable in strict mode.",
  369. StrictEvalArguments: "Assigning to '%0' in strict mode.",
  370. StrictEvalArgumentsBinding: "Binding '%0' in strict mode.",
  371. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  372. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  373. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  374. StrictWith: "'with' in strict mode.",
  375. 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?",
  376. SuperPrivateField: "Private fields can't be accessed on super.",
  377. TrailingDecorator: "Decorators must be attached to a class element.",
  378. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  379. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  380. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  381. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  382. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  383. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  384. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  385. UnexpectedKeyword: "Unexpected keyword '%0'.",
  386. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  387. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  388. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  389. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  390. UnexpectedPrivateField: "Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p).",
  391. UnexpectedReservedWord: "Unexpected reserved word '%0'.",
  392. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  393. UnexpectedToken: "Unexpected token '%0'.",
  394. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  395. UnsupportedBind: "Binding should be performed on object property.",
  396. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  397. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  398. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  399. UnsupportedMetaProperty: "The only valid meta property for %0 is %0.%1.",
  400. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  401. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  402. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  403. UnterminatedComment: "Unterminated comment.",
  404. UnterminatedRegExp: "Unterminated regular expression.",
  405. UnterminatedString: "Unterminated string constant.",
  406. UnterminatedTemplate: "Unterminated template.",
  407. VarRedeclaration: "Identifier '%0' has already been declared.",
  408. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  409. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  410. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  411. }, ErrorCodes.SyntaxError);
  412. const SourceTypeModuleErrorMessages = makeErrorTemplates({
  413. ImportMetaOutsideModule: `import.meta may appear only with 'sourceType: "module"'`,
  414. ImportOutsideModule: `'import' and 'export' may appear only with 'sourceType: "module"'`
  415. }, ErrorCodes.SourceTypeModuleError);
  416. function keepReasonCodeCompat(reasonCode, syntaxPlugin) {
  417. {
  418. if (syntaxPlugin === "flow" && reasonCode === "PatternIsOptional") {
  419. return "OptionalBindingPattern";
  420. }
  421. }
  422. return reasonCode;
  423. }
  424. function makeErrorTemplates(messages, code, syntaxPlugin) {
  425. const templates = {};
  426. Object.keys(messages).forEach(reasonCode => {
  427. templates[reasonCode] = Object.freeze({
  428. code,
  429. reasonCode: keepReasonCodeCompat(reasonCode, syntaxPlugin),
  430. template: messages[reasonCode]
  431. });
  432. });
  433. return Object.freeze(templates);
  434. }
  435. class ParserError extends CommentsParser {
  436. getLocationForPosition(pos) {
  437. let loc;
  438. if (pos === this.state.start) loc = this.state.startLoc;else if (pos === this.state.lastTokStart) loc = this.state.lastTokStartLoc;else if (pos === this.state.end) loc = this.state.endLoc;else if (pos === this.state.lastTokEnd) loc = this.state.lastTokEndLoc;else loc = getLineInfo(this.input, pos);
  439. return loc;
  440. }
  441. raise(pos, {
  442. code,
  443. reasonCode,
  444. template
  445. }, ...params) {
  446. return this.raiseWithData(pos, {
  447. code,
  448. reasonCode
  449. }, template, ...params);
  450. }
  451. raiseOverwrite(pos, {
  452. code,
  453. template
  454. }, ...params) {
  455. const loc = this.getLocationForPosition(pos);
  456. const message = template.replace(/%(\d+)/g, (_, i) => params[i]) + ` (${loc.line}:${loc.column})`;
  457. if (this.options.errorRecovery) {
  458. const errors = this.state.errors;
  459. for (let i = errors.length - 1; i >= 0; i--) {
  460. const error = errors[i];
  461. if (error.pos === pos) {
  462. return Object.assign(error, {
  463. message
  464. });
  465. } else if (error.pos < pos) {
  466. break;
  467. }
  468. }
  469. }
  470. return this._raise({
  471. code,
  472. loc,
  473. pos
  474. }, message);
  475. }
  476. raiseWithData(pos, data, errorTemplate, ...params) {
  477. const loc = this.getLocationForPosition(pos);
  478. const message = errorTemplate.replace(/%(\d+)/g, (_, i) => params[i]) + ` (${loc.line}:${loc.column})`;
  479. return this._raise(Object.assign({
  480. loc,
  481. pos
  482. }, data), message);
  483. }
  484. _raise(errorContext, message) {
  485. const err = new SyntaxError(message);
  486. Object.assign(err, errorContext);
  487. if (this.options.errorRecovery) {
  488. if (!this.isLookahead) this.state.errors.push(err);
  489. return err;
  490. } else {
  491. throw err;
  492. }
  493. }
  494. }
  495. var estree = (superClass => class extends superClass {
  496. parseRegExpLiteral({
  497. pattern,
  498. flags
  499. }) {
  500. let regex = null;
  501. try {
  502. regex = new RegExp(pattern, flags);
  503. } catch (e) {}
  504. const node = this.estreeParseLiteral(regex);
  505. node.regex = {
  506. pattern,
  507. flags
  508. };
  509. return node;
  510. }
  511. parseBigIntLiteral(value) {
  512. let bigInt;
  513. try {
  514. bigInt = BigInt(value);
  515. } catch (_unused) {
  516. bigInt = null;
  517. }
  518. const node = this.estreeParseLiteral(bigInt);
  519. node.bigint = String(node.value || value);
  520. return node;
  521. }
  522. parseDecimalLiteral(value) {
  523. const decimal = null;
  524. const node = this.estreeParseLiteral(decimal);
  525. node.decimal = String(node.value || value);
  526. return node;
  527. }
  528. estreeParseLiteral(value) {
  529. return this.parseLiteral(value, "Literal");
  530. }
  531. parseStringLiteral(value) {
  532. return this.estreeParseLiteral(value);
  533. }
  534. parseNumericLiteral(value) {
  535. return this.estreeParseLiteral(value);
  536. }
  537. parseNullLiteral() {
  538. return this.estreeParseLiteral(null);
  539. }
  540. parseBooleanLiteral(value) {
  541. return this.estreeParseLiteral(value);
  542. }
  543. directiveToStmt(directive) {
  544. const directiveLiteral = directive.value;
  545. const stmt = this.startNodeAt(directive.start, directive.loc.start);
  546. const expression = this.startNodeAt(directiveLiteral.start, directiveLiteral.loc.start);
  547. expression.value = directiveLiteral.extra.expressionValue;
  548. expression.raw = directiveLiteral.extra.raw;
  549. stmt.expression = this.finishNodeAt(expression, "Literal", directiveLiteral.end, directiveLiteral.loc.end);
  550. stmt.directive = directiveLiteral.extra.raw.slice(1, -1);
  551. return this.finishNodeAt(stmt, "ExpressionStatement", directive.end, directive.loc.end);
  552. }
  553. initFunction(node, isAsync) {
  554. super.initFunction(node, isAsync);
  555. node.expression = false;
  556. }
  557. checkDeclaration(node) {
  558. if (node != null && this.isObjectProperty(node)) {
  559. this.checkDeclaration(node.value);
  560. } else {
  561. super.checkDeclaration(node);
  562. }
  563. }
  564. getObjectOrClassMethodParams(method) {
  565. return method.value.params;
  566. }
  567. isValidDirective(stmt) {
  568. var _stmt$expression$extr;
  569. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  570. }
  571. parseBlockBody(node, ...args) {
  572. super.parseBlockBody(node, ...args);
  573. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  574. node.body = directiveStatements.concat(node.body);
  575. delete node.directives;
  576. }
  577. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  578. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  579. if (method.typeParameters) {
  580. method.value.typeParameters = method.typeParameters;
  581. delete method.typeParameters;
  582. }
  583. classBody.body.push(method);
  584. }
  585. parsePrivateName() {
  586. const node = super.parsePrivateName();
  587. {
  588. if (!this.getPluginOption("estree", "classFeatures")) {
  589. return node;
  590. }
  591. }
  592. return this.convertPrivateNameToPrivateIdentifier(node);
  593. }
  594. convertPrivateNameToPrivateIdentifier(node) {
  595. const name = super.getPrivateNameSV(node);
  596. node = node;
  597. delete node.id;
  598. node.name = name;
  599. node.type = "PrivateIdentifier";
  600. return node;
  601. }
  602. isPrivateName(node) {
  603. {
  604. if (!this.getPluginOption("estree", "classFeatures")) {
  605. return super.isPrivateName(node);
  606. }
  607. }
  608. return node.type === "PrivateIdentifier";
  609. }
  610. getPrivateNameSV(node) {
  611. {
  612. if (!this.getPluginOption("estree", "classFeatures")) {
  613. return super.getPrivateNameSV(node);
  614. }
  615. }
  616. return node.name;
  617. }
  618. parseLiteral(value, type) {
  619. const node = super.parseLiteral(value, type);
  620. node.raw = node.extra.raw;
  621. delete node.extra;
  622. return node;
  623. }
  624. parseFunctionBody(node, allowExpression, isMethod = false) {
  625. super.parseFunctionBody(node, allowExpression, isMethod);
  626. node.expression = node.body.type !== "BlockStatement";
  627. }
  628. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  629. let funcNode = this.startNode();
  630. funcNode.kind = node.kind;
  631. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  632. funcNode.type = "FunctionExpression";
  633. delete funcNode.kind;
  634. node.value = funcNode;
  635. if (type === "ClassPrivateMethod") {
  636. node.computed = false;
  637. }
  638. type = "MethodDefinition";
  639. return this.finishNode(node, type);
  640. }
  641. parseClassProperty(...args) {
  642. const propertyNode = super.parseClassProperty(...args);
  643. {
  644. if (!this.getPluginOption("estree", "classFeatures")) {
  645. return propertyNode;
  646. }
  647. }
  648. propertyNode.type = "PropertyDefinition";
  649. return propertyNode;
  650. }
  651. parseClassPrivateProperty(...args) {
  652. const propertyNode = super.parseClassPrivateProperty(...args);
  653. {
  654. if (!this.getPluginOption("estree", "classFeatures")) {
  655. return propertyNode;
  656. }
  657. }
  658. propertyNode.type = "PropertyDefinition";
  659. propertyNode.computed = false;
  660. return propertyNode;
  661. }
  662. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  663. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  664. if (node) {
  665. node.type = "Property";
  666. if (node.kind === "method") node.kind = "init";
  667. node.shorthand = false;
  668. }
  669. return node;
  670. }
  671. parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors) {
  672. const node = super.parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors);
  673. if (node) {
  674. node.kind = "init";
  675. node.type = "Property";
  676. }
  677. return node;
  678. }
  679. isAssignable(node, isBinding) {
  680. if (node != null && this.isObjectProperty(node)) {
  681. return this.isAssignable(node.value, isBinding);
  682. }
  683. return super.isAssignable(node, isBinding);
  684. }
  685. toAssignable(node, isLHS = false) {
  686. if (node != null && this.isObjectProperty(node)) {
  687. this.toAssignable(node.value, isLHS);
  688. return node;
  689. }
  690. return super.toAssignable(node, isLHS);
  691. }
  692. toAssignableObjectExpressionProp(prop, ...args) {
  693. if (prop.kind === "get" || prop.kind === "set") {
  694. this.raise(prop.key.start, ErrorMessages.PatternHasAccessor);
  695. } else if (prop.method) {
  696. this.raise(prop.key.start, ErrorMessages.PatternHasMethod);
  697. } else {
  698. super.toAssignableObjectExpressionProp(prop, ...args);
  699. }
  700. }
  701. finishCallExpression(node, optional) {
  702. super.finishCallExpression(node, optional);
  703. if (node.callee.type === "Import") {
  704. node.type = "ImportExpression";
  705. node.source = node.arguments[0];
  706. if (this.hasPlugin("importAssertions")) {
  707. var _node$arguments$;
  708. node.attributes = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  709. }
  710. delete node.arguments;
  711. delete node.callee;
  712. }
  713. return node;
  714. }
  715. toReferencedArguments(node) {
  716. if (node.type === "ImportExpression") {
  717. return;
  718. }
  719. super.toReferencedArguments(node);
  720. }
  721. parseExport(node) {
  722. super.parseExport(node);
  723. switch (node.type) {
  724. case "ExportAllDeclaration":
  725. node.exported = null;
  726. break;
  727. case "ExportNamedDeclaration":
  728. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  729. node.type = "ExportAllDeclaration";
  730. node.exported = node.specifiers[0].exported;
  731. delete node.specifiers;
  732. }
  733. break;
  734. }
  735. return node;
  736. }
  737. parseSubscript(base, startPos, startLoc, noCalls, state) {
  738. const node = super.parseSubscript(base, startPos, startLoc, noCalls, state);
  739. if (state.optionalChainMember) {
  740. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  741. node.type = node.type.substring(8);
  742. }
  743. if (state.stop) {
  744. const chain = this.startNodeAtNode(node);
  745. chain.expression = node;
  746. return this.finishNode(chain, "ChainExpression");
  747. }
  748. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  749. node.optional = false;
  750. }
  751. return node;
  752. }
  753. hasPropertyAsPrivateName(node) {
  754. if (node.type === "ChainExpression") {
  755. node = node.expression;
  756. }
  757. return super.hasPropertyAsPrivateName(node);
  758. }
  759. isOptionalChain(node) {
  760. return node.type === "ChainExpression";
  761. }
  762. isObjectProperty(node) {
  763. return node.type === "Property" && node.kind === "init" && !node.method;
  764. }
  765. isObjectMethod(node) {
  766. return node.method || node.kind === "get" || node.kind === "set";
  767. }
  768. });
  769. class TokContext {
  770. constructor(token, preserveSpace) {
  771. this.token = void 0;
  772. this.preserveSpace = void 0;
  773. this.token = token;
  774. this.preserveSpace = !!preserveSpace;
  775. }
  776. }
  777. const types = {
  778. brace: new TokContext("{"),
  779. template: new TokContext("`", true)
  780. };
  781. const beforeExpr = true;
  782. const startsExpr = true;
  783. const isLoop = true;
  784. const isAssign = true;
  785. const prefix = true;
  786. const postfix = true;
  787. class ExportedTokenType {
  788. constructor(label, conf = {}) {
  789. this.label = void 0;
  790. this.keyword = void 0;
  791. this.beforeExpr = void 0;
  792. this.startsExpr = void 0;
  793. this.rightAssociative = void 0;
  794. this.isLoop = void 0;
  795. this.isAssign = void 0;
  796. this.prefix = void 0;
  797. this.postfix = void 0;
  798. this.binop = void 0;
  799. this.label = label;
  800. this.keyword = conf.keyword;
  801. this.beforeExpr = !!conf.beforeExpr;
  802. this.startsExpr = !!conf.startsExpr;
  803. this.rightAssociative = !!conf.rightAssociative;
  804. this.isLoop = !!conf.isLoop;
  805. this.isAssign = !!conf.isAssign;
  806. this.prefix = !!conf.prefix;
  807. this.postfix = !!conf.postfix;
  808. this.binop = conf.binop != null ? conf.binop : null;
  809. {
  810. this.updateContext = null;
  811. }
  812. }
  813. }
  814. const keywords$1 = new Map();
  815. function createKeyword(name, options = {}) {
  816. options.keyword = name;
  817. const token = createToken(name, options);
  818. keywords$1.set(name, token);
  819. return token;
  820. }
  821. function createBinop(name, binop) {
  822. return createToken(name, {
  823. beforeExpr,
  824. binop
  825. });
  826. }
  827. let tokenTypeCounter = -1;
  828. const tokenTypes = [];
  829. const tokenLabels = [];
  830. const tokenBinops = [];
  831. const tokenBeforeExprs = [];
  832. const tokenStartsExprs = [];
  833. const tokenPrefixes = [];
  834. function createToken(name, options = {}) {
  835. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  836. ++tokenTypeCounter;
  837. tokenLabels.push(name);
  838. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  839. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  840. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  841. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  842. tokenTypes.push(new ExportedTokenType(name, options));
  843. return tokenTypeCounter;
  844. }
  845. function createKeywordLike(name, options = {}) {
  846. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  847. ++tokenTypeCounter;
  848. keywords$1.set(name, tokenTypeCounter);
  849. tokenLabels.push(name);
  850. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  851. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  852. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  853. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  854. tokenTypes.push(new ExportedTokenType("name", options));
  855. return tokenTypeCounter;
  856. }
  857. const tt = {
  858. bracketL: createToken("[", {
  859. beforeExpr,
  860. startsExpr
  861. }),
  862. bracketHashL: createToken("#[", {
  863. beforeExpr,
  864. startsExpr
  865. }),
  866. bracketBarL: createToken("[|", {
  867. beforeExpr,
  868. startsExpr
  869. }),
  870. bracketR: createToken("]"),
  871. bracketBarR: createToken("|]"),
  872. braceL: createToken("{", {
  873. beforeExpr,
  874. startsExpr
  875. }),
  876. braceBarL: createToken("{|", {
  877. beforeExpr,
  878. startsExpr
  879. }),
  880. braceHashL: createToken("#{", {
  881. beforeExpr,
  882. startsExpr
  883. }),
  884. braceR: createToken("}", {
  885. beforeExpr
  886. }),
  887. braceBarR: createToken("|}"),
  888. parenL: createToken("(", {
  889. beforeExpr,
  890. startsExpr
  891. }),
  892. parenR: createToken(")"),
  893. comma: createToken(",", {
  894. beforeExpr
  895. }),
  896. semi: createToken(";", {
  897. beforeExpr
  898. }),
  899. colon: createToken(":", {
  900. beforeExpr
  901. }),
  902. doubleColon: createToken("::", {
  903. beforeExpr
  904. }),
  905. dot: createToken("."),
  906. question: createToken("?", {
  907. beforeExpr
  908. }),
  909. questionDot: createToken("?."),
  910. arrow: createToken("=>", {
  911. beforeExpr
  912. }),
  913. template: createToken("template"),
  914. ellipsis: createToken("...", {
  915. beforeExpr
  916. }),
  917. backQuote: createToken("`", {
  918. startsExpr
  919. }),
  920. dollarBraceL: createToken("${", {
  921. beforeExpr,
  922. startsExpr
  923. }),
  924. at: createToken("@"),
  925. hash: createToken("#", {
  926. startsExpr
  927. }),
  928. interpreterDirective: createToken("#!..."),
  929. eq: createToken("=", {
  930. beforeExpr,
  931. isAssign
  932. }),
  933. assign: createToken("_=", {
  934. beforeExpr,
  935. isAssign
  936. }),
  937. slashAssign: createToken("_=", {
  938. beforeExpr,
  939. isAssign
  940. }),
  941. xorAssign: createToken("_=", {
  942. beforeExpr,
  943. isAssign
  944. }),
  945. moduloAssign: createToken("_=", {
  946. beforeExpr,
  947. isAssign
  948. }),
  949. incDec: createToken("++/--", {
  950. prefix,
  951. postfix,
  952. startsExpr
  953. }),
  954. bang: createToken("!", {
  955. beforeExpr,
  956. prefix,
  957. startsExpr
  958. }),
  959. tilde: createToken("~", {
  960. beforeExpr,
  961. prefix,
  962. startsExpr
  963. }),
  964. pipeline: createBinop("|>", 0),
  965. nullishCoalescing: createBinop("??", 1),
  966. logicalOR: createBinop("||", 1),
  967. logicalAND: createBinop("&&", 2),
  968. bitwiseOR: createBinop("|", 3),
  969. bitwiseXOR: createBinop("^", 4),
  970. bitwiseAND: createBinop("&", 5),
  971. equality: createBinop("==/!=/===/!==", 6),
  972. lt: createBinop("</>/<=/>=", 7),
  973. gt: createBinop("</>/<=/>=", 7),
  974. relational: createBinop("</>/<=/>=", 7),
  975. bitShift: createBinop("<</>>/>>>", 8),
  976. plusMin: createToken("+/-", {
  977. beforeExpr,
  978. binop: 9,
  979. prefix,
  980. startsExpr
  981. }),
  982. modulo: createToken("%", {
  983. binop: 10,
  984. startsExpr
  985. }),
  986. star: createToken("*", {
  987. binop: 10
  988. }),
  989. slash: createBinop("/", 10),
  990. exponent: createToken("**", {
  991. beforeExpr,
  992. binop: 11,
  993. rightAssociative: true
  994. }),
  995. _in: createKeyword("in", {
  996. beforeExpr,
  997. binop: 7
  998. }),
  999. _instanceof: createKeyword("instanceof", {
  1000. beforeExpr,
  1001. binop: 7
  1002. }),
  1003. _break: createKeyword("break"),
  1004. _case: createKeyword("case", {
  1005. beforeExpr
  1006. }),
  1007. _catch: createKeyword("catch"),
  1008. _continue: createKeyword("continue"),
  1009. _debugger: createKeyword("debugger"),
  1010. _default: createKeyword("default", {
  1011. beforeExpr
  1012. }),
  1013. _else: createKeyword("else", {
  1014. beforeExpr
  1015. }),
  1016. _finally: createKeyword("finally"),
  1017. _function: createKeyword("function", {
  1018. startsExpr
  1019. }),
  1020. _if: createKeyword("if"),
  1021. _return: createKeyword("return", {
  1022. beforeExpr
  1023. }),
  1024. _switch: createKeyword("switch"),
  1025. _throw: createKeyword("throw", {
  1026. beforeExpr,
  1027. prefix,
  1028. startsExpr
  1029. }),
  1030. _try: createKeyword("try"),
  1031. _var: createKeyword("var"),
  1032. _const: createKeyword("const"),
  1033. _with: createKeyword("with"),
  1034. _new: createKeyword("new", {
  1035. beforeExpr,
  1036. startsExpr
  1037. }),
  1038. _this: createKeyword("this", {
  1039. startsExpr
  1040. }),
  1041. _super: createKeyword("super", {
  1042. startsExpr
  1043. }),
  1044. _class: createKeyword("class", {
  1045. startsExpr
  1046. }),
  1047. _extends: createKeyword("extends", {
  1048. beforeExpr
  1049. }),
  1050. _export: createKeyword("export"),
  1051. _import: createKeyword("import", {
  1052. startsExpr
  1053. }),
  1054. _null: createKeyword("null", {
  1055. startsExpr
  1056. }),
  1057. _true: createKeyword("true", {
  1058. startsExpr
  1059. }),
  1060. _false: createKeyword("false", {
  1061. startsExpr
  1062. }),
  1063. _typeof: createKeyword("typeof", {
  1064. beforeExpr,
  1065. prefix,
  1066. startsExpr
  1067. }),
  1068. _void: createKeyword("void", {
  1069. beforeExpr,
  1070. prefix,
  1071. startsExpr
  1072. }),
  1073. _delete: createKeyword("delete", {
  1074. beforeExpr,
  1075. prefix,
  1076. startsExpr
  1077. }),
  1078. _do: createKeyword("do", {
  1079. isLoop,
  1080. beforeExpr
  1081. }),
  1082. _for: createKeyword("for", {
  1083. isLoop
  1084. }),
  1085. _while: createKeyword("while", {
  1086. isLoop
  1087. }),
  1088. _as: createKeywordLike("as", {
  1089. startsExpr
  1090. }),
  1091. _assert: createKeywordLike("assert", {
  1092. startsExpr
  1093. }),
  1094. _async: createKeywordLike("async", {
  1095. startsExpr
  1096. }),
  1097. _await: createKeywordLike("await", {
  1098. startsExpr
  1099. }),
  1100. _from: createKeywordLike("from", {
  1101. startsExpr
  1102. }),
  1103. _get: createKeywordLike("get", {
  1104. startsExpr
  1105. }),
  1106. _let: createKeywordLike("let", {
  1107. startsExpr
  1108. }),
  1109. _meta: createKeywordLike("meta", {
  1110. startsExpr
  1111. }),
  1112. _of: createKeywordLike("of", {
  1113. startsExpr
  1114. }),
  1115. _sent: createKeywordLike("sent", {
  1116. startsExpr
  1117. }),
  1118. _set: createKeywordLike("set", {
  1119. startsExpr
  1120. }),
  1121. _static: createKeywordLike("static", {
  1122. startsExpr
  1123. }),
  1124. _yield: createKeywordLike("yield", {
  1125. startsExpr
  1126. }),
  1127. _asserts: createKeywordLike("asserts", {
  1128. startsExpr
  1129. }),
  1130. _checks: createKeywordLike("checks", {
  1131. startsExpr
  1132. }),
  1133. _exports: createKeywordLike("exports", {
  1134. startsExpr
  1135. }),
  1136. _global: createKeywordLike("global", {
  1137. startsExpr
  1138. }),
  1139. _implements: createKeywordLike("implements", {
  1140. startsExpr
  1141. }),
  1142. _intrinsic: createKeywordLike("intrinsic", {
  1143. startsExpr
  1144. }),
  1145. _infer: createKeywordLike("infer", {
  1146. startsExpr
  1147. }),
  1148. _is: createKeywordLike("is", {
  1149. startsExpr
  1150. }),
  1151. _mixins: createKeywordLike("mixins", {
  1152. startsExpr
  1153. }),
  1154. _proto: createKeywordLike("proto", {
  1155. startsExpr
  1156. }),
  1157. _require: createKeywordLike("require", {
  1158. startsExpr
  1159. }),
  1160. _keyof: createKeywordLike("keyof", {
  1161. startsExpr
  1162. }),
  1163. _readonly: createKeywordLike("readonly", {
  1164. startsExpr
  1165. }),
  1166. _unique: createKeywordLike("unique", {
  1167. startsExpr
  1168. }),
  1169. _abstract: createKeywordLike("abstract", {
  1170. startsExpr
  1171. }),
  1172. _declare: createKeywordLike("declare", {
  1173. startsExpr
  1174. }),
  1175. _enum: createKeywordLike("enum", {
  1176. startsExpr
  1177. }),
  1178. _module: createKeywordLike("module", {
  1179. startsExpr
  1180. }),
  1181. _namespace: createKeywordLike("namespace", {
  1182. startsExpr
  1183. }),
  1184. _interface: createKeywordLike("interface", {
  1185. startsExpr
  1186. }),
  1187. _type: createKeywordLike("type", {
  1188. startsExpr
  1189. }),
  1190. _opaque: createKeywordLike("opaque", {
  1191. startsExpr
  1192. }),
  1193. name: createToken("name", {
  1194. startsExpr
  1195. }),
  1196. string: createToken("string", {
  1197. startsExpr
  1198. }),
  1199. num: createToken("num", {
  1200. startsExpr
  1201. }),
  1202. bigint: createToken("bigint", {
  1203. startsExpr
  1204. }),
  1205. decimal: createToken("decimal", {
  1206. startsExpr
  1207. }),
  1208. regexp: createToken("regexp", {
  1209. startsExpr
  1210. }),
  1211. privateName: createToken("#name", {
  1212. startsExpr
  1213. }),
  1214. eof: createToken("eof"),
  1215. jsxName: createToken("jsxName"),
  1216. jsxText: createToken("jsxText", {
  1217. beforeExpr: true
  1218. }),
  1219. jsxTagStart: createToken("jsxTagStart", {
  1220. startsExpr: true
  1221. }),
  1222. jsxTagEnd: createToken("jsxTagEnd"),
  1223. placeholder: createToken("%%", {
  1224. startsExpr: true
  1225. })
  1226. };
  1227. function tokenIsIdentifier(token) {
  1228. return token >= 87 && token <= 122;
  1229. }
  1230. function tokenKeywordOrIdentifierIsKeyword(token) {
  1231. return token <= 86;
  1232. }
  1233. function tokenIsKeywordOrIdentifier(token) {
  1234. return token >= 52 && token <= 122;
  1235. }
  1236. function tokenIsLiteralPropertyName(token) {
  1237. return token >= 52 && token <= 126;
  1238. }
  1239. function tokenComesBeforeExpression(token) {
  1240. return tokenBeforeExprs[token];
  1241. }
  1242. function tokenCanStartExpression(token) {
  1243. return tokenStartsExprs[token];
  1244. }
  1245. function tokenIsAssignment(token) {
  1246. return token >= 27 && token <= 31;
  1247. }
  1248. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1249. return token >= 119 && token <= 121;
  1250. }
  1251. function tokenIsLoop(token) {
  1252. return token >= 84 && token <= 86;
  1253. }
  1254. function tokenIsKeyword(token) {
  1255. return token >= 52 && token <= 86;
  1256. }
  1257. function tokenIsOperator(token) {
  1258. return token >= 35 && token <= 53;
  1259. }
  1260. function tokenIsPostfix(token) {
  1261. return token === 32;
  1262. }
  1263. function tokenIsPrefix(token) {
  1264. return tokenPrefixes[token];
  1265. }
  1266. function tokenIsTSTypeOperator(token) {
  1267. return token >= 111 && token <= 113;
  1268. }
  1269. function tokenIsTSDeclarationStart(token) {
  1270. return token >= 114 && token <= 120;
  1271. }
  1272. function tokenLabelName(token) {
  1273. return tokenLabels[token];
  1274. }
  1275. function tokenOperatorPrecedence(token) {
  1276. return tokenBinops[token];
  1277. }
  1278. function tokenIsRightAssociative(token) {
  1279. return token === 51;
  1280. }
  1281. function getExportedToken(token) {
  1282. return tokenTypes[token];
  1283. }
  1284. function isTokenType(obj) {
  1285. return typeof obj === "number";
  1286. }
  1287. {
  1288. tokenTypes[8].updateContext = context => {
  1289. context.pop();
  1290. };
  1291. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1292. context.push(types.brace);
  1293. };
  1294. tokenTypes[22].updateContext = context => {
  1295. if (context[context.length - 1] === types.template) {
  1296. context.pop();
  1297. } else {
  1298. context.push(types.template);
  1299. }
  1300. };
  1301. tokenTypes[132].updateContext = context => {
  1302. context.push(types.j_expr, types.j_oTag);
  1303. };
  1304. }
  1305. 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";
  1306. 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";
  1307. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1308. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1309. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1310. 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];
  1311. 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];
  1312. function isInAstralSet(code, set) {
  1313. let pos = 0x10000;
  1314. for (let i = 0, length = set.length; i < length; i += 2) {
  1315. pos += set[i];
  1316. if (pos > code) return false;
  1317. pos += set[i + 1];
  1318. if (pos >= code) return true;
  1319. }
  1320. return false;
  1321. }
  1322. function isIdentifierStart(code) {
  1323. if (code < 65) return code === 36;
  1324. if (code <= 90) return true;
  1325. if (code < 97) return code === 95;
  1326. if (code <= 122) return true;
  1327. if (code <= 0xffff) {
  1328. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1329. }
  1330. return isInAstralSet(code, astralIdentifierStartCodes);
  1331. }
  1332. function isIdentifierChar(code) {
  1333. if (code < 48) return code === 36;
  1334. if (code < 58) return true;
  1335. if (code < 65) return false;
  1336. if (code <= 90) return true;
  1337. if (code < 97) return code === 95;
  1338. if (code <= 122) return true;
  1339. if (code <= 0xffff) {
  1340. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1341. }
  1342. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1343. }
  1344. const reservedWords = {
  1345. 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"],
  1346. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1347. strictBind: ["eval", "arguments"]
  1348. };
  1349. const keywords = new Set(reservedWords.keyword);
  1350. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1351. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1352. function isReservedWord(word, inModule) {
  1353. return inModule && word === "await" || word === "enum";
  1354. }
  1355. function isStrictReservedWord(word, inModule) {
  1356. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1357. }
  1358. function isStrictBindOnlyReservedWord(word) {
  1359. return reservedWordsStrictBindSet.has(word);
  1360. }
  1361. function isStrictBindReservedWord(word, inModule) {
  1362. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1363. }
  1364. function isKeyword(word) {
  1365. return keywords.has(word);
  1366. }
  1367. function isIteratorStart(current, next) {
  1368. return current === 64 && next === 64;
  1369. }
  1370. 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"]);
  1371. function canBeReservedWord(word) {
  1372. return reservedWordLikeSet.has(word);
  1373. }
  1374. const SCOPE_OTHER = 0b000000000,
  1375. SCOPE_PROGRAM = 0b000000001,
  1376. SCOPE_FUNCTION = 0b000000010,
  1377. SCOPE_ARROW = 0b000000100,
  1378. SCOPE_SIMPLE_CATCH = 0b000001000,
  1379. SCOPE_SUPER = 0b000010000,
  1380. SCOPE_DIRECT_SUPER = 0b000100000,
  1381. SCOPE_CLASS = 0b001000000,
  1382. SCOPE_STATIC_BLOCK = 0b010000000,
  1383. SCOPE_TS_MODULE = 0b100000000,
  1384. SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_TS_MODULE;
  1385. const BIND_KIND_VALUE = 0b000000000001,
  1386. BIND_KIND_TYPE = 0b000000000010,
  1387. BIND_SCOPE_VAR = 0b000000000100,
  1388. BIND_SCOPE_LEXICAL = 0b000000001000,
  1389. BIND_SCOPE_FUNCTION = 0b000000010000,
  1390. BIND_FLAGS_NONE = 0b000001000000,
  1391. BIND_FLAGS_CLASS = 0b000010000000,
  1392. BIND_FLAGS_TS_ENUM = 0b000100000000,
  1393. BIND_FLAGS_TS_CONST_ENUM = 0b001000000000,
  1394. BIND_FLAGS_TS_EXPORT_ONLY = 0b010000000000,
  1395. BIND_FLAGS_FLOW_DECLARE_FN = 0b100000000000;
  1396. const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS,
  1397. BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0,
  1398. BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0,
  1399. BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0,
  1400. BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS,
  1401. BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0,
  1402. BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM,
  1403. BIND_TS_AMBIENT = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1404. BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE,
  1405. BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE,
  1406. BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM,
  1407. BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
  1408. BIND_FLOW_DECLARE_FN = BIND_FLAGS_FLOW_DECLARE_FN;
  1409. const CLASS_ELEMENT_FLAG_STATIC = 0b100,
  1410. CLASS_ELEMENT_KIND_GETTER = 0b010,
  1411. CLASS_ELEMENT_KIND_SETTER = 0b001,
  1412. CLASS_ELEMENT_KIND_ACCESSOR = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_KIND_SETTER;
  1413. const CLASS_ELEMENT_STATIC_GETTER = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_FLAG_STATIC,
  1414. CLASS_ELEMENT_STATIC_SETTER = CLASS_ELEMENT_KIND_SETTER | CLASS_ELEMENT_FLAG_STATIC,
  1415. CLASS_ELEMENT_INSTANCE_GETTER = CLASS_ELEMENT_KIND_GETTER,
  1416. CLASS_ELEMENT_INSTANCE_SETTER = CLASS_ELEMENT_KIND_SETTER,
  1417. CLASS_ELEMENT_OTHER = 0;
  1418. class Scope {
  1419. constructor(flags) {
  1420. this.var = new Set();
  1421. this.lexical = new Set();
  1422. this.functions = new Set();
  1423. this.flags = flags;
  1424. }
  1425. }
  1426. class ScopeHandler {
  1427. constructor(raise, inModule) {
  1428. this.scopeStack = [];
  1429. this.undefinedExports = new Map();
  1430. this.undefinedPrivateNames = new Map();
  1431. this.raise = raise;
  1432. this.inModule = inModule;
  1433. }
  1434. get inFunction() {
  1435. return (this.currentVarScopeFlags() & SCOPE_FUNCTION) > 0;
  1436. }
  1437. get allowSuper() {
  1438. return (this.currentThisScopeFlags() & SCOPE_SUPER) > 0;
  1439. }
  1440. get allowDirectSuper() {
  1441. return (this.currentThisScopeFlags() & SCOPE_DIRECT_SUPER) > 0;
  1442. }
  1443. get inClass() {
  1444. return (this.currentThisScopeFlags() & SCOPE_CLASS) > 0;
  1445. }
  1446. get inClassAndNotInNonArrowFunction() {
  1447. const flags = this.currentThisScopeFlags();
  1448. return (flags & SCOPE_CLASS) > 0 && (flags & SCOPE_FUNCTION) === 0;
  1449. }
  1450. get inStaticBlock() {
  1451. for (let i = this.scopeStack.length - 1;; i--) {
  1452. const {
  1453. flags
  1454. } = this.scopeStack[i];
  1455. if (flags & SCOPE_STATIC_BLOCK) {
  1456. return true;
  1457. }
  1458. if (flags & (SCOPE_VAR | SCOPE_CLASS)) {
  1459. return false;
  1460. }
  1461. }
  1462. }
  1463. get inNonArrowFunction() {
  1464. return (this.currentThisScopeFlags() & SCOPE_FUNCTION) > 0;
  1465. }
  1466. get treatFunctionsAsVar() {
  1467. return this.treatFunctionsAsVarInScope(this.currentScope());
  1468. }
  1469. createScope(flags) {
  1470. return new Scope(flags);
  1471. }
  1472. enter(flags) {
  1473. this.scopeStack.push(this.createScope(flags));
  1474. }
  1475. exit() {
  1476. this.scopeStack.pop();
  1477. }
  1478. treatFunctionsAsVarInScope(scope) {
  1479. return !!(scope.flags & SCOPE_FUNCTION || !this.inModule && scope.flags & SCOPE_PROGRAM);
  1480. }
  1481. declareName(name, bindingType, pos) {
  1482. let scope = this.currentScope();
  1483. if (bindingType & BIND_SCOPE_LEXICAL || bindingType & BIND_SCOPE_FUNCTION) {
  1484. this.checkRedeclarationInScope(scope, name, bindingType, pos);
  1485. if (bindingType & BIND_SCOPE_FUNCTION) {
  1486. scope.functions.add(name);
  1487. } else {
  1488. scope.lexical.add(name);
  1489. }
  1490. if (bindingType & BIND_SCOPE_LEXICAL) {
  1491. this.maybeExportDefined(scope, name);
  1492. }
  1493. } else if (bindingType & BIND_SCOPE_VAR) {
  1494. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1495. scope = this.scopeStack[i];
  1496. this.checkRedeclarationInScope(scope, name, bindingType, pos);
  1497. scope.var.add(name);
  1498. this.maybeExportDefined(scope, name);
  1499. if (scope.flags & SCOPE_VAR) break;
  1500. }
  1501. }
  1502. if (this.inModule && scope.flags & SCOPE_PROGRAM) {
  1503. this.undefinedExports.delete(name);
  1504. }
  1505. }
  1506. maybeExportDefined(scope, name) {
  1507. if (this.inModule && scope.flags & SCOPE_PROGRAM) {
  1508. this.undefinedExports.delete(name);
  1509. }
  1510. }
  1511. checkRedeclarationInScope(scope, name, bindingType, pos) {
  1512. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1513. this.raise(pos, ErrorMessages.VarRedeclaration, name);
  1514. }
  1515. }
  1516. isRedeclaredInScope(scope, name, bindingType) {
  1517. if (!(bindingType & BIND_KIND_VALUE)) return false;
  1518. if (bindingType & BIND_SCOPE_LEXICAL) {
  1519. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  1520. }
  1521. if (bindingType & BIND_SCOPE_FUNCTION) {
  1522. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  1523. }
  1524. return scope.lexical.has(name) && !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  1525. }
  1526. checkLocalExport(id) {
  1527. const {
  1528. name
  1529. } = id;
  1530. const topLevelScope = this.scopeStack[0];
  1531. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
  1532. this.undefinedExports.set(name, id.start);
  1533. }
  1534. }
  1535. currentScope() {
  1536. return this.scopeStack[this.scopeStack.length - 1];
  1537. }
  1538. currentVarScopeFlags() {
  1539. for (let i = this.scopeStack.length - 1;; i--) {
  1540. const {
  1541. flags
  1542. } = this.scopeStack[i];
  1543. if (flags & SCOPE_VAR) {
  1544. return flags;
  1545. }
  1546. }
  1547. }
  1548. currentThisScopeFlags() {
  1549. for (let i = this.scopeStack.length - 1;; i--) {
  1550. const {
  1551. flags
  1552. } = this.scopeStack[i];
  1553. if (flags & (SCOPE_VAR | SCOPE_CLASS) && !(flags & SCOPE_ARROW)) {
  1554. return flags;
  1555. }
  1556. }
  1557. }
  1558. }
  1559. class FlowScope extends Scope {
  1560. constructor(...args) {
  1561. super(...args);
  1562. this.declareFunctions = new Set();
  1563. }
  1564. }
  1565. class FlowScopeHandler extends ScopeHandler {
  1566. createScope(flags) {
  1567. return new FlowScope(flags);
  1568. }
  1569. declareName(name, bindingType, pos) {
  1570. const scope = this.currentScope();
  1571. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  1572. this.checkRedeclarationInScope(scope, name, bindingType, pos);
  1573. this.maybeExportDefined(scope, name);
  1574. scope.declareFunctions.add(name);
  1575. return;
  1576. }
  1577. super.declareName(...arguments);
  1578. }
  1579. isRedeclaredInScope(scope, name, bindingType) {
  1580. if (super.isRedeclaredInScope(...arguments)) return true;
  1581. if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {
  1582. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  1583. }
  1584. return false;
  1585. }
  1586. checkLocalExport(id) {
  1587. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1588. super.checkLocalExport(id);
  1589. }
  1590. }
  1591. }
  1592. class State {
  1593. constructor() {
  1594. this.strict = void 0;
  1595. this.curLine = void 0;
  1596. this.lineStart = void 0;
  1597. this.startLoc = void 0;
  1598. this.endLoc = void 0;
  1599. this.errors = [];
  1600. this.potentialArrowAt = -1;
  1601. this.noArrowAt = [];
  1602. this.noArrowParamsConversionAt = [];
  1603. this.maybeInArrowParameters = false;
  1604. this.inType = false;
  1605. this.noAnonFunctionType = false;
  1606. this.hasFlowComment = false;
  1607. this.isAmbientContext = false;
  1608. this.inAbstractClass = false;
  1609. this.topicContext = {
  1610. maxNumOfResolvableTopics: 0,
  1611. maxTopicIndex: null
  1612. };
  1613. this.soloAwait = false;
  1614. this.inFSharpPipelineDirectBody = false;
  1615. this.labels = [];
  1616. this.decoratorStack = [[]];
  1617. this.comments = [];
  1618. this.commentStack = [];
  1619. this.pos = 0;
  1620. this.type = 129;
  1621. this.value = null;
  1622. this.start = 0;
  1623. this.end = 0;
  1624. this.lastTokEndLoc = null;
  1625. this.lastTokStartLoc = null;
  1626. this.lastTokStart = 0;
  1627. this.lastTokEnd = 0;
  1628. this.context = [types.brace];
  1629. this.canStartJSXElement = true;
  1630. this.containsEsc = false;
  1631. this.strictErrors = new Map();
  1632. this.tokensLength = 0;
  1633. }
  1634. init({
  1635. strictMode,
  1636. sourceType,
  1637. startLine,
  1638. startColumn
  1639. }) {
  1640. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1641. this.curLine = startLine;
  1642. this.lineStart = -startColumn;
  1643. this.startLoc = this.endLoc = new Position(startLine, startColumn);
  1644. }
  1645. curPosition() {
  1646. return new Position(this.curLine, this.pos - this.lineStart);
  1647. }
  1648. clone(skipArrays) {
  1649. const state = new State();
  1650. const keys = Object.keys(this);
  1651. for (let i = 0, length = keys.length; i < length; i++) {
  1652. const key = keys[i];
  1653. let val = this[key];
  1654. if (!skipArrays && Array.isArray(val)) {
  1655. val = val.slice();
  1656. }
  1657. state[key] = val;
  1658. }
  1659. return state;
  1660. }
  1661. }
  1662. var _isDigit = function isDigit(code) {
  1663. return code >= 48 && code <= 57;
  1664. };
  1665. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100]);
  1666. const forbiddenNumericSeparatorSiblings = {
  1667. decBinOct: [46, 66, 69, 79, 95, 98, 101, 111],
  1668. hex: [46, 88, 95, 120]
  1669. };
  1670. const allowedNumericSeparatorSiblings = {};
  1671. allowedNumericSeparatorSiblings.bin = [48, 49];
  1672. allowedNumericSeparatorSiblings.oct = [...allowedNumericSeparatorSiblings.bin, 50, 51, 52, 53, 54, 55];
  1673. allowedNumericSeparatorSiblings.dec = [...allowedNumericSeparatorSiblings.oct, 56, 57];
  1674. allowedNumericSeparatorSiblings.hex = [...allowedNumericSeparatorSiblings.dec, 65, 66, 67, 68, 69, 70, 97, 98, 99, 100, 101, 102];
  1675. class Token {
  1676. constructor(state) {
  1677. this.type = state.type;
  1678. this.value = state.value;
  1679. this.start = state.start;
  1680. this.end = state.end;
  1681. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  1682. }
  1683. }
  1684. class Tokenizer extends ParserError {
  1685. constructor(options, input) {
  1686. super();
  1687. this.isLookahead = void 0;
  1688. this.tokens = [];
  1689. this.state = new State();
  1690. this.state.init(options);
  1691. this.input = input;
  1692. this.length = input.length;
  1693. this.isLookahead = false;
  1694. }
  1695. pushToken(token) {
  1696. this.tokens.length = this.state.tokensLength;
  1697. this.tokens.push(token);
  1698. ++this.state.tokensLength;
  1699. }
  1700. next() {
  1701. this.checkKeywordEscapes();
  1702. if (this.options.tokens) {
  1703. this.pushToken(new Token(this.state));
  1704. }
  1705. this.state.lastTokEnd = this.state.end;
  1706. this.state.lastTokStart = this.state.start;
  1707. this.state.lastTokEndLoc = this.state.endLoc;
  1708. this.state.lastTokStartLoc = this.state.startLoc;
  1709. this.nextToken();
  1710. }
  1711. eat(type) {
  1712. if (this.match(type)) {
  1713. this.next();
  1714. return true;
  1715. } else {
  1716. return false;
  1717. }
  1718. }
  1719. match(type) {
  1720. return this.state.type === type;
  1721. }
  1722. createLookaheadState(state) {
  1723. return {
  1724. pos: state.pos,
  1725. value: null,
  1726. type: state.type,
  1727. start: state.start,
  1728. end: state.end,
  1729. lastTokEnd: state.end,
  1730. context: [this.curContext()],
  1731. inType: state.inType
  1732. };
  1733. }
  1734. lookahead() {
  1735. const old = this.state;
  1736. this.state = this.createLookaheadState(old);
  1737. this.isLookahead = true;
  1738. this.nextToken();
  1739. this.isLookahead = false;
  1740. const curr = this.state;
  1741. this.state = old;
  1742. return curr;
  1743. }
  1744. nextTokenStart() {
  1745. return this.nextTokenStartSince(this.state.pos);
  1746. }
  1747. nextTokenStartSince(pos) {
  1748. skipWhiteSpace.lastIndex = pos;
  1749. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  1750. }
  1751. lookaheadCharCode() {
  1752. return this.input.charCodeAt(this.nextTokenStart());
  1753. }
  1754. codePointAtPos(pos) {
  1755. let cp = this.input.charCodeAt(pos);
  1756. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  1757. const trail = this.input.charCodeAt(pos);
  1758. if ((trail & 0xfc00) === 0xdc00) {
  1759. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  1760. }
  1761. }
  1762. return cp;
  1763. }
  1764. setStrict(strict) {
  1765. this.state.strict = strict;
  1766. if (strict) {
  1767. this.state.strictErrors.forEach((message, pos) => this.raise(pos, message));
  1768. this.state.strictErrors.clear();
  1769. }
  1770. }
  1771. curContext() {
  1772. return this.state.context[this.state.context.length - 1];
  1773. }
  1774. nextToken() {
  1775. const curContext = this.curContext();
  1776. if (!curContext.preserveSpace) this.skipSpace();
  1777. this.state.start = this.state.pos;
  1778. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  1779. if (this.state.pos >= this.length) {
  1780. this.finishToken(129);
  1781. return;
  1782. }
  1783. if (curContext === types.template) {
  1784. this.readTmplToken();
  1785. } else {
  1786. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  1787. }
  1788. }
  1789. skipBlockComment() {
  1790. let startLoc;
  1791. if (!this.isLookahead) startLoc = this.state.curPosition();
  1792. const start = this.state.pos;
  1793. const end = this.input.indexOf("*/", start + 2);
  1794. if (end === -1) throw this.raise(start, ErrorMessages.UnterminatedComment);
  1795. this.state.pos = end + 2;
  1796. lineBreakG.lastIndex = start + 2;
  1797. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  1798. ++this.state.curLine;
  1799. this.state.lineStart = lineBreakG.lastIndex;
  1800. }
  1801. if (this.isLookahead) return;
  1802. const comment = {
  1803. type: "CommentBlock",
  1804. value: this.input.slice(start + 2, end),
  1805. start,
  1806. end: end + 2,
  1807. loc: new SourceLocation(startLoc, this.state.curPosition())
  1808. };
  1809. if (this.options.tokens) this.pushToken(comment);
  1810. return comment;
  1811. }
  1812. skipLineComment(startSkip) {
  1813. const start = this.state.pos;
  1814. let startLoc;
  1815. if (!this.isLookahead) startLoc = this.state.curPosition();
  1816. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  1817. if (this.state.pos < this.length) {
  1818. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  1819. ch = this.input.charCodeAt(this.state.pos);
  1820. }
  1821. }
  1822. if (this.isLookahead) return;
  1823. const end = this.state.pos;
  1824. const value = this.input.slice(start + startSkip, end);
  1825. const comment = {
  1826. type: "CommentLine",
  1827. value,
  1828. start,
  1829. end,
  1830. loc: new SourceLocation(startLoc, this.state.curPosition())
  1831. };
  1832. if (this.options.tokens) this.pushToken(comment);
  1833. return comment;
  1834. }
  1835. skipSpace() {
  1836. const spaceStart = this.state.pos;
  1837. const comments = [];
  1838. loop: while (this.state.pos < this.length) {
  1839. const ch = this.input.charCodeAt(this.state.pos);
  1840. switch (ch) {
  1841. case 32:
  1842. case 160:
  1843. case 9:
  1844. ++this.state.pos;
  1845. break;
  1846. case 13:
  1847. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  1848. ++this.state.pos;
  1849. }
  1850. case 10:
  1851. case 8232:
  1852. case 8233:
  1853. ++this.state.pos;
  1854. ++this.state.curLine;
  1855. this.state.lineStart = this.state.pos;
  1856. break;
  1857. case 47:
  1858. switch (this.input.charCodeAt(this.state.pos + 1)) {
  1859. case 42:
  1860. {
  1861. const comment = this.skipBlockComment();
  1862. if (comment !== undefined) {
  1863. this.addComment(comment);
  1864. if (this.options.attachComment) comments.push(comment);
  1865. }
  1866. break;
  1867. }
  1868. case 47:
  1869. {
  1870. const comment = this.skipLineComment(2);
  1871. if (comment !== undefined) {
  1872. this.addComment(comment);
  1873. if (this.options.attachComment) comments.push(comment);
  1874. }
  1875. break;
  1876. }
  1877. default:
  1878. break loop;
  1879. }
  1880. break;
  1881. default:
  1882. if (isWhitespace(ch)) {
  1883. ++this.state.pos;
  1884. } else if (ch === 45 && !this.inModule) {
  1885. const pos = this.state.pos;
  1886. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  1887. const comment = this.skipLineComment(3);
  1888. if (comment !== undefined) {
  1889. this.addComment(comment);
  1890. if (this.options.attachComment) comments.push(comment);
  1891. }
  1892. } else {
  1893. break loop;
  1894. }
  1895. } else if (ch === 60 && !this.inModule) {
  1896. const pos = this.state.pos;
  1897. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  1898. const comment = this.skipLineComment(4);
  1899. if (comment !== undefined) {
  1900. this.addComment(comment);
  1901. if (this.options.attachComment) comments.push(comment);
  1902. }
  1903. } else {
  1904. break loop;
  1905. }
  1906. } else {
  1907. break loop;
  1908. }
  1909. }
  1910. }
  1911. if (comments.length > 0) {
  1912. const end = this.state.pos;
  1913. const CommentWhitespace = {
  1914. start: spaceStart,
  1915. end,
  1916. comments,
  1917. leadingNode: null,
  1918. trailingNode: null,
  1919. containingNode: null
  1920. };
  1921. this.state.commentStack.push(CommentWhitespace);
  1922. }
  1923. }
  1924. finishToken(type, val) {
  1925. this.state.end = this.state.pos;
  1926. const prevType = this.state.type;
  1927. this.state.type = type;
  1928. this.state.value = val;
  1929. if (!this.isLookahead) {
  1930. this.state.endLoc = this.state.curPosition();
  1931. this.updateContext(prevType);
  1932. }
  1933. }
  1934. replaceToken(type) {
  1935. this.state.type = type;
  1936. this.updateContext();
  1937. }
  1938. readToken_numberSign() {
  1939. if (this.state.pos === 0 && this.readToken_interpreter()) {
  1940. return;
  1941. }
  1942. const nextPos = this.state.pos + 1;
  1943. const next = this.codePointAtPos(nextPos);
  1944. if (next >= 48 && next <= 57) {
  1945. throw this.raise(this.state.pos, ErrorMessages.UnexpectedDigitAfterHash);
  1946. }
  1947. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  1948. this.expectPlugin("recordAndTuple");
  1949. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "hash") {
  1950. throw this.raise(this.state.pos, next === 123 ? ErrorMessages.RecordExpressionHashIncorrectStartSyntaxType : ErrorMessages.TupleExpressionHashIncorrectStartSyntaxType);
  1951. }
  1952. this.state.pos += 2;
  1953. if (next === 123) {
  1954. this.finishToken(7);
  1955. } else {
  1956. this.finishToken(1);
  1957. }
  1958. } else if (isIdentifierStart(next)) {
  1959. ++this.state.pos;
  1960. this.finishToken(128, this.readWord1(next));
  1961. } else if (next === 92) {
  1962. ++this.state.pos;
  1963. this.finishToken(128, this.readWord1());
  1964. } else {
  1965. this.finishOp(25, 1);
  1966. }
  1967. }
  1968. readToken_dot() {
  1969. const next = this.input.charCodeAt(this.state.pos + 1);
  1970. if (next >= 48 && next <= 57) {
  1971. this.readNumber(true);
  1972. return;
  1973. }
  1974. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  1975. this.state.pos += 3;
  1976. this.finishToken(21);
  1977. } else {
  1978. ++this.state.pos;
  1979. this.finishToken(16);
  1980. }
  1981. }
  1982. readToken_slash() {
  1983. const next = this.input.charCodeAt(this.state.pos + 1);
  1984. if (next === 61) {
  1985. this.finishOp(29, 2);
  1986. } else {
  1987. this.finishOp(50, 1);
  1988. }
  1989. }
  1990. readToken_interpreter() {
  1991. if (this.state.pos !== 0 || this.length < 2) return false;
  1992. let ch = this.input.charCodeAt(this.state.pos + 1);
  1993. if (ch !== 33) return false;
  1994. const start = this.state.pos;
  1995. this.state.pos += 1;
  1996. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  1997. ch = this.input.charCodeAt(this.state.pos);
  1998. }
  1999. const value = this.input.slice(start + 2, this.state.pos);
  2000. this.finishToken(26, value);
  2001. return true;
  2002. }
  2003. readToken_mult_modulo(code) {
  2004. let type = code === 42 ? 49 : 48;
  2005. let width = 1;
  2006. let next = this.input.charCodeAt(this.state.pos + 1);
  2007. if (code === 42 && next === 42) {
  2008. width++;
  2009. next = this.input.charCodeAt(this.state.pos + 2);
  2010. type = 51;
  2011. }
  2012. if (next === 61 && !this.state.inType) {
  2013. width++;
  2014. type = code === 37 ? 31 : 28;
  2015. }
  2016. this.finishOp(type, width);
  2017. }
  2018. readToken_pipe_amp(code) {
  2019. const next = this.input.charCodeAt(this.state.pos + 1);
  2020. if (next === code) {
  2021. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2022. this.finishOp(28, 3);
  2023. } else {
  2024. this.finishOp(code === 124 ? 37 : 38, 2);
  2025. }
  2026. return;
  2027. }
  2028. if (code === 124) {
  2029. if (next === 62) {
  2030. this.finishOp(35, 2);
  2031. return;
  2032. }
  2033. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2034. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2035. throw this.raise(this.state.pos, ErrorMessages.RecordExpressionBarIncorrectEndSyntaxType);
  2036. }
  2037. this.state.pos += 2;
  2038. this.finishToken(9);
  2039. return;
  2040. }
  2041. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2042. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2043. throw this.raise(this.state.pos, ErrorMessages.TupleExpressionBarIncorrectEndSyntaxType);
  2044. }
  2045. this.state.pos += 2;
  2046. this.finishToken(4);
  2047. return;
  2048. }
  2049. }
  2050. if (next === 61) {
  2051. this.finishOp(28, 2);
  2052. return;
  2053. }
  2054. this.finishOp(code === 124 ? 39 : 41, 1);
  2055. }
  2056. readToken_caret() {
  2057. const next = this.input.charCodeAt(this.state.pos + 1);
  2058. if (next === 61 && !this.state.inType) {
  2059. this.finishOp(30, 2);
  2060. } else {
  2061. this.finishOp(40, 1);
  2062. }
  2063. }
  2064. readToken_plus_min(code) {
  2065. const next = this.input.charCodeAt(this.state.pos + 1);
  2066. if (next === code) {
  2067. this.finishOp(32, 2);
  2068. return;
  2069. }
  2070. if (next === 61) {
  2071. this.finishOp(28, 2);
  2072. } else {
  2073. this.finishOp(47, 1);
  2074. }
  2075. }
  2076. readToken_lt() {
  2077. const {
  2078. pos
  2079. } = this.state;
  2080. const next = this.input.charCodeAt(pos + 1);
  2081. if (next === 60) {
  2082. if (this.input.charCodeAt(pos + 2) === 61) {
  2083. this.finishOp(28, 3);
  2084. return;
  2085. }
  2086. this.finishOp(46, 2);
  2087. return;
  2088. }
  2089. if (next === 61) {
  2090. this.finishOp(45, 2);
  2091. return;
  2092. }
  2093. this.finishOp(43, 1);
  2094. }
  2095. readToken_gt() {
  2096. const {
  2097. pos
  2098. } = this.state;
  2099. const next = this.input.charCodeAt(pos + 1);
  2100. if (next === 62) {
  2101. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2102. if (this.input.charCodeAt(pos + size) === 61) {
  2103. this.finishOp(28, size + 1);
  2104. return;
  2105. }
  2106. this.finishOp(46, size);
  2107. return;
  2108. }
  2109. if (next === 61) {
  2110. this.finishOp(45, 2);
  2111. return;
  2112. }
  2113. this.finishOp(44, 1);
  2114. }
  2115. readToken_eq_excl(code) {
  2116. const next = this.input.charCodeAt(this.state.pos + 1);
  2117. if (next === 61) {
  2118. this.finishOp(42, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2119. return;
  2120. }
  2121. if (code === 61 && next === 62) {
  2122. this.state.pos += 2;
  2123. this.finishToken(19);
  2124. return;
  2125. }
  2126. this.finishOp(code === 61 ? 27 : 33, 1);
  2127. }
  2128. readToken_question() {
  2129. const next = this.input.charCodeAt(this.state.pos + 1);
  2130. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2131. if (next === 63) {
  2132. if (next2 === 61) {
  2133. this.finishOp(28, 3);
  2134. } else {
  2135. this.finishOp(36, 2);
  2136. }
  2137. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2138. this.state.pos += 2;
  2139. this.finishToken(18);
  2140. } else {
  2141. ++this.state.pos;
  2142. this.finishToken(17);
  2143. }
  2144. }
  2145. getTokenFromCode(code) {
  2146. switch (code) {
  2147. case 46:
  2148. this.readToken_dot();
  2149. return;
  2150. case 40:
  2151. ++this.state.pos;
  2152. this.finishToken(10);
  2153. return;
  2154. case 41:
  2155. ++this.state.pos;
  2156. this.finishToken(11);
  2157. return;
  2158. case 59:
  2159. ++this.state.pos;
  2160. this.finishToken(13);
  2161. return;
  2162. case 44:
  2163. ++this.state.pos;
  2164. this.finishToken(12);
  2165. return;
  2166. case 91:
  2167. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2168. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2169. throw this.raise(this.state.pos, ErrorMessages.TupleExpressionBarIncorrectStartSyntaxType);
  2170. }
  2171. this.state.pos += 2;
  2172. this.finishToken(2);
  2173. } else {
  2174. ++this.state.pos;
  2175. this.finishToken(0);
  2176. }
  2177. return;
  2178. case 93:
  2179. ++this.state.pos;
  2180. this.finishToken(3);
  2181. return;
  2182. case 123:
  2183. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2184. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2185. throw this.raise(this.state.pos, ErrorMessages.RecordExpressionBarIncorrectStartSyntaxType);
  2186. }
  2187. this.state.pos += 2;
  2188. this.finishToken(6);
  2189. } else {
  2190. ++this.state.pos;
  2191. this.finishToken(5);
  2192. }
  2193. return;
  2194. case 125:
  2195. ++this.state.pos;
  2196. this.finishToken(8);
  2197. return;
  2198. case 58:
  2199. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2200. this.finishOp(15, 2);
  2201. } else {
  2202. ++this.state.pos;
  2203. this.finishToken(14);
  2204. }
  2205. return;
  2206. case 63:
  2207. this.readToken_question();
  2208. return;
  2209. case 96:
  2210. ++this.state.pos;
  2211. this.finishToken(22);
  2212. return;
  2213. case 48:
  2214. {
  2215. const next = this.input.charCodeAt(this.state.pos + 1);
  2216. if (next === 120 || next === 88) {
  2217. this.readRadixNumber(16);
  2218. return;
  2219. }
  2220. if (next === 111 || next === 79) {
  2221. this.readRadixNumber(8);
  2222. return;
  2223. }
  2224. if (next === 98 || next === 66) {
  2225. this.readRadixNumber(2);
  2226. return;
  2227. }
  2228. }
  2229. case 49:
  2230. case 50:
  2231. case 51:
  2232. case 52:
  2233. case 53:
  2234. case 54:
  2235. case 55:
  2236. case 56:
  2237. case 57:
  2238. this.readNumber(false);
  2239. return;
  2240. case 34:
  2241. case 39:
  2242. this.readString(code);
  2243. return;
  2244. case 47:
  2245. this.readToken_slash();
  2246. return;
  2247. case 37:
  2248. case 42:
  2249. this.readToken_mult_modulo(code);
  2250. return;
  2251. case 124:
  2252. case 38:
  2253. this.readToken_pipe_amp(code);
  2254. return;
  2255. case 94:
  2256. this.readToken_caret();
  2257. return;
  2258. case 43:
  2259. case 45:
  2260. this.readToken_plus_min(code);
  2261. return;
  2262. case 60:
  2263. this.readToken_lt();
  2264. return;
  2265. case 62:
  2266. this.readToken_gt();
  2267. return;
  2268. case 61:
  2269. case 33:
  2270. this.readToken_eq_excl(code);
  2271. return;
  2272. case 126:
  2273. this.finishOp(34, 1);
  2274. return;
  2275. case 64:
  2276. ++this.state.pos;
  2277. this.finishToken(24);
  2278. return;
  2279. case 35:
  2280. this.readToken_numberSign();
  2281. return;
  2282. case 92:
  2283. this.readWord();
  2284. return;
  2285. default:
  2286. if (isIdentifierStart(code)) {
  2287. this.readWord(code);
  2288. return;
  2289. }
  2290. }
  2291. throw this.raise(this.state.pos, ErrorMessages.InvalidOrUnexpectedToken, String.fromCodePoint(code));
  2292. }
  2293. finishOp(type, size) {
  2294. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2295. this.state.pos += size;
  2296. this.finishToken(type, str);
  2297. }
  2298. readRegexp() {
  2299. const start = this.state.start + 1;
  2300. let escaped, inClass;
  2301. let {
  2302. pos
  2303. } = this.state;
  2304. for (;; ++pos) {
  2305. if (pos >= this.length) {
  2306. throw this.raise(start, ErrorMessages.UnterminatedRegExp);
  2307. }
  2308. const ch = this.input.charCodeAt(pos);
  2309. if (isNewLine(ch)) {
  2310. throw this.raise(start, ErrorMessages.UnterminatedRegExp);
  2311. }
  2312. if (escaped) {
  2313. escaped = false;
  2314. } else {
  2315. if (ch === 91) {
  2316. inClass = true;
  2317. } else if (ch === 93 && inClass) {
  2318. inClass = false;
  2319. } else if (ch === 47 && !inClass) {
  2320. break;
  2321. }
  2322. escaped = ch === 92;
  2323. }
  2324. }
  2325. const content = this.input.slice(start, pos);
  2326. ++pos;
  2327. let mods = "";
  2328. while (pos < this.length) {
  2329. const cp = this.codePointAtPos(pos);
  2330. const char = String.fromCharCode(cp);
  2331. if (VALID_REGEX_FLAGS.has(cp)) {
  2332. if (mods.includes(char)) {
  2333. this.raise(pos + 1, ErrorMessages.DuplicateRegExpFlags);
  2334. }
  2335. } else if (isIdentifierChar(cp) || cp === 92) {
  2336. this.raise(pos + 1, ErrorMessages.MalformedRegExpFlags);
  2337. } else {
  2338. break;
  2339. }
  2340. ++pos;
  2341. mods += char;
  2342. }
  2343. this.state.pos = pos;
  2344. this.finishToken(127, {
  2345. pattern: content,
  2346. flags: mods
  2347. });
  2348. }
  2349. readInt(radix, len, forceLen, allowNumSeparator = true) {
  2350. const start = this.state.pos;
  2351. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2352. const allowedSiblings = radix === 16 ? allowedNumericSeparatorSiblings.hex : radix === 10 ? allowedNumericSeparatorSiblings.dec : radix === 8 ? allowedNumericSeparatorSiblings.oct : allowedNumericSeparatorSiblings.bin;
  2353. let invalid = false;
  2354. let total = 0;
  2355. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2356. const code = this.input.charCodeAt(this.state.pos);
  2357. let val;
  2358. if (code === 95) {
  2359. const prev = this.input.charCodeAt(this.state.pos - 1);
  2360. const next = this.input.charCodeAt(this.state.pos + 1);
  2361. if (allowedSiblings.indexOf(next) === -1) {
  2362. this.raise(this.state.pos, ErrorMessages.UnexpectedNumericSeparator);
  2363. } else if (forbiddenSiblings.indexOf(prev) > -1 || forbiddenSiblings.indexOf(next) > -1 || Number.isNaN(next)) {
  2364. this.raise(this.state.pos, ErrorMessages.UnexpectedNumericSeparator);
  2365. }
  2366. if (!allowNumSeparator) {
  2367. this.raise(this.state.pos, ErrorMessages.NumericSeparatorInEscapeSequence);
  2368. }
  2369. ++this.state.pos;
  2370. continue;
  2371. }
  2372. if (code >= 97) {
  2373. val = code - 97 + 10;
  2374. } else if (code >= 65) {
  2375. val = code - 65 + 10;
  2376. } else if (_isDigit(code)) {
  2377. val = code - 48;
  2378. } else {
  2379. val = Infinity;
  2380. }
  2381. if (val >= radix) {
  2382. if (this.options.errorRecovery && val <= 9) {
  2383. val = 0;
  2384. this.raise(this.state.start + i + 2, ErrorMessages.InvalidDigit, radix);
  2385. } else if (forceLen) {
  2386. val = 0;
  2387. invalid = true;
  2388. } else {
  2389. break;
  2390. }
  2391. }
  2392. ++this.state.pos;
  2393. total = total * radix + val;
  2394. }
  2395. if (this.state.pos === start || len != null && this.state.pos - start !== len || invalid) {
  2396. return null;
  2397. }
  2398. return total;
  2399. }
  2400. readRadixNumber(radix) {
  2401. const start = this.state.pos;
  2402. let isBigInt = false;
  2403. this.state.pos += 2;
  2404. const val = this.readInt(radix);
  2405. if (val == null) {
  2406. this.raise(this.state.start + 2, ErrorMessages.InvalidDigit, radix);
  2407. }
  2408. const next = this.input.charCodeAt(this.state.pos);
  2409. if (next === 110) {
  2410. ++this.state.pos;
  2411. isBigInt = true;
  2412. } else if (next === 109) {
  2413. throw this.raise(start, ErrorMessages.InvalidDecimal);
  2414. }
  2415. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  2416. throw this.raise(this.state.pos, ErrorMessages.NumberIdentifier);
  2417. }
  2418. if (isBigInt) {
  2419. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  2420. this.finishToken(125, str);
  2421. return;
  2422. }
  2423. this.finishToken(124, val);
  2424. }
  2425. readNumber(startsWithDot) {
  2426. const start = this.state.pos;
  2427. let isFloat = false;
  2428. let isBigInt = false;
  2429. let isDecimal = false;
  2430. let hasExponent = false;
  2431. let isOctal = false;
  2432. if (!startsWithDot && this.readInt(10) === null) {
  2433. this.raise(start, ErrorMessages.InvalidNumber);
  2434. }
  2435. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  2436. if (hasLeadingZero) {
  2437. const integer = this.input.slice(start, this.state.pos);
  2438. this.recordStrictModeErrors(start, ErrorMessages.StrictOctalLiteral);
  2439. if (!this.state.strict) {
  2440. const underscorePos = integer.indexOf("_");
  2441. if (underscorePos > 0) {
  2442. this.raise(underscorePos + start, ErrorMessages.ZeroDigitNumericSeparator);
  2443. }
  2444. }
  2445. isOctal = hasLeadingZero && !/[89]/.test(integer);
  2446. }
  2447. let next = this.input.charCodeAt(this.state.pos);
  2448. if (next === 46 && !isOctal) {
  2449. ++this.state.pos;
  2450. this.readInt(10);
  2451. isFloat = true;
  2452. next = this.input.charCodeAt(this.state.pos);
  2453. }
  2454. if ((next === 69 || next === 101) && !isOctal) {
  2455. next = this.input.charCodeAt(++this.state.pos);
  2456. if (next === 43 || next === 45) {
  2457. ++this.state.pos;
  2458. }
  2459. if (this.readInt(10) === null) {
  2460. this.raise(start, ErrorMessages.InvalidOrMissingExponent);
  2461. }
  2462. isFloat = true;
  2463. hasExponent = true;
  2464. next = this.input.charCodeAt(this.state.pos);
  2465. }
  2466. if (next === 110) {
  2467. if (isFloat || hasLeadingZero) {
  2468. this.raise(start, ErrorMessages.InvalidBigIntLiteral);
  2469. }
  2470. ++this.state.pos;
  2471. isBigInt = true;
  2472. }
  2473. if (next === 109) {
  2474. this.expectPlugin("decimal", this.state.pos);
  2475. if (hasExponent || hasLeadingZero) {
  2476. this.raise(start, ErrorMessages.InvalidDecimal);
  2477. }
  2478. ++this.state.pos;
  2479. isDecimal = true;
  2480. }
  2481. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  2482. throw this.raise(this.state.pos, ErrorMessages.NumberIdentifier);
  2483. }
  2484. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  2485. if (isBigInt) {
  2486. this.finishToken(125, str);
  2487. return;
  2488. }
  2489. if (isDecimal) {
  2490. this.finishToken(126, str);
  2491. return;
  2492. }
  2493. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  2494. this.finishToken(124, val);
  2495. }
  2496. readCodePoint(throwOnInvalid) {
  2497. const ch = this.input.charCodeAt(this.state.pos);
  2498. let code;
  2499. if (ch === 123) {
  2500. const codePos = ++this.state.pos;
  2501. code = this.readHexChar(this.input.indexOf("}", this.state.pos) - this.state.pos, true, throwOnInvalid);
  2502. ++this.state.pos;
  2503. if (code !== null && code > 0x10ffff) {
  2504. if (throwOnInvalid) {
  2505. this.raise(codePos, ErrorMessages.InvalidCodePoint);
  2506. } else {
  2507. return null;
  2508. }
  2509. }
  2510. } else {
  2511. code = this.readHexChar(4, false, throwOnInvalid);
  2512. }
  2513. return code;
  2514. }
  2515. readString(quote) {
  2516. let out = "",
  2517. chunkStart = ++this.state.pos;
  2518. for (;;) {
  2519. if (this.state.pos >= this.length) {
  2520. throw this.raise(this.state.start, ErrorMessages.UnterminatedString);
  2521. }
  2522. const ch = this.input.charCodeAt(this.state.pos);
  2523. if (ch === quote) break;
  2524. if (ch === 92) {
  2525. out += this.input.slice(chunkStart, this.state.pos);
  2526. out += this.readEscapedChar(false);
  2527. chunkStart = this.state.pos;
  2528. } else if (ch === 8232 || ch === 8233) {
  2529. ++this.state.pos;
  2530. ++this.state.curLine;
  2531. this.state.lineStart = this.state.pos;
  2532. } else if (isNewLine(ch)) {
  2533. throw this.raise(this.state.start, ErrorMessages.UnterminatedString);
  2534. } else {
  2535. ++this.state.pos;
  2536. }
  2537. }
  2538. out += this.input.slice(chunkStart, this.state.pos++);
  2539. this.finishToken(123, out);
  2540. }
  2541. readTmplToken() {
  2542. let out = "",
  2543. chunkStart = this.state.pos,
  2544. containsInvalid = false;
  2545. for (;;) {
  2546. if (this.state.pos >= this.length) {
  2547. throw this.raise(this.state.start, ErrorMessages.UnterminatedTemplate);
  2548. }
  2549. const ch = this.input.charCodeAt(this.state.pos);
  2550. if (ch === 96 || ch === 36 && this.input.charCodeAt(this.state.pos + 1) === 123) {
  2551. if (this.state.pos === this.state.start && this.match(20)) {
  2552. if (ch === 36) {
  2553. this.state.pos += 2;
  2554. this.finishToken(23);
  2555. return;
  2556. } else {
  2557. ++this.state.pos;
  2558. this.finishToken(22);
  2559. return;
  2560. }
  2561. }
  2562. out += this.input.slice(chunkStart, this.state.pos);
  2563. this.finishToken(20, containsInvalid ? null : out);
  2564. return;
  2565. }
  2566. if (ch === 92) {
  2567. out += this.input.slice(chunkStart, this.state.pos);
  2568. const escaped = this.readEscapedChar(true);
  2569. if (escaped === null) {
  2570. containsInvalid = true;
  2571. } else {
  2572. out += escaped;
  2573. }
  2574. chunkStart = this.state.pos;
  2575. } else if (isNewLine(ch)) {
  2576. out += this.input.slice(chunkStart, this.state.pos);
  2577. ++this.state.pos;
  2578. switch (ch) {
  2579. case 13:
  2580. if (this.input.charCodeAt(this.state.pos) === 10) {
  2581. ++this.state.pos;
  2582. }
  2583. case 10:
  2584. out += "\n";
  2585. break;
  2586. default:
  2587. out += String.fromCharCode(ch);
  2588. break;
  2589. }
  2590. ++this.state.curLine;
  2591. this.state.lineStart = this.state.pos;
  2592. chunkStart = this.state.pos;
  2593. } else {
  2594. ++this.state.pos;
  2595. }
  2596. }
  2597. }
  2598. recordStrictModeErrors(pos, message) {
  2599. if (this.state.strict && !this.state.strictErrors.has(pos)) {
  2600. this.raise(pos, message);
  2601. } else {
  2602. this.state.strictErrors.set(pos, message);
  2603. }
  2604. }
  2605. readEscapedChar(inTemplate) {
  2606. const throwOnInvalid = !inTemplate;
  2607. const ch = this.input.charCodeAt(++this.state.pos);
  2608. ++this.state.pos;
  2609. switch (ch) {
  2610. case 110:
  2611. return "\n";
  2612. case 114:
  2613. return "\r";
  2614. case 120:
  2615. {
  2616. const code = this.readHexChar(2, false, throwOnInvalid);
  2617. return code === null ? null : String.fromCharCode(code);
  2618. }
  2619. case 117:
  2620. {
  2621. const code = this.readCodePoint(throwOnInvalid);
  2622. return code === null ? null : String.fromCodePoint(code);
  2623. }
  2624. case 116:
  2625. return "\t";
  2626. case 98:
  2627. return "\b";
  2628. case 118:
  2629. return "\u000b";
  2630. case 102:
  2631. return "\f";
  2632. case 13:
  2633. if (this.input.charCodeAt(this.state.pos) === 10) {
  2634. ++this.state.pos;
  2635. }
  2636. case 10:
  2637. this.state.lineStart = this.state.pos;
  2638. ++this.state.curLine;
  2639. case 8232:
  2640. case 8233:
  2641. return "";
  2642. case 56:
  2643. case 57:
  2644. if (inTemplate) {
  2645. return null;
  2646. } else {
  2647. this.recordStrictModeErrors(this.state.pos - 1, ErrorMessages.StrictNumericEscape);
  2648. }
  2649. default:
  2650. if (ch >= 48 && ch <= 55) {
  2651. const codePos = this.state.pos - 1;
  2652. const match = this.input.substr(this.state.pos - 1, 3).match(/^[0-7]+/);
  2653. let octalStr = match[0];
  2654. let octal = parseInt(octalStr, 8);
  2655. if (octal > 255) {
  2656. octalStr = octalStr.slice(0, -1);
  2657. octal = parseInt(octalStr, 8);
  2658. }
  2659. this.state.pos += octalStr.length - 1;
  2660. const next = this.input.charCodeAt(this.state.pos);
  2661. if (octalStr !== "0" || next === 56 || next === 57) {
  2662. if (inTemplate) {
  2663. return null;
  2664. } else {
  2665. this.recordStrictModeErrors(codePos, ErrorMessages.StrictNumericEscape);
  2666. }
  2667. }
  2668. return String.fromCharCode(octal);
  2669. }
  2670. return String.fromCharCode(ch);
  2671. }
  2672. }
  2673. readHexChar(len, forceLen, throwOnInvalid) {
  2674. const codePos = this.state.pos;
  2675. const n = this.readInt(16, len, forceLen, false);
  2676. if (n === null) {
  2677. if (throwOnInvalid) {
  2678. this.raise(codePos, ErrorMessages.InvalidEscapeSequence);
  2679. } else {
  2680. this.state.pos = codePos - 1;
  2681. }
  2682. }
  2683. return n;
  2684. }
  2685. readWord1(firstCode) {
  2686. this.state.containsEsc = false;
  2687. let word = "";
  2688. const start = this.state.pos;
  2689. let chunkStart = this.state.pos;
  2690. if (firstCode !== undefined) {
  2691. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  2692. }
  2693. while (this.state.pos < this.length) {
  2694. const ch = this.codePointAtPos(this.state.pos);
  2695. if (isIdentifierChar(ch)) {
  2696. this.state.pos += ch <= 0xffff ? 1 : 2;
  2697. } else if (ch === 92) {
  2698. this.state.containsEsc = true;
  2699. word += this.input.slice(chunkStart, this.state.pos);
  2700. const escStart = this.state.pos;
  2701. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  2702. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  2703. this.raise(this.state.pos, ErrorMessages.MissingUnicodeEscape);
  2704. chunkStart = this.state.pos - 1;
  2705. continue;
  2706. }
  2707. ++this.state.pos;
  2708. const esc = this.readCodePoint(true);
  2709. if (esc !== null) {
  2710. if (!identifierCheck(esc)) {
  2711. this.raise(escStart, ErrorMessages.EscapedCharNotAnIdentifier);
  2712. }
  2713. word += String.fromCodePoint(esc);
  2714. }
  2715. chunkStart = this.state.pos;
  2716. } else {
  2717. break;
  2718. }
  2719. }
  2720. return word + this.input.slice(chunkStart, this.state.pos);
  2721. }
  2722. readWord(firstCode) {
  2723. const word = this.readWord1(firstCode);
  2724. const type = keywords$1.get(word);
  2725. if (type !== undefined) {
  2726. this.finishToken(type, tokenLabelName(type));
  2727. } else {
  2728. this.finishToken(122, word);
  2729. }
  2730. }
  2731. checkKeywordEscapes() {
  2732. const {
  2733. type
  2734. } = this.state;
  2735. if (tokenIsKeyword(type) && this.state.containsEsc) {
  2736. this.raise(this.state.start, ErrorMessages.InvalidEscapedReservedWord, tokenLabelName(type));
  2737. }
  2738. }
  2739. updateContext(prevType) {
  2740. const {
  2741. context,
  2742. type
  2743. } = this.state;
  2744. switch (type) {
  2745. case 8:
  2746. context.pop();
  2747. break;
  2748. case 5:
  2749. case 7:
  2750. case 23:
  2751. context.push(types.brace);
  2752. break;
  2753. case 22:
  2754. if (context[context.length - 1] === types.template) {
  2755. context.pop();
  2756. } else {
  2757. context.push(types.template);
  2758. }
  2759. break;
  2760. }
  2761. }
  2762. }
  2763. class ClassScope {
  2764. constructor() {
  2765. this.privateNames = new Set();
  2766. this.loneAccessors = new Map();
  2767. this.undefinedPrivateNames = new Map();
  2768. }
  2769. }
  2770. class ClassScopeHandler {
  2771. constructor(raise) {
  2772. this.stack = [];
  2773. this.undefinedPrivateNames = new Map();
  2774. this.raise = raise;
  2775. }
  2776. current() {
  2777. return this.stack[this.stack.length - 1];
  2778. }
  2779. enter() {
  2780. this.stack.push(new ClassScope());
  2781. }
  2782. exit() {
  2783. const oldClassScope = this.stack.pop();
  2784. const current = this.current();
  2785. for (const [name, pos] of Array.from(oldClassScope.undefinedPrivateNames)) {
  2786. if (current) {
  2787. if (!current.undefinedPrivateNames.has(name)) {
  2788. current.undefinedPrivateNames.set(name, pos);
  2789. }
  2790. } else {
  2791. this.raise(pos, ErrorMessages.InvalidPrivateFieldResolution, name);
  2792. }
  2793. }
  2794. }
  2795. declarePrivateName(name, elementType, pos) {
  2796. const classScope = this.current();
  2797. let redefined = classScope.privateNames.has(name);
  2798. if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) {
  2799. const accessor = redefined && classScope.loneAccessors.get(name);
  2800. if (accessor) {
  2801. const oldStatic = accessor & CLASS_ELEMENT_FLAG_STATIC;
  2802. const newStatic = elementType & CLASS_ELEMENT_FLAG_STATIC;
  2803. const oldKind = accessor & CLASS_ELEMENT_KIND_ACCESSOR;
  2804. const newKind = elementType & CLASS_ELEMENT_KIND_ACCESSOR;
  2805. redefined = oldKind === newKind || oldStatic !== newStatic;
  2806. if (!redefined) classScope.loneAccessors.delete(name);
  2807. } else if (!redefined) {
  2808. classScope.loneAccessors.set(name, elementType);
  2809. }
  2810. }
  2811. if (redefined) {
  2812. this.raise(pos, ErrorMessages.PrivateNameRedeclaration, name);
  2813. }
  2814. classScope.privateNames.add(name);
  2815. classScope.undefinedPrivateNames.delete(name);
  2816. }
  2817. usePrivateName(name, pos) {
  2818. let classScope;
  2819. for (classScope of this.stack) {
  2820. if (classScope.privateNames.has(name)) return;
  2821. }
  2822. if (classScope) {
  2823. classScope.undefinedPrivateNames.set(name, pos);
  2824. } else {
  2825. this.raise(pos, ErrorMessages.InvalidPrivateFieldResolution, name);
  2826. }
  2827. }
  2828. }
  2829. const kExpression = 0,
  2830. kMaybeArrowParameterDeclaration = 1,
  2831. kMaybeAsyncArrowParameterDeclaration = 2,
  2832. kParameterDeclaration = 3;
  2833. class ExpressionScope {
  2834. constructor(type = kExpression) {
  2835. this.type = void 0;
  2836. this.type = type;
  2837. }
  2838. canBeArrowParameterDeclaration() {
  2839. return this.type === kMaybeAsyncArrowParameterDeclaration || this.type === kMaybeArrowParameterDeclaration;
  2840. }
  2841. isCertainlyParameterDeclaration() {
  2842. return this.type === kParameterDeclaration;
  2843. }
  2844. }
  2845. class ArrowHeadParsingScope extends ExpressionScope {
  2846. constructor(type) {
  2847. super(type);
  2848. this.errors = new Map();
  2849. }
  2850. recordDeclarationError(pos, template) {
  2851. this.errors.set(pos, template);
  2852. }
  2853. clearDeclarationError(pos) {
  2854. this.errors.delete(pos);
  2855. }
  2856. iterateErrors(iterator) {
  2857. this.errors.forEach(iterator);
  2858. }
  2859. }
  2860. class ExpressionScopeHandler {
  2861. constructor(raise) {
  2862. this.stack = [new ExpressionScope()];
  2863. this.raise = raise;
  2864. }
  2865. enter(scope) {
  2866. this.stack.push(scope);
  2867. }
  2868. exit() {
  2869. this.stack.pop();
  2870. }
  2871. recordParameterInitializerError(pos, template) {
  2872. const {
  2873. stack
  2874. } = this;
  2875. let i = stack.length - 1;
  2876. let scope = stack[i];
  2877. while (!scope.isCertainlyParameterDeclaration()) {
  2878. if (scope.canBeArrowParameterDeclaration()) {
  2879. scope.recordDeclarationError(pos, template);
  2880. } else {
  2881. return;
  2882. }
  2883. scope = stack[--i];
  2884. }
  2885. this.raise(pos, template);
  2886. }
  2887. recordParenthesizedIdentifierError(pos, template) {
  2888. const {
  2889. stack
  2890. } = this;
  2891. const scope = stack[stack.length - 1];
  2892. if (scope.isCertainlyParameterDeclaration()) {
  2893. this.raise(pos, template);
  2894. } else if (scope.canBeArrowParameterDeclaration()) {
  2895. scope.recordDeclarationError(pos, template);
  2896. } else {
  2897. return;
  2898. }
  2899. }
  2900. recordAsyncArrowParametersError(pos, template) {
  2901. const {
  2902. stack
  2903. } = this;
  2904. let i = stack.length - 1;
  2905. let scope = stack[i];
  2906. while (scope.canBeArrowParameterDeclaration()) {
  2907. if (scope.type === kMaybeAsyncArrowParameterDeclaration) {
  2908. scope.recordDeclarationError(pos, template);
  2909. }
  2910. scope = stack[--i];
  2911. }
  2912. }
  2913. validateAsPattern() {
  2914. const {
  2915. stack
  2916. } = this;
  2917. const currentScope = stack[stack.length - 1];
  2918. if (!currentScope.canBeArrowParameterDeclaration()) return;
  2919. currentScope.iterateErrors((template, pos) => {
  2920. this.raise(pos, template);
  2921. let i = stack.length - 2;
  2922. let scope = stack[i];
  2923. while (scope.canBeArrowParameterDeclaration()) {
  2924. scope.clearDeclarationError(pos);
  2925. scope = stack[--i];
  2926. }
  2927. });
  2928. }
  2929. }
  2930. function newParameterDeclarationScope() {
  2931. return new ExpressionScope(kParameterDeclaration);
  2932. }
  2933. function newArrowHeadScope() {
  2934. return new ArrowHeadParsingScope(kMaybeArrowParameterDeclaration);
  2935. }
  2936. function newAsyncArrowScope() {
  2937. return new ArrowHeadParsingScope(kMaybeAsyncArrowParameterDeclaration);
  2938. }
  2939. function newExpressionScope() {
  2940. return new ExpressionScope();
  2941. }
  2942. const PARAM = 0b0000,
  2943. PARAM_YIELD = 0b0001,
  2944. PARAM_AWAIT = 0b0010,
  2945. PARAM_RETURN = 0b0100,
  2946. PARAM_IN = 0b1000;
  2947. class ProductionParameterHandler {
  2948. constructor() {
  2949. this.stacks = [];
  2950. }
  2951. enter(flags) {
  2952. this.stacks.push(flags);
  2953. }
  2954. exit() {
  2955. this.stacks.pop();
  2956. }
  2957. currentFlags() {
  2958. return this.stacks[this.stacks.length - 1];
  2959. }
  2960. get hasAwait() {
  2961. return (this.currentFlags() & PARAM_AWAIT) > 0;
  2962. }
  2963. get hasYield() {
  2964. return (this.currentFlags() & PARAM_YIELD) > 0;
  2965. }
  2966. get hasReturn() {
  2967. return (this.currentFlags() & PARAM_RETURN) > 0;
  2968. }
  2969. get hasIn() {
  2970. return (this.currentFlags() & PARAM_IN) > 0;
  2971. }
  2972. }
  2973. function functionFlags(isAsync, isGenerator) {
  2974. return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
  2975. }
  2976. class UtilParser extends Tokenizer {
  2977. addExtra(node, key, val) {
  2978. if (!node) return;
  2979. const extra = node.extra = node.extra || {};
  2980. extra[key] = val;
  2981. }
  2982. isContextual(token) {
  2983. return this.state.type === token && !this.state.containsEsc;
  2984. }
  2985. isUnparsedContextual(nameStart, name) {
  2986. const nameEnd = nameStart + name.length;
  2987. if (this.input.slice(nameStart, nameEnd) === name) {
  2988. const nextCh = this.input.charCodeAt(nameEnd);
  2989. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  2990. }
  2991. return false;
  2992. }
  2993. isLookaheadContextual(name) {
  2994. const next = this.nextTokenStart();
  2995. return this.isUnparsedContextual(next, name);
  2996. }
  2997. eatContextual(token) {
  2998. if (this.isContextual(token)) {
  2999. this.next();
  3000. return true;
  3001. }
  3002. return false;
  3003. }
  3004. expectContextual(token, template) {
  3005. if (!this.eatContextual(token)) this.unexpected(null, template);
  3006. }
  3007. canInsertSemicolon() {
  3008. return this.match(129) || this.match(8) || this.hasPrecedingLineBreak();
  3009. }
  3010. hasPrecedingLineBreak() {
  3011. return lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start));
  3012. }
  3013. hasFollowingLineBreak() {
  3014. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  3015. return skipWhiteSpaceToLineBreak.test(this.input);
  3016. }
  3017. isLineTerminator() {
  3018. return this.eat(13) || this.canInsertSemicolon();
  3019. }
  3020. semicolon(allowAsi = true) {
  3021. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3022. this.raise(this.state.lastTokEnd, ErrorMessages.MissingSemicolon);
  3023. }
  3024. expect(type, pos) {
  3025. this.eat(type) || this.unexpected(pos, type);
  3026. }
  3027. assertNoSpace(message = "Unexpected space.") {
  3028. if (this.state.start > this.state.lastTokEnd) {
  3029. this.raise(this.state.lastTokEnd, {
  3030. code: ErrorCodes.SyntaxError,
  3031. reasonCode: "UnexpectedSpace",
  3032. template: message
  3033. });
  3034. }
  3035. }
  3036. unexpected(pos, messageOrType = {
  3037. code: ErrorCodes.SyntaxError,
  3038. reasonCode: "UnexpectedToken",
  3039. template: "Unexpected token"
  3040. }) {
  3041. if (isTokenType(messageOrType)) {
  3042. messageOrType = {
  3043. code: ErrorCodes.SyntaxError,
  3044. reasonCode: "UnexpectedToken",
  3045. template: `Unexpected token, expected "${tokenLabelName(messageOrType)}"`
  3046. };
  3047. }
  3048. throw this.raise(pos != null ? pos : this.state.start, messageOrType);
  3049. }
  3050. expectPlugin(name, pos) {
  3051. if (!this.hasPlugin(name)) {
  3052. throw this.raiseWithData(pos != null ? pos : this.state.start, {
  3053. missingPlugin: [name]
  3054. }, `This experimental syntax requires enabling the parser plugin: '${name}'`);
  3055. }
  3056. return true;
  3057. }
  3058. expectOnePlugin(names, pos) {
  3059. if (!names.some(n => this.hasPlugin(n))) {
  3060. throw this.raiseWithData(pos != null ? pos : this.state.start, {
  3061. missingPlugin: names
  3062. }, `This experimental syntax requires enabling one of the following parser plugin(s): '${names.join(", ")}'`);
  3063. }
  3064. }
  3065. tryParse(fn, oldState = this.state.clone()) {
  3066. const abortSignal = {
  3067. node: null
  3068. };
  3069. try {
  3070. const node = fn((node = null) => {
  3071. abortSignal.node = node;
  3072. throw abortSignal;
  3073. });
  3074. if (this.state.errors.length > oldState.errors.length) {
  3075. const failState = this.state;
  3076. this.state = oldState;
  3077. this.state.tokensLength = failState.tokensLength;
  3078. return {
  3079. node,
  3080. error: failState.errors[oldState.errors.length],
  3081. thrown: false,
  3082. aborted: false,
  3083. failState
  3084. };
  3085. }
  3086. return {
  3087. node,
  3088. error: null,
  3089. thrown: false,
  3090. aborted: false,
  3091. failState: null
  3092. };
  3093. } catch (error) {
  3094. const failState = this.state;
  3095. this.state = oldState;
  3096. if (error instanceof SyntaxError) {
  3097. return {
  3098. node: null,
  3099. error,
  3100. thrown: true,
  3101. aborted: false,
  3102. failState
  3103. };
  3104. }
  3105. if (error === abortSignal) {
  3106. return {
  3107. node: abortSignal.node,
  3108. error: null,
  3109. thrown: false,
  3110. aborted: true,
  3111. failState
  3112. };
  3113. }
  3114. throw error;
  3115. }
  3116. }
  3117. checkExpressionErrors(refExpressionErrors, andThrow) {
  3118. if (!refExpressionErrors) return false;
  3119. const {
  3120. shorthandAssign,
  3121. doubleProto,
  3122. optionalParameters
  3123. } = refExpressionErrors;
  3124. const hasErrors = shorthandAssign + doubleProto + optionalParameters > -3;
  3125. if (!andThrow) {
  3126. return hasErrors;
  3127. } else if (hasErrors) {
  3128. if (shorthandAssign >= 0) {
  3129. this.unexpected(shorthandAssign);
  3130. }
  3131. if (doubleProto >= 0) {
  3132. this.raise(doubleProto, ErrorMessages.DuplicateProto);
  3133. }
  3134. if (optionalParameters >= 0) {
  3135. this.unexpected(optionalParameters);
  3136. }
  3137. }
  3138. }
  3139. isLiteralPropertyName() {
  3140. return tokenIsLiteralPropertyName(this.state.type);
  3141. }
  3142. isPrivateName(node) {
  3143. return node.type === "PrivateName";
  3144. }
  3145. getPrivateNameSV(node) {
  3146. return node.id.name;
  3147. }
  3148. hasPropertyAsPrivateName(node) {
  3149. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3150. }
  3151. isOptionalChain(node) {
  3152. return node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression";
  3153. }
  3154. isObjectProperty(node) {
  3155. return node.type === "ObjectProperty";
  3156. }
  3157. isObjectMethod(node) {
  3158. return node.type === "ObjectMethod";
  3159. }
  3160. initializeScopes(inModule = this.options.sourceType === "module") {
  3161. const oldLabels = this.state.labels;
  3162. this.state.labels = [];
  3163. const oldExportedIdentifiers = this.exportedIdentifiers;
  3164. this.exportedIdentifiers = new Set();
  3165. const oldInModule = this.inModule;
  3166. this.inModule = inModule;
  3167. const oldScope = this.scope;
  3168. const ScopeHandler = this.getScopeHandler();
  3169. this.scope = new ScopeHandler(this.raise.bind(this), this.inModule);
  3170. const oldProdParam = this.prodParam;
  3171. this.prodParam = new ProductionParameterHandler();
  3172. const oldClassScope = this.classScope;
  3173. this.classScope = new ClassScopeHandler(this.raise.bind(this));
  3174. const oldExpressionScope = this.expressionScope;
  3175. this.expressionScope = new ExpressionScopeHandler(this.raise.bind(this));
  3176. return () => {
  3177. this.state.labels = oldLabels;
  3178. this.exportedIdentifiers = oldExportedIdentifiers;
  3179. this.inModule = oldInModule;
  3180. this.scope = oldScope;
  3181. this.prodParam = oldProdParam;
  3182. this.classScope = oldClassScope;
  3183. this.expressionScope = oldExpressionScope;
  3184. };
  3185. }
  3186. enterInitialScopes() {
  3187. let paramFlags = PARAM;
  3188. if (this.inModule) {
  3189. paramFlags |= PARAM_AWAIT;
  3190. }
  3191. this.scope.enter(SCOPE_PROGRAM);
  3192. this.prodParam.enter(paramFlags);
  3193. }
  3194. }
  3195. class ExpressionErrors {
  3196. constructor() {
  3197. this.shorthandAssign = -1;
  3198. this.doubleProto = -1;
  3199. this.optionalParameters = -1;
  3200. }
  3201. }
  3202. class Node {
  3203. constructor(parser, pos, loc) {
  3204. this.type = "";
  3205. this.start = pos;
  3206. this.end = 0;
  3207. this.loc = new SourceLocation(loc);
  3208. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3209. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3210. }
  3211. }
  3212. const NodePrototype = Node.prototype;
  3213. {
  3214. NodePrototype.__clone = function () {
  3215. const newNode = new Node();
  3216. const keys = Object.keys(this);
  3217. for (let i = 0, length = keys.length; i < length; i++) {
  3218. const key = keys[i];
  3219. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3220. newNode[key] = this[key];
  3221. }
  3222. }
  3223. return newNode;
  3224. };
  3225. }
  3226. function clonePlaceholder(node) {
  3227. return cloneIdentifier(node);
  3228. }
  3229. function cloneIdentifier(node) {
  3230. const {
  3231. type,
  3232. start,
  3233. end,
  3234. loc,
  3235. range,
  3236. extra,
  3237. name
  3238. } = node;
  3239. const cloned = Object.create(NodePrototype);
  3240. cloned.type = type;
  3241. cloned.start = start;
  3242. cloned.end = end;
  3243. cloned.loc = loc;
  3244. cloned.range = range;
  3245. cloned.extra = extra;
  3246. cloned.name = name;
  3247. if (type === "Placeholder") {
  3248. cloned.expectedNode = node.expectedNode;
  3249. }
  3250. return cloned;
  3251. }
  3252. function cloneStringLiteral(node) {
  3253. const {
  3254. type,
  3255. start,
  3256. end,
  3257. loc,
  3258. range,
  3259. extra
  3260. } = node;
  3261. if (type === "Placeholder") {
  3262. return clonePlaceholder(node);
  3263. }
  3264. const cloned = Object.create(NodePrototype);
  3265. cloned.type = "StringLiteral";
  3266. cloned.start = start;
  3267. cloned.end = end;
  3268. cloned.loc = loc;
  3269. cloned.range = range;
  3270. cloned.extra = extra;
  3271. cloned.value = node.value;
  3272. return cloned;
  3273. }
  3274. class NodeUtils extends UtilParser {
  3275. startNode() {
  3276. return new Node(this, this.state.start, this.state.startLoc);
  3277. }
  3278. startNodeAt(pos, loc) {
  3279. return new Node(this, pos, loc);
  3280. }
  3281. startNodeAtNode(type) {
  3282. return this.startNodeAt(type.start, type.loc.start);
  3283. }
  3284. finishNode(node, type) {
  3285. return this.finishNodeAt(node, type, this.state.lastTokEnd, this.state.lastTokEndLoc);
  3286. }
  3287. finishNodeAt(node, type, pos, loc) {
  3288. node.type = type;
  3289. node.end = pos;
  3290. node.loc.end = loc;
  3291. if (this.options.ranges) node.range[1] = pos;
  3292. if (this.options.attachComment) this.processComment(node);
  3293. return node;
  3294. }
  3295. resetStartLocation(node, start, startLoc) {
  3296. node.start = start;
  3297. node.loc.start = startLoc;
  3298. if (this.options.ranges) node.range[0] = start;
  3299. }
  3300. resetEndLocation(node, end = this.state.lastTokEnd, endLoc = this.state.lastTokEndLoc) {
  3301. node.end = end;
  3302. node.loc.end = endLoc;
  3303. if (this.options.ranges) node.range[1] = end;
  3304. }
  3305. resetStartLocationFromNode(node, locationNode) {
  3306. this.resetStartLocation(node, locationNode.start, locationNode.loc.start);
  3307. }
  3308. }
  3309. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3310. const FlowErrors = makeErrorTemplates({
  3311. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3312. 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.",
  3313. AssignReservedType: "Cannot overwrite reserved type %0.",
  3314. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3315. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3316. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3317. EnumBooleanMemberNotInitialized: "Boolean enum members need to be initialized. Use either `%0 = true,` or `%0 = false,` in enum `%1`.",
  3318. EnumDuplicateMemberName: "Enum member names need to be unique, but the name `%0` has already been used before in enum `%1`.",
  3319. EnumInconsistentMemberValues: "Enum `%0` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.",
  3320. EnumInvalidExplicitType: "Enum type `%1` is not valid. Use one of `boolean`, `number`, `string`, or `symbol` in enum `%0`.",
  3321. EnumInvalidExplicitTypeUnknownSupplied: "Supplied enum type is not valid. Use one of `boolean`, `number`, `string`, or `symbol` in enum `%0`.",
  3322. EnumInvalidMemberInitializerPrimaryType: "Enum `%0` has type `%2`, so the initializer of `%1` needs to be a %2 literal.",
  3323. EnumInvalidMemberInitializerSymbolType: "Symbol enum members cannot be initialized. Use `%1,` in enum `%0`.",
  3324. EnumInvalidMemberInitializerUnknownType: "The enum member initializer for `%1` needs to be a literal (either a boolean, number, or string) in enum `%0`.",
  3325. EnumInvalidMemberName: "Enum member names cannot start with lowercase 'a' through 'z'. Instead of using `%0`, consider using `%1`, in enum `%2`.",
  3326. EnumNumberMemberNotInitialized: "Number enum members need to be initialized, e.g. `%1 = 1` in enum `%0`.",
  3327. EnumStringMemberInconsistentlyInitailized: "String enum members need to consistently either all use initializers, or use no initializers, in enum `%0`.",
  3328. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3329. 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.",
  3330. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3331. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3332. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3333. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3334. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3335. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3336. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3337. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  3338. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3339. SpreadVariance: "Spread properties cannot have variance.",
  3340. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3341. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3342. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3343. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3344. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3345. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3346. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3347. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3348. UnexpectedReservedType: "Unexpected reserved type %0.",
  3349. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3350. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3351. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3352. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3353. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3354. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3355. UnsupportedDeclareExportKind: "`declare export %0` is not supported. Use `%1` instead.",
  3356. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3357. UnterminatedFlowComment: "Unterminated flow-comment."
  3358. }, ErrorCodes.SyntaxError, "flow");
  3359. function isEsModuleType(bodyElement) {
  3360. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3361. }
  3362. function hasTypeImportKind(node) {
  3363. return node.importKind === "type" || node.importKind === "typeof";
  3364. }
  3365. function isMaybeDefaultImport(type) {
  3366. return tokenIsKeywordOrIdentifier(type) && type !== 91;
  3367. }
  3368. const exportSuggestions = {
  3369. const: "declare export var",
  3370. let: "declare export var",
  3371. type: "export type",
  3372. interface: "export interface"
  3373. };
  3374. function partition(list, test) {
  3375. const list1 = [];
  3376. const list2 = [];
  3377. for (let i = 0; i < list.length; i++) {
  3378. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  3379. }
  3380. return [list1, list2];
  3381. }
  3382. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  3383. var flow = (superClass => class extends superClass {
  3384. constructor(...args) {
  3385. super(...args);
  3386. this.flowPragma = undefined;
  3387. }
  3388. getScopeHandler() {
  3389. return FlowScopeHandler;
  3390. }
  3391. shouldParseTypes() {
  3392. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  3393. }
  3394. shouldParseEnums() {
  3395. return !!this.getPluginOption("flow", "enums");
  3396. }
  3397. finishToken(type, val) {
  3398. if (type !== 123 && type !== 13 && type !== 26) {
  3399. if (this.flowPragma === undefined) {
  3400. this.flowPragma = null;
  3401. }
  3402. }
  3403. return super.finishToken(type, val);
  3404. }
  3405. addComment(comment) {
  3406. if (this.flowPragma === undefined) {
  3407. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  3408. if (!matches) ; else if (matches[1] === "flow") {
  3409. this.flowPragma = "flow";
  3410. } else if (matches[1] === "noflow") {
  3411. this.flowPragma = "noflow";
  3412. } else {
  3413. throw new Error("Unexpected flow pragma");
  3414. }
  3415. }
  3416. return super.addComment(comment);
  3417. }
  3418. flowParseTypeInitialiser(tok) {
  3419. const oldInType = this.state.inType;
  3420. this.state.inType = true;
  3421. this.expect(tok || 14);
  3422. const type = this.flowParseType();
  3423. this.state.inType = oldInType;
  3424. return type;
  3425. }
  3426. flowParsePredicate() {
  3427. const node = this.startNode();
  3428. const moduloPos = this.state.start;
  3429. this.next();
  3430. this.expectContextual(101);
  3431. if (this.state.lastTokStart > moduloPos + 1) {
  3432. this.raise(moduloPos, FlowErrors.UnexpectedSpaceBetweenModuloChecks);
  3433. }
  3434. if (this.eat(10)) {
  3435. node.value = this.parseExpression();
  3436. this.expect(11);
  3437. return this.finishNode(node, "DeclaredPredicate");
  3438. } else {
  3439. return this.finishNode(node, "InferredPredicate");
  3440. }
  3441. }
  3442. flowParseTypeAndPredicateInitialiser() {
  3443. const oldInType = this.state.inType;
  3444. this.state.inType = true;
  3445. this.expect(14);
  3446. let type = null;
  3447. let predicate = null;
  3448. if (this.match(48)) {
  3449. this.state.inType = oldInType;
  3450. predicate = this.flowParsePredicate();
  3451. } else {
  3452. type = this.flowParseType();
  3453. this.state.inType = oldInType;
  3454. if (this.match(48)) {
  3455. predicate = this.flowParsePredicate();
  3456. }
  3457. }
  3458. return [type, predicate];
  3459. }
  3460. flowParseDeclareClass(node) {
  3461. this.next();
  3462. this.flowParseInterfaceish(node, true);
  3463. return this.finishNode(node, "DeclareClass");
  3464. }
  3465. flowParseDeclareFunction(node) {
  3466. this.next();
  3467. const id = node.id = this.parseIdentifier();
  3468. const typeNode = this.startNode();
  3469. const typeContainer = this.startNode();
  3470. if (this.match(43)) {
  3471. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  3472. } else {
  3473. typeNode.typeParameters = null;
  3474. }
  3475. this.expect(10);
  3476. const tmp = this.flowParseFunctionTypeParams();
  3477. typeNode.params = tmp.params;
  3478. typeNode.rest = tmp.rest;
  3479. typeNode.this = tmp._this;
  3480. this.expect(11);
  3481. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  3482. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  3483. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  3484. this.resetEndLocation(id);
  3485. this.semicolon();
  3486. this.scope.declareName(node.id.name, BIND_FLOW_DECLARE_FN, node.id.start);
  3487. return this.finishNode(node, "DeclareFunction");
  3488. }
  3489. flowParseDeclare(node, insideModule) {
  3490. if (this.match(74)) {
  3491. return this.flowParseDeclareClass(node);
  3492. } else if (this.match(62)) {
  3493. return this.flowParseDeclareFunction(node);
  3494. } else if (this.match(68)) {
  3495. return this.flowParseDeclareVariable(node);
  3496. } else if (this.eatContextual(117)) {
  3497. if (this.match(16)) {
  3498. return this.flowParseDeclareModuleExports(node);
  3499. } else {
  3500. if (insideModule) {
  3501. this.raise(this.state.lastTokStart, FlowErrors.NestedDeclareModule);
  3502. }
  3503. return this.flowParseDeclareModule(node);
  3504. }
  3505. } else if (this.isContextual(120)) {
  3506. return this.flowParseDeclareTypeAlias(node);
  3507. } else if (this.isContextual(121)) {
  3508. return this.flowParseDeclareOpaqueType(node);
  3509. } else if (this.isContextual(119)) {
  3510. return this.flowParseDeclareInterface(node);
  3511. } else if (this.match(76)) {
  3512. return this.flowParseDeclareExportDeclaration(node, insideModule);
  3513. } else {
  3514. throw this.unexpected();
  3515. }
  3516. }
  3517. flowParseDeclareVariable(node) {
  3518. this.next();
  3519. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  3520. this.scope.declareName(node.id.name, BIND_VAR, node.id.start);
  3521. this.semicolon();
  3522. return this.finishNode(node, "DeclareVariable");
  3523. }
  3524. flowParseDeclareModule(node) {
  3525. this.scope.enter(SCOPE_OTHER);
  3526. if (this.match(123)) {
  3527. node.id = this.parseExprAtom();
  3528. } else {
  3529. node.id = this.parseIdentifier();
  3530. }
  3531. const bodyNode = node.body = this.startNode();
  3532. const body = bodyNode.body = [];
  3533. this.expect(5);
  3534. while (!this.match(8)) {
  3535. let bodyNode = this.startNode();
  3536. if (this.match(77)) {
  3537. this.next();
  3538. if (!this.isContextual(120) && !this.match(81)) {
  3539. this.raise(this.state.lastTokStart, FlowErrors.InvalidNonTypeImportInDeclareModule);
  3540. }
  3541. this.parseImport(bodyNode);
  3542. } else {
  3543. this.expectContextual(115, FlowErrors.UnsupportedStatementInDeclareModule);
  3544. bodyNode = this.flowParseDeclare(bodyNode, true);
  3545. }
  3546. body.push(bodyNode);
  3547. }
  3548. this.scope.exit();
  3549. this.expect(8);
  3550. this.finishNode(bodyNode, "BlockStatement");
  3551. let kind = null;
  3552. let hasModuleExport = false;
  3553. body.forEach(bodyElement => {
  3554. if (isEsModuleType(bodyElement)) {
  3555. if (kind === "CommonJS") {
  3556. this.raise(bodyElement.start, FlowErrors.AmbiguousDeclareModuleKind);
  3557. }
  3558. kind = "ES";
  3559. } else if (bodyElement.type === "DeclareModuleExports") {
  3560. if (hasModuleExport) {
  3561. this.raise(bodyElement.start, FlowErrors.DuplicateDeclareModuleExports);
  3562. }
  3563. if (kind === "ES") {
  3564. this.raise(bodyElement.start, FlowErrors.AmbiguousDeclareModuleKind);
  3565. }
  3566. kind = "CommonJS";
  3567. hasModuleExport = true;
  3568. }
  3569. });
  3570. node.kind = kind || "CommonJS";
  3571. return this.finishNode(node, "DeclareModule");
  3572. }
  3573. flowParseDeclareExportDeclaration(node, insideModule) {
  3574. this.expect(76);
  3575. if (this.eat(59)) {
  3576. if (this.match(62) || this.match(74)) {
  3577. node.declaration = this.flowParseDeclare(this.startNode());
  3578. } else {
  3579. node.declaration = this.flowParseType();
  3580. this.semicolon();
  3581. }
  3582. node.default = true;
  3583. return this.finishNode(node, "DeclareExportDeclaration");
  3584. } else {
  3585. if (this.match(69) || this.isLet() || (this.isContextual(120) || this.isContextual(119)) && !insideModule) {
  3586. const label = this.state.value;
  3587. const suggestion = exportSuggestions[label];
  3588. throw this.raise(this.state.start, FlowErrors.UnsupportedDeclareExportKind, label, suggestion);
  3589. }
  3590. if (this.match(68) || this.match(62) || this.match(74) || this.isContextual(121)) {
  3591. node.declaration = this.flowParseDeclare(this.startNode());
  3592. node.default = false;
  3593. return this.finishNode(node, "DeclareExportDeclaration");
  3594. } else if (this.match(49) || this.match(5) || this.isContextual(119) || this.isContextual(120) || this.isContextual(121)) {
  3595. node = this.parseExport(node);
  3596. if (node.type === "ExportNamedDeclaration") {
  3597. node.type = "ExportDeclaration";
  3598. node.default = false;
  3599. delete node.exportKind;
  3600. }
  3601. node.type = "Declare" + node.type;
  3602. return node;
  3603. }
  3604. }
  3605. throw this.unexpected();
  3606. }
  3607. flowParseDeclareModuleExports(node) {
  3608. this.next();
  3609. this.expectContextual(102);
  3610. node.typeAnnotation = this.flowParseTypeAnnotation();
  3611. this.semicolon();
  3612. return this.finishNode(node, "DeclareModuleExports");
  3613. }
  3614. flowParseDeclareTypeAlias(node) {
  3615. this.next();
  3616. this.flowParseTypeAlias(node);
  3617. node.type = "DeclareTypeAlias";
  3618. return node;
  3619. }
  3620. flowParseDeclareOpaqueType(node) {
  3621. this.next();
  3622. this.flowParseOpaqueType(node, true);
  3623. node.type = "DeclareOpaqueType";
  3624. return node;
  3625. }
  3626. flowParseDeclareInterface(node) {
  3627. this.next();
  3628. this.flowParseInterfaceish(node);
  3629. return this.finishNode(node, "DeclareInterface");
  3630. }
  3631. flowParseInterfaceish(node, isClass = false) {
  3632. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  3633. this.scope.declareName(node.id.name, isClass ? BIND_FUNCTION : BIND_LEXICAL, node.id.start);
  3634. if (this.match(43)) {
  3635. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3636. } else {
  3637. node.typeParameters = null;
  3638. }
  3639. node.extends = [];
  3640. node.implements = [];
  3641. node.mixins = [];
  3642. if (this.eat(75)) {
  3643. do {
  3644. node.extends.push(this.flowParseInterfaceExtends());
  3645. } while (!isClass && this.eat(12));
  3646. }
  3647. if (this.isContextual(108)) {
  3648. this.next();
  3649. do {
  3650. node.mixins.push(this.flowParseInterfaceExtends());
  3651. } while (this.eat(12));
  3652. }
  3653. if (this.isContextual(104)) {
  3654. this.next();
  3655. do {
  3656. node.implements.push(this.flowParseInterfaceExtends());
  3657. } while (this.eat(12));
  3658. }
  3659. node.body = this.flowParseObjectType({
  3660. allowStatic: isClass,
  3661. allowExact: false,
  3662. allowSpread: false,
  3663. allowProto: isClass,
  3664. allowInexact: false
  3665. });
  3666. }
  3667. flowParseInterfaceExtends() {
  3668. const node = this.startNode();
  3669. node.id = this.flowParseQualifiedTypeIdentifier();
  3670. if (this.match(43)) {
  3671. node.typeParameters = this.flowParseTypeParameterInstantiation();
  3672. } else {
  3673. node.typeParameters = null;
  3674. }
  3675. return this.finishNode(node, "InterfaceExtends");
  3676. }
  3677. flowParseInterface(node) {
  3678. this.flowParseInterfaceish(node);
  3679. return this.finishNode(node, "InterfaceDeclaration");
  3680. }
  3681. checkNotUnderscore(word) {
  3682. if (word === "_") {
  3683. this.raise(this.state.start, FlowErrors.UnexpectedReservedUnderscore);
  3684. }
  3685. }
  3686. checkReservedType(word, startLoc, declaration) {
  3687. if (!reservedTypes.has(word)) return;
  3688. this.raise(startLoc, declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, word);
  3689. }
  3690. flowParseRestrictedIdentifier(liberal, declaration) {
  3691. this.checkReservedType(this.state.value, this.state.start, declaration);
  3692. return this.parseIdentifier(liberal);
  3693. }
  3694. flowParseTypeAlias(node) {
  3695. node.id = this.flowParseRestrictedIdentifier(false, true);
  3696. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.start);
  3697. if (this.match(43)) {
  3698. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3699. } else {
  3700. node.typeParameters = null;
  3701. }
  3702. node.right = this.flowParseTypeInitialiser(27);
  3703. this.semicolon();
  3704. return this.finishNode(node, "TypeAlias");
  3705. }
  3706. flowParseOpaqueType(node, declare) {
  3707. this.expectContextual(120);
  3708. node.id = this.flowParseRestrictedIdentifier(true, true);
  3709. this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.start);
  3710. if (this.match(43)) {
  3711. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3712. } else {
  3713. node.typeParameters = null;
  3714. }
  3715. node.supertype = null;
  3716. if (this.match(14)) {
  3717. node.supertype = this.flowParseTypeInitialiser(14);
  3718. }
  3719. node.impltype = null;
  3720. if (!declare) {
  3721. node.impltype = this.flowParseTypeInitialiser(27);
  3722. }
  3723. this.semicolon();
  3724. return this.finishNode(node, "OpaqueType");
  3725. }
  3726. flowParseTypeParameter(requireDefault = false) {
  3727. const nodeStart = this.state.start;
  3728. const node = this.startNode();
  3729. const variance = this.flowParseVariance();
  3730. const ident = this.flowParseTypeAnnotatableIdentifier();
  3731. node.name = ident.name;
  3732. node.variance = variance;
  3733. node.bound = ident.typeAnnotation;
  3734. if (this.match(27)) {
  3735. this.eat(27);
  3736. node.default = this.flowParseType();
  3737. } else {
  3738. if (requireDefault) {
  3739. this.raise(nodeStart, FlowErrors.MissingTypeParamDefault);
  3740. }
  3741. }
  3742. return this.finishNode(node, "TypeParameter");
  3743. }
  3744. flowParseTypeParameterDeclaration() {
  3745. const oldInType = this.state.inType;
  3746. const node = this.startNode();
  3747. node.params = [];
  3748. this.state.inType = true;
  3749. if (this.match(43) || this.match(132)) {
  3750. this.next();
  3751. } else {
  3752. this.unexpected();
  3753. }
  3754. let defaultRequired = false;
  3755. do {
  3756. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  3757. node.params.push(typeParameter);
  3758. if (typeParameter.default) {
  3759. defaultRequired = true;
  3760. }
  3761. if (!this.match(44)) {
  3762. this.expect(12);
  3763. }
  3764. } while (!this.match(44));
  3765. this.expect(44);
  3766. this.state.inType = oldInType;
  3767. return this.finishNode(node, "TypeParameterDeclaration");
  3768. }
  3769. flowParseTypeParameterInstantiation() {
  3770. const node = this.startNode();
  3771. const oldInType = this.state.inType;
  3772. node.params = [];
  3773. this.state.inType = true;
  3774. this.expect(43);
  3775. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  3776. this.state.noAnonFunctionType = false;
  3777. while (!this.match(44)) {
  3778. node.params.push(this.flowParseType());
  3779. if (!this.match(44)) {
  3780. this.expect(12);
  3781. }
  3782. }
  3783. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  3784. this.expect(44);
  3785. this.state.inType = oldInType;
  3786. return this.finishNode(node, "TypeParameterInstantiation");
  3787. }
  3788. flowParseTypeParameterInstantiationCallOrNew() {
  3789. const node = this.startNode();
  3790. const oldInType = this.state.inType;
  3791. node.params = [];
  3792. this.state.inType = true;
  3793. this.expect(43);
  3794. while (!this.match(44)) {
  3795. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  3796. if (!this.match(44)) {
  3797. this.expect(12);
  3798. }
  3799. }
  3800. this.expect(44);
  3801. this.state.inType = oldInType;
  3802. return this.finishNode(node, "TypeParameterInstantiation");
  3803. }
  3804. flowParseInterfaceType() {
  3805. const node = this.startNode();
  3806. this.expectContextual(119);
  3807. node.extends = [];
  3808. if (this.eat(75)) {
  3809. do {
  3810. node.extends.push(this.flowParseInterfaceExtends());
  3811. } while (this.eat(12));
  3812. }
  3813. node.body = this.flowParseObjectType({
  3814. allowStatic: false,
  3815. allowExact: false,
  3816. allowSpread: false,
  3817. allowProto: false,
  3818. allowInexact: false
  3819. });
  3820. return this.finishNode(node, "InterfaceTypeAnnotation");
  3821. }
  3822. flowParseObjectPropertyKey() {
  3823. return this.match(124) || this.match(123) ? this.parseExprAtom() : this.parseIdentifier(true);
  3824. }
  3825. flowParseObjectTypeIndexer(node, isStatic, variance) {
  3826. node.static = isStatic;
  3827. if (this.lookahead().type === 14) {
  3828. node.id = this.flowParseObjectPropertyKey();
  3829. node.key = this.flowParseTypeInitialiser();
  3830. } else {
  3831. node.id = null;
  3832. node.key = this.flowParseType();
  3833. }
  3834. this.expect(3);
  3835. node.value = this.flowParseTypeInitialiser();
  3836. node.variance = variance;
  3837. return this.finishNode(node, "ObjectTypeIndexer");
  3838. }
  3839. flowParseObjectTypeInternalSlot(node, isStatic) {
  3840. node.static = isStatic;
  3841. node.id = this.flowParseObjectPropertyKey();
  3842. this.expect(3);
  3843. this.expect(3);
  3844. if (this.match(43) || this.match(10)) {
  3845. node.method = true;
  3846. node.optional = false;
  3847. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.start, node.loc.start));
  3848. } else {
  3849. node.method = false;
  3850. if (this.eat(17)) {
  3851. node.optional = true;
  3852. }
  3853. node.value = this.flowParseTypeInitialiser();
  3854. }
  3855. return this.finishNode(node, "ObjectTypeInternalSlot");
  3856. }
  3857. flowParseObjectTypeMethodish(node) {
  3858. node.params = [];
  3859. node.rest = null;
  3860. node.typeParameters = null;
  3861. node.this = null;
  3862. if (this.match(43)) {
  3863. node.typeParameters = this.flowParseTypeParameterDeclaration();
  3864. }
  3865. this.expect(10);
  3866. if (this.match(72)) {
  3867. node.this = this.flowParseFunctionTypeParam(true);
  3868. node.this.name = null;
  3869. if (!this.match(11)) {
  3870. this.expect(12);
  3871. }
  3872. }
  3873. while (!this.match(11) && !this.match(21)) {
  3874. node.params.push(this.flowParseFunctionTypeParam(false));
  3875. if (!this.match(11)) {
  3876. this.expect(12);
  3877. }
  3878. }
  3879. if (this.eat(21)) {
  3880. node.rest = this.flowParseFunctionTypeParam(false);
  3881. }
  3882. this.expect(11);
  3883. node.returnType = this.flowParseTypeInitialiser();
  3884. return this.finishNode(node, "FunctionTypeAnnotation");
  3885. }
  3886. flowParseObjectTypeCallProperty(node, isStatic) {
  3887. const valueNode = this.startNode();
  3888. node.static = isStatic;
  3889. node.value = this.flowParseObjectTypeMethodish(valueNode);
  3890. return this.finishNode(node, "ObjectTypeCallProperty");
  3891. }
  3892. flowParseObjectType({
  3893. allowStatic,
  3894. allowExact,
  3895. allowSpread,
  3896. allowProto,
  3897. allowInexact
  3898. }) {
  3899. const oldInType = this.state.inType;
  3900. this.state.inType = true;
  3901. const nodeStart = this.startNode();
  3902. nodeStart.callProperties = [];
  3903. nodeStart.properties = [];
  3904. nodeStart.indexers = [];
  3905. nodeStart.internalSlots = [];
  3906. let endDelim;
  3907. let exact;
  3908. let inexact = false;
  3909. if (allowExact && this.match(6)) {
  3910. this.expect(6);
  3911. endDelim = 9;
  3912. exact = true;
  3913. } else {
  3914. this.expect(5);
  3915. endDelim = 8;
  3916. exact = false;
  3917. }
  3918. nodeStart.exact = exact;
  3919. while (!this.match(endDelim)) {
  3920. let isStatic = false;
  3921. let protoStart = null;
  3922. let inexactStart = null;
  3923. const node = this.startNode();
  3924. if (allowProto && this.isContextual(109)) {
  3925. const lookahead = this.lookahead();
  3926. if (lookahead.type !== 14 && lookahead.type !== 17) {
  3927. this.next();
  3928. protoStart = this.state.start;
  3929. allowStatic = false;
  3930. }
  3931. }
  3932. if (allowStatic && this.isContextual(98)) {
  3933. const lookahead = this.lookahead();
  3934. if (lookahead.type !== 14 && lookahead.type !== 17) {
  3935. this.next();
  3936. isStatic = true;
  3937. }
  3938. }
  3939. const variance = this.flowParseVariance();
  3940. if (this.eat(0)) {
  3941. if (protoStart != null) {
  3942. this.unexpected(protoStart);
  3943. }
  3944. if (this.eat(0)) {
  3945. if (variance) {
  3946. this.unexpected(variance.start);
  3947. }
  3948. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  3949. } else {
  3950. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  3951. }
  3952. } else if (this.match(10) || this.match(43)) {
  3953. if (protoStart != null) {
  3954. this.unexpected(protoStart);
  3955. }
  3956. if (variance) {
  3957. this.unexpected(variance.start);
  3958. }
  3959. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  3960. } else {
  3961. let kind = "init";
  3962. if (this.isContextual(92) || this.isContextual(97)) {
  3963. const lookahead = this.lookahead();
  3964. if (tokenIsLiteralPropertyName(lookahead.type)) {
  3965. kind = this.state.value;
  3966. this.next();
  3967. }
  3968. }
  3969. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStart, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  3970. if (propOrInexact === null) {
  3971. inexact = true;
  3972. inexactStart = this.state.lastTokStart;
  3973. } else {
  3974. nodeStart.properties.push(propOrInexact);
  3975. }
  3976. }
  3977. this.flowObjectTypeSemicolon();
  3978. if (inexactStart && !this.match(8) && !this.match(9)) {
  3979. this.raise(inexactStart, FlowErrors.UnexpectedExplicitInexactInObject);
  3980. }
  3981. }
  3982. this.expect(endDelim);
  3983. if (allowSpread) {
  3984. nodeStart.inexact = inexact;
  3985. }
  3986. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  3987. this.state.inType = oldInType;
  3988. return out;
  3989. }
  3990. flowParseObjectTypeProperty(node, isStatic, protoStart, variance, kind, allowSpread, allowInexact) {
  3991. if (this.eat(21)) {
  3992. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  3993. if (isInexactToken) {
  3994. if (!allowSpread) {
  3995. this.raise(this.state.lastTokStart, FlowErrors.InexactInsideNonObject);
  3996. } else if (!allowInexact) {
  3997. this.raise(this.state.lastTokStart, FlowErrors.InexactInsideExact);
  3998. }
  3999. if (variance) {
  4000. this.raise(variance.start, FlowErrors.InexactVariance);
  4001. }
  4002. return null;
  4003. }
  4004. if (!allowSpread) {
  4005. this.raise(this.state.lastTokStart, FlowErrors.UnexpectedSpreadType);
  4006. }
  4007. if (protoStart != null) {
  4008. this.unexpected(protoStart);
  4009. }
  4010. if (variance) {
  4011. this.raise(variance.start, FlowErrors.SpreadVariance);
  4012. }
  4013. node.argument = this.flowParseType();
  4014. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4015. } else {
  4016. node.key = this.flowParseObjectPropertyKey();
  4017. node.static = isStatic;
  4018. node.proto = protoStart != null;
  4019. node.kind = kind;
  4020. let optional = false;
  4021. if (this.match(43) || this.match(10)) {
  4022. node.method = true;
  4023. if (protoStart != null) {
  4024. this.unexpected(protoStart);
  4025. }
  4026. if (variance) {
  4027. this.unexpected(variance.start);
  4028. }
  4029. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.start, node.loc.start));
  4030. if (kind === "get" || kind === "set") {
  4031. this.flowCheckGetterSetterParams(node);
  4032. }
  4033. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4034. this.raise(node.value.this.start, FlowErrors.ThisParamBannedInConstructor);
  4035. }
  4036. } else {
  4037. if (kind !== "init") this.unexpected();
  4038. node.method = false;
  4039. if (this.eat(17)) {
  4040. optional = true;
  4041. }
  4042. node.value = this.flowParseTypeInitialiser();
  4043. node.variance = variance;
  4044. }
  4045. node.optional = optional;
  4046. return this.finishNode(node, "ObjectTypeProperty");
  4047. }
  4048. }
  4049. flowCheckGetterSetterParams(property) {
  4050. const paramCount = property.kind === "get" ? 0 : 1;
  4051. const start = property.start;
  4052. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4053. if (property.value.this) {
  4054. this.raise(property.value.this.start, property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam);
  4055. }
  4056. if (length !== paramCount) {
  4057. if (property.kind === "get") {
  4058. this.raise(start, ErrorMessages.BadGetterArity);
  4059. } else {
  4060. this.raise(start, ErrorMessages.BadSetterArity);
  4061. }
  4062. }
  4063. if (property.kind === "set" && property.value.rest) {
  4064. this.raise(start, ErrorMessages.BadSetterRestParameter);
  4065. }
  4066. }
  4067. flowObjectTypeSemicolon() {
  4068. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4069. this.unexpected();
  4070. }
  4071. }
  4072. flowParseQualifiedTypeIdentifier(startPos, startLoc, id) {
  4073. startPos = startPos || this.state.start;
  4074. startLoc = startLoc || this.state.startLoc;
  4075. let node = id || this.flowParseRestrictedIdentifier(true);
  4076. while (this.eat(16)) {
  4077. const node2 = this.startNodeAt(startPos, startLoc);
  4078. node2.qualification = node;
  4079. node2.id = this.flowParseRestrictedIdentifier(true);
  4080. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4081. }
  4082. return node;
  4083. }
  4084. flowParseGenericType(startPos, startLoc, id) {
  4085. const node = this.startNodeAt(startPos, startLoc);
  4086. node.typeParameters = null;
  4087. node.id = this.flowParseQualifiedTypeIdentifier(startPos, startLoc, id);
  4088. if (this.match(43)) {
  4089. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4090. }
  4091. return this.finishNode(node, "GenericTypeAnnotation");
  4092. }
  4093. flowParseTypeofType() {
  4094. const node = this.startNode();
  4095. this.expect(81);
  4096. node.argument = this.flowParsePrimaryType();
  4097. return this.finishNode(node, "TypeofTypeAnnotation");
  4098. }
  4099. flowParseTupleType() {
  4100. const node = this.startNode();
  4101. node.types = [];
  4102. this.expect(0);
  4103. while (this.state.pos < this.length && !this.match(3)) {
  4104. node.types.push(this.flowParseType());
  4105. if (this.match(3)) break;
  4106. this.expect(12);
  4107. }
  4108. this.expect(3);
  4109. return this.finishNode(node, "TupleTypeAnnotation");
  4110. }
  4111. flowParseFunctionTypeParam(first) {
  4112. let name = null;
  4113. let optional = false;
  4114. let typeAnnotation = null;
  4115. const node = this.startNode();
  4116. const lh = this.lookahead();
  4117. const isThis = this.state.type === 72;
  4118. if (lh.type === 14 || lh.type === 17) {
  4119. if (isThis && !first) {
  4120. this.raise(node.start, FlowErrors.ThisParamMustBeFirst);
  4121. }
  4122. name = this.parseIdentifier(isThis);
  4123. if (this.eat(17)) {
  4124. optional = true;
  4125. if (isThis) {
  4126. this.raise(node.start, FlowErrors.ThisParamMayNotBeOptional);
  4127. }
  4128. }
  4129. typeAnnotation = this.flowParseTypeInitialiser();
  4130. } else {
  4131. typeAnnotation = this.flowParseType();
  4132. }
  4133. node.name = name;
  4134. node.optional = optional;
  4135. node.typeAnnotation = typeAnnotation;
  4136. return this.finishNode(node, "FunctionTypeParam");
  4137. }
  4138. reinterpretTypeAsFunctionTypeParam(type) {
  4139. const node = this.startNodeAt(type.start, type.loc.start);
  4140. node.name = null;
  4141. node.optional = false;
  4142. node.typeAnnotation = type;
  4143. return this.finishNode(node, "FunctionTypeParam");
  4144. }
  4145. flowParseFunctionTypeParams(params = []) {
  4146. let rest = null;
  4147. let _this = null;
  4148. if (this.match(72)) {
  4149. _this = this.flowParseFunctionTypeParam(true);
  4150. _this.name = null;
  4151. if (!this.match(11)) {
  4152. this.expect(12);
  4153. }
  4154. }
  4155. while (!this.match(11) && !this.match(21)) {
  4156. params.push(this.flowParseFunctionTypeParam(false));
  4157. if (!this.match(11)) {
  4158. this.expect(12);
  4159. }
  4160. }
  4161. if (this.eat(21)) {
  4162. rest = this.flowParseFunctionTypeParam(false);
  4163. }
  4164. return {
  4165. params,
  4166. rest,
  4167. _this
  4168. };
  4169. }
  4170. flowIdentToTypeAnnotation(startPos, startLoc, node, id) {
  4171. switch (id.name) {
  4172. case "any":
  4173. return this.finishNode(node, "AnyTypeAnnotation");
  4174. case "bool":
  4175. case "boolean":
  4176. return this.finishNode(node, "BooleanTypeAnnotation");
  4177. case "mixed":
  4178. return this.finishNode(node, "MixedTypeAnnotation");
  4179. case "empty":
  4180. return this.finishNode(node, "EmptyTypeAnnotation");
  4181. case "number":
  4182. return this.finishNode(node, "NumberTypeAnnotation");
  4183. case "string":
  4184. return this.finishNode(node, "StringTypeAnnotation");
  4185. case "symbol":
  4186. return this.finishNode(node, "SymbolTypeAnnotation");
  4187. default:
  4188. this.checkNotUnderscore(id.name);
  4189. return this.flowParseGenericType(startPos, startLoc, id);
  4190. }
  4191. }
  4192. flowParsePrimaryType() {
  4193. const startPos = this.state.start;
  4194. const startLoc = this.state.startLoc;
  4195. const node = this.startNode();
  4196. let tmp;
  4197. let type;
  4198. let isGroupedType = false;
  4199. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4200. switch (this.state.type) {
  4201. case 5:
  4202. return this.flowParseObjectType({
  4203. allowStatic: false,
  4204. allowExact: false,
  4205. allowSpread: true,
  4206. allowProto: false,
  4207. allowInexact: true
  4208. });
  4209. case 6:
  4210. return this.flowParseObjectType({
  4211. allowStatic: false,
  4212. allowExact: true,
  4213. allowSpread: true,
  4214. allowProto: false,
  4215. allowInexact: false
  4216. });
  4217. case 0:
  4218. this.state.noAnonFunctionType = false;
  4219. type = this.flowParseTupleType();
  4220. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4221. return type;
  4222. case 43:
  4223. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4224. this.expect(10);
  4225. tmp = this.flowParseFunctionTypeParams();
  4226. node.params = tmp.params;
  4227. node.rest = tmp.rest;
  4228. node.this = tmp._this;
  4229. this.expect(11);
  4230. this.expect(19);
  4231. node.returnType = this.flowParseType();
  4232. return this.finishNode(node, "FunctionTypeAnnotation");
  4233. case 10:
  4234. this.next();
  4235. if (!this.match(11) && !this.match(21)) {
  4236. if (tokenIsIdentifier(this.state.type) || this.match(72)) {
  4237. const token = this.lookahead().type;
  4238. isGroupedType = token !== 17 && token !== 14;
  4239. } else {
  4240. isGroupedType = true;
  4241. }
  4242. }
  4243. if (isGroupedType) {
  4244. this.state.noAnonFunctionType = false;
  4245. type = this.flowParseType();
  4246. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4247. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4248. this.expect(11);
  4249. return type;
  4250. } else {
  4251. this.eat(12);
  4252. }
  4253. }
  4254. if (type) {
  4255. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4256. } else {
  4257. tmp = this.flowParseFunctionTypeParams();
  4258. }
  4259. node.params = tmp.params;
  4260. node.rest = tmp.rest;
  4261. node.this = tmp._this;
  4262. this.expect(11);
  4263. this.expect(19);
  4264. node.returnType = this.flowParseType();
  4265. node.typeParameters = null;
  4266. return this.finishNode(node, "FunctionTypeAnnotation");
  4267. case 123:
  4268. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4269. case 79:
  4270. case 80:
  4271. node.value = this.match(79);
  4272. this.next();
  4273. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4274. case 47:
  4275. if (this.state.value === "-") {
  4276. this.next();
  4277. if (this.match(124)) {
  4278. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4279. }
  4280. if (this.match(125)) {
  4281. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4282. }
  4283. throw this.raise(this.state.start, FlowErrors.UnexpectedSubtractionOperand);
  4284. }
  4285. throw this.unexpected();
  4286. case 124:
  4287. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4288. case 125:
  4289. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4290. case 82:
  4291. this.next();
  4292. return this.finishNode(node, "VoidTypeAnnotation");
  4293. case 78:
  4294. this.next();
  4295. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4296. case 72:
  4297. this.next();
  4298. return this.finishNode(node, "ThisTypeAnnotation");
  4299. case 49:
  4300. this.next();
  4301. return this.finishNode(node, "ExistsTypeAnnotation");
  4302. case 81:
  4303. return this.flowParseTypeofType();
  4304. default:
  4305. if (tokenIsKeyword(this.state.type)) {
  4306. const label = tokenLabelName(this.state.type);
  4307. this.next();
  4308. return super.createIdentifier(node, label);
  4309. } else if (tokenIsIdentifier(this.state.type)) {
  4310. if (this.isContextual(119)) {
  4311. return this.flowParseInterfaceType();
  4312. }
  4313. return this.flowIdentToTypeAnnotation(startPos, startLoc, node, this.parseIdentifier());
  4314. }
  4315. }
  4316. throw this.unexpected();
  4317. }
  4318. flowParsePostfixType() {
  4319. const startPos = this.state.start;
  4320. const startLoc = this.state.startLoc;
  4321. let type = this.flowParsePrimaryType();
  4322. let seenOptionalIndexedAccess = false;
  4323. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4324. const node = this.startNodeAt(startPos, startLoc);
  4325. const optional = this.eat(18);
  4326. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  4327. this.expect(0);
  4328. if (!optional && this.match(3)) {
  4329. node.elementType = type;
  4330. this.next();
  4331. type = this.finishNode(node, "ArrayTypeAnnotation");
  4332. } else {
  4333. node.objectType = type;
  4334. node.indexType = this.flowParseType();
  4335. this.expect(3);
  4336. if (seenOptionalIndexedAccess) {
  4337. node.optional = optional;
  4338. type = this.finishNode(node, "OptionalIndexedAccessType");
  4339. } else {
  4340. type = this.finishNode(node, "IndexedAccessType");
  4341. }
  4342. }
  4343. }
  4344. return type;
  4345. }
  4346. flowParsePrefixType() {
  4347. const node = this.startNode();
  4348. if (this.eat(17)) {
  4349. node.typeAnnotation = this.flowParsePrefixType();
  4350. return this.finishNode(node, "NullableTypeAnnotation");
  4351. } else {
  4352. return this.flowParsePostfixType();
  4353. }
  4354. }
  4355. flowParseAnonFunctionWithoutParens() {
  4356. const param = this.flowParsePrefixType();
  4357. if (!this.state.noAnonFunctionType && this.eat(19)) {
  4358. const node = this.startNodeAt(param.start, param.loc.start);
  4359. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  4360. node.rest = null;
  4361. node.this = null;
  4362. node.returnType = this.flowParseType();
  4363. node.typeParameters = null;
  4364. return this.finishNode(node, "FunctionTypeAnnotation");
  4365. }
  4366. return param;
  4367. }
  4368. flowParseIntersectionType() {
  4369. const node = this.startNode();
  4370. this.eat(41);
  4371. const type = this.flowParseAnonFunctionWithoutParens();
  4372. node.types = [type];
  4373. while (this.eat(41)) {
  4374. node.types.push(this.flowParseAnonFunctionWithoutParens());
  4375. }
  4376. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  4377. }
  4378. flowParseUnionType() {
  4379. const node = this.startNode();
  4380. this.eat(39);
  4381. const type = this.flowParseIntersectionType();
  4382. node.types = [type];
  4383. while (this.eat(39)) {
  4384. node.types.push(this.flowParseIntersectionType());
  4385. }
  4386. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  4387. }
  4388. flowParseType() {
  4389. const oldInType = this.state.inType;
  4390. this.state.inType = true;
  4391. const type = this.flowParseUnionType();
  4392. this.state.inType = oldInType;
  4393. return type;
  4394. }
  4395. flowParseTypeOrImplicitInstantiation() {
  4396. if (this.state.type === 122 && this.state.value === "_") {
  4397. const startPos = this.state.start;
  4398. const startLoc = this.state.startLoc;
  4399. const node = this.parseIdentifier();
  4400. return this.flowParseGenericType(startPos, startLoc, node);
  4401. } else {
  4402. return this.flowParseType();
  4403. }
  4404. }
  4405. flowParseTypeAnnotation() {
  4406. const node = this.startNode();
  4407. node.typeAnnotation = this.flowParseTypeInitialiser();
  4408. return this.finishNode(node, "TypeAnnotation");
  4409. }
  4410. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  4411. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  4412. if (this.match(14)) {
  4413. ident.typeAnnotation = this.flowParseTypeAnnotation();
  4414. this.resetEndLocation(ident);
  4415. }
  4416. return ident;
  4417. }
  4418. typeCastToParameter(node) {
  4419. node.expression.typeAnnotation = node.typeAnnotation;
  4420. this.resetEndLocation(node.expression, node.typeAnnotation.end, node.typeAnnotation.loc.end);
  4421. return node.expression;
  4422. }
  4423. flowParseVariance() {
  4424. let variance = null;
  4425. if (this.match(47)) {
  4426. variance = this.startNode();
  4427. if (this.state.value === "+") {
  4428. variance.kind = "plus";
  4429. } else {
  4430. variance.kind = "minus";
  4431. }
  4432. this.next();
  4433. this.finishNode(variance, "Variance");
  4434. }
  4435. return variance;
  4436. }
  4437. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  4438. if (allowExpressionBody) {
  4439. return this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  4440. }
  4441. return super.parseFunctionBody(node, false, isMethod);
  4442. }
  4443. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  4444. if (this.match(14)) {
  4445. const typeNode = this.startNode();
  4446. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4447. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  4448. }
  4449. super.parseFunctionBodyAndFinish(node, type, isMethod);
  4450. }
  4451. parseStatement(context, topLevel) {
  4452. if (this.state.strict && this.isContextual(119)) {
  4453. const lookahead = this.lookahead();
  4454. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  4455. const node = this.startNode();
  4456. this.next();
  4457. return this.flowParseInterface(node);
  4458. }
  4459. } else if (this.shouldParseEnums() && this.isContextual(116)) {
  4460. const node = this.startNode();
  4461. this.next();
  4462. return this.flowParseEnumDeclaration(node);
  4463. }
  4464. const stmt = super.parseStatement(context, topLevel);
  4465. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  4466. this.flowPragma = null;
  4467. }
  4468. return stmt;
  4469. }
  4470. parseExpressionStatement(node, expr) {
  4471. if (expr.type === "Identifier") {
  4472. if (expr.name === "declare") {
  4473. if (this.match(74) || tokenIsIdentifier(this.state.type) || this.match(62) || this.match(68) || this.match(76)) {
  4474. return this.flowParseDeclare(node);
  4475. }
  4476. } else if (tokenIsIdentifier(this.state.type)) {
  4477. if (expr.name === "interface") {
  4478. return this.flowParseInterface(node);
  4479. } else if (expr.name === "type") {
  4480. return this.flowParseTypeAlias(node);
  4481. } else if (expr.name === "opaque") {
  4482. return this.flowParseOpaqueType(node, false);
  4483. }
  4484. }
  4485. }
  4486. return super.parseExpressionStatement(node, expr);
  4487. }
  4488. shouldParseExportDeclaration() {
  4489. const {
  4490. type
  4491. } = this.state;
  4492. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 116) {
  4493. return !this.state.containsEsc;
  4494. }
  4495. return super.shouldParseExportDeclaration();
  4496. }
  4497. isExportDefaultSpecifier() {
  4498. const {
  4499. type
  4500. } = this.state;
  4501. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 116) {
  4502. return this.state.containsEsc;
  4503. }
  4504. return super.isExportDefaultSpecifier();
  4505. }
  4506. parseExportDefaultExpression() {
  4507. if (this.shouldParseEnums() && this.isContextual(116)) {
  4508. const node = this.startNode();
  4509. this.next();
  4510. return this.flowParseEnumDeclaration(node);
  4511. }
  4512. return super.parseExportDefaultExpression();
  4513. }
  4514. parseConditional(expr, startPos, startLoc, refExpressionErrors) {
  4515. if (!this.match(17)) return expr;
  4516. if (this.state.maybeInArrowParameters) {
  4517. const nextCh = this.lookaheadCharCode();
  4518. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  4519. this.setOptionalParametersError(refExpressionErrors);
  4520. return expr;
  4521. }
  4522. }
  4523. this.expect(17);
  4524. const state = this.state.clone();
  4525. const originalNoArrowAt = this.state.noArrowAt;
  4526. const node = this.startNodeAt(startPos, startLoc);
  4527. let {
  4528. consequent,
  4529. failed
  4530. } = this.tryParseConditionalConsequent();
  4531. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  4532. if (failed || invalid.length > 0) {
  4533. const noArrowAt = [...originalNoArrowAt];
  4534. if (invalid.length > 0) {
  4535. this.state = state;
  4536. this.state.noArrowAt = noArrowAt;
  4537. for (let i = 0; i < invalid.length; i++) {
  4538. noArrowAt.push(invalid[i].start);
  4539. }
  4540. ({
  4541. consequent,
  4542. failed
  4543. } = this.tryParseConditionalConsequent());
  4544. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  4545. }
  4546. if (failed && valid.length > 1) {
  4547. this.raise(state.start, FlowErrors.AmbiguousConditionalArrow);
  4548. }
  4549. if (failed && valid.length === 1) {
  4550. this.state = state;
  4551. noArrowAt.push(valid[0].start);
  4552. this.state.noArrowAt = noArrowAt;
  4553. ({
  4554. consequent,
  4555. failed
  4556. } = this.tryParseConditionalConsequent());
  4557. }
  4558. }
  4559. this.getArrowLikeExpressions(consequent, true);
  4560. this.state.noArrowAt = originalNoArrowAt;
  4561. this.expect(14);
  4562. node.test = expr;
  4563. node.consequent = consequent;
  4564. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  4565. return this.finishNode(node, "ConditionalExpression");
  4566. }
  4567. tryParseConditionalConsequent() {
  4568. this.state.noArrowParamsConversionAt.push(this.state.start);
  4569. const consequent = this.parseMaybeAssignAllowIn();
  4570. const failed = !this.match(14);
  4571. this.state.noArrowParamsConversionAt.pop();
  4572. return {
  4573. consequent,
  4574. failed
  4575. };
  4576. }
  4577. getArrowLikeExpressions(node, disallowInvalid) {
  4578. const stack = [node];
  4579. const arrows = [];
  4580. while (stack.length !== 0) {
  4581. const node = stack.pop();
  4582. if (node.type === "ArrowFunctionExpression") {
  4583. if (node.typeParameters || !node.returnType) {
  4584. this.finishArrowValidation(node);
  4585. } else {
  4586. arrows.push(node);
  4587. }
  4588. stack.push(node.body);
  4589. } else if (node.type === "ConditionalExpression") {
  4590. stack.push(node.consequent);
  4591. stack.push(node.alternate);
  4592. }
  4593. }
  4594. if (disallowInvalid) {
  4595. arrows.forEach(node => this.finishArrowValidation(node));
  4596. return [arrows, []];
  4597. }
  4598. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  4599. }
  4600. finishArrowValidation(node) {
  4601. var _node$extra;
  4602. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingComma, false);
  4603. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  4604. super.checkParams(node, false, true);
  4605. this.scope.exit();
  4606. }
  4607. forwardNoArrowParamsConversionAt(node, parse) {
  4608. let result;
  4609. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  4610. this.state.noArrowParamsConversionAt.push(this.state.start);
  4611. result = parse();
  4612. this.state.noArrowParamsConversionAt.pop();
  4613. } else {
  4614. result = parse();
  4615. }
  4616. return result;
  4617. }
  4618. parseParenItem(node, startPos, startLoc) {
  4619. node = super.parseParenItem(node, startPos, startLoc);
  4620. if (this.eat(17)) {
  4621. node.optional = true;
  4622. this.resetEndLocation(node);
  4623. }
  4624. if (this.match(14)) {
  4625. const typeCastNode = this.startNodeAt(startPos, startLoc);
  4626. typeCastNode.expression = node;
  4627. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  4628. return this.finishNode(typeCastNode, "TypeCastExpression");
  4629. }
  4630. return node;
  4631. }
  4632. assertModuleNodeAllowed(node) {
  4633. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  4634. return;
  4635. }
  4636. super.assertModuleNodeAllowed(node);
  4637. }
  4638. parseExport(node) {
  4639. const decl = super.parseExport(node);
  4640. if (decl.type === "ExportNamedDeclaration" || decl.type === "ExportAllDeclaration") {
  4641. decl.exportKind = decl.exportKind || "value";
  4642. }
  4643. return decl;
  4644. }
  4645. parseExportDeclaration(node) {
  4646. if (this.isContextual(120)) {
  4647. node.exportKind = "type";
  4648. const declarationNode = this.startNode();
  4649. this.next();
  4650. if (this.match(5)) {
  4651. node.specifiers = this.parseExportSpecifiers(true);
  4652. this.parseExportFrom(node);
  4653. return null;
  4654. } else {
  4655. return this.flowParseTypeAlias(declarationNode);
  4656. }
  4657. } else if (this.isContextual(121)) {
  4658. node.exportKind = "type";
  4659. const declarationNode = this.startNode();
  4660. this.next();
  4661. return this.flowParseOpaqueType(declarationNode, false);
  4662. } else if (this.isContextual(119)) {
  4663. node.exportKind = "type";
  4664. const declarationNode = this.startNode();
  4665. this.next();
  4666. return this.flowParseInterface(declarationNode);
  4667. } else if (this.shouldParseEnums() && this.isContextual(116)) {
  4668. node.exportKind = "value";
  4669. const declarationNode = this.startNode();
  4670. this.next();
  4671. return this.flowParseEnumDeclaration(declarationNode);
  4672. } else {
  4673. return super.parseExportDeclaration(node);
  4674. }
  4675. }
  4676. eatExportStar(node) {
  4677. if (super.eatExportStar(...arguments)) return true;
  4678. if (this.isContextual(120) && this.lookahead().type === 49) {
  4679. node.exportKind = "type";
  4680. this.next();
  4681. this.next();
  4682. return true;
  4683. }
  4684. return false;
  4685. }
  4686. maybeParseExportNamespaceSpecifier(node) {
  4687. const pos = this.state.start;
  4688. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  4689. if (hasNamespace && node.exportKind === "type") {
  4690. this.unexpected(pos);
  4691. }
  4692. return hasNamespace;
  4693. }
  4694. parseClassId(node, isStatement, optionalId) {
  4695. super.parseClassId(node, isStatement, optionalId);
  4696. if (this.match(43)) {
  4697. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4698. }
  4699. }
  4700. parseClassMember(classBody, member, state) {
  4701. const pos = this.state.start;
  4702. if (this.isContextual(115)) {
  4703. if (this.parseClassMemberFromModifier(classBody, member)) {
  4704. return;
  4705. }
  4706. member.declare = true;
  4707. }
  4708. super.parseClassMember(classBody, member, state);
  4709. if (member.declare) {
  4710. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  4711. this.raise(pos, FlowErrors.DeclareClassElement);
  4712. } else if (member.value) {
  4713. this.raise(member.value.start, FlowErrors.DeclareClassFieldInitializer);
  4714. }
  4715. }
  4716. }
  4717. isIterator(word) {
  4718. return word === "iterator" || word === "asyncIterator";
  4719. }
  4720. readIterator() {
  4721. const word = super.readWord1();
  4722. const fullWord = "@@" + word;
  4723. if (!this.isIterator(word) || !this.state.inType) {
  4724. this.raise(this.state.pos, ErrorMessages.InvalidIdentifier, fullWord);
  4725. }
  4726. this.finishToken(122, fullWord);
  4727. }
  4728. getTokenFromCode(code) {
  4729. const next = this.input.charCodeAt(this.state.pos + 1);
  4730. if (code === 123 && next === 124) {
  4731. return this.finishOp(6, 2);
  4732. } else if (this.state.inType && (code === 62 || code === 60)) {
  4733. return this.finishOp(code === 62 ? 44 : 43, 1);
  4734. } else if (this.state.inType && code === 63) {
  4735. if (next === 46) {
  4736. return this.finishOp(18, 2);
  4737. }
  4738. return this.finishOp(17, 1);
  4739. } else if (isIteratorStart(code, next)) {
  4740. this.state.pos += 2;
  4741. return this.readIterator();
  4742. } else {
  4743. return super.getTokenFromCode(code);
  4744. }
  4745. }
  4746. isAssignable(node, isBinding) {
  4747. if (node.type === "TypeCastExpression") {
  4748. return this.isAssignable(node.expression, isBinding);
  4749. } else {
  4750. return super.isAssignable(node, isBinding);
  4751. }
  4752. }
  4753. toAssignable(node, isLHS = false) {
  4754. if (node.type === "TypeCastExpression") {
  4755. return super.toAssignable(this.typeCastToParameter(node), isLHS);
  4756. } else {
  4757. return super.toAssignable(node, isLHS);
  4758. }
  4759. }
  4760. toAssignableList(exprList, trailingCommaPos, isLHS) {
  4761. for (let i = 0; i < exprList.length; i++) {
  4762. const expr = exprList[i];
  4763. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  4764. exprList[i] = this.typeCastToParameter(expr);
  4765. }
  4766. }
  4767. return super.toAssignableList(exprList, trailingCommaPos, isLHS);
  4768. }
  4769. toReferencedList(exprList, isParenthesizedExpr) {
  4770. for (let i = 0; i < exprList.length; i++) {
  4771. var _expr$extra;
  4772. const expr = exprList[i];
  4773. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  4774. this.raise(expr.typeAnnotation.start, FlowErrors.TypeCastInPattern);
  4775. }
  4776. }
  4777. return exprList;
  4778. }
  4779. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  4780. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  4781. if (canBePattern && !this.state.maybeInArrowParameters) {
  4782. this.toReferencedList(node.elements);
  4783. }
  4784. return node;
  4785. }
  4786. checkLVal(expr, ...args) {
  4787. if (expr.type !== "TypeCastExpression") {
  4788. return super.checkLVal(expr, ...args);
  4789. }
  4790. }
  4791. parseClassProperty(node) {
  4792. if (this.match(14)) {
  4793. node.typeAnnotation = this.flowParseTypeAnnotation();
  4794. }
  4795. return super.parseClassProperty(node);
  4796. }
  4797. parseClassPrivateProperty(node) {
  4798. if (this.match(14)) {
  4799. node.typeAnnotation = this.flowParseTypeAnnotation();
  4800. }
  4801. return super.parseClassPrivateProperty(node);
  4802. }
  4803. isClassMethod() {
  4804. return this.match(43) || super.isClassMethod();
  4805. }
  4806. isClassProperty() {
  4807. return this.match(14) || super.isClassProperty();
  4808. }
  4809. isNonstaticConstructor(method) {
  4810. return !this.match(14) && super.isNonstaticConstructor(method);
  4811. }
  4812. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  4813. if (method.variance) {
  4814. this.unexpected(method.variance.start);
  4815. }
  4816. delete method.variance;
  4817. if (this.match(43)) {
  4818. method.typeParameters = this.flowParseTypeParameterDeclaration();
  4819. }
  4820. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  4821. if (method.params && isConstructor) {
  4822. const params = method.params;
  4823. if (params.length > 0 && this.isThisParam(params[0])) {
  4824. this.raise(method.start, FlowErrors.ThisParamBannedInConstructor);
  4825. }
  4826. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  4827. const params = method.value.params;
  4828. if (params.length > 0 && this.isThisParam(params[0])) {
  4829. this.raise(method.start, FlowErrors.ThisParamBannedInConstructor);
  4830. }
  4831. }
  4832. }
  4833. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  4834. if (method.variance) {
  4835. this.unexpected(method.variance.start);
  4836. }
  4837. delete method.variance;
  4838. if (this.match(43)) {
  4839. method.typeParameters = this.flowParseTypeParameterDeclaration();
  4840. }
  4841. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  4842. }
  4843. parseClassSuper(node) {
  4844. super.parseClassSuper(node);
  4845. if (node.superClass && this.match(43)) {
  4846. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  4847. }
  4848. if (this.isContextual(104)) {
  4849. this.next();
  4850. const implemented = node.implements = [];
  4851. do {
  4852. const node = this.startNode();
  4853. node.id = this.flowParseRestrictedIdentifier(true);
  4854. if (this.match(43)) {
  4855. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4856. } else {
  4857. node.typeParameters = null;
  4858. }
  4859. implemented.push(this.finishNode(node, "ClassImplements"));
  4860. } while (this.eat(12));
  4861. }
  4862. }
  4863. checkGetterSetterParams(method) {
  4864. super.checkGetterSetterParams(method);
  4865. const params = this.getObjectOrClassMethodParams(method);
  4866. if (params.length > 0) {
  4867. const param = params[0];
  4868. if (this.isThisParam(param) && method.kind === "get") {
  4869. this.raise(param.start, FlowErrors.GetterMayNotHaveThisParam);
  4870. } else if (this.isThisParam(param)) {
  4871. this.raise(param.start, FlowErrors.SetterMayNotHaveThisParam);
  4872. }
  4873. }
  4874. }
  4875. parsePropertyNamePrefixOperator(node) {
  4876. node.variance = this.flowParseVariance();
  4877. }
  4878. parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  4879. if (prop.variance) {
  4880. this.unexpected(prop.variance.start);
  4881. }
  4882. delete prop.variance;
  4883. let typeParameters;
  4884. if (this.match(43) && !isAccessor) {
  4885. typeParameters = this.flowParseTypeParameterDeclaration();
  4886. if (!this.match(10)) this.unexpected();
  4887. }
  4888. super.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  4889. if (typeParameters) {
  4890. (prop.value || prop).typeParameters = typeParameters;
  4891. }
  4892. }
  4893. parseAssignableListItemTypes(param) {
  4894. if (this.eat(17)) {
  4895. if (param.type !== "Identifier") {
  4896. this.raise(param.start, FlowErrors.PatternIsOptional);
  4897. }
  4898. if (this.isThisParam(param)) {
  4899. this.raise(param.start, FlowErrors.ThisParamMayNotBeOptional);
  4900. }
  4901. param.optional = true;
  4902. }
  4903. if (this.match(14)) {
  4904. param.typeAnnotation = this.flowParseTypeAnnotation();
  4905. } else if (this.isThisParam(param)) {
  4906. this.raise(param.start, FlowErrors.ThisParamAnnotationRequired);
  4907. }
  4908. if (this.match(27) && this.isThisParam(param)) {
  4909. this.raise(param.start, FlowErrors.ThisParamNoDefault);
  4910. }
  4911. this.resetEndLocation(param);
  4912. return param;
  4913. }
  4914. parseMaybeDefault(startPos, startLoc, left) {
  4915. const node = super.parseMaybeDefault(startPos, startLoc, left);
  4916. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  4917. this.raise(node.typeAnnotation.start, FlowErrors.TypeBeforeInitializer);
  4918. }
  4919. return node;
  4920. }
  4921. shouldParseDefaultImport(node) {
  4922. if (!hasTypeImportKind(node)) {
  4923. return super.shouldParseDefaultImport(node);
  4924. }
  4925. return isMaybeDefaultImport(this.state.type);
  4926. }
  4927. parseImportSpecifierLocal(node, specifier, type, contextDescription) {
  4928. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  4929. this.checkLVal(specifier.local, contextDescription, BIND_LEXICAL);
  4930. node.specifiers.push(this.finishNode(specifier, type));
  4931. }
  4932. maybeParseDefaultImportSpecifier(node) {
  4933. node.importKind = "value";
  4934. let kind = null;
  4935. if (this.match(81)) {
  4936. kind = "typeof";
  4937. } else if (this.isContextual(120)) {
  4938. kind = "type";
  4939. }
  4940. if (kind) {
  4941. const lh = this.lookahead();
  4942. const {
  4943. type
  4944. } = lh;
  4945. if (kind === "type" && type === 49) {
  4946. this.unexpected(lh.start);
  4947. }
  4948. if (isMaybeDefaultImport(type) || type === 5 || type === 49) {
  4949. this.next();
  4950. node.importKind = kind;
  4951. }
  4952. }
  4953. return super.maybeParseDefaultImportSpecifier(node);
  4954. }
  4955. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly) {
  4956. const firstIdent = specifier.imported;
  4957. let specifierTypeKind = null;
  4958. if (firstIdent.type === "Identifier") {
  4959. if (firstIdent.name === "type") {
  4960. specifierTypeKind = "type";
  4961. } else if (firstIdent.name === "typeof") {
  4962. specifierTypeKind = "typeof";
  4963. }
  4964. }
  4965. let isBinding = false;
  4966. if (this.isContextual(87) && !this.isLookaheadContextual("as")) {
  4967. const as_ident = this.parseIdentifier(true);
  4968. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  4969. specifier.imported = as_ident;
  4970. specifier.importKind = specifierTypeKind;
  4971. specifier.local = cloneIdentifier(as_ident);
  4972. } else {
  4973. specifier.imported = firstIdent;
  4974. specifier.importKind = null;
  4975. specifier.local = this.parseIdentifier();
  4976. }
  4977. } else {
  4978. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  4979. specifier.imported = this.parseIdentifier(true);
  4980. specifier.importKind = specifierTypeKind;
  4981. } else {
  4982. if (importedIsString) {
  4983. throw this.raise(specifier.start, ErrorMessages.ImportBindingIsString, firstIdent.value);
  4984. }
  4985. specifier.imported = firstIdent;
  4986. specifier.importKind = null;
  4987. }
  4988. if (this.eatContextual(87)) {
  4989. specifier.local = this.parseIdentifier();
  4990. } else {
  4991. isBinding = true;
  4992. specifier.local = cloneIdentifier(specifier.imported);
  4993. }
  4994. }
  4995. const specifierIsTypeImport = hasTypeImportKind(specifier);
  4996. if (isInTypeOnlyImport && specifierIsTypeImport) {
  4997. this.raise(specifier.start, FlowErrors.ImportTypeShorthandOnlyInPureImport);
  4998. }
  4999. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5000. this.checkReservedType(specifier.local.name, specifier.local.start, true);
  5001. }
  5002. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5003. this.checkReservedWord(specifier.local.name, specifier.start, true, true);
  5004. }
  5005. this.checkLVal(specifier.local, "import specifier", BIND_LEXICAL);
  5006. return this.finishNode(specifier, "ImportSpecifier");
  5007. }
  5008. parseBindingAtom() {
  5009. switch (this.state.type) {
  5010. case 72:
  5011. return this.parseIdentifier(true);
  5012. default:
  5013. return super.parseBindingAtom();
  5014. }
  5015. }
  5016. parseFunctionParams(node, allowModifiers) {
  5017. const kind = node.kind;
  5018. if (kind !== "get" && kind !== "set" && this.match(43)) {
  5019. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5020. }
  5021. super.parseFunctionParams(node, allowModifiers);
  5022. }
  5023. parseVarId(decl, kind) {
  5024. super.parseVarId(decl, kind);
  5025. if (this.match(14)) {
  5026. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5027. this.resetEndLocation(decl.id);
  5028. }
  5029. }
  5030. parseAsyncArrowFromCallExpression(node, call) {
  5031. if (this.match(14)) {
  5032. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5033. this.state.noAnonFunctionType = true;
  5034. node.returnType = this.flowParseTypeAnnotation();
  5035. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5036. }
  5037. return super.parseAsyncArrowFromCallExpression(node, call);
  5038. }
  5039. shouldParseAsyncArrow() {
  5040. return this.match(14) || super.shouldParseAsyncArrow();
  5041. }
  5042. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5043. var _jsx;
  5044. let state = null;
  5045. let jsx;
  5046. if (this.hasPlugin("jsx") && (this.match(132) || this.match(43))) {
  5047. state = this.state.clone();
  5048. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5049. if (!jsx.error) return jsx.node;
  5050. const {
  5051. context
  5052. } = this.state;
  5053. const curContext = context[context.length - 1];
  5054. if (curContext === types.j_oTag) {
  5055. context.length -= 2;
  5056. } else if (curContext === types.j_expr) {
  5057. context.length -= 1;
  5058. }
  5059. }
  5060. if ((_jsx = jsx) != null && _jsx.error || this.match(43)) {
  5061. var _jsx2, _jsx3;
  5062. state = state || this.state.clone();
  5063. let typeParameters;
  5064. const arrow = this.tryParse(abort => {
  5065. var _arrowExpression$extr;
  5066. typeParameters = this.flowParseTypeParameterDeclaration();
  5067. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5068. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5069. this.resetStartLocationFromNode(result, typeParameters);
  5070. return result;
  5071. });
  5072. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5073. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5074. if (expr.type !== "ArrowFunctionExpression") abort();
  5075. expr.typeParameters = typeParameters;
  5076. this.resetStartLocationFromNode(expr, typeParameters);
  5077. return arrowExpression;
  5078. }, state);
  5079. let arrowExpression = null;
  5080. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5081. if (!arrow.error && !arrow.aborted) {
  5082. if (arrow.node.async) {
  5083. this.raise(typeParameters.start, FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction);
  5084. }
  5085. return arrow.node;
  5086. }
  5087. arrowExpression = arrow.node;
  5088. }
  5089. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5090. this.state = jsx.failState;
  5091. return jsx.node;
  5092. }
  5093. if (arrowExpression) {
  5094. this.state = arrow.failState;
  5095. return arrowExpression;
  5096. }
  5097. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5098. if (arrow.thrown) throw arrow.error;
  5099. throw this.raise(typeParameters.start, FlowErrors.UnexpectedTokenAfterTypeParameter);
  5100. }
  5101. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5102. }
  5103. parseArrow(node) {
  5104. if (this.match(14)) {
  5105. const result = this.tryParse(() => {
  5106. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5107. this.state.noAnonFunctionType = true;
  5108. const typeNode = this.startNode();
  5109. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5110. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5111. if (this.canInsertSemicolon()) this.unexpected();
  5112. if (!this.match(19)) this.unexpected();
  5113. return typeNode;
  5114. });
  5115. if (result.thrown) return null;
  5116. if (result.error) this.state = result.failState;
  5117. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5118. }
  5119. return super.parseArrow(node);
  5120. }
  5121. shouldParseArrow(params) {
  5122. return this.match(14) || super.shouldParseArrow(params);
  5123. }
  5124. setArrowFunctionParameters(node, params) {
  5125. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5126. node.params = params;
  5127. } else {
  5128. super.setArrowFunctionParameters(node, params);
  5129. }
  5130. }
  5131. checkParams(node, allowDuplicates, isArrowFunction) {
  5132. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5133. return;
  5134. }
  5135. for (let i = 0; i < node.params.length; i++) {
  5136. if (this.isThisParam(node.params[i]) && i > 0) {
  5137. this.raise(node.params[i].start, FlowErrors.ThisParamMustBeFirst);
  5138. }
  5139. }
  5140. return super.checkParams(...arguments);
  5141. }
  5142. parseParenAndDistinguishExpression(canBeArrow) {
  5143. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  5144. }
  5145. parseSubscripts(base, startPos, startLoc, noCalls) {
  5146. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startPos) !== -1) {
  5147. this.next();
  5148. const node = this.startNodeAt(startPos, startLoc);
  5149. node.callee = base;
  5150. node.arguments = this.parseCallExpressionArguments(11, false);
  5151. base = this.finishNode(node, "CallExpression");
  5152. } else if (base.type === "Identifier" && base.name === "async" && this.match(43)) {
  5153. const state = this.state.clone();
  5154. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startPos, startLoc) || abort(), state);
  5155. if (!arrow.error && !arrow.aborted) return arrow.node;
  5156. const result = this.tryParse(() => super.parseSubscripts(base, startPos, startLoc, noCalls), state);
  5157. if (result.node && !result.error) return result.node;
  5158. if (arrow.node) {
  5159. this.state = arrow.failState;
  5160. return arrow.node;
  5161. }
  5162. if (result.node) {
  5163. this.state = result.failState;
  5164. return result.node;
  5165. }
  5166. throw arrow.error || result.error;
  5167. }
  5168. return super.parseSubscripts(base, startPos, startLoc, noCalls);
  5169. }
  5170. parseSubscript(base, startPos, startLoc, noCalls, subscriptState) {
  5171. if (this.match(18) && this.isLookaheadToken_lt()) {
  5172. subscriptState.optionalChainMember = true;
  5173. if (noCalls) {
  5174. subscriptState.stop = true;
  5175. return base;
  5176. }
  5177. this.next();
  5178. const node = this.startNodeAt(startPos, startLoc);
  5179. node.callee = base;
  5180. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5181. this.expect(10);
  5182. node.arguments = this.parseCallExpressionArguments(11, false);
  5183. node.optional = true;
  5184. return this.finishCallExpression(node, true);
  5185. } else if (!noCalls && this.shouldParseTypes() && this.match(43)) {
  5186. const node = this.startNodeAt(startPos, startLoc);
  5187. node.callee = base;
  5188. const result = this.tryParse(() => {
  5189. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5190. this.expect(10);
  5191. node.arguments = this.parseCallExpressionArguments(11, false);
  5192. if (subscriptState.optionalChainMember) node.optional = false;
  5193. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5194. });
  5195. if (result.node) {
  5196. if (result.error) this.state = result.failState;
  5197. return result.node;
  5198. }
  5199. }
  5200. return super.parseSubscript(base, startPos, startLoc, noCalls, subscriptState);
  5201. }
  5202. parseNewArguments(node) {
  5203. let targs = null;
  5204. if (this.shouldParseTypes() && this.match(43)) {
  5205. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5206. }
  5207. node.typeArguments = targs;
  5208. super.parseNewArguments(node);
  5209. }
  5210. parseAsyncArrowWithTypeParameters(startPos, startLoc) {
  5211. const node = this.startNodeAt(startPos, startLoc);
  5212. this.parseFunctionParams(node);
  5213. if (!this.parseArrow(node)) return;
  5214. return this.parseArrowExpression(node, undefined, true);
  5215. }
  5216. readToken_mult_modulo(code) {
  5217. const next = this.input.charCodeAt(this.state.pos + 1);
  5218. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5219. this.state.hasFlowComment = false;
  5220. this.state.pos += 2;
  5221. this.nextToken();
  5222. return;
  5223. }
  5224. super.readToken_mult_modulo(code);
  5225. }
  5226. readToken_pipe_amp(code) {
  5227. const next = this.input.charCodeAt(this.state.pos + 1);
  5228. if (code === 124 && next === 125) {
  5229. this.finishOp(9, 2);
  5230. return;
  5231. }
  5232. super.readToken_pipe_amp(code);
  5233. }
  5234. parseTopLevel(file, program) {
  5235. const fileNode = super.parseTopLevel(file, program);
  5236. if (this.state.hasFlowComment) {
  5237. this.raise(this.state.pos, FlowErrors.UnterminatedFlowComment);
  5238. }
  5239. return fileNode;
  5240. }
  5241. skipBlockComment() {
  5242. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5243. if (this.state.hasFlowComment) {
  5244. this.unexpected(null, FlowErrors.NestedFlowComment);
  5245. }
  5246. this.hasFlowCommentCompletion();
  5247. this.state.pos += this.skipFlowComment();
  5248. this.state.hasFlowComment = true;
  5249. return;
  5250. }
  5251. if (this.state.hasFlowComment) {
  5252. const end = this.input.indexOf("*-/", this.state.pos += 2);
  5253. if (end === -1) {
  5254. throw this.raise(this.state.pos - 2, ErrorMessages.UnterminatedComment);
  5255. }
  5256. this.state.pos = end + 3;
  5257. return;
  5258. }
  5259. return super.skipBlockComment();
  5260. }
  5261. skipFlowComment() {
  5262. const {
  5263. pos
  5264. } = this.state;
  5265. let shiftToFirstNonWhiteSpace = 2;
  5266. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5267. shiftToFirstNonWhiteSpace++;
  5268. }
  5269. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5270. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5271. if (ch2 === 58 && ch3 === 58) {
  5272. return shiftToFirstNonWhiteSpace + 2;
  5273. }
  5274. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5275. return shiftToFirstNonWhiteSpace + 12;
  5276. }
  5277. if (ch2 === 58 && ch3 !== 58) {
  5278. return shiftToFirstNonWhiteSpace;
  5279. }
  5280. return false;
  5281. }
  5282. hasFlowCommentCompletion() {
  5283. const end = this.input.indexOf("*/", this.state.pos);
  5284. if (end === -1) {
  5285. throw this.raise(this.state.pos, ErrorMessages.UnterminatedComment);
  5286. }
  5287. }
  5288. flowEnumErrorBooleanMemberNotInitialized(pos, {
  5289. enumName,
  5290. memberName
  5291. }) {
  5292. this.raise(pos, FlowErrors.EnumBooleanMemberNotInitialized, memberName, enumName);
  5293. }
  5294. flowEnumErrorInvalidMemberName(pos, {
  5295. enumName,
  5296. memberName
  5297. }) {
  5298. const suggestion = memberName[0].toUpperCase() + memberName.slice(1);
  5299. this.raise(pos, FlowErrors.EnumInvalidMemberName, memberName, suggestion, enumName);
  5300. }
  5301. flowEnumErrorDuplicateMemberName(pos, {
  5302. enumName,
  5303. memberName
  5304. }) {
  5305. this.raise(pos, FlowErrors.EnumDuplicateMemberName, memberName, enumName);
  5306. }
  5307. flowEnumErrorInconsistentMemberValues(pos, {
  5308. enumName
  5309. }) {
  5310. this.raise(pos, FlowErrors.EnumInconsistentMemberValues, enumName);
  5311. }
  5312. flowEnumErrorInvalidExplicitType(pos, {
  5313. enumName,
  5314. suppliedType
  5315. }) {
  5316. return this.raise(pos, suppliedType === null ? FlowErrors.EnumInvalidExplicitTypeUnknownSupplied : FlowErrors.EnumInvalidExplicitType, enumName, suppliedType);
  5317. }
  5318. flowEnumErrorInvalidMemberInitializer(pos, {
  5319. enumName,
  5320. explicitType,
  5321. memberName
  5322. }) {
  5323. let message = null;
  5324. switch (explicitType) {
  5325. case "boolean":
  5326. case "number":
  5327. case "string":
  5328. message = FlowErrors.EnumInvalidMemberInitializerPrimaryType;
  5329. break;
  5330. case "symbol":
  5331. message = FlowErrors.EnumInvalidMemberInitializerSymbolType;
  5332. break;
  5333. default:
  5334. message = FlowErrors.EnumInvalidMemberInitializerUnknownType;
  5335. }
  5336. return this.raise(pos, message, enumName, memberName, explicitType);
  5337. }
  5338. flowEnumErrorNumberMemberNotInitialized(pos, {
  5339. enumName,
  5340. memberName
  5341. }) {
  5342. this.raise(pos, FlowErrors.EnumNumberMemberNotInitialized, enumName, memberName);
  5343. }
  5344. flowEnumErrorStringMemberInconsistentlyInitailized(pos, {
  5345. enumName
  5346. }) {
  5347. this.raise(pos, FlowErrors.EnumStringMemberInconsistentlyInitailized, enumName);
  5348. }
  5349. flowEnumMemberInit() {
  5350. const startPos = this.state.start;
  5351. const endOfInit = () => this.match(12) || this.match(8);
  5352. switch (this.state.type) {
  5353. case 124:
  5354. {
  5355. const literal = this.parseNumericLiteral(this.state.value);
  5356. if (endOfInit()) {
  5357. return {
  5358. type: "number",
  5359. pos: literal.start,
  5360. value: literal
  5361. };
  5362. }
  5363. return {
  5364. type: "invalid",
  5365. pos: startPos
  5366. };
  5367. }
  5368. case 123:
  5369. {
  5370. const literal = this.parseStringLiteral(this.state.value);
  5371. if (endOfInit()) {
  5372. return {
  5373. type: "string",
  5374. pos: literal.start,
  5375. value: literal
  5376. };
  5377. }
  5378. return {
  5379. type: "invalid",
  5380. pos: startPos
  5381. };
  5382. }
  5383. case 79:
  5384. case 80:
  5385. {
  5386. const literal = this.parseBooleanLiteral(this.match(79));
  5387. if (endOfInit()) {
  5388. return {
  5389. type: "boolean",
  5390. pos: literal.start,
  5391. value: literal
  5392. };
  5393. }
  5394. return {
  5395. type: "invalid",
  5396. pos: startPos
  5397. };
  5398. }
  5399. default:
  5400. return {
  5401. type: "invalid",
  5402. pos: startPos
  5403. };
  5404. }
  5405. }
  5406. flowEnumMemberRaw() {
  5407. const pos = this.state.start;
  5408. const id = this.parseIdentifier(true);
  5409. const init = this.eat(27) ? this.flowEnumMemberInit() : {
  5410. type: "none",
  5411. pos
  5412. };
  5413. return {
  5414. id,
  5415. init
  5416. };
  5417. }
  5418. flowEnumCheckExplicitTypeMismatch(pos, context, expectedType) {
  5419. const {
  5420. explicitType
  5421. } = context;
  5422. if (explicitType === null) {
  5423. return;
  5424. }
  5425. if (explicitType !== expectedType) {
  5426. this.flowEnumErrorInvalidMemberInitializer(pos, context);
  5427. }
  5428. }
  5429. flowEnumMembers({
  5430. enumName,
  5431. explicitType
  5432. }) {
  5433. const seenNames = new Set();
  5434. const members = {
  5435. booleanMembers: [],
  5436. numberMembers: [],
  5437. stringMembers: [],
  5438. defaultedMembers: []
  5439. };
  5440. let hasUnknownMembers = false;
  5441. while (!this.match(8)) {
  5442. if (this.eat(21)) {
  5443. hasUnknownMembers = true;
  5444. break;
  5445. }
  5446. const memberNode = this.startNode();
  5447. const {
  5448. id,
  5449. init
  5450. } = this.flowEnumMemberRaw();
  5451. const memberName = id.name;
  5452. if (memberName === "") {
  5453. continue;
  5454. }
  5455. if (/^[a-z]/.test(memberName)) {
  5456. this.flowEnumErrorInvalidMemberName(id.start, {
  5457. enumName,
  5458. memberName
  5459. });
  5460. }
  5461. if (seenNames.has(memberName)) {
  5462. this.flowEnumErrorDuplicateMemberName(id.start, {
  5463. enumName,
  5464. memberName
  5465. });
  5466. }
  5467. seenNames.add(memberName);
  5468. const context = {
  5469. enumName,
  5470. explicitType,
  5471. memberName
  5472. };
  5473. memberNode.id = id;
  5474. switch (init.type) {
  5475. case "boolean":
  5476. {
  5477. this.flowEnumCheckExplicitTypeMismatch(init.pos, context, "boolean");
  5478. memberNode.init = init.value;
  5479. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  5480. break;
  5481. }
  5482. case "number":
  5483. {
  5484. this.flowEnumCheckExplicitTypeMismatch(init.pos, context, "number");
  5485. memberNode.init = init.value;
  5486. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  5487. break;
  5488. }
  5489. case "string":
  5490. {
  5491. this.flowEnumCheckExplicitTypeMismatch(init.pos, context, "string");
  5492. memberNode.init = init.value;
  5493. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  5494. break;
  5495. }
  5496. case "invalid":
  5497. {
  5498. throw this.flowEnumErrorInvalidMemberInitializer(init.pos, context);
  5499. }
  5500. case "none":
  5501. {
  5502. switch (explicitType) {
  5503. case "boolean":
  5504. this.flowEnumErrorBooleanMemberNotInitialized(init.pos, context);
  5505. break;
  5506. case "number":
  5507. this.flowEnumErrorNumberMemberNotInitialized(init.pos, context);
  5508. break;
  5509. default:
  5510. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  5511. }
  5512. }
  5513. }
  5514. if (!this.match(8)) {
  5515. this.expect(12);
  5516. }
  5517. }
  5518. return {
  5519. members,
  5520. hasUnknownMembers
  5521. };
  5522. }
  5523. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  5524. enumName
  5525. }) {
  5526. if (initializedMembers.length === 0) {
  5527. return defaultedMembers;
  5528. } else if (defaultedMembers.length === 0) {
  5529. return initializedMembers;
  5530. } else if (defaultedMembers.length > initializedMembers.length) {
  5531. for (const member of initializedMembers) {
  5532. this.flowEnumErrorStringMemberInconsistentlyInitailized(member.start, {
  5533. enumName
  5534. });
  5535. }
  5536. return defaultedMembers;
  5537. } else {
  5538. for (const member of defaultedMembers) {
  5539. this.flowEnumErrorStringMemberInconsistentlyInitailized(member.start, {
  5540. enumName
  5541. });
  5542. }
  5543. return initializedMembers;
  5544. }
  5545. }
  5546. flowEnumParseExplicitType({
  5547. enumName
  5548. }) {
  5549. if (this.eatContextual(95)) {
  5550. if (!tokenIsIdentifier(this.state.type)) {
  5551. throw this.flowEnumErrorInvalidExplicitType(this.state.start, {
  5552. enumName,
  5553. suppliedType: null
  5554. });
  5555. }
  5556. const {
  5557. value
  5558. } = this.state;
  5559. this.next();
  5560. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  5561. this.flowEnumErrorInvalidExplicitType(this.state.start, {
  5562. enumName,
  5563. suppliedType: value
  5564. });
  5565. }
  5566. return value;
  5567. }
  5568. return null;
  5569. }
  5570. flowEnumBody(node, {
  5571. enumName,
  5572. nameLoc
  5573. }) {
  5574. const explicitType = this.flowEnumParseExplicitType({
  5575. enumName
  5576. });
  5577. this.expect(5);
  5578. const {
  5579. members,
  5580. hasUnknownMembers
  5581. } = this.flowEnumMembers({
  5582. enumName,
  5583. explicitType
  5584. });
  5585. node.hasUnknownMembers = hasUnknownMembers;
  5586. switch (explicitType) {
  5587. case "boolean":
  5588. node.explicitType = true;
  5589. node.members = members.booleanMembers;
  5590. this.expect(8);
  5591. return this.finishNode(node, "EnumBooleanBody");
  5592. case "number":
  5593. node.explicitType = true;
  5594. node.members = members.numberMembers;
  5595. this.expect(8);
  5596. return this.finishNode(node, "EnumNumberBody");
  5597. case "string":
  5598. node.explicitType = true;
  5599. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  5600. enumName
  5601. });
  5602. this.expect(8);
  5603. return this.finishNode(node, "EnumStringBody");
  5604. case "symbol":
  5605. node.members = members.defaultedMembers;
  5606. this.expect(8);
  5607. return this.finishNode(node, "EnumSymbolBody");
  5608. default:
  5609. {
  5610. const empty = () => {
  5611. node.members = [];
  5612. this.expect(8);
  5613. return this.finishNode(node, "EnumStringBody");
  5614. };
  5615. node.explicitType = false;
  5616. const boolsLen = members.booleanMembers.length;
  5617. const numsLen = members.numberMembers.length;
  5618. const strsLen = members.stringMembers.length;
  5619. const defaultedLen = members.defaultedMembers.length;
  5620. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  5621. return empty();
  5622. } else if (!boolsLen && !numsLen) {
  5623. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  5624. enumName
  5625. });
  5626. this.expect(8);
  5627. return this.finishNode(node, "EnumStringBody");
  5628. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  5629. for (const member of members.defaultedMembers) {
  5630. this.flowEnumErrorBooleanMemberNotInitialized(member.start, {
  5631. enumName,
  5632. memberName: member.id.name
  5633. });
  5634. }
  5635. node.members = members.booleanMembers;
  5636. this.expect(8);
  5637. return this.finishNode(node, "EnumBooleanBody");
  5638. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  5639. for (const member of members.defaultedMembers) {
  5640. this.flowEnumErrorNumberMemberNotInitialized(member.start, {
  5641. enumName,
  5642. memberName: member.id.name
  5643. });
  5644. }
  5645. node.members = members.numberMembers;
  5646. this.expect(8);
  5647. return this.finishNode(node, "EnumNumberBody");
  5648. } else {
  5649. this.flowEnumErrorInconsistentMemberValues(nameLoc, {
  5650. enumName
  5651. });
  5652. return empty();
  5653. }
  5654. }
  5655. }
  5656. }
  5657. flowParseEnumDeclaration(node) {
  5658. const id = this.parseIdentifier();
  5659. node.id = id;
  5660. node.body = this.flowEnumBody(this.startNode(), {
  5661. enumName: id.name,
  5662. nameLoc: id.start
  5663. });
  5664. return this.finishNode(node, "EnumDeclaration");
  5665. }
  5666. isLookaheadToken_lt() {
  5667. const next = this.nextTokenStart();
  5668. if (this.input.charCodeAt(next) === 60) {
  5669. const afterNext = this.input.charCodeAt(next + 1);
  5670. return afterNext !== 60 && afterNext !== 61;
  5671. }
  5672. return false;
  5673. }
  5674. maybeUnwrapTypeCastExpression(node) {
  5675. return node.type === "TypeCastExpression" ? node.expression : node;
  5676. }
  5677. });
  5678. const entities = {
  5679. quot: "\u0022",
  5680. amp: "&",
  5681. apos: "\u0027",
  5682. lt: "<",
  5683. gt: ">",
  5684. nbsp: "\u00A0",
  5685. iexcl: "\u00A1",
  5686. cent: "\u00A2",
  5687. pound: "\u00A3",
  5688. curren: "\u00A4",
  5689. yen: "\u00A5",
  5690. brvbar: "\u00A6",
  5691. sect: "\u00A7",
  5692. uml: "\u00A8",
  5693. copy: "\u00A9",
  5694. ordf: "\u00AA",
  5695. laquo: "\u00AB",
  5696. not: "\u00AC",
  5697. shy: "\u00AD",
  5698. reg: "\u00AE",
  5699. macr: "\u00AF",
  5700. deg: "\u00B0",
  5701. plusmn: "\u00B1",
  5702. sup2: "\u00B2",
  5703. sup3: "\u00B3",
  5704. acute: "\u00B4",
  5705. micro: "\u00B5",
  5706. para: "\u00B6",
  5707. middot: "\u00B7",
  5708. cedil: "\u00B8",
  5709. sup1: "\u00B9",
  5710. ordm: "\u00BA",
  5711. raquo: "\u00BB",
  5712. frac14: "\u00BC",
  5713. frac12: "\u00BD",
  5714. frac34: "\u00BE",
  5715. iquest: "\u00BF",
  5716. Agrave: "\u00C0",
  5717. Aacute: "\u00C1",
  5718. Acirc: "\u00C2",
  5719. Atilde: "\u00C3",
  5720. Auml: "\u00C4",
  5721. Aring: "\u00C5",
  5722. AElig: "\u00C6",
  5723. Ccedil: "\u00C7",
  5724. Egrave: "\u00C8",
  5725. Eacute: "\u00C9",
  5726. Ecirc: "\u00CA",
  5727. Euml: "\u00CB",
  5728. Igrave: "\u00CC",
  5729. Iacute: "\u00CD",
  5730. Icirc: "\u00CE",
  5731. Iuml: "\u00CF",
  5732. ETH: "\u00D0",
  5733. Ntilde: "\u00D1",
  5734. Ograve: "\u00D2",
  5735. Oacute: "\u00D3",
  5736. Ocirc: "\u00D4",
  5737. Otilde: "\u00D5",
  5738. Ouml: "\u00D6",
  5739. times: "\u00D7",
  5740. Oslash: "\u00D8",
  5741. Ugrave: "\u00D9",
  5742. Uacute: "\u00DA",
  5743. Ucirc: "\u00DB",
  5744. Uuml: "\u00DC",
  5745. Yacute: "\u00DD",
  5746. THORN: "\u00DE",
  5747. szlig: "\u00DF",
  5748. agrave: "\u00E0",
  5749. aacute: "\u00E1",
  5750. acirc: "\u00E2",
  5751. atilde: "\u00E3",
  5752. auml: "\u00E4",
  5753. aring: "\u00E5",
  5754. aelig: "\u00E6",
  5755. ccedil: "\u00E7",
  5756. egrave: "\u00E8",
  5757. eacute: "\u00E9",
  5758. ecirc: "\u00EA",
  5759. euml: "\u00EB",
  5760. igrave: "\u00EC",
  5761. iacute: "\u00ED",
  5762. icirc: "\u00EE",
  5763. iuml: "\u00EF",
  5764. eth: "\u00F0",
  5765. ntilde: "\u00F1",
  5766. ograve: "\u00F2",
  5767. oacute: "\u00F3",
  5768. ocirc: "\u00F4",
  5769. otilde: "\u00F5",
  5770. ouml: "\u00F6",
  5771. divide: "\u00F7",
  5772. oslash: "\u00F8",
  5773. ugrave: "\u00F9",
  5774. uacute: "\u00FA",
  5775. ucirc: "\u00FB",
  5776. uuml: "\u00FC",
  5777. yacute: "\u00FD",
  5778. thorn: "\u00FE",
  5779. yuml: "\u00FF",
  5780. OElig: "\u0152",
  5781. oelig: "\u0153",
  5782. Scaron: "\u0160",
  5783. scaron: "\u0161",
  5784. Yuml: "\u0178",
  5785. fnof: "\u0192",
  5786. circ: "\u02C6",
  5787. tilde: "\u02DC",
  5788. Alpha: "\u0391",
  5789. Beta: "\u0392",
  5790. Gamma: "\u0393",
  5791. Delta: "\u0394",
  5792. Epsilon: "\u0395",
  5793. Zeta: "\u0396",
  5794. Eta: "\u0397",
  5795. Theta: "\u0398",
  5796. Iota: "\u0399",
  5797. Kappa: "\u039A",
  5798. Lambda: "\u039B",
  5799. Mu: "\u039C",
  5800. Nu: "\u039D",
  5801. Xi: "\u039E",
  5802. Omicron: "\u039F",
  5803. Pi: "\u03A0",
  5804. Rho: "\u03A1",
  5805. Sigma: "\u03A3",
  5806. Tau: "\u03A4",
  5807. Upsilon: "\u03A5",
  5808. Phi: "\u03A6",
  5809. Chi: "\u03A7",
  5810. Psi: "\u03A8",
  5811. Omega: "\u03A9",
  5812. alpha: "\u03B1",
  5813. beta: "\u03B2",
  5814. gamma: "\u03B3",
  5815. delta: "\u03B4",
  5816. epsilon: "\u03B5",
  5817. zeta: "\u03B6",
  5818. eta: "\u03B7",
  5819. theta: "\u03B8",
  5820. iota: "\u03B9",
  5821. kappa: "\u03BA",
  5822. lambda: "\u03BB",
  5823. mu: "\u03BC",
  5824. nu: "\u03BD",
  5825. xi: "\u03BE",
  5826. omicron: "\u03BF",
  5827. pi: "\u03C0",
  5828. rho: "\u03C1",
  5829. sigmaf: "\u03C2",
  5830. sigma: "\u03C3",
  5831. tau: "\u03C4",
  5832. upsilon: "\u03C5",
  5833. phi: "\u03C6",
  5834. chi: "\u03C7",
  5835. psi: "\u03C8",
  5836. omega: "\u03C9",
  5837. thetasym: "\u03D1",
  5838. upsih: "\u03D2",
  5839. piv: "\u03D6",
  5840. ensp: "\u2002",
  5841. emsp: "\u2003",
  5842. thinsp: "\u2009",
  5843. zwnj: "\u200C",
  5844. zwj: "\u200D",
  5845. lrm: "\u200E",
  5846. rlm: "\u200F",
  5847. ndash: "\u2013",
  5848. mdash: "\u2014",
  5849. lsquo: "\u2018",
  5850. rsquo: "\u2019",
  5851. sbquo: "\u201A",
  5852. ldquo: "\u201C",
  5853. rdquo: "\u201D",
  5854. bdquo: "\u201E",
  5855. dagger: "\u2020",
  5856. Dagger: "\u2021",
  5857. bull: "\u2022",
  5858. hellip: "\u2026",
  5859. permil: "\u2030",
  5860. prime: "\u2032",
  5861. Prime: "\u2033",
  5862. lsaquo: "\u2039",
  5863. rsaquo: "\u203A",
  5864. oline: "\u203E",
  5865. frasl: "\u2044",
  5866. euro: "\u20AC",
  5867. image: "\u2111",
  5868. weierp: "\u2118",
  5869. real: "\u211C",
  5870. trade: "\u2122",
  5871. alefsym: "\u2135",
  5872. larr: "\u2190",
  5873. uarr: "\u2191",
  5874. rarr: "\u2192",
  5875. darr: "\u2193",
  5876. harr: "\u2194",
  5877. crarr: "\u21B5",
  5878. lArr: "\u21D0",
  5879. uArr: "\u21D1",
  5880. rArr: "\u21D2",
  5881. dArr: "\u21D3",
  5882. hArr: "\u21D4",
  5883. forall: "\u2200",
  5884. part: "\u2202",
  5885. exist: "\u2203",
  5886. empty: "\u2205",
  5887. nabla: "\u2207",
  5888. isin: "\u2208",
  5889. notin: "\u2209",
  5890. ni: "\u220B",
  5891. prod: "\u220F",
  5892. sum: "\u2211",
  5893. minus: "\u2212",
  5894. lowast: "\u2217",
  5895. radic: "\u221A",
  5896. prop: "\u221D",
  5897. infin: "\u221E",
  5898. ang: "\u2220",
  5899. and: "\u2227",
  5900. or: "\u2228",
  5901. cap: "\u2229",
  5902. cup: "\u222A",
  5903. int: "\u222B",
  5904. there4: "\u2234",
  5905. sim: "\u223C",
  5906. cong: "\u2245",
  5907. asymp: "\u2248",
  5908. ne: "\u2260",
  5909. equiv: "\u2261",
  5910. le: "\u2264",
  5911. ge: "\u2265",
  5912. sub: "\u2282",
  5913. sup: "\u2283",
  5914. nsub: "\u2284",
  5915. sube: "\u2286",
  5916. supe: "\u2287",
  5917. oplus: "\u2295",
  5918. otimes: "\u2297",
  5919. perp: "\u22A5",
  5920. sdot: "\u22C5",
  5921. lceil: "\u2308",
  5922. rceil: "\u2309",
  5923. lfloor: "\u230A",
  5924. rfloor: "\u230B",
  5925. lang: "\u2329",
  5926. rang: "\u232A",
  5927. loz: "\u25CA",
  5928. spades: "\u2660",
  5929. clubs: "\u2663",
  5930. hearts: "\u2665",
  5931. diams: "\u2666"
  5932. };
  5933. const HEX_NUMBER = /^[\da-fA-F]+$/;
  5934. const DECIMAL_NUMBER = /^\d+$/;
  5935. const JsxErrors = makeErrorTemplates({
  5936. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  5937. MissingClosingTagElement: "Expected corresponding JSX closing tag for <%0>.",
  5938. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  5939. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  5940. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  5941. UnterminatedJsxContent: "Unterminated JSX contents.",
  5942. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  5943. }, ErrorCodes.SyntaxError, "jsx");
  5944. types.j_oTag = new TokContext("<tag");
  5945. types.j_cTag = new TokContext("</tag");
  5946. types.j_expr = new TokContext("<tag>...</tag>", true);
  5947. function isFragment(object) {
  5948. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  5949. }
  5950. function getQualifiedJSXName(object) {
  5951. if (object.type === "JSXIdentifier") {
  5952. return object.name;
  5953. }
  5954. if (object.type === "JSXNamespacedName") {
  5955. return object.namespace.name + ":" + object.name.name;
  5956. }
  5957. if (object.type === "JSXMemberExpression") {
  5958. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  5959. }
  5960. throw new Error("Node had unexpected type: " + object.type);
  5961. }
  5962. var jsx = (superClass => class extends superClass {
  5963. jsxReadToken() {
  5964. let out = "";
  5965. let chunkStart = this.state.pos;
  5966. for (;;) {
  5967. if (this.state.pos >= this.length) {
  5968. throw this.raise(this.state.start, JsxErrors.UnterminatedJsxContent);
  5969. }
  5970. const ch = this.input.charCodeAt(this.state.pos);
  5971. switch (ch) {
  5972. case 60:
  5973. case 123:
  5974. if (this.state.pos === this.state.start) {
  5975. if (ch === 60 && this.state.canStartJSXElement) {
  5976. ++this.state.pos;
  5977. return this.finishToken(132);
  5978. }
  5979. return super.getTokenFromCode(ch);
  5980. }
  5981. out += this.input.slice(chunkStart, this.state.pos);
  5982. return this.finishToken(131, out);
  5983. case 38:
  5984. out += this.input.slice(chunkStart, this.state.pos);
  5985. out += this.jsxReadEntity();
  5986. chunkStart = this.state.pos;
  5987. break;
  5988. case 62:
  5989. case 125:
  5990. default:
  5991. if (isNewLine(ch)) {
  5992. out += this.input.slice(chunkStart, this.state.pos);
  5993. out += this.jsxReadNewLine(true);
  5994. chunkStart = this.state.pos;
  5995. } else {
  5996. ++this.state.pos;
  5997. }
  5998. }
  5999. }
  6000. }
  6001. jsxReadNewLine(normalizeCRLF) {
  6002. const ch = this.input.charCodeAt(this.state.pos);
  6003. let out;
  6004. ++this.state.pos;
  6005. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6006. ++this.state.pos;
  6007. out = normalizeCRLF ? "\n" : "\r\n";
  6008. } else {
  6009. out = String.fromCharCode(ch);
  6010. }
  6011. ++this.state.curLine;
  6012. this.state.lineStart = this.state.pos;
  6013. return out;
  6014. }
  6015. jsxReadString(quote) {
  6016. let out = "";
  6017. let chunkStart = ++this.state.pos;
  6018. for (;;) {
  6019. if (this.state.pos >= this.length) {
  6020. throw this.raise(this.state.start, ErrorMessages.UnterminatedString);
  6021. }
  6022. const ch = this.input.charCodeAt(this.state.pos);
  6023. if (ch === quote) break;
  6024. if (ch === 38) {
  6025. out += this.input.slice(chunkStart, this.state.pos);
  6026. out += this.jsxReadEntity();
  6027. chunkStart = this.state.pos;
  6028. } else if (isNewLine(ch)) {
  6029. out += this.input.slice(chunkStart, this.state.pos);
  6030. out += this.jsxReadNewLine(false);
  6031. chunkStart = this.state.pos;
  6032. } else {
  6033. ++this.state.pos;
  6034. }
  6035. }
  6036. out += this.input.slice(chunkStart, this.state.pos++);
  6037. return this.finishToken(123, out);
  6038. }
  6039. jsxReadEntity() {
  6040. let str = "";
  6041. let count = 0;
  6042. let entity;
  6043. let ch = this.input[this.state.pos];
  6044. const startPos = ++this.state.pos;
  6045. while (this.state.pos < this.length && count++ < 10) {
  6046. ch = this.input[this.state.pos++];
  6047. if (ch === ";") {
  6048. if (str[0] === "#") {
  6049. if (str[1] === "x") {
  6050. str = str.substr(2);
  6051. if (HEX_NUMBER.test(str)) {
  6052. entity = String.fromCodePoint(parseInt(str, 16));
  6053. }
  6054. } else {
  6055. str = str.substr(1);
  6056. if (DECIMAL_NUMBER.test(str)) {
  6057. entity = String.fromCodePoint(parseInt(str, 10));
  6058. }
  6059. }
  6060. } else {
  6061. entity = entities[str];
  6062. }
  6063. break;
  6064. }
  6065. str += ch;
  6066. }
  6067. if (!entity) {
  6068. this.state.pos = startPos;
  6069. return "&";
  6070. }
  6071. return entity;
  6072. }
  6073. jsxReadWord() {
  6074. let ch;
  6075. const start = this.state.pos;
  6076. do {
  6077. ch = this.input.charCodeAt(++this.state.pos);
  6078. } while (isIdentifierChar(ch) || ch === 45);
  6079. return this.finishToken(130, this.input.slice(start, this.state.pos));
  6080. }
  6081. jsxParseIdentifier() {
  6082. const node = this.startNode();
  6083. if (this.match(130)) {
  6084. node.name = this.state.value;
  6085. } else if (tokenIsKeyword(this.state.type)) {
  6086. node.name = tokenLabelName(this.state.type);
  6087. } else {
  6088. this.unexpected();
  6089. }
  6090. this.next();
  6091. return this.finishNode(node, "JSXIdentifier");
  6092. }
  6093. jsxParseNamespacedName() {
  6094. const startPos = this.state.start;
  6095. const startLoc = this.state.startLoc;
  6096. const name = this.jsxParseIdentifier();
  6097. if (!this.eat(14)) return name;
  6098. const node = this.startNodeAt(startPos, startLoc);
  6099. node.namespace = name;
  6100. node.name = this.jsxParseIdentifier();
  6101. return this.finishNode(node, "JSXNamespacedName");
  6102. }
  6103. jsxParseElementName() {
  6104. const startPos = this.state.start;
  6105. const startLoc = this.state.startLoc;
  6106. let node = this.jsxParseNamespacedName();
  6107. if (node.type === "JSXNamespacedName") {
  6108. return node;
  6109. }
  6110. while (this.eat(16)) {
  6111. const newNode = this.startNodeAt(startPos, startLoc);
  6112. newNode.object = node;
  6113. newNode.property = this.jsxParseIdentifier();
  6114. node = this.finishNode(newNode, "JSXMemberExpression");
  6115. }
  6116. return node;
  6117. }
  6118. jsxParseAttributeValue() {
  6119. let node;
  6120. switch (this.state.type) {
  6121. case 5:
  6122. node = this.startNode();
  6123. this.next();
  6124. node = this.jsxParseExpressionContainer(node);
  6125. if (node.expression.type === "JSXEmptyExpression") {
  6126. this.raise(node.start, JsxErrors.AttributeIsEmpty);
  6127. }
  6128. return node;
  6129. case 132:
  6130. case 123:
  6131. return this.parseExprAtom();
  6132. default:
  6133. throw this.raise(this.state.start, JsxErrors.UnsupportedJsxValue);
  6134. }
  6135. }
  6136. jsxParseEmptyExpression() {
  6137. const node = this.startNodeAt(this.state.lastTokEnd, this.state.lastTokEndLoc);
  6138. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.start, this.state.startLoc);
  6139. }
  6140. jsxParseSpreadChild(node) {
  6141. this.next();
  6142. node.expression = this.parseExpression();
  6143. this.expect(8);
  6144. return this.finishNode(node, "JSXSpreadChild");
  6145. }
  6146. jsxParseExpressionContainer(node) {
  6147. if (this.match(8)) {
  6148. node.expression = this.jsxParseEmptyExpression();
  6149. } else {
  6150. const expression = this.parseExpression();
  6151. node.expression = expression;
  6152. }
  6153. this.expect(8);
  6154. return this.finishNode(node, "JSXExpressionContainer");
  6155. }
  6156. jsxParseAttribute() {
  6157. const node = this.startNode();
  6158. if (this.eat(5)) {
  6159. this.expect(21);
  6160. node.argument = this.parseMaybeAssignAllowIn();
  6161. this.expect(8);
  6162. return this.finishNode(node, "JSXSpreadAttribute");
  6163. }
  6164. node.name = this.jsxParseNamespacedName();
  6165. node.value = this.eat(27) ? this.jsxParseAttributeValue() : null;
  6166. return this.finishNode(node, "JSXAttribute");
  6167. }
  6168. jsxParseOpeningElementAt(startPos, startLoc) {
  6169. const node = this.startNodeAt(startPos, startLoc);
  6170. if (this.match(133)) {
  6171. this.expect(133);
  6172. return this.finishNode(node, "JSXOpeningFragment");
  6173. }
  6174. node.name = this.jsxParseElementName();
  6175. return this.jsxParseOpeningElementAfterName(node);
  6176. }
  6177. jsxParseOpeningElementAfterName(node) {
  6178. const attributes = [];
  6179. while (!this.match(50) && !this.match(133)) {
  6180. attributes.push(this.jsxParseAttribute());
  6181. }
  6182. node.attributes = attributes;
  6183. node.selfClosing = this.eat(50);
  6184. this.expect(133);
  6185. return this.finishNode(node, "JSXOpeningElement");
  6186. }
  6187. jsxParseClosingElementAt(startPos, startLoc) {
  6188. const node = this.startNodeAt(startPos, startLoc);
  6189. if (this.match(133)) {
  6190. this.expect(133);
  6191. return this.finishNode(node, "JSXClosingFragment");
  6192. }
  6193. node.name = this.jsxParseElementName();
  6194. this.expect(133);
  6195. return this.finishNode(node, "JSXClosingElement");
  6196. }
  6197. jsxParseElementAt(startPos, startLoc) {
  6198. const node = this.startNodeAt(startPos, startLoc);
  6199. const children = [];
  6200. const openingElement = this.jsxParseOpeningElementAt(startPos, startLoc);
  6201. let closingElement = null;
  6202. if (!openingElement.selfClosing) {
  6203. contents: for (;;) {
  6204. switch (this.state.type) {
  6205. case 132:
  6206. startPos = this.state.start;
  6207. startLoc = this.state.startLoc;
  6208. this.next();
  6209. if (this.eat(50)) {
  6210. closingElement = this.jsxParseClosingElementAt(startPos, startLoc);
  6211. break contents;
  6212. }
  6213. children.push(this.jsxParseElementAt(startPos, startLoc));
  6214. break;
  6215. case 131:
  6216. children.push(this.parseExprAtom());
  6217. break;
  6218. case 5:
  6219. {
  6220. const node = this.startNode();
  6221. this.next();
  6222. if (this.match(21)) {
  6223. children.push(this.jsxParseSpreadChild(node));
  6224. } else {
  6225. children.push(this.jsxParseExpressionContainer(node));
  6226. }
  6227. break;
  6228. }
  6229. default:
  6230. throw this.unexpected();
  6231. }
  6232. }
  6233. if (isFragment(openingElement) && !isFragment(closingElement)) {
  6234. this.raise(closingElement.start, JsxErrors.MissingClosingTagFragment);
  6235. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6236. this.raise(closingElement.start, JsxErrors.MissingClosingTagElement, getQualifiedJSXName(openingElement.name));
  6237. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6238. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6239. this.raise(closingElement.start, JsxErrors.MissingClosingTagElement, getQualifiedJSXName(openingElement.name));
  6240. }
  6241. }
  6242. }
  6243. if (isFragment(openingElement)) {
  6244. node.openingFragment = openingElement;
  6245. node.closingFragment = closingElement;
  6246. } else {
  6247. node.openingElement = openingElement;
  6248. node.closingElement = closingElement;
  6249. }
  6250. node.children = children;
  6251. if (this.match(43)) {
  6252. throw this.raise(this.state.start, JsxErrors.UnwrappedAdjacentJSXElements);
  6253. }
  6254. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6255. }
  6256. jsxParseElement() {
  6257. const startPos = this.state.start;
  6258. const startLoc = this.state.startLoc;
  6259. this.next();
  6260. return this.jsxParseElementAt(startPos, startLoc);
  6261. }
  6262. parseExprAtom(refExpressionErrors) {
  6263. if (this.match(131)) {
  6264. return this.parseLiteral(this.state.value, "JSXText");
  6265. } else if (this.match(132)) {
  6266. return this.jsxParseElement();
  6267. } else if (this.match(43) && this.input.charCodeAt(this.state.pos) !== 33) {
  6268. this.replaceToken(132);
  6269. return this.jsxParseElement();
  6270. } else {
  6271. return super.parseExprAtom(refExpressionErrors);
  6272. }
  6273. }
  6274. getTokenFromCode(code) {
  6275. const context = this.curContext();
  6276. if (context === types.j_expr) {
  6277. return this.jsxReadToken();
  6278. }
  6279. if (context === types.j_oTag || context === types.j_cTag) {
  6280. if (isIdentifierStart(code)) {
  6281. return this.jsxReadWord();
  6282. }
  6283. if (code === 62) {
  6284. ++this.state.pos;
  6285. return this.finishToken(133);
  6286. }
  6287. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6288. return this.jsxReadString(code);
  6289. }
  6290. }
  6291. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  6292. ++this.state.pos;
  6293. return this.finishToken(132);
  6294. }
  6295. return super.getTokenFromCode(code);
  6296. }
  6297. updateContext(prevType) {
  6298. super.updateContext(prevType);
  6299. const {
  6300. context,
  6301. type
  6302. } = this.state;
  6303. if (type === 50 && prevType === 132) {
  6304. context.splice(-2, 2, types.j_cTag);
  6305. this.state.canStartJSXElement = false;
  6306. } else if (type === 132) {
  6307. context.push(types.j_expr, types.j_oTag);
  6308. } else if (type === 133) {
  6309. const out = context.pop();
  6310. if (out === types.j_oTag && prevType === 50 || out === types.j_cTag) {
  6311. context.pop();
  6312. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  6313. } else {
  6314. this.state.canStartJSXElement = true;
  6315. }
  6316. } else {
  6317. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  6318. }
  6319. }
  6320. });
  6321. class TypeScriptScope extends Scope {
  6322. constructor(...args) {
  6323. super(...args);
  6324. this.types = new Set();
  6325. this.enums = new Set();
  6326. this.constEnums = new Set();
  6327. this.classes = new Set();
  6328. this.exportOnlyBindings = new Set();
  6329. }
  6330. }
  6331. class TypeScriptScopeHandler extends ScopeHandler {
  6332. createScope(flags) {
  6333. return new TypeScriptScope(flags);
  6334. }
  6335. declareName(name, bindingType, pos) {
  6336. const scope = this.currentScope();
  6337. if (bindingType & BIND_FLAGS_TS_EXPORT_ONLY) {
  6338. this.maybeExportDefined(scope, name);
  6339. scope.exportOnlyBindings.add(name);
  6340. return;
  6341. }
  6342. super.declareName(...arguments);
  6343. if (bindingType & BIND_KIND_TYPE) {
  6344. if (!(bindingType & BIND_KIND_VALUE)) {
  6345. this.checkRedeclarationInScope(scope, name, bindingType, pos);
  6346. this.maybeExportDefined(scope, name);
  6347. }
  6348. scope.types.add(name);
  6349. }
  6350. if (bindingType & BIND_FLAGS_TS_ENUM) scope.enums.add(name);
  6351. if (bindingType & BIND_FLAGS_TS_CONST_ENUM) scope.constEnums.add(name);
  6352. if (bindingType & BIND_FLAGS_CLASS) scope.classes.add(name);
  6353. }
  6354. isRedeclaredInScope(scope, name, bindingType) {
  6355. if (scope.enums.has(name)) {
  6356. if (bindingType & BIND_FLAGS_TS_ENUM) {
  6357. const isConst = !!(bindingType & BIND_FLAGS_TS_CONST_ENUM);
  6358. const wasConst = scope.constEnums.has(name);
  6359. return isConst !== wasConst;
  6360. }
  6361. return true;
  6362. }
  6363. if (bindingType & BIND_FLAGS_CLASS && scope.classes.has(name)) {
  6364. if (scope.lexical.has(name)) {
  6365. return !!(bindingType & BIND_KIND_VALUE);
  6366. } else {
  6367. return false;
  6368. }
  6369. }
  6370. if (bindingType & BIND_KIND_TYPE && scope.types.has(name)) {
  6371. return true;
  6372. }
  6373. return super.isRedeclaredInScope(...arguments);
  6374. }
  6375. checkLocalExport(id) {
  6376. const topLevelScope = this.scopeStack[0];
  6377. const {
  6378. name
  6379. } = id;
  6380. if (!topLevelScope.types.has(name) && !topLevelScope.exportOnlyBindings.has(name)) {
  6381. super.checkLocalExport(id);
  6382. }
  6383. }
  6384. }
  6385. function nonNull(x) {
  6386. if (x == null) {
  6387. throw new Error(`Unexpected ${x} value.`);
  6388. }
  6389. return x;
  6390. }
  6391. function assert(x) {
  6392. if (!x) {
  6393. throw new Error("Assert fail");
  6394. }
  6395. }
  6396. const TSErrors = makeErrorTemplates({
  6397. AbstractMethodHasImplementation: "Method '%0' cannot have an implementation because it is marked abstract.",
  6398. AbstractPropertyHasInitializer: "Property '%0' cannot have an initializer because it is marked abstract.",
  6399. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  6400. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  6401. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  6402. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  6403. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  6404. DeclareAccessor: "'declare' is not allowed in %0ters.",
  6405. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  6406. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  6407. DuplicateAccessibilityModifier: "Accessibility modifier already seen.",
  6408. DuplicateModifier: "Duplicate modifier: '%0'.",
  6409. EmptyHeritageClauseType: "'%0' list cannot be empty.",
  6410. EmptyTypeArguments: "Type argument list cannot be empty.",
  6411. EmptyTypeParameters: "Type parameter list cannot be empty.",
  6412. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  6413. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  6414. IncompatibleModifiers: "'%0' modifier cannot be used with '%1' modifier.",
  6415. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  6416. IndexSignatureHasAccessibility: "Index signatures cannot have an accessibility modifier ('%0').",
  6417. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  6418. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  6419. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  6420. InvalidModifierOnTypeMember: "'%0' modifier cannot appear on a type member.",
  6421. InvalidModifiersOrder: "'%0' modifier must precede '%1' modifier.",
  6422. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  6423. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  6424. MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
  6425. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  6426. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  6427. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  6428. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  6429. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  6430. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  6431. PrivateElementHasAccessibility: "Private elements cannot have an accessibility modifier ('%0').",
  6432. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  6433. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  6434. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  6435. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  6436. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  6437. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  6438. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  6439. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  6440. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  6441. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  6442. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  6443. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  6444. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  6445. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  6446. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  6447. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  6448. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  6449. UnsupportedSignatureParameterKind: "Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got %0."
  6450. }, ErrorCodes.SyntaxError, "typescript");
  6451. function keywordTypeFromName(value) {
  6452. switch (value) {
  6453. case "any":
  6454. return "TSAnyKeyword";
  6455. case "boolean":
  6456. return "TSBooleanKeyword";
  6457. case "bigint":
  6458. return "TSBigIntKeyword";
  6459. case "never":
  6460. return "TSNeverKeyword";
  6461. case "number":
  6462. return "TSNumberKeyword";
  6463. case "object":
  6464. return "TSObjectKeyword";
  6465. case "string":
  6466. return "TSStringKeyword";
  6467. case "symbol":
  6468. return "TSSymbolKeyword";
  6469. case "undefined":
  6470. return "TSUndefinedKeyword";
  6471. case "unknown":
  6472. return "TSUnknownKeyword";
  6473. default:
  6474. return undefined;
  6475. }
  6476. }
  6477. function tsIsAccessModifier(modifier) {
  6478. return modifier === "private" || modifier === "public" || modifier === "protected";
  6479. }
  6480. var typescript = (superClass => class extends superClass {
  6481. getScopeHandler() {
  6482. return TypeScriptScopeHandler;
  6483. }
  6484. tsIsIdentifier() {
  6485. return tokenIsIdentifier(this.state.type);
  6486. }
  6487. tsTokenCanFollowModifier() {
  6488. return (this.match(0) || this.match(5) || this.match(49) || this.match(21) || this.match(128) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  6489. }
  6490. tsNextTokenCanFollowModifier() {
  6491. this.next();
  6492. return this.tsTokenCanFollowModifier();
  6493. }
  6494. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  6495. if (!tokenIsIdentifier(this.state.type)) {
  6496. return undefined;
  6497. }
  6498. const modifier = this.state.value;
  6499. if (allowedModifiers.indexOf(modifier) !== -1) {
  6500. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  6501. return undefined;
  6502. }
  6503. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  6504. return modifier;
  6505. }
  6506. }
  6507. return undefined;
  6508. }
  6509. tsParseModifiers(modified, allowedModifiers, disallowedModifiers, errorTemplate, stopOnStartOfClassStaticBlock) {
  6510. const enforceOrder = (pos, modifier, before, after) => {
  6511. if (modifier === before && modified[after]) {
  6512. this.raise(pos, TSErrors.InvalidModifiersOrder, before, after);
  6513. }
  6514. };
  6515. const incompatible = (pos, modifier, mod1, mod2) => {
  6516. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  6517. this.raise(pos, TSErrors.IncompatibleModifiers, mod1, mod2);
  6518. }
  6519. };
  6520. for (;;) {
  6521. const startPos = this.state.start;
  6522. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  6523. if (!modifier) break;
  6524. if (tsIsAccessModifier(modifier)) {
  6525. if (modified.accessibility) {
  6526. this.raise(startPos, TSErrors.DuplicateAccessibilityModifier);
  6527. } else {
  6528. enforceOrder(startPos, modifier, modifier, "override");
  6529. enforceOrder(startPos, modifier, modifier, "static");
  6530. enforceOrder(startPos, modifier, modifier, "readonly");
  6531. modified.accessibility = modifier;
  6532. }
  6533. } else {
  6534. if (Object.hasOwnProperty.call(modified, modifier)) {
  6535. this.raise(startPos, TSErrors.DuplicateModifier, modifier);
  6536. } else {
  6537. enforceOrder(startPos, modifier, "static", "readonly");
  6538. enforceOrder(startPos, modifier, "static", "override");
  6539. enforceOrder(startPos, modifier, "override", "readonly");
  6540. enforceOrder(startPos, modifier, "abstract", "override");
  6541. incompatible(startPos, modifier, "declare", "override");
  6542. incompatible(startPos, modifier, "static", "abstract");
  6543. }
  6544. modified[modifier] = true;
  6545. }
  6546. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  6547. this.raise(startPos, errorTemplate, modifier);
  6548. }
  6549. }
  6550. }
  6551. tsIsListTerminator(kind) {
  6552. switch (kind) {
  6553. case "EnumMembers":
  6554. case "TypeMembers":
  6555. return this.match(8);
  6556. case "HeritageClauseElement":
  6557. return this.match(5);
  6558. case "TupleElementTypes":
  6559. return this.match(3);
  6560. case "TypeParametersOrArguments":
  6561. return this.match(44);
  6562. }
  6563. throw new Error("Unreachable");
  6564. }
  6565. tsParseList(kind, parseElement) {
  6566. const result = [];
  6567. while (!this.tsIsListTerminator(kind)) {
  6568. result.push(parseElement());
  6569. }
  6570. return result;
  6571. }
  6572. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  6573. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  6574. }
  6575. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  6576. const result = [];
  6577. let trailingCommaPos = -1;
  6578. for (;;) {
  6579. if (this.tsIsListTerminator(kind)) {
  6580. break;
  6581. }
  6582. trailingCommaPos = -1;
  6583. const element = parseElement();
  6584. if (element == null) {
  6585. return undefined;
  6586. }
  6587. result.push(element);
  6588. if (this.eat(12)) {
  6589. trailingCommaPos = this.state.lastTokStart;
  6590. continue;
  6591. }
  6592. if (this.tsIsListTerminator(kind)) {
  6593. break;
  6594. }
  6595. if (expectSuccess) {
  6596. this.expect(12);
  6597. }
  6598. return undefined;
  6599. }
  6600. if (refTrailingCommaPos) {
  6601. refTrailingCommaPos.value = trailingCommaPos;
  6602. }
  6603. return result;
  6604. }
  6605. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  6606. if (!skipFirstToken) {
  6607. if (bracket) {
  6608. this.expect(0);
  6609. } else {
  6610. this.expect(43);
  6611. }
  6612. }
  6613. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  6614. if (bracket) {
  6615. this.expect(3);
  6616. } else {
  6617. this.expect(44);
  6618. }
  6619. return result;
  6620. }
  6621. tsParseImportType() {
  6622. const node = this.startNode();
  6623. this.expect(77);
  6624. this.expect(10);
  6625. if (!this.match(123)) {
  6626. this.raise(this.state.start, TSErrors.UnsupportedImportTypeArgument);
  6627. }
  6628. node.argument = this.parseExprAtom();
  6629. this.expect(11);
  6630. if (this.eat(16)) {
  6631. node.qualifier = this.tsParseEntityName(true);
  6632. }
  6633. if (this.match(43)) {
  6634. node.typeParameters = this.tsParseTypeArguments();
  6635. }
  6636. return this.finishNode(node, "TSImportType");
  6637. }
  6638. tsParseEntityName(allowReservedWords) {
  6639. let entity = this.parseIdentifier();
  6640. while (this.eat(16)) {
  6641. const node = this.startNodeAtNode(entity);
  6642. node.left = entity;
  6643. node.right = this.parseIdentifier(allowReservedWords);
  6644. entity = this.finishNode(node, "TSQualifiedName");
  6645. }
  6646. return entity;
  6647. }
  6648. tsParseTypeReference() {
  6649. const node = this.startNode();
  6650. node.typeName = this.tsParseEntityName(false);
  6651. if (!this.hasPrecedingLineBreak() && this.match(43)) {
  6652. node.typeParameters = this.tsParseTypeArguments();
  6653. }
  6654. return this.finishNode(node, "TSTypeReference");
  6655. }
  6656. tsParseThisTypePredicate(lhs) {
  6657. this.next();
  6658. const node = this.startNodeAtNode(lhs);
  6659. node.parameterName = lhs;
  6660. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  6661. node.asserts = false;
  6662. return this.finishNode(node, "TSTypePredicate");
  6663. }
  6664. tsParseThisTypeNode() {
  6665. const node = this.startNode();
  6666. this.next();
  6667. return this.finishNode(node, "TSThisType");
  6668. }
  6669. tsParseTypeQuery() {
  6670. const node = this.startNode();
  6671. this.expect(81);
  6672. if (this.match(77)) {
  6673. node.exprName = this.tsParseImportType();
  6674. } else {
  6675. node.exprName = this.tsParseEntityName(true);
  6676. }
  6677. return this.finishNode(node, "TSTypeQuery");
  6678. }
  6679. tsParseTypeParameter() {
  6680. const node = this.startNode();
  6681. node.name = this.tsParseTypeParameterName();
  6682. node.constraint = this.tsEatThenParseType(75);
  6683. node.default = this.tsEatThenParseType(27);
  6684. return this.finishNode(node, "TSTypeParameter");
  6685. }
  6686. tsTryParseTypeParameters() {
  6687. if (this.match(43)) {
  6688. return this.tsParseTypeParameters();
  6689. }
  6690. }
  6691. tsParseTypeParameters() {
  6692. const node = this.startNode();
  6693. if (this.match(43) || this.match(132)) {
  6694. this.next();
  6695. } else {
  6696. this.unexpected();
  6697. }
  6698. const refTrailingCommaPos = {
  6699. value: -1
  6700. };
  6701. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this), false, true, refTrailingCommaPos);
  6702. if (node.params.length === 0) {
  6703. this.raise(node.start, TSErrors.EmptyTypeParameters);
  6704. }
  6705. if (refTrailingCommaPos.value !== -1) {
  6706. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  6707. }
  6708. return this.finishNode(node, "TSTypeParameterDeclaration");
  6709. }
  6710. tsTryNextParseConstantContext() {
  6711. if (this.lookahead().type === 69) {
  6712. this.next();
  6713. return this.tsParseTypeReference();
  6714. }
  6715. return null;
  6716. }
  6717. tsFillSignature(returnToken, signature) {
  6718. const returnTokenRequired = returnToken === 19;
  6719. signature.typeParameters = this.tsTryParseTypeParameters();
  6720. this.expect(10);
  6721. signature.parameters = this.tsParseBindingListForSignature();
  6722. if (returnTokenRequired) {
  6723. signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  6724. } else if (this.match(returnToken)) {
  6725. signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  6726. }
  6727. }
  6728. tsParseBindingListForSignature() {
  6729. return this.parseBindingList(11, 41).map(pattern => {
  6730. if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") {
  6731. this.raise(pattern.start, TSErrors.UnsupportedSignatureParameterKind, pattern.type);
  6732. }
  6733. return pattern;
  6734. });
  6735. }
  6736. tsParseTypeMemberSemicolon() {
  6737. if (!this.eat(12) && !this.isLineTerminator()) {
  6738. this.expect(13);
  6739. }
  6740. }
  6741. tsParseSignatureMember(kind, node) {
  6742. this.tsFillSignature(14, node);
  6743. this.tsParseTypeMemberSemicolon();
  6744. return this.finishNode(node, kind);
  6745. }
  6746. tsIsUnambiguouslyIndexSignature() {
  6747. this.next();
  6748. if (tokenIsIdentifier(this.state.type)) {
  6749. this.next();
  6750. return this.match(14);
  6751. }
  6752. return false;
  6753. }
  6754. tsTryParseIndexSignature(node) {
  6755. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  6756. return undefined;
  6757. }
  6758. this.expect(0);
  6759. const id = this.parseIdentifier();
  6760. id.typeAnnotation = this.tsParseTypeAnnotation();
  6761. this.resetEndLocation(id);
  6762. this.expect(3);
  6763. node.parameters = [id];
  6764. const type = this.tsTryParseTypeAnnotation();
  6765. if (type) node.typeAnnotation = type;
  6766. this.tsParseTypeMemberSemicolon();
  6767. return this.finishNode(node, "TSIndexSignature");
  6768. }
  6769. tsParsePropertyOrMethodSignature(node, readonly) {
  6770. if (this.eat(17)) node.optional = true;
  6771. const nodeAny = node;
  6772. if (this.match(10) || this.match(43)) {
  6773. if (readonly) {
  6774. this.raise(node.start, TSErrors.ReadonlyForMethodSignature);
  6775. }
  6776. const method = nodeAny;
  6777. if (method.kind && this.match(43)) {
  6778. this.raise(this.state.pos, TSErrors.AccesorCannotHaveTypeParameters);
  6779. }
  6780. this.tsFillSignature(14, method);
  6781. this.tsParseTypeMemberSemicolon();
  6782. if (method.kind === "get") {
  6783. if (method.parameters.length > 0) {
  6784. this.raise(this.state.pos, ErrorMessages.BadGetterArity);
  6785. if (this.isThisParam(method.parameters[0])) {
  6786. this.raise(this.state.pos, TSErrors.AccesorCannotDeclareThisParameter);
  6787. }
  6788. }
  6789. } else if (method.kind === "set") {
  6790. if (method.parameters.length !== 1) {
  6791. this.raise(this.state.pos, ErrorMessages.BadSetterArity);
  6792. } else {
  6793. const firstParameter = method.parameters[0];
  6794. if (this.isThisParam(firstParameter)) {
  6795. this.raise(this.state.pos, TSErrors.AccesorCannotDeclareThisParameter);
  6796. }
  6797. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  6798. this.raise(this.state.pos, TSErrors.SetAccesorCannotHaveOptionalParameter);
  6799. }
  6800. if (firstParameter.type === "RestElement") {
  6801. this.raise(this.state.pos, TSErrors.SetAccesorCannotHaveRestParameter);
  6802. }
  6803. }
  6804. if (method.typeAnnotation) {
  6805. this.raise(method.typeAnnotation.start, TSErrors.SetAccesorCannotHaveReturnType);
  6806. }
  6807. } else {
  6808. method.kind = "method";
  6809. }
  6810. return this.finishNode(method, "TSMethodSignature");
  6811. } else {
  6812. const property = nodeAny;
  6813. if (readonly) property.readonly = true;
  6814. const type = this.tsTryParseTypeAnnotation();
  6815. if (type) property.typeAnnotation = type;
  6816. this.tsParseTypeMemberSemicolon();
  6817. return this.finishNode(property, "TSPropertySignature");
  6818. }
  6819. }
  6820. tsParseTypeMember() {
  6821. const node = this.startNode();
  6822. if (this.match(10) || this.match(43)) {
  6823. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  6824. }
  6825. if (this.match(71)) {
  6826. const id = this.startNode();
  6827. this.next();
  6828. if (this.match(10) || this.match(43)) {
  6829. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  6830. } else {
  6831. node.key = this.createIdentifier(id, "new");
  6832. return this.tsParsePropertyOrMethodSignature(node, false);
  6833. }
  6834. }
  6835. this.tsParseModifiers(node, ["readonly"], ["declare", "abstract", "private", "protected", "public", "static", "override"], TSErrors.InvalidModifierOnTypeMember);
  6836. const idx = this.tsTryParseIndexSignature(node);
  6837. if (idx) {
  6838. return idx;
  6839. }
  6840. this.parsePropertyName(node);
  6841. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  6842. node.kind = node.key.name;
  6843. this.parsePropertyName(node);
  6844. }
  6845. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  6846. }
  6847. tsParseTypeLiteral() {
  6848. const node = this.startNode();
  6849. node.members = this.tsParseObjectTypeMembers();
  6850. return this.finishNode(node, "TSTypeLiteral");
  6851. }
  6852. tsParseObjectTypeMembers() {
  6853. this.expect(5);
  6854. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  6855. this.expect(8);
  6856. return members;
  6857. }
  6858. tsIsStartOfMappedType() {
  6859. this.next();
  6860. if (this.eat(47)) {
  6861. return this.isContextual(112);
  6862. }
  6863. if (this.isContextual(112)) {
  6864. this.next();
  6865. }
  6866. if (!this.match(0)) {
  6867. return false;
  6868. }
  6869. this.next();
  6870. if (!this.tsIsIdentifier()) {
  6871. return false;
  6872. }
  6873. this.next();
  6874. return this.match(52);
  6875. }
  6876. tsParseMappedTypeParameter() {
  6877. const node = this.startNode();
  6878. node.name = this.tsParseTypeParameterName();
  6879. node.constraint = this.tsExpectThenParseType(52);
  6880. return this.finishNode(node, "TSTypeParameter");
  6881. }
  6882. tsParseMappedType() {
  6883. const node = this.startNode();
  6884. this.expect(5);
  6885. if (this.match(47)) {
  6886. node.readonly = this.state.value;
  6887. this.next();
  6888. this.expectContextual(112);
  6889. } else if (this.eatContextual(112)) {
  6890. node.readonly = true;
  6891. }
  6892. this.expect(0);
  6893. node.typeParameter = this.tsParseMappedTypeParameter();
  6894. node.nameType = this.eatContextual(87) ? this.tsParseType() : null;
  6895. this.expect(3);
  6896. if (this.match(47)) {
  6897. node.optional = this.state.value;
  6898. this.next();
  6899. this.expect(17);
  6900. } else if (this.eat(17)) {
  6901. node.optional = true;
  6902. }
  6903. node.typeAnnotation = this.tsTryParseType();
  6904. this.semicolon();
  6905. this.expect(8);
  6906. return this.finishNode(node, "TSMappedType");
  6907. }
  6908. tsParseTupleType() {
  6909. const node = this.startNode();
  6910. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  6911. let seenOptionalElement = false;
  6912. let labeledElements = null;
  6913. node.elementTypes.forEach(elementNode => {
  6914. var _labeledElements;
  6915. let {
  6916. type
  6917. } = elementNode;
  6918. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  6919. this.raise(elementNode.start, TSErrors.OptionalTypeBeforeRequired);
  6920. }
  6921. seenOptionalElement = seenOptionalElement || type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType";
  6922. if (type === "TSRestType") {
  6923. elementNode = elementNode.typeAnnotation;
  6924. type = elementNode.type;
  6925. }
  6926. const isLabeled = type === "TSNamedTupleMember";
  6927. labeledElements = (_labeledElements = labeledElements) != null ? _labeledElements : isLabeled;
  6928. if (labeledElements !== isLabeled) {
  6929. this.raise(elementNode.start, TSErrors.MixedLabeledAndUnlabeledElements);
  6930. }
  6931. });
  6932. return this.finishNode(node, "TSTupleType");
  6933. }
  6934. tsParseTupleElementType() {
  6935. const {
  6936. start: startPos,
  6937. startLoc
  6938. } = this.state;
  6939. const rest = this.eat(21);
  6940. let type = this.tsParseType();
  6941. const optional = this.eat(17);
  6942. const labeled = this.eat(14);
  6943. if (labeled) {
  6944. const labeledNode = this.startNodeAtNode(type);
  6945. labeledNode.optional = optional;
  6946. if (type.type === "TSTypeReference" && !type.typeParameters && type.typeName.type === "Identifier") {
  6947. labeledNode.label = type.typeName;
  6948. } else {
  6949. this.raise(type.start, TSErrors.InvalidTupleMemberLabel);
  6950. labeledNode.label = type;
  6951. }
  6952. labeledNode.elementType = this.tsParseType();
  6953. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  6954. } else if (optional) {
  6955. const optionalTypeNode = this.startNodeAtNode(type);
  6956. optionalTypeNode.typeAnnotation = type;
  6957. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  6958. }
  6959. if (rest) {
  6960. const restNode = this.startNodeAt(startPos, startLoc);
  6961. restNode.typeAnnotation = type;
  6962. type = this.finishNode(restNode, "TSRestType");
  6963. }
  6964. return type;
  6965. }
  6966. tsParseParenthesizedType() {
  6967. const node = this.startNode();
  6968. this.expect(10);
  6969. node.typeAnnotation = this.tsParseType();
  6970. this.expect(11);
  6971. return this.finishNode(node, "TSParenthesizedType");
  6972. }
  6973. tsParseFunctionOrConstructorType(type, abstract) {
  6974. const node = this.startNode();
  6975. if (type === "TSConstructorType") {
  6976. node.abstract = !!abstract;
  6977. if (abstract) this.next();
  6978. this.next();
  6979. }
  6980. this.tsFillSignature(19, node);
  6981. return this.finishNode(node, type);
  6982. }
  6983. tsParseLiteralTypeNode() {
  6984. const node = this.startNode();
  6985. node.literal = (() => {
  6986. switch (this.state.type) {
  6987. case 124:
  6988. case 125:
  6989. case 123:
  6990. case 79:
  6991. case 80:
  6992. return this.parseExprAtom();
  6993. default:
  6994. throw this.unexpected();
  6995. }
  6996. })();
  6997. return this.finishNode(node, "TSLiteralType");
  6998. }
  6999. tsParseTemplateLiteralType() {
  7000. const node = this.startNode();
  7001. node.literal = this.parseTemplate(false);
  7002. return this.finishNode(node, "TSLiteralType");
  7003. }
  7004. parseTemplateSubstitution() {
  7005. if (this.state.inType) return this.tsParseType();
  7006. return super.parseTemplateSubstitution();
  7007. }
  7008. tsParseThisTypeOrThisTypePredicate() {
  7009. const thisKeyword = this.tsParseThisTypeNode();
  7010. if (this.isContextual(107) && !this.hasPrecedingLineBreak()) {
  7011. return this.tsParseThisTypePredicate(thisKeyword);
  7012. } else {
  7013. return thisKeyword;
  7014. }
  7015. }
  7016. tsParseNonArrayType() {
  7017. switch (this.state.type) {
  7018. case 123:
  7019. case 124:
  7020. case 125:
  7021. case 79:
  7022. case 80:
  7023. return this.tsParseLiteralTypeNode();
  7024. case 47:
  7025. if (this.state.value === "-") {
  7026. const node = this.startNode();
  7027. const nextToken = this.lookahead();
  7028. if (nextToken.type !== 124 && nextToken.type !== 125) {
  7029. throw this.unexpected();
  7030. }
  7031. node.literal = this.parseMaybeUnary();
  7032. return this.finishNode(node, "TSLiteralType");
  7033. }
  7034. break;
  7035. case 72:
  7036. return this.tsParseThisTypeOrThisTypePredicate();
  7037. case 81:
  7038. return this.tsParseTypeQuery();
  7039. case 77:
  7040. return this.tsParseImportType();
  7041. case 5:
  7042. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  7043. case 0:
  7044. return this.tsParseTupleType();
  7045. case 10:
  7046. return this.tsParseParenthesizedType();
  7047. case 22:
  7048. return this.tsParseTemplateLiteralType();
  7049. default:
  7050. {
  7051. const {
  7052. type
  7053. } = this.state;
  7054. if (tokenIsIdentifier(type) || type === 82 || type === 78) {
  7055. const nodeType = type === 82 ? "TSVoidKeyword" : type === 78 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  7056. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  7057. const node = this.startNode();
  7058. this.next();
  7059. return this.finishNode(node, nodeType);
  7060. }
  7061. return this.tsParseTypeReference();
  7062. }
  7063. }
  7064. }
  7065. throw this.unexpected();
  7066. }
  7067. tsParseArrayTypeOrHigher() {
  7068. let type = this.tsParseNonArrayType();
  7069. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  7070. if (this.match(3)) {
  7071. const node = this.startNodeAtNode(type);
  7072. node.elementType = type;
  7073. this.expect(3);
  7074. type = this.finishNode(node, "TSArrayType");
  7075. } else {
  7076. const node = this.startNodeAtNode(type);
  7077. node.objectType = type;
  7078. node.indexType = this.tsParseType();
  7079. this.expect(3);
  7080. type = this.finishNode(node, "TSIndexedAccessType");
  7081. }
  7082. }
  7083. return type;
  7084. }
  7085. tsParseTypeOperator() {
  7086. const node = this.startNode();
  7087. const operator = this.state.value;
  7088. this.next();
  7089. node.operator = operator;
  7090. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  7091. if (operator === "readonly") {
  7092. this.tsCheckTypeAnnotationForReadOnly(node);
  7093. }
  7094. return this.finishNode(node, "TSTypeOperator");
  7095. }
  7096. tsCheckTypeAnnotationForReadOnly(node) {
  7097. switch (node.typeAnnotation.type) {
  7098. case "TSTupleType":
  7099. case "TSArrayType":
  7100. return;
  7101. default:
  7102. this.raise(node.start, TSErrors.UnexpectedReadonly);
  7103. }
  7104. }
  7105. tsParseInferType() {
  7106. const node = this.startNode();
  7107. this.expectContextual(106);
  7108. const typeParameter = this.startNode();
  7109. typeParameter.name = this.tsParseTypeParameterName();
  7110. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  7111. return this.finishNode(node, "TSInferType");
  7112. }
  7113. tsParseTypeOperatorOrHigher() {
  7114. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  7115. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(106) ? this.tsParseInferType() : this.tsParseArrayTypeOrHigher();
  7116. }
  7117. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  7118. const node = this.startNode();
  7119. const hasLeadingOperator = this.eat(operator);
  7120. const types = [];
  7121. do {
  7122. types.push(parseConstituentType());
  7123. } while (this.eat(operator));
  7124. if (types.length === 1 && !hasLeadingOperator) {
  7125. return types[0];
  7126. }
  7127. node.types = types;
  7128. return this.finishNode(node, kind);
  7129. }
  7130. tsParseIntersectionTypeOrHigher() {
  7131. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 41);
  7132. }
  7133. tsParseUnionTypeOrHigher() {
  7134. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 39);
  7135. }
  7136. tsIsStartOfFunctionType() {
  7137. if (this.match(43)) {
  7138. return true;
  7139. }
  7140. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  7141. }
  7142. tsSkipParameterStart() {
  7143. if (tokenIsIdentifier(this.state.type) || this.match(72)) {
  7144. this.next();
  7145. return true;
  7146. }
  7147. if (this.match(5)) {
  7148. let braceStackCounter = 1;
  7149. this.next();
  7150. while (braceStackCounter > 0) {
  7151. if (this.match(5)) {
  7152. ++braceStackCounter;
  7153. } else if (this.match(8)) {
  7154. --braceStackCounter;
  7155. }
  7156. this.next();
  7157. }
  7158. return true;
  7159. }
  7160. if (this.match(0)) {
  7161. let braceStackCounter = 1;
  7162. this.next();
  7163. while (braceStackCounter > 0) {
  7164. if (this.match(0)) {
  7165. ++braceStackCounter;
  7166. } else if (this.match(3)) {
  7167. --braceStackCounter;
  7168. }
  7169. this.next();
  7170. }
  7171. return true;
  7172. }
  7173. return false;
  7174. }
  7175. tsIsUnambiguouslyStartOfFunctionType() {
  7176. this.next();
  7177. if (this.match(11) || this.match(21)) {
  7178. return true;
  7179. }
  7180. if (this.tsSkipParameterStart()) {
  7181. if (this.match(14) || this.match(12) || this.match(17) || this.match(27)) {
  7182. return true;
  7183. }
  7184. if (this.match(11)) {
  7185. this.next();
  7186. if (this.match(19)) {
  7187. return true;
  7188. }
  7189. }
  7190. }
  7191. return false;
  7192. }
  7193. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  7194. return this.tsInType(() => {
  7195. const t = this.startNode();
  7196. this.expect(returnToken);
  7197. const node = this.startNode();
  7198. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  7199. if (asserts && this.match(72)) {
  7200. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  7201. if (thisTypePredicate.type === "TSThisType") {
  7202. node.parameterName = thisTypePredicate;
  7203. node.asserts = true;
  7204. node.typeAnnotation = null;
  7205. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  7206. } else {
  7207. this.resetStartLocationFromNode(thisTypePredicate, node);
  7208. thisTypePredicate.asserts = true;
  7209. }
  7210. t.typeAnnotation = thisTypePredicate;
  7211. return this.finishNode(t, "TSTypeAnnotation");
  7212. }
  7213. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  7214. if (!typePredicateVariable) {
  7215. if (!asserts) {
  7216. return this.tsParseTypeAnnotation(false, t);
  7217. }
  7218. node.parameterName = this.parseIdentifier();
  7219. node.asserts = asserts;
  7220. node.typeAnnotation = null;
  7221. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  7222. return this.finishNode(t, "TSTypeAnnotation");
  7223. }
  7224. const type = this.tsParseTypeAnnotation(false);
  7225. node.parameterName = typePredicateVariable;
  7226. node.typeAnnotation = type;
  7227. node.asserts = asserts;
  7228. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  7229. return this.finishNode(t, "TSTypeAnnotation");
  7230. });
  7231. }
  7232. tsTryParseTypeOrTypePredicateAnnotation() {
  7233. return this.match(14) ? this.tsParseTypeOrTypePredicateAnnotation(14) : undefined;
  7234. }
  7235. tsTryParseTypeAnnotation() {
  7236. return this.match(14) ? this.tsParseTypeAnnotation() : undefined;
  7237. }
  7238. tsTryParseType() {
  7239. return this.tsEatThenParseType(14);
  7240. }
  7241. tsParseTypePredicatePrefix() {
  7242. const id = this.parseIdentifier();
  7243. if (this.isContextual(107) && !this.hasPrecedingLineBreak()) {
  7244. this.next();
  7245. return id;
  7246. }
  7247. }
  7248. tsParseTypePredicateAsserts() {
  7249. if (this.state.type !== 100) {
  7250. return false;
  7251. }
  7252. const containsEsc = this.state.containsEsc;
  7253. this.next();
  7254. if (!tokenIsIdentifier(this.state.type) && !this.match(72)) {
  7255. return false;
  7256. }
  7257. if (containsEsc) {
  7258. this.raise(this.state.lastTokStart, ErrorMessages.InvalidEscapedReservedWord, "asserts");
  7259. }
  7260. return true;
  7261. }
  7262. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  7263. this.tsInType(() => {
  7264. if (eatColon) this.expect(14);
  7265. t.typeAnnotation = this.tsParseType();
  7266. });
  7267. return this.finishNode(t, "TSTypeAnnotation");
  7268. }
  7269. tsParseType() {
  7270. assert(this.state.inType);
  7271. const type = this.tsParseNonConditionalType();
  7272. if (this.hasPrecedingLineBreak() || !this.eat(75)) {
  7273. return type;
  7274. }
  7275. const node = this.startNodeAtNode(type);
  7276. node.checkType = type;
  7277. node.extendsType = this.tsParseNonConditionalType();
  7278. this.expect(17);
  7279. node.trueType = this.tsParseType();
  7280. this.expect(14);
  7281. node.falseType = this.tsParseType();
  7282. return this.finishNode(node, "TSConditionalType");
  7283. }
  7284. isAbstractConstructorSignature() {
  7285. return this.isContextual(114) && this.lookahead().type === 71;
  7286. }
  7287. tsParseNonConditionalType() {
  7288. if (this.tsIsStartOfFunctionType()) {
  7289. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  7290. }
  7291. if (this.match(71)) {
  7292. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  7293. } else if (this.isAbstractConstructorSignature()) {
  7294. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  7295. }
  7296. return this.tsParseUnionTypeOrHigher();
  7297. }
  7298. tsParseTypeAssertion() {
  7299. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  7300. this.raise(this.state.start, TSErrors.ReservedTypeAssertion);
  7301. }
  7302. const node = this.startNode();
  7303. const _const = this.tsTryNextParseConstantContext();
  7304. node.typeAnnotation = _const || this.tsNextThenParseType();
  7305. this.expect(44);
  7306. node.expression = this.parseMaybeUnary();
  7307. return this.finishNode(node, "TSTypeAssertion");
  7308. }
  7309. tsParseHeritageClause(descriptor) {
  7310. const originalStart = this.state.start;
  7311. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", this.tsParseExpressionWithTypeArguments.bind(this));
  7312. if (!delimitedList.length) {
  7313. this.raise(originalStart, TSErrors.EmptyHeritageClauseType, descriptor);
  7314. }
  7315. return delimitedList;
  7316. }
  7317. tsParseExpressionWithTypeArguments() {
  7318. const node = this.startNode();
  7319. node.expression = this.tsParseEntityName(false);
  7320. if (this.match(43)) {
  7321. node.typeParameters = this.tsParseTypeArguments();
  7322. }
  7323. return this.finishNode(node, "TSExpressionWithTypeArguments");
  7324. }
  7325. tsParseInterfaceDeclaration(node) {
  7326. if (tokenIsIdentifier(this.state.type)) {
  7327. node.id = this.parseIdentifier();
  7328. this.checkLVal(node.id, "typescript interface declaration", BIND_TS_INTERFACE);
  7329. } else {
  7330. node.id = null;
  7331. this.raise(this.state.start, TSErrors.MissingInterfaceName);
  7332. }
  7333. node.typeParameters = this.tsTryParseTypeParameters();
  7334. if (this.eat(75)) {
  7335. node.extends = this.tsParseHeritageClause("extends");
  7336. }
  7337. const body = this.startNode();
  7338. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  7339. node.body = this.finishNode(body, "TSInterfaceBody");
  7340. return this.finishNode(node, "TSInterfaceDeclaration");
  7341. }
  7342. tsParseTypeAliasDeclaration(node) {
  7343. node.id = this.parseIdentifier();
  7344. this.checkLVal(node.id, "typescript type alias", BIND_TS_TYPE);
  7345. node.typeParameters = this.tsTryParseTypeParameters();
  7346. node.typeAnnotation = this.tsInType(() => {
  7347. this.expect(27);
  7348. if (this.isContextual(105) && this.lookahead().type !== 16) {
  7349. const node = this.startNode();
  7350. this.next();
  7351. return this.finishNode(node, "TSIntrinsicKeyword");
  7352. }
  7353. return this.tsParseType();
  7354. });
  7355. this.semicolon();
  7356. return this.finishNode(node, "TSTypeAliasDeclaration");
  7357. }
  7358. tsInNoContext(cb) {
  7359. const oldContext = this.state.context;
  7360. this.state.context = [oldContext[0]];
  7361. try {
  7362. return cb();
  7363. } finally {
  7364. this.state.context = oldContext;
  7365. }
  7366. }
  7367. tsInType(cb) {
  7368. const oldInType = this.state.inType;
  7369. this.state.inType = true;
  7370. try {
  7371. return cb();
  7372. } finally {
  7373. this.state.inType = oldInType;
  7374. }
  7375. }
  7376. tsEatThenParseType(token) {
  7377. return !this.match(token) ? undefined : this.tsNextThenParseType();
  7378. }
  7379. tsExpectThenParseType(token) {
  7380. return this.tsDoThenParseType(() => this.expect(token));
  7381. }
  7382. tsNextThenParseType() {
  7383. return this.tsDoThenParseType(() => this.next());
  7384. }
  7385. tsDoThenParseType(cb) {
  7386. return this.tsInType(() => {
  7387. cb();
  7388. return this.tsParseType();
  7389. });
  7390. }
  7391. tsParseEnumMember() {
  7392. const node = this.startNode();
  7393. node.id = this.match(123) ? this.parseExprAtom() : this.parseIdentifier(true);
  7394. if (this.eat(27)) {
  7395. node.initializer = this.parseMaybeAssignAllowIn();
  7396. }
  7397. return this.finishNode(node, "TSEnumMember");
  7398. }
  7399. tsParseEnumDeclaration(node, isConst) {
  7400. if (isConst) node.const = true;
  7401. node.id = this.parseIdentifier();
  7402. this.checkLVal(node.id, "typescript enum declaration", isConst ? BIND_TS_CONST_ENUM : BIND_TS_ENUM);
  7403. this.expect(5);
  7404. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  7405. this.expect(8);
  7406. return this.finishNode(node, "TSEnumDeclaration");
  7407. }
  7408. tsParseModuleBlock() {
  7409. const node = this.startNode();
  7410. this.scope.enter(SCOPE_OTHER);
  7411. this.expect(5);
  7412. this.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  7413. this.scope.exit();
  7414. return this.finishNode(node, "TSModuleBlock");
  7415. }
  7416. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  7417. node.id = this.parseIdentifier();
  7418. if (!nested) {
  7419. this.checkLVal(node.id, "module or namespace declaration", BIND_TS_NAMESPACE);
  7420. }
  7421. if (this.eat(16)) {
  7422. const inner = this.startNode();
  7423. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  7424. node.body = inner;
  7425. } else {
  7426. this.scope.enter(SCOPE_TS_MODULE);
  7427. this.prodParam.enter(PARAM);
  7428. node.body = this.tsParseModuleBlock();
  7429. this.prodParam.exit();
  7430. this.scope.exit();
  7431. }
  7432. return this.finishNode(node, "TSModuleDeclaration");
  7433. }
  7434. tsParseAmbientExternalModuleDeclaration(node) {
  7435. if (this.isContextual(103)) {
  7436. node.global = true;
  7437. node.id = this.parseIdentifier();
  7438. } else if (this.match(123)) {
  7439. node.id = this.parseExprAtom();
  7440. } else {
  7441. this.unexpected();
  7442. }
  7443. if (this.match(5)) {
  7444. this.scope.enter(SCOPE_TS_MODULE);
  7445. this.prodParam.enter(PARAM);
  7446. node.body = this.tsParseModuleBlock();
  7447. this.prodParam.exit();
  7448. this.scope.exit();
  7449. } else {
  7450. this.semicolon();
  7451. }
  7452. return this.finishNode(node, "TSModuleDeclaration");
  7453. }
  7454. tsParseImportEqualsDeclaration(node, isExport) {
  7455. node.isExport = isExport || false;
  7456. node.id = this.parseIdentifier();
  7457. this.checkLVal(node.id, "import equals declaration", BIND_LEXICAL);
  7458. this.expect(27);
  7459. const moduleReference = this.tsParseModuleReference();
  7460. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  7461. this.raise(moduleReference.start, TSErrors.ImportAliasHasImportType);
  7462. }
  7463. node.moduleReference = moduleReference;
  7464. this.semicolon();
  7465. return this.finishNode(node, "TSImportEqualsDeclaration");
  7466. }
  7467. tsIsExternalModuleReference() {
  7468. return this.isContextual(110) && this.lookaheadCharCode() === 40;
  7469. }
  7470. tsParseModuleReference() {
  7471. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  7472. }
  7473. tsParseExternalModuleReference() {
  7474. const node = this.startNode();
  7475. this.expectContextual(110);
  7476. this.expect(10);
  7477. if (!this.match(123)) {
  7478. throw this.unexpected();
  7479. }
  7480. node.expression = this.parseExprAtom();
  7481. this.expect(11);
  7482. return this.finishNode(node, "TSExternalModuleReference");
  7483. }
  7484. tsLookAhead(f) {
  7485. const state = this.state.clone();
  7486. const res = f();
  7487. this.state = state;
  7488. return res;
  7489. }
  7490. tsTryParseAndCatch(f) {
  7491. const result = this.tryParse(abort => f() || abort());
  7492. if (result.aborted || !result.node) return undefined;
  7493. if (result.error) this.state = result.failState;
  7494. return result.node;
  7495. }
  7496. tsTryParse(f) {
  7497. const state = this.state.clone();
  7498. const result = f();
  7499. if (result !== undefined && result !== false) {
  7500. return result;
  7501. } else {
  7502. this.state = state;
  7503. return undefined;
  7504. }
  7505. }
  7506. tsTryParseDeclare(nany) {
  7507. if (this.isLineTerminator()) {
  7508. return;
  7509. }
  7510. let starttype = this.state.type;
  7511. let kind;
  7512. if (this.isContextual(93)) {
  7513. starttype = 68;
  7514. kind = "let";
  7515. }
  7516. return this.tsInAmbientContext(() => {
  7517. switch (starttype) {
  7518. case 62:
  7519. nany.declare = true;
  7520. return this.parseFunctionStatement(nany, false, true);
  7521. case 74:
  7522. nany.declare = true;
  7523. return this.parseClass(nany, true, false);
  7524. case 69:
  7525. if (this.match(69) && this.isLookaheadContextual("enum")) {
  7526. this.expect(69);
  7527. this.expectContextual(116);
  7528. return this.tsParseEnumDeclaration(nany, true);
  7529. }
  7530. case 68:
  7531. kind = kind || this.state.value;
  7532. return this.parseVarStatement(nany, kind);
  7533. case 103:
  7534. return this.tsParseAmbientExternalModuleDeclaration(nany);
  7535. default:
  7536. {
  7537. if (tokenIsIdentifier(starttype)) {
  7538. return this.tsParseDeclaration(nany, this.state.value, true);
  7539. }
  7540. }
  7541. }
  7542. });
  7543. }
  7544. tsTryParseExportDeclaration() {
  7545. return this.tsParseDeclaration(this.startNode(), this.state.value, true);
  7546. }
  7547. tsParseExpressionStatement(node, expr) {
  7548. switch (expr.name) {
  7549. case "declare":
  7550. {
  7551. const declaration = this.tsTryParseDeclare(node);
  7552. if (declaration) {
  7553. declaration.declare = true;
  7554. return declaration;
  7555. }
  7556. break;
  7557. }
  7558. case "global":
  7559. if (this.match(5)) {
  7560. this.scope.enter(SCOPE_TS_MODULE);
  7561. this.prodParam.enter(PARAM);
  7562. const mod = node;
  7563. mod.global = true;
  7564. mod.id = expr;
  7565. mod.body = this.tsParseModuleBlock();
  7566. this.scope.exit();
  7567. this.prodParam.exit();
  7568. return this.finishNode(mod, "TSModuleDeclaration");
  7569. }
  7570. break;
  7571. default:
  7572. return this.tsParseDeclaration(node, expr.name, false);
  7573. }
  7574. }
  7575. tsParseDeclaration(node, value, next) {
  7576. switch (value) {
  7577. case "abstract":
  7578. if (this.tsCheckLineTerminator(next) && (this.match(74) || tokenIsIdentifier(this.state.type))) {
  7579. return this.tsParseAbstractDeclaration(node);
  7580. }
  7581. break;
  7582. case "enum":
  7583. if (next || tokenIsIdentifier(this.state.type)) {
  7584. if (next) this.next();
  7585. return this.tsParseEnumDeclaration(node, false);
  7586. }
  7587. break;
  7588. case "interface":
  7589. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  7590. return this.tsParseInterfaceDeclaration(node);
  7591. }
  7592. break;
  7593. case "module":
  7594. if (this.tsCheckLineTerminator(next)) {
  7595. if (this.match(123)) {
  7596. return this.tsParseAmbientExternalModuleDeclaration(node);
  7597. } else if (tokenIsIdentifier(this.state.type)) {
  7598. return this.tsParseModuleOrNamespaceDeclaration(node);
  7599. }
  7600. }
  7601. break;
  7602. case "namespace":
  7603. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  7604. return this.tsParseModuleOrNamespaceDeclaration(node);
  7605. }
  7606. break;
  7607. case "type":
  7608. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  7609. return this.tsParseTypeAliasDeclaration(node);
  7610. }
  7611. break;
  7612. }
  7613. }
  7614. tsCheckLineTerminator(next) {
  7615. if (next) {
  7616. if (this.hasFollowingLineBreak()) return false;
  7617. this.next();
  7618. return true;
  7619. }
  7620. return !this.isLineTerminator();
  7621. }
  7622. tsTryParseGenericAsyncArrowFunction(startPos, startLoc) {
  7623. if (!this.match(43)) {
  7624. return undefined;
  7625. }
  7626. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  7627. this.state.maybeInArrowParameters = true;
  7628. const res = this.tsTryParseAndCatch(() => {
  7629. const node = this.startNodeAt(startPos, startLoc);
  7630. node.typeParameters = this.tsParseTypeParameters();
  7631. super.parseFunctionParams(node);
  7632. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  7633. this.expect(19);
  7634. return node;
  7635. });
  7636. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  7637. if (!res) {
  7638. return undefined;
  7639. }
  7640. return this.parseArrowExpression(res, null, true);
  7641. }
  7642. tsParseTypeArguments() {
  7643. const node = this.startNode();
  7644. node.params = this.tsInType(() => this.tsInNoContext(() => {
  7645. this.expect(43);
  7646. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  7647. }));
  7648. if (node.params.length === 0) {
  7649. this.raise(node.start, TSErrors.EmptyTypeArguments);
  7650. }
  7651. this.expect(44);
  7652. return this.finishNode(node, "TSTypeParameterInstantiation");
  7653. }
  7654. tsIsDeclarationStart() {
  7655. return tokenIsTSDeclarationStart(this.state.type);
  7656. }
  7657. isExportDefaultSpecifier() {
  7658. if (this.tsIsDeclarationStart()) return false;
  7659. return super.isExportDefaultSpecifier();
  7660. }
  7661. parseAssignableListItem(allowModifiers, decorators) {
  7662. const startPos = this.state.start;
  7663. const startLoc = this.state.startLoc;
  7664. let accessibility;
  7665. let readonly = false;
  7666. let override = false;
  7667. if (allowModifiers !== undefined) {
  7668. const modified = {};
  7669. this.tsParseModifiers(modified, ["public", "private", "protected", "override", "readonly"]);
  7670. accessibility = modified.accessibility;
  7671. override = modified.override;
  7672. readonly = modified.readonly;
  7673. if (allowModifiers === false && (accessibility || readonly || override)) {
  7674. this.raise(startPos, TSErrors.UnexpectedParameterModifier);
  7675. }
  7676. }
  7677. const left = this.parseMaybeDefault();
  7678. this.parseAssignableListItemTypes(left);
  7679. const elt = this.parseMaybeDefault(left.start, left.loc.start, left);
  7680. if (accessibility || readonly || override) {
  7681. const pp = this.startNodeAt(startPos, startLoc);
  7682. if (decorators.length) {
  7683. pp.decorators = decorators;
  7684. }
  7685. if (accessibility) pp.accessibility = accessibility;
  7686. if (readonly) pp.readonly = readonly;
  7687. if (override) pp.override = override;
  7688. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  7689. this.raise(pp.start, TSErrors.UnsupportedParameterPropertyKind);
  7690. }
  7691. pp.parameter = elt;
  7692. return this.finishNode(pp, "TSParameterProperty");
  7693. }
  7694. if (decorators.length) {
  7695. left.decorators = decorators;
  7696. }
  7697. return elt;
  7698. }
  7699. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  7700. if (this.match(14)) {
  7701. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  7702. }
  7703. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  7704. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  7705. this.finishNode(node, bodilessType);
  7706. return;
  7707. }
  7708. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  7709. this.raise(node.start, TSErrors.DeclareFunctionHasImplementation);
  7710. if (node.declare) {
  7711. super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  7712. return;
  7713. }
  7714. }
  7715. super.parseFunctionBodyAndFinish(node, type, isMethod);
  7716. }
  7717. registerFunctionStatementId(node) {
  7718. if (!node.body && node.id) {
  7719. this.checkLVal(node.id, "function name", BIND_TS_AMBIENT);
  7720. } else {
  7721. super.registerFunctionStatementId(...arguments);
  7722. }
  7723. }
  7724. tsCheckForInvalidTypeCasts(items) {
  7725. items.forEach(node => {
  7726. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  7727. this.raise(node.typeAnnotation.start, TSErrors.UnexpectedTypeAnnotation);
  7728. }
  7729. });
  7730. }
  7731. toReferencedList(exprList, isInParens) {
  7732. this.tsCheckForInvalidTypeCasts(exprList);
  7733. return exprList;
  7734. }
  7735. parseArrayLike(...args) {
  7736. const node = super.parseArrayLike(...args);
  7737. if (node.type === "ArrayExpression") {
  7738. this.tsCheckForInvalidTypeCasts(node.elements);
  7739. }
  7740. return node;
  7741. }
  7742. parseSubscript(base, startPos, startLoc, noCalls, state) {
  7743. if (!this.hasPrecedingLineBreak() && this.match(33)) {
  7744. this.state.canStartJSXElement = false;
  7745. this.next();
  7746. const nonNullExpression = this.startNodeAt(startPos, startLoc);
  7747. nonNullExpression.expression = base;
  7748. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  7749. }
  7750. let isOptionalCall = false;
  7751. if (this.match(18) && this.lookaheadCharCode() === 60) {
  7752. if (noCalls) {
  7753. state.stop = true;
  7754. return base;
  7755. }
  7756. state.optionalChainMember = isOptionalCall = true;
  7757. this.next();
  7758. }
  7759. if (this.match(43)) {
  7760. let missingParenErrorPos;
  7761. const result = this.tsTryParseAndCatch(() => {
  7762. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  7763. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startPos, startLoc);
  7764. if (asyncArrowFn) {
  7765. return asyncArrowFn;
  7766. }
  7767. }
  7768. const node = this.startNodeAt(startPos, startLoc);
  7769. node.callee = base;
  7770. const typeArguments = this.tsParseTypeArguments();
  7771. if (typeArguments) {
  7772. if (isOptionalCall && !this.match(10)) {
  7773. missingParenErrorPos = this.state.pos;
  7774. this.unexpected();
  7775. }
  7776. if (!noCalls && this.eat(10)) {
  7777. node.arguments = this.parseCallExpressionArguments(11, false);
  7778. this.tsCheckForInvalidTypeCasts(node.arguments);
  7779. node.typeParameters = typeArguments;
  7780. if (state.optionalChainMember) {
  7781. node.optional = isOptionalCall;
  7782. }
  7783. return this.finishCallExpression(node, state.optionalChainMember);
  7784. } else if (this.match(22)) {
  7785. const result = this.parseTaggedTemplateExpression(base, startPos, startLoc, state);
  7786. result.typeParameters = typeArguments;
  7787. return result;
  7788. }
  7789. }
  7790. this.unexpected();
  7791. });
  7792. if (missingParenErrorPos) {
  7793. this.unexpected(missingParenErrorPos, 10);
  7794. }
  7795. if (result) return result;
  7796. }
  7797. return super.parseSubscript(base, startPos, startLoc, noCalls, state);
  7798. }
  7799. parseNewArguments(node) {
  7800. if (this.match(43)) {
  7801. const typeParameters = this.tsTryParseAndCatch(() => {
  7802. const args = this.tsParseTypeArguments();
  7803. if (!this.match(10)) this.unexpected();
  7804. return args;
  7805. });
  7806. if (typeParameters) {
  7807. node.typeParameters = typeParameters;
  7808. }
  7809. }
  7810. super.parseNewArguments(node);
  7811. }
  7812. parseExprOp(left, leftStartPos, leftStartLoc, minPrec) {
  7813. if (tokenOperatorPrecedence(52) > minPrec && !this.hasPrecedingLineBreak() && this.isContextual(87)) {
  7814. const node = this.startNodeAt(leftStartPos, leftStartLoc);
  7815. node.expression = left;
  7816. const _const = this.tsTryNextParseConstantContext();
  7817. if (_const) {
  7818. node.typeAnnotation = _const;
  7819. } else {
  7820. node.typeAnnotation = this.tsNextThenParseType();
  7821. }
  7822. this.finishNode(node, "TSAsExpression");
  7823. this.reScan_lt_gt();
  7824. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec);
  7825. }
  7826. return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec);
  7827. }
  7828. checkReservedWord(word, startLoc, checkKeywords, isBinding) {}
  7829. checkDuplicateExports() {}
  7830. parseImport(node) {
  7831. node.importKind = "value";
  7832. if (tokenIsIdentifier(this.state.type) || this.match(49) || this.match(5)) {
  7833. let ahead = this.lookahead();
  7834. if (this.isContextual(120) && ahead.type !== 12 && ahead.type !== 91 && ahead.type !== 27) {
  7835. node.importKind = "type";
  7836. this.next();
  7837. ahead = this.lookahead();
  7838. }
  7839. if (tokenIsIdentifier(this.state.type) && ahead.type === 27) {
  7840. return this.tsParseImportEqualsDeclaration(node);
  7841. }
  7842. }
  7843. const importNode = super.parseImport(node);
  7844. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  7845. this.raise(importNode.start, TSErrors.TypeImportCannotSpecifyDefaultAndNamed);
  7846. }
  7847. return importNode;
  7848. }
  7849. parseExport(node) {
  7850. if (this.match(77)) {
  7851. this.next();
  7852. if (this.isContextual(120) && this.lookaheadCharCode() !== 61) {
  7853. node.importKind = "type";
  7854. this.next();
  7855. } else {
  7856. node.importKind = "value";
  7857. }
  7858. return this.tsParseImportEqualsDeclaration(node, true);
  7859. } else if (this.eat(27)) {
  7860. const assign = node;
  7861. assign.expression = this.parseExpression();
  7862. this.semicolon();
  7863. return this.finishNode(assign, "TSExportAssignment");
  7864. } else if (this.eatContextual(87)) {
  7865. const decl = node;
  7866. this.expectContextual(118);
  7867. decl.id = this.parseIdentifier();
  7868. this.semicolon();
  7869. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  7870. } else {
  7871. if (this.isContextual(120) && this.lookahead().type === 5) {
  7872. this.next();
  7873. node.exportKind = "type";
  7874. } else {
  7875. node.exportKind = "value";
  7876. }
  7877. return super.parseExport(node);
  7878. }
  7879. }
  7880. isAbstractClass() {
  7881. return this.isContextual(114) && this.lookahead().type === 74;
  7882. }
  7883. parseExportDefaultExpression() {
  7884. if (this.isAbstractClass()) {
  7885. const cls = this.startNode();
  7886. this.next();
  7887. cls.abstract = true;
  7888. this.parseClass(cls, true, true);
  7889. return cls;
  7890. }
  7891. if (this.match(119)) {
  7892. const interfaceNode = this.startNode();
  7893. this.next();
  7894. const result = this.tsParseInterfaceDeclaration(interfaceNode);
  7895. if (result) return result;
  7896. }
  7897. return super.parseExportDefaultExpression();
  7898. }
  7899. parseStatementContent(context, topLevel) {
  7900. if (this.state.type === 69) {
  7901. const ahead = this.lookahead();
  7902. if (ahead.type === 116) {
  7903. const node = this.startNode();
  7904. this.next();
  7905. this.expectContextual(116);
  7906. return this.tsParseEnumDeclaration(node, true);
  7907. }
  7908. }
  7909. return super.parseStatementContent(context, topLevel);
  7910. }
  7911. parseAccessModifier() {
  7912. return this.tsParseModifier(["public", "protected", "private"]);
  7913. }
  7914. tsHasSomeModifiers(member, modifiers) {
  7915. return modifiers.some(modifier => {
  7916. if (tsIsAccessModifier(modifier)) {
  7917. return member.accessibility === modifier;
  7918. }
  7919. return !!member[modifier];
  7920. });
  7921. }
  7922. tsIsStartOfStaticBlocks() {
  7923. return this.isContextual(98) && this.lookaheadCharCode() === 123;
  7924. }
  7925. parseClassMember(classBody, member, state) {
  7926. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  7927. this.tsParseModifiers(member, modifiers, undefined, undefined, true);
  7928. const callParseClassMemberWithIsStatic = () => {
  7929. if (this.tsIsStartOfStaticBlocks()) {
  7930. this.next();
  7931. this.next();
  7932. if (this.tsHasSomeModifiers(member, modifiers)) {
  7933. this.raise(this.state.pos, TSErrors.StaticBlockCannotHaveModifier);
  7934. }
  7935. this.parseClassStaticBlock(classBody, member);
  7936. } else {
  7937. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  7938. }
  7939. };
  7940. if (member.declare) {
  7941. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  7942. } else {
  7943. callParseClassMemberWithIsStatic();
  7944. }
  7945. }
  7946. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  7947. const idx = this.tsTryParseIndexSignature(member);
  7948. if (idx) {
  7949. classBody.body.push(idx);
  7950. if (member.abstract) {
  7951. this.raise(member.start, TSErrors.IndexSignatureHasAbstract);
  7952. }
  7953. if (member.accessibility) {
  7954. this.raise(member.start, TSErrors.IndexSignatureHasAccessibility, member.accessibility);
  7955. }
  7956. if (member.declare) {
  7957. this.raise(member.start, TSErrors.IndexSignatureHasDeclare);
  7958. }
  7959. if (member.override) {
  7960. this.raise(member.start, TSErrors.IndexSignatureHasOverride);
  7961. }
  7962. return;
  7963. }
  7964. if (!this.state.inAbstractClass && member.abstract) {
  7965. this.raise(member.start, TSErrors.NonAbstractClassHasAbstractMethod);
  7966. }
  7967. if (member.override) {
  7968. if (!state.hadSuperClass) {
  7969. this.raise(member.start, TSErrors.OverrideNotInSubClass);
  7970. }
  7971. }
  7972. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  7973. }
  7974. parsePostMemberNameModifiers(methodOrProp) {
  7975. const optional = this.eat(17);
  7976. if (optional) methodOrProp.optional = true;
  7977. if (methodOrProp.readonly && this.match(10)) {
  7978. this.raise(methodOrProp.start, TSErrors.ClassMethodHasReadonly);
  7979. }
  7980. if (methodOrProp.declare && this.match(10)) {
  7981. this.raise(methodOrProp.start, TSErrors.ClassMethodHasDeclare);
  7982. }
  7983. }
  7984. parseExpressionStatement(node, expr) {
  7985. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr) : undefined;
  7986. return decl || super.parseExpressionStatement(node, expr);
  7987. }
  7988. shouldParseExportDeclaration() {
  7989. if (this.tsIsDeclarationStart()) return true;
  7990. return super.shouldParseExportDeclaration();
  7991. }
  7992. parseConditional(expr, startPos, startLoc, refExpressionErrors) {
  7993. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  7994. return super.parseConditional(expr, startPos, startLoc, refExpressionErrors);
  7995. }
  7996. const result = this.tryParse(() => super.parseConditional(expr, startPos, startLoc));
  7997. if (!result.node) {
  7998. if (result.error) {
  7999. super.setOptionalParametersError(refExpressionErrors, result.error);
  8000. }
  8001. return expr;
  8002. }
  8003. if (result.error) this.state = result.failState;
  8004. return result.node;
  8005. }
  8006. parseParenItem(node, startPos, startLoc) {
  8007. node = super.parseParenItem(node, startPos, startLoc);
  8008. if (this.eat(17)) {
  8009. node.optional = true;
  8010. this.resetEndLocation(node);
  8011. }
  8012. if (this.match(14)) {
  8013. const typeCastNode = this.startNodeAt(startPos, startLoc);
  8014. typeCastNode.expression = node;
  8015. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  8016. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  8017. }
  8018. return node;
  8019. }
  8020. parseExportDeclaration(node) {
  8021. const startPos = this.state.start;
  8022. const startLoc = this.state.startLoc;
  8023. const isDeclare = this.eatContextual(115);
  8024. if (isDeclare && (this.isContextual(115) || !this.shouldParseExportDeclaration())) {
  8025. throw this.raise(this.state.start, TSErrors.ExpectedAmbientAfterExportDeclare);
  8026. }
  8027. let declaration;
  8028. if (tokenIsIdentifier(this.state.type)) {
  8029. declaration = this.tsTryParseExportDeclaration();
  8030. }
  8031. if (!declaration) {
  8032. declaration = super.parseExportDeclaration(node);
  8033. }
  8034. if (declaration && (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare)) {
  8035. node.exportKind = "type";
  8036. }
  8037. if (declaration && isDeclare) {
  8038. this.resetStartLocation(declaration, startPos, startLoc);
  8039. declaration.declare = true;
  8040. }
  8041. return declaration;
  8042. }
  8043. parseClassId(node, isStatement, optionalId) {
  8044. if ((!isStatement || optionalId) && this.isContextual(104)) {
  8045. return;
  8046. }
  8047. super.parseClassId(node, isStatement, optionalId, node.declare ? BIND_TS_AMBIENT : BIND_CLASS);
  8048. const typeParameters = this.tsTryParseTypeParameters();
  8049. if (typeParameters) node.typeParameters = typeParameters;
  8050. }
  8051. parseClassPropertyAnnotation(node) {
  8052. if (!node.optional && this.eat(33)) {
  8053. node.definite = true;
  8054. }
  8055. const type = this.tsTryParseTypeAnnotation();
  8056. if (type) node.typeAnnotation = type;
  8057. }
  8058. parseClassProperty(node) {
  8059. this.parseClassPropertyAnnotation(node);
  8060. if (this.state.isAmbientContext && this.match(27)) {
  8061. this.raise(this.state.start, TSErrors.DeclareClassFieldHasInitializer);
  8062. }
  8063. if (node.abstract && this.match(27)) {
  8064. const {
  8065. key
  8066. } = node;
  8067. this.raise(this.state.start, TSErrors.AbstractPropertyHasInitializer, key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`);
  8068. }
  8069. return super.parseClassProperty(node);
  8070. }
  8071. parseClassPrivateProperty(node) {
  8072. if (node.abstract) {
  8073. this.raise(node.start, TSErrors.PrivateElementHasAbstract);
  8074. }
  8075. if (node.accessibility) {
  8076. this.raise(node.start, TSErrors.PrivateElementHasAccessibility, node.accessibility);
  8077. }
  8078. this.parseClassPropertyAnnotation(node);
  8079. return super.parseClassPrivateProperty(node);
  8080. }
  8081. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  8082. const typeParameters = this.tsTryParseTypeParameters();
  8083. if (typeParameters && isConstructor) {
  8084. this.raise(typeParameters.start, TSErrors.ConstructorHasTypeParameters);
  8085. }
  8086. if (method.declare && (method.kind === "get" || method.kind === "set")) {
  8087. this.raise(method.start, TSErrors.DeclareAccessor, method.kind);
  8088. }
  8089. if (typeParameters) method.typeParameters = typeParameters;
  8090. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  8091. }
  8092. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  8093. const typeParameters = this.tsTryParseTypeParameters();
  8094. if (typeParameters) method.typeParameters = typeParameters;
  8095. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  8096. }
  8097. declareClassPrivateMethodInScope(node, kind) {
  8098. if (node.type === "TSDeclareMethod") return;
  8099. if (node.type === "MethodDefinition" && !node.value.body) return;
  8100. super.declareClassPrivateMethodInScope(node, kind);
  8101. }
  8102. parseClassSuper(node) {
  8103. super.parseClassSuper(node);
  8104. if (node.superClass && this.match(43)) {
  8105. node.superTypeParameters = this.tsParseTypeArguments();
  8106. }
  8107. if (this.eatContextual(104)) {
  8108. node.implements = this.tsParseHeritageClause("implements");
  8109. }
  8110. }
  8111. parseObjPropValue(prop, ...args) {
  8112. const typeParameters = this.tsTryParseTypeParameters();
  8113. if (typeParameters) prop.typeParameters = typeParameters;
  8114. super.parseObjPropValue(prop, ...args);
  8115. }
  8116. parseFunctionParams(node, allowModifiers) {
  8117. const typeParameters = this.tsTryParseTypeParameters();
  8118. if (typeParameters) node.typeParameters = typeParameters;
  8119. super.parseFunctionParams(node, allowModifiers);
  8120. }
  8121. parseVarId(decl, kind) {
  8122. super.parseVarId(decl, kind);
  8123. if (decl.id.type === "Identifier" && this.eat(33)) {
  8124. decl.definite = true;
  8125. }
  8126. const type = this.tsTryParseTypeAnnotation();
  8127. if (type) {
  8128. decl.id.typeAnnotation = type;
  8129. this.resetEndLocation(decl.id);
  8130. }
  8131. }
  8132. parseAsyncArrowFromCallExpression(node, call) {
  8133. if (this.match(14)) {
  8134. node.returnType = this.tsParseTypeAnnotation();
  8135. }
  8136. return super.parseAsyncArrowFromCallExpression(node, call);
  8137. }
  8138. parseMaybeAssign(...args) {
  8139. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2, _jsx4, _typeCast3;
  8140. let state;
  8141. let jsx;
  8142. let typeCast;
  8143. if (this.hasPlugin("jsx") && (this.match(132) || this.match(43))) {
  8144. state = this.state.clone();
  8145. jsx = this.tryParse(() => super.parseMaybeAssign(...args), state);
  8146. if (!jsx.error) return jsx.node;
  8147. const {
  8148. context
  8149. } = this.state;
  8150. if (context[context.length - 1] === types.j_oTag) {
  8151. context.length -= 2;
  8152. } else if (context[context.length - 1] === types.j_expr) {
  8153. context.length -= 1;
  8154. }
  8155. }
  8156. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(43)) {
  8157. return super.parseMaybeAssign(...args);
  8158. }
  8159. let typeParameters;
  8160. state = state || this.state.clone();
  8161. const arrow = this.tryParse(abort => {
  8162. var _expr$extra, _typeParameters;
  8163. typeParameters = this.tsParseTypeParameters();
  8164. const expr = super.parseMaybeAssign(...args);
  8165. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  8166. abort();
  8167. }
  8168. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  8169. this.resetStartLocationFromNode(expr, typeParameters);
  8170. }
  8171. expr.typeParameters = typeParameters;
  8172. return expr;
  8173. }, state);
  8174. if (!arrow.error && !arrow.aborted) {
  8175. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  8176. return arrow.node;
  8177. }
  8178. if (!jsx) {
  8179. assert(!this.hasPlugin("jsx"));
  8180. typeCast = this.tryParse(() => super.parseMaybeAssign(...args), state);
  8181. if (!typeCast.error) return typeCast.node;
  8182. }
  8183. if ((_jsx2 = jsx) != null && _jsx2.node) {
  8184. this.state = jsx.failState;
  8185. return jsx.node;
  8186. }
  8187. if (arrow.node) {
  8188. this.state = arrow.failState;
  8189. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  8190. return arrow.node;
  8191. }
  8192. if ((_typeCast = typeCast) != null && _typeCast.node) {
  8193. this.state = typeCast.failState;
  8194. return typeCast.node;
  8195. }
  8196. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  8197. if (arrow.thrown) throw arrow.error;
  8198. if ((_typeCast2 = typeCast) != null && _typeCast2.thrown) throw typeCast.error;
  8199. throw ((_jsx4 = jsx) == null ? void 0 : _jsx4.error) || arrow.error || ((_typeCast3 = typeCast) == null ? void 0 : _typeCast3.error);
  8200. }
  8201. reportReservedArrowTypeParam(node) {
  8202. var _node$extra;
  8203. if (node.params.length === 1 && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8204. this.raise(node.start, TSErrors.ReservedArrowTypeParam);
  8205. }
  8206. }
  8207. parseMaybeUnary(refExpressionErrors) {
  8208. if (!this.hasPlugin("jsx") && this.match(43)) {
  8209. return this.tsParseTypeAssertion();
  8210. } else {
  8211. return super.parseMaybeUnary(refExpressionErrors);
  8212. }
  8213. }
  8214. parseArrow(node) {
  8215. if (this.match(14)) {
  8216. const result = this.tryParse(abort => {
  8217. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  8218. if (this.canInsertSemicolon() || !this.match(19)) abort();
  8219. return returnType;
  8220. });
  8221. if (result.aborted) return;
  8222. if (!result.thrown) {
  8223. if (result.error) this.state = result.failState;
  8224. node.returnType = result.node;
  8225. }
  8226. }
  8227. return super.parseArrow(node);
  8228. }
  8229. parseAssignableListItemTypes(param) {
  8230. if (this.eat(17)) {
  8231. if (param.type !== "Identifier" && !this.state.isAmbientContext && !this.state.inType) {
  8232. this.raise(param.start, TSErrors.PatternIsOptional);
  8233. }
  8234. param.optional = true;
  8235. }
  8236. const type = this.tsTryParseTypeAnnotation();
  8237. if (type) param.typeAnnotation = type;
  8238. this.resetEndLocation(param);
  8239. return param;
  8240. }
  8241. isAssignable(node, isBinding) {
  8242. switch (node.type) {
  8243. case "TSTypeCastExpression":
  8244. return this.isAssignable(node.expression, isBinding);
  8245. case "TSParameterProperty":
  8246. return true;
  8247. default:
  8248. return super.isAssignable(node, isBinding);
  8249. }
  8250. }
  8251. toAssignable(node, isLHS = false) {
  8252. switch (node.type) {
  8253. case "TSTypeCastExpression":
  8254. return super.toAssignable(this.typeCastToParameter(node), isLHS);
  8255. case "TSParameterProperty":
  8256. return super.toAssignable(node, isLHS);
  8257. case "ParenthesizedExpression":
  8258. return this.toAssignableParenthesizedExpression(node, isLHS);
  8259. case "TSAsExpression":
  8260. case "TSNonNullExpression":
  8261. case "TSTypeAssertion":
  8262. node.expression = this.toAssignable(node.expression, isLHS);
  8263. return node;
  8264. default:
  8265. return super.toAssignable(node, isLHS);
  8266. }
  8267. }
  8268. toAssignableParenthesizedExpression(node, isLHS) {
  8269. switch (node.expression.type) {
  8270. case "TSAsExpression":
  8271. case "TSNonNullExpression":
  8272. case "TSTypeAssertion":
  8273. case "ParenthesizedExpression":
  8274. node.expression = this.toAssignable(node.expression, isLHS);
  8275. return node;
  8276. default:
  8277. return super.toAssignable(node, isLHS);
  8278. }
  8279. }
  8280. checkLVal(expr, contextDescription, ...args) {
  8281. var _expr$extra2;
  8282. switch (expr.type) {
  8283. case "TSTypeCastExpression":
  8284. return;
  8285. case "TSParameterProperty":
  8286. this.checkLVal(expr.parameter, "parameter property", ...args);
  8287. return;
  8288. case "TSAsExpression":
  8289. case "TSTypeAssertion":
  8290. if (!args[0] && contextDescription !== "parenthesized expression" && !((_expr$extra2 = expr.extra) != null && _expr$extra2.parenthesized)) {
  8291. this.raise(expr.start, ErrorMessages.InvalidLhs, contextDescription);
  8292. break;
  8293. }
  8294. this.checkLVal(expr.expression, "parenthesized expression", ...args);
  8295. return;
  8296. case "TSNonNullExpression":
  8297. this.checkLVal(expr.expression, contextDescription, ...args);
  8298. return;
  8299. default:
  8300. super.checkLVal(expr, contextDescription, ...args);
  8301. return;
  8302. }
  8303. }
  8304. parseBindingAtom() {
  8305. switch (this.state.type) {
  8306. case 72:
  8307. return this.parseIdentifier(true);
  8308. default:
  8309. return super.parseBindingAtom();
  8310. }
  8311. }
  8312. parseMaybeDecoratorArguments(expr) {
  8313. if (this.match(43)) {
  8314. const typeArguments = this.tsParseTypeArguments();
  8315. if (this.match(10)) {
  8316. const call = super.parseMaybeDecoratorArguments(expr);
  8317. call.typeParameters = typeArguments;
  8318. return call;
  8319. }
  8320. this.unexpected(this.state.start, 10);
  8321. }
  8322. return super.parseMaybeDecoratorArguments(expr);
  8323. }
  8324. checkCommaAfterRest(close) {
  8325. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  8326. this.next();
  8327. } else {
  8328. super.checkCommaAfterRest(close);
  8329. }
  8330. }
  8331. isClassMethod() {
  8332. return this.match(43) || super.isClassMethod();
  8333. }
  8334. isClassProperty() {
  8335. return this.match(33) || this.match(14) || super.isClassProperty();
  8336. }
  8337. parseMaybeDefault(...args) {
  8338. const node = super.parseMaybeDefault(...args);
  8339. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  8340. this.raise(node.typeAnnotation.start, TSErrors.TypeAnnotationAfterAssign);
  8341. }
  8342. return node;
  8343. }
  8344. getTokenFromCode(code) {
  8345. if (this.state.inType) {
  8346. if (code === 62) {
  8347. return this.finishOp(44, 1);
  8348. }
  8349. if (code === 60) {
  8350. return this.finishOp(43, 1);
  8351. }
  8352. }
  8353. return super.getTokenFromCode(code);
  8354. }
  8355. reScan_lt_gt() {
  8356. const {
  8357. type
  8358. } = this.state;
  8359. if (type === 43) {
  8360. this.state.pos -= 1;
  8361. this.readToken_lt();
  8362. } else if (type === 44) {
  8363. this.state.pos -= 1;
  8364. this.readToken_gt();
  8365. }
  8366. }
  8367. toAssignableList(exprList) {
  8368. for (let i = 0; i < exprList.length; i++) {
  8369. const expr = exprList[i];
  8370. if (!expr) continue;
  8371. switch (expr.type) {
  8372. case "TSTypeCastExpression":
  8373. exprList[i] = this.typeCastToParameter(expr);
  8374. break;
  8375. case "TSAsExpression":
  8376. case "TSTypeAssertion":
  8377. if (!this.state.maybeInArrowParameters) {
  8378. exprList[i] = this.typeCastToParameter(expr);
  8379. } else {
  8380. this.raise(expr.start, TSErrors.UnexpectedTypeCastInParameter);
  8381. }
  8382. break;
  8383. }
  8384. }
  8385. return super.toAssignableList(...arguments);
  8386. }
  8387. typeCastToParameter(node) {
  8388. node.expression.typeAnnotation = node.typeAnnotation;
  8389. this.resetEndLocation(node.expression, node.typeAnnotation.end, node.typeAnnotation.loc.end);
  8390. return node.expression;
  8391. }
  8392. shouldParseArrow(params) {
  8393. if (this.match(14)) {
  8394. return params.every(expr => this.isAssignable(expr, true));
  8395. }
  8396. return super.shouldParseArrow(params);
  8397. }
  8398. shouldParseAsyncArrow() {
  8399. return this.match(14) || super.shouldParseAsyncArrow();
  8400. }
  8401. canHaveLeadingDecorator() {
  8402. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  8403. }
  8404. jsxParseOpeningElementAfterName(node) {
  8405. if (this.match(43)) {
  8406. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArguments());
  8407. if (typeArguments) node.typeParameters = typeArguments;
  8408. }
  8409. return super.jsxParseOpeningElementAfterName(node);
  8410. }
  8411. getGetterSetterExpectedParamCount(method) {
  8412. const baseCount = super.getGetterSetterExpectedParamCount(method);
  8413. const params = this.getObjectOrClassMethodParams(method);
  8414. const firstParam = params[0];
  8415. const hasContextParam = firstParam && this.isThisParam(firstParam);
  8416. return hasContextParam ? baseCount + 1 : baseCount;
  8417. }
  8418. parseCatchClauseParam() {
  8419. const param = super.parseCatchClauseParam();
  8420. const type = this.tsTryParseTypeAnnotation();
  8421. if (type) {
  8422. param.typeAnnotation = type;
  8423. this.resetEndLocation(param);
  8424. }
  8425. return param;
  8426. }
  8427. tsInAmbientContext(cb) {
  8428. const oldIsAmbientContext = this.state.isAmbientContext;
  8429. this.state.isAmbientContext = true;
  8430. try {
  8431. return cb();
  8432. } finally {
  8433. this.state.isAmbientContext = oldIsAmbientContext;
  8434. }
  8435. }
  8436. parseClass(node, ...args) {
  8437. const oldInAbstractClass = this.state.inAbstractClass;
  8438. this.state.inAbstractClass = !!node.abstract;
  8439. try {
  8440. return super.parseClass(node, ...args);
  8441. } finally {
  8442. this.state.inAbstractClass = oldInAbstractClass;
  8443. }
  8444. }
  8445. tsParseAbstractDeclaration(node) {
  8446. if (this.match(74)) {
  8447. node.abstract = true;
  8448. return this.parseClass(node, true, false);
  8449. } else if (this.isContextual(119)) {
  8450. if (!this.hasFollowingLineBreak()) {
  8451. node.abstract = true;
  8452. this.raise(node.start, TSErrors.NonClassMethodPropertyHasAbstractModifer);
  8453. this.next();
  8454. return this.tsParseInterfaceDeclaration(node);
  8455. }
  8456. } else {
  8457. this.unexpected(null, 74);
  8458. }
  8459. }
  8460. parseMethod(...args) {
  8461. const method = super.parseMethod(...args);
  8462. if (method.abstract) {
  8463. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  8464. if (hasBody) {
  8465. const {
  8466. key
  8467. } = method;
  8468. this.raise(method.start, TSErrors.AbstractMethodHasImplementation, key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`);
  8469. }
  8470. }
  8471. return method;
  8472. }
  8473. tsParseTypeParameterName() {
  8474. const typeName = this.parseIdentifier();
  8475. return typeName.name;
  8476. }
  8477. shouldParseAsAmbientContext() {
  8478. return !!this.getPluginOption("typescript", "dts");
  8479. }
  8480. parse() {
  8481. if (this.shouldParseAsAmbientContext()) {
  8482. this.state.isAmbientContext = true;
  8483. }
  8484. return super.parse();
  8485. }
  8486. getExpression() {
  8487. if (this.shouldParseAsAmbientContext()) {
  8488. this.state.isAmbientContext = true;
  8489. }
  8490. return super.getExpression();
  8491. }
  8492. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  8493. if (!isString && isMaybeTypeOnly) {
  8494. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  8495. return this.finishNode(node, "ExportSpecifier");
  8496. }
  8497. node.exportKind = "value";
  8498. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  8499. }
  8500. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly) {
  8501. if (!importedIsString && isMaybeTypeOnly) {
  8502. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  8503. return this.finishNode(specifier, "ImportSpecifier");
  8504. }
  8505. specifier.importKind = "value";
  8506. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly);
  8507. }
  8508. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  8509. const leftOfAsKey = isImport ? "imported" : "local";
  8510. const rightOfAsKey = isImport ? "local" : "exported";
  8511. let leftOfAs = node[leftOfAsKey];
  8512. let rightOfAs;
  8513. let hasTypeSpecifier = false;
  8514. let canParseAsKeyword = true;
  8515. const pos = leftOfAs.start;
  8516. if (this.isContextual(87)) {
  8517. const firstAs = this.parseIdentifier();
  8518. if (this.isContextual(87)) {
  8519. const secondAs = this.parseIdentifier();
  8520. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  8521. hasTypeSpecifier = true;
  8522. leftOfAs = firstAs;
  8523. rightOfAs = this.parseIdentifier();
  8524. canParseAsKeyword = false;
  8525. } else {
  8526. rightOfAs = secondAs;
  8527. canParseAsKeyword = false;
  8528. }
  8529. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  8530. canParseAsKeyword = false;
  8531. rightOfAs = this.parseIdentifier();
  8532. } else {
  8533. hasTypeSpecifier = true;
  8534. leftOfAs = firstAs;
  8535. }
  8536. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  8537. hasTypeSpecifier = true;
  8538. leftOfAs = this.parseIdentifier();
  8539. }
  8540. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  8541. this.raise(pos, isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports);
  8542. }
  8543. node[leftOfAsKey] = leftOfAs;
  8544. node[rightOfAsKey] = rightOfAs;
  8545. const kindKey = isImport ? "importKind" : "exportKind";
  8546. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  8547. if (canParseAsKeyword && this.eatContextual(87)) {
  8548. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  8549. }
  8550. if (!node[rightOfAsKey]) {
  8551. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  8552. }
  8553. if (isImport) {
  8554. this.checkLVal(node[rightOfAsKey], "import specifier", BIND_LEXICAL);
  8555. }
  8556. }
  8557. });
  8558. const PlaceHolderErrors = makeErrorTemplates({
  8559. ClassNameIsRequired: "A class name is required."
  8560. }, ErrorCodes.SyntaxError);
  8561. var placeholders = (superClass => class extends superClass {
  8562. parsePlaceholder(expectedNode) {
  8563. if (this.match(134)) {
  8564. const node = this.startNode();
  8565. this.next();
  8566. this.assertNoSpace("Unexpected space in placeholder.");
  8567. node.name = super.parseIdentifier(true);
  8568. this.assertNoSpace("Unexpected space in placeholder.");
  8569. this.expect(134);
  8570. return this.finishPlaceholder(node, expectedNode);
  8571. }
  8572. }
  8573. finishPlaceholder(node, expectedNode) {
  8574. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  8575. node.expectedNode = expectedNode;
  8576. return isFinished ? node : this.finishNode(node, "Placeholder");
  8577. }
  8578. getTokenFromCode(code) {
  8579. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  8580. return this.finishOp(134, 2);
  8581. }
  8582. return super.getTokenFromCode(...arguments);
  8583. }
  8584. parseExprAtom() {
  8585. return this.parsePlaceholder("Expression") || super.parseExprAtom(...arguments);
  8586. }
  8587. parseIdentifier() {
  8588. return this.parsePlaceholder("Identifier") || super.parseIdentifier(...arguments);
  8589. }
  8590. checkReservedWord(word) {
  8591. if (word !== undefined) super.checkReservedWord(...arguments);
  8592. }
  8593. parseBindingAtom() {
  8594. return this.parsePlaceholder("Pattern") || super.parseBindingAtom(...arguments);
  8595. }
  8596. checkLVal(expr) {
  8597. if (expr.type !== "Placeholder") super.checkLVal(...arguments);
  8598. }
  8599. toAssignable(node) {
  8600. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  8601. node.expectedNode = "Pattern";
  8602. return node;
  8603. }
  8604. return super.toAssignable(...arguments);
  8605. }
  8606. isLet(context) {
  8607. if (super.isLet(context)) {
  8608. return true;
  8609. }
  8610. if (!this.isContextual(93)) {
  8611. return false;
  8612. }
  8613. if (context) return false;
  8614. const nextToken = this.lookahead();
  8615. if (nextToken.type === 134) {
  8616. return true;
  8617. }
  8618. return false;
  8619. }
  8620. verifyBreakContinue(node) {
  8621. if (node.label && node.label.type === "Placeholder") return;
  8622. super.verifyBreakContinue(...arguments);
  8623. }
  8624. parseExpressionStatement(node, expr) {
  8625. if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) {
  8626. return super.parseExpressionStatement(...arguments);
  8627. }
  8628. if (this.match(14)) {
  8629. const stmt = node;
  8630. stmt.label = this.finishPlaceholder(expr, "Identifier");
  8631. this.next();
  8632. stmt.body = this.parseStatement("label");
  8633. return this.finishNode(stmt, "LabeledStatement");
  8634. }
  8635. this.semicolon();
  8636. node.name = expr.name;
  8637. return this.finishPlaceholder(node, "Statement");
  8638. }
  8639. parseBlock() {
  8640. return this.parsePlaceholder("BlockStatement") || super.parseBlock(...arguments);
  8641. }
  8642. parseFunctionId() {
  8643. return this.parsePlaceholder("Identifier") || super.parseFunctionId(...arguments);
  8644. }
  8645. parseClass(node, isStatement, optionalId) {
  8646. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  8647. this.next();
  8648. this.takeDecorators(node);
  8649. const oldStrict = this.state.strict;
  8650. const placeholder = this.parsePlaceholder("Identifier");
  8651. if (placeholder) {
  8652. if (this.match(75) || this.match(134) || this.match(5)) {
  8653. node.id = placeholder;
  8654. } else if (optionalId || !isStatement) {
  8655. node.id = null;
  8656. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  8657. return this.finishNode(node, type);
  8658. } else {
  8659. this.unexpected(null, PlaceHolderErrors.ClassNameIsRequired);
  8660. }
  8661. } else {
  8662. this.parseClassId(node, isStatement, optionalId);
  8663. }
  8664. this.parseClassSuper(node);
  8665. node.body = this.parsePlaceholder("ClassBody") || this.parseClassBody(!!node.superClass, oldStrict);
  8666. return this.finishNode(node, type);
  8667. }
  8668. parseExport(node) {
  8669. const placeholder = this.parsePlaceholder("Identifier");
  8670. if (!placeholder) return super.parseExport(...arguments);
  8671. if (!this.isContextual(91) && !this.match(12)) {
  8672. node.specifiers = [];
  8673. node.source = null;
  8674. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  8675. return this.finishNode(node, "ExportNamedDeclaration");
  8676. }
  8677. this.expectPlugin("exportDefaultFrom");
  8678. const specifier = this.startNode();
  8679. specifier.exported = placeholder;
  8680. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  8681. return super.parseExport(node);
  8682. }
  8683. isExportDefaultSpecifier() {
  8684. if (this.match(59)) {
  8685. const next = this.nextTokenStart();
  8686. if (this.isUnparsedContextual(next, "from")) {
  8687. if (this.input.startsWith(tokenLabelName(134), this.nextTokenStartSince(next + 4))) {
  8688. return true;
  8689. }
  8690. }
  8691. }
  8692. return super.isExportDefaultSpecifier();
  8693. }
  8694. maybeParseExportDefaultSpecifier(node) {
  8695. if (node.specifiers && node.specifiers.length > 0) {
  8696. return true;
  8697. }
  8698. return super.maybeParseExportDefaultSpecifier(...arguments);
  8699. }
  8700. checkExport(node) {
  8701. const {
  8702. specifiers
  8703. } = node;
  8704. if (specifiers != null && specifiers.length) {
  8705. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  8706. }
  8707. super.checkExport(node);
  8708. node.specifiers = specifiers;
  8709. }
  8710. parseImport(node) {
  8711. const placeholder = this.parsePlaceholder("Identifier");
  8712. if (!placeholder) return super.parseImport(...arguments);
  8713. node.specifiers = [];
  8714. if (!this.isContextual(91) && !this.match(12)) {
  8715. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  8716. this.semicolon();
  8717. return this.finishNode(node, "ImportDeclaration");
  8718. }
  8719. const specifier = this.startNodeAtNode(placeholder);
  8720. specifier.local = placeholder;
  8721. this.finishNode(specifier, "ImportDefaultSpecifier");
  8722. node.specifiers.push(specifier);
  8723. if (this.eat(12)) {
  8724. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  8725. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  8726. }
  8727. this.expectContextual(91);
  8728. node.source = this.parseImportSource();
  8729. this.semicolon();
  8730. return this.finishNode(node, "ImportDeclaration");
  8731. }
  8732. parseImportSource() {
  8733. return this.parsePlaceholder("StringLiteral") || super.parseImportSource(...arguments);
  8734. }
  8735. });
  8736. var v8intrinsic = (superClass => class extends superClass {
  8737. parseV8Intrinsic() {
  8738. if (this.match(48)) {
  8739. const v8IntrinsicStart = this.state.start;
  8740. const node = this.startNode();
  8741. this.next();
  8742. if (tokenIsIdentifier(this.state.type)) {
  8743. const name = this.parseIdentifierName(this.state.start);
  8744. const identifier = this.createIdentifier(node, name);
  8745. identifier.type = "V8IntrinsicIdentifier";
  8746. if (this.match(10)) {
  8747. return identifier;
  8748. }
  8749. }
  8750. this.unexpected(v8IntrinsicStart);
  8751. }
  8752. }
  8753. parseExprAtom() {
  8754. return this.parseV8Intrinsic() || super.parseExprAtom(...arguments);
  8755. }
  8756. });
  8757. function hasPlugin(plugins, name) {
  8758. return plugins.some(plugin => {
  8759. if (Array.isArray(plugin)) {
  8760. return plugin[0] === name;
  8761. } else {
  8762. return plugin === name;
  8763. }
  8764. });
  8765. }
  8766. function getPluginOption(plugins, name, option) {
  8767. const plugin = plugins.find(plugin => {
  8768. if (Array.isArray(plugin)) {
  8769. return plugin[0] === name;
  8770. } else {
  8771. return plugin === name;
  8772. }
  8773. });
  8774. if (plugin && Array.isArray(plugin)) {
  8775. return plugin[1][option];
  8776. }
  8777. return null;
  8778. }
  8779. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  8780. const TOPIC_TOKENS = ["^", "%", "#"];
  8781. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  8782. function validatePlugins(plugins) {
  8783. if (hasPlugin(plugins, "decorators")) {
  8784. if (hasPlugin(plugins, "decorators-legacy")) {
  8785. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  8786. }
  8787. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  8788. if (decoratorsBeforeExport == null) {
  8789. 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'.");
  8790. } else if (typeof decoratorsBeforeExport !== "boolean") {
  8791. throw new Error("'decoratorsBeforeExport' must be a boolean.");
  8792. }
  8793. }
  8794. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  8795. throw new Error("Cannot combine flow and typescript plugins.");
  8796. }
  8797. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  8798. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  8799. }
  8800. if (hasPlugin(plugins, "pipelineOperator")) {
  8801. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  8802. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  8803. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  8804. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  8805. }
  8806. const tupleSyntaxIsHash = hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") === "hash";
  8807. if (proposal === "hack") {
  8808. if (hasPlugin(plugins, "placeholders")) {
  8809. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  8810. }
  8811. if (hasPlugin(plugins, "v8intrinsic")) {
  8812. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  8813. }
  8814. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  8815. if (!TOPIC_TOKENS.includes(topicToken)) {
  8816. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  8817. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  8818. }
  8819. if (topicToken === "#" && tupleSyntaxIsHash) {
  8820. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  8821. }
  8822. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  8823. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  8824. }
  8825. }
  8826. if (hasPlugin(plugins, "moduleAttributes")) {
  8827. {
  8828. if (hasPlugin(plugins, "importAssertions")) {
  8829. throw new Error("Cannot combine importAssertions and moduleAttributes plugins.");
  8830. }
  8831. const moduleAttributesVerionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  8832. if (moduleAttributesVerionPluginOption !== "may-2020") {
  8833. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  8834. }
  8835. }
  8836. }
  8837. if (hasPlugin(plugins, "recordAndTuple") && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  8838. throw new Error("'recordAndTuple' requires 'syntaxType' option whose value should be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  8839. }
  8840. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  8841. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  8842. error.missingPlugins = "doExpressions";
  8843. throw error;
  8844. }
  8845. }
  8846. const mixinPlugins = {
  8847. estree,
  8848. jsx,
  8849. flow,
  8850. typescript,
  8851. v8intrinsic,
  8852. placeholders
  8853. };
  8854. const mixinPluginNames = Object.keys(mixinPlugins);
  8855. const defaultOptions = {
  8856. sourceType: "script",
  8857. sourceFilename: undefined,
  8858. startColumn: 0,
  8859. startLine: 1,
  8860. allowAwaitOutsideFunction: false,
  8861. allowReturnOutsideFunction: false,
  8862. allowImportExportEverywhere: false,
  8863. allowSuperOutsideMethod: false,
  8864. allowUndeclaredExports: false,
  8865. plugins: [],
  8866. strictMode: null,
  8867. ranges: false,
  8868. tokens: false,
  8869. createParenthesizedExpressions: false,
  8870. errorRecovery: false,
  8871. attachComment: true
  8872. };
  8873. function getOptions(opts) {
  8874. const options = {};
  8875. for (const key of Object.keys(defaultOptions)) {
  8876. options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key];
  8877. }
  8878. return options;
  8879. }
  8880. const unwrapParenthesizedExpression = node => {
  8881. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  8882. };
  8883. class LValParser extends NodeUtils {
  8884. toAssignable(node, isLHS = false) {
  8885. var _node$extra, _node$extra3;
  8886. let parenthesized = undefined;
  8887. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  8888. parenthesized = unwrapParenthesizedExpression(node);
  8889. if (isLHS) {
  8890. if (parenthesized.type === "Identifier") {
  8891. this.expressionScope.recordParenthesizedIdentifierError(node.start, ErrorMessages.InvalidParenthesizedAssignment);
  8892. } else if (parenthesized.type !== "MemberExpression") {
  8893. this.raise(node.start, ErrorMessages.InvalidParenthesizedAssignment);
  8894. }
  8895. } else {
  8896. this.raise(node.start, ErrorMessages.InvalidParenthesizedAssignment);
  8897. }
  8898. }
  8899. switch (node.type) {
  8900. case "Identifier":
  8901. case "ObjectPattern":
  8902. case "ArrayPattern":
  8903. case "AssignmentPattern":
  8904. case "RestElement":
  8905. break;
  8906. case "ObjectExpression":
  8907. node.type = "ObjectPattern";
  8908. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  8909. var _node$extra2;
  8910. const prop = node.properties[i];
  8911. const isLast = i === last;
  8912. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  8913. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingComma) {
  8914. this.raiseRestNotLast(node.extra.trailingComma);
  8915. }
  8916. }
  8917. break;
  8918. case "ObjectProperty":
  8919. this.toAssignable(node.value, isLHS);
  8920. break;
  8921. case "SpreadElement":
  8922. {
  8923. this.checkToRestConversion(node);
  8924. node.type = "RestElement";
  8925. const arg = node.argument;
  8926. this.toAssignable(arg, isLHS);
  8927. break;
  8928. }
  8929. case "ArrayExpression":
  8930. node.type = "ArrayPattern";
  8931. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingComma, isLHS);
  8932. break;
  8933. case "AssignmentExpression":
  8934. if (node.operator !== "=") {
  8935. this.raise(node.left.end, ErrorMessages.MissingEqInAssignment);
  8936. }
  8937. node.type = "AssignmentPattern";
  8938. delete node.operator;
  8939. this.toAssignable(node.left, isLHS);
  8940. break;
  8941. case "ParenthesizedExpression":
  8942. this.toAssignable(parenthesized, isLHS);
  8943. break;
  8944. }
  8945. return node;
  8946. }
  8947. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  8948. if (prop.type === "ObjectMethod") {
  8949. const error = prop.kind === "get" || prop.kind === "set" ? ErrorMessages.PatternHasAccessor : ErrorMessages.PatternHasMethod;
  8950. this.raise(prop.key.start, error);
  8951. } else if (prop.type === "SpreadElement" && !isLast) {
  8952. this.raiseRestNotLast(prop.start);
  8953. } else {
  8954. this.toAssignable(prop, isLHS);
  8955. }
  8956. }
  8957. toAssignableList(exprList, trailingCommaPos, isLHS) {
  8958. let end = exprList.length;
  8959. if (end) {
  8960. const last = exprList[end - 1];
  8961. if ((last == null ? void 0 : last.type) === "RestElement") {
  8962. --end;
  8963. } else if ((last == null ? void 0 : last.type) === "SpreadElement") {
  8964. last.type = "RestElement";
  8965. let arg = last.argument;
  8966. this.toAssignable(arg, isLHS);
  8967. arg = unwrapParenthesizedExpression(arg);
  8968. if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern" && arg.type !== "ObjectPattern") {
  8969. this.unexpected(arg.start);
  8970. }
  8971. if (trailingCommaPos) {
  8972. this.raiseTrailingCommaAfterRest(trailingCommaPos);
  8973. }
  8974. --end;
  8975. }
  8976. }
  8977. for (let i = 0; i < end; i++) {
  8978. const elt = exprList[i];
  8979. if (elt) {
  8980. this.toAssignable(elt, isLHS);
  8981. if (elt.type === "RestElement") {
  8982. this.raiseRestNotLast(elt.start);
  8983. }
  8984. }
  8985. }
  8986. return exprList;
  8987. }
  8988. isAssignable(node, isBinding) {
  8989. switch (node.type) {
  8990. case "Identifier":
  8991. case "ObjectPattern":
  8992. case "ArrayPattern":
  8993. case "AssignmentPattern":
  8994. case "RestElement":
  8995. return true;
  8996. case "ObjectExpression":
  8997. {
  8998. const last = node.properties.length - 1;
  8999. return node.properties.every((prop, i) => {
  9000. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  9001. });
  9002. }
  9003. case "ObjectProperty":
  9004. return this.isAssignable(node.value);
  9005. case "SpreadElement":
  9006. return this.isAssignable(node.argument);
  9007. case "ArrayExpression":
  9008. return node.elements.every(element => element === null || this.isAssignable(element));
  9009. case "AssignmentExpression":
  9010. return node.operator === "=";
  9011. case "ParenthesizedExpression":
  9012. return this.isAssignable(node.expression);
  9013. case "MemberExpression":
  9014. case "OptionalMemberExpression":
  9015. return !isBinding;
  9016. default:
  9017. return false;
  9018. }
  9019. }
  9020. toReferencedList(exprList, isParenthesizedExpr) {
  9021. return exprList;
  9022. }
  9023. toReferencedListDeep(exprList, isParenthesizedExpr) {
  9024. this.toReferencedList(exprList, isParenthesizedExpr);
  9025. for (const expr of exprList) {
  9026. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  9027. this.toReferencedListDeep(expr.elements);
  9028. }
  9029. }
  9030. }
  9031. parseSpread(refExpressionErrors, refNeedsArrowPos) {
  9032. const node = this.startNode();
  9033. this.next();
  9034. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined, refNeedsArrowPos);
  9035. return this.finishNode(node, "SpreadElement");
  9036. }
  9037. parseRestBinding() {
  9038. const node = this.startNode();
  9039. this.next();
  9040. node.argument = this.parseBindingAtom();
  9041. return this.finishNode(node, "RestElement");
  9042. }
  9043. parseBindingAtom() {
  9044. switch (this.state.type) {
  9045. case 0:
  9046. {
  9047. const node = this.startNode();
  9048. this.next();
  9049. node.elements = this.parseBindingList(3, 93, true);
  9050. return this.finishNode(node, "ArrayPattern");
  9051. }
  9052. case 5:
  9053. return this.parseObjectLike(8, true);
  9054. }
  9055. return this.parseIdentifier();
  9056. }
  9057. parseBindingList(close, closeCharCode, allowEmpty, allowModifiers) {
  9058. const elts = [];
  9059. let first = true;
  9060. while (!this.eat(close)) {
  9061. if (first) {
  9062. first = false;
  9063. } else {
  9064. this.expect(12);
  9065. }
  9066. if (allowEmpty && this.match(12)) {
  9067. elts.push(null);
  9068. } else if (this.eat(close)) {
  9069. break;
  9070. } else if (this.match(21)) {
  9071. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding()));
  9072. this.checkCommaAfterRest(closeCharCode);
  9073. this.expect(close);
  9074. break;
  9075. } else {
  9076. const decorators = [];
  9077. if (this.match(24) && this.hasPlugin("decorators")) {
  9078. this.raise(this.state.start, ErrorMessages.UnsupportedParameterDecorator);
  9079. }
  9080. while (this.match(24)) {
  9081. decorators.push(this.parseDecorator());
  9082. }
  9083. elts.push(this.parseAssignableListItem(allowModifiers, decorators));
  9084. }
  9085. }
  9086. return elts;
  9087. }
  9088. parseBindingRestProperty(prop) {
  9089. this.next();
  9090. prop.argument = this.parseIdentifier();
  9091. this.checkCommaAfterRest(125);
  9092. return this.finishNode(prop, "RestElement");
  9093. }
  9094. parseBindingProperty() {
  9095. const prop = this.startNode();
  9096. const {
  9097. type,
  9098. start: startPos,
  9099. startLoc
  9100. } = this.state;
  9101. if (type === 21) {
  9102. return this.parseBindingRestProperty(prop);
  9103. } else {
  9104. this.parsePropertyName(prop);
  9105. }
  9106. prop.method = false;
  9107. this.parseObjPropValue(prop, startPos, startLoc, false, false, true, false);
  9108. return prop;
  9109. }
  9110. parseAssignableListItem(allowModifiers, decorators) {
  9111. const left = this.parseMaybeDefault();
  9112. this.parseAssignableListItemTypes(left);
  9113. const elt = this.parseMaybeDefault(left.start, left.loc.start, left);
  9114. if (decorators.length) {
  9115. left.decorators = decorators;
  9116. }
  9117. return elt;
  9118. }
  9119. parseAssignableListItemTypes(param) {
  9120. return param;
  9121. }
  9122. parseMaybeDefault(startPos, startLoc, left) {
  9123. var _startLoc, _startPos, _left;
  9124. startLoc = (_startLoc = startLoc) != null ? _startLoc : this.state.startLoc;
  9125. startPos = (_startPos = startPos) != null ? _startPos : this.state.start;
  9126. left = (_left = left) != null ? _left : this.parseBindingAtom();
  9127. if (!this.eat(27)) return left;
  9128. const node = this.startNodeAt(startPos, startLoc);
  9129. node.left = left;
  9130. node.right = this.parseMaybeAssignAllowIn();
  9131. return this.finishNode(node, "AssignmentPattern");
  9132. }
  9133. checkLVal(expr, contextDescription, bindingType = BIND_NONE, checkClashes, disallowLetBinding, strictModeChanged = false) {
  9134. switch (expr.type) {
  9135. case "Identifier":
  9136. {
  9137. const {
  9138. name
  9139. } = expr;
  9140. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(name, this.inModule) : isStrictBindOnlyReservedWord(name))) {
  9141. this.raise(expr.start, bindingType === BIND_NONE ? ErrorMessages.StrictEvalArguments : ErrorMessages.StrictEvalArgumentsBinding, name);
  9142. }
  9143. if (checkClashes) {
  9144. if (checkClashes.has(name)) {
  9145. this.raise(expr.start, ErrorMessages.ParamDupe);
  9146. } else {
  9147. checkClashes.add(name);
  9148. }
  9149. }
  9150. if (disallowLetBinding && name === "let") {
  9151. this.raise(expr.start, ErrorMessages.LetInLexicalBinding);
  9152. }
  9153. if (!(bindingType & BIND_NONE)) {
  9154. this.scope.declareName(name, bindingType, expr.start);
  9155. }
  9156. break;
  9157. }
  9158. case "MemberExpression":
  9159. if (bindingType !== BIND_NONE) {
  9160. this.raise(expr.start, ErrorMessages.InvalidPropertyBindingPattern);
  9161. }
  9162. break;
  9163. case "ObjectPattern":
  9164. for (let prop of expr.properties) {
  9165. if (this.isObjectProperty(prop)) prop = prop.value;else if (this.isObjectMethod(prop)) continue;
  9166. this.checkLVal(prop, "object destructuring pattern", bindingType, checkClashes, disallowLetBinding);
  9167. }
  9168. break;
  9169. case "ArrayPattern":
  9170. for (const elem of expr.elements) {
  9171. if (elem) {
  9172. this.checkLVal(elem, "array destructuring pattern", bindingType, checkClashes, disallowLetBinding);
  9173. }
  9174. }
  9175. break;
  9176. case "AssignmentPattern":
  9177. this.checkLVal(expr.left, "assignment pattern", bindingType, checkClashes);
  9178. break;
  9179. case "RestElement":
  9180. this.checkLVal(expr.argument, "rest element", bindingType, checkClashes);
  9181. break;
  9182. case "ParenthesizedExpression":
  9183. this.checkLVal(expr.expression, "parenthesized expression", bindingType, checkClashes);
  9184. break;
  9185. default:
  9186. {
  9187. this.raise(expr.start, bindingType === BIND_NONE ? ErrorMessages.InvalidLhs : ErrorMessages.InvalidLhsBinding, contextDescription);
  9188. }
  9189. }
  9190. }
  9191. checkToRestConversion(node) {
  9192. if (node.argument.type !== "Identifier" && node.argument.type !== "MemberExpression") {
  9193. this.raise(node.argument.start, ErrorMessages.InvalidRestAssignmentPattern);
  9194. }
  9195. }
  9196. checkCommaAfterRest(close) {
  9197. if (this.match(12)) {
  9198. if (this.lookaheadCharCode() === close) {
  9199. this.raiseTrailingCommaAfterRest(this.state.start);
  9200. } else {
  9201. this.raiseRestNotLast(this.state.start);
  9202. }
  9203. }
  9204. }
  9205. raiseRestNotLast(pos) {
  9206. throw this.raise(pos, ErrorMessages.ElementAfterRest);
  9207. }
  9208. raiseTrailingCommaAfterRest(pos) {
  9209. this.raise(pos, ErrorMessages.RestTrailingComma);
  9210. }
  9211. }
  9212. const invalidHackPipeBodies = new Map([["ArrowFunctionExpression", "arrow function"], ["AssignmentExpression", "assignment"], ["ConditionalExpression", "conditional"], ["YieldExpression", "yield"]]);
  9213. class ExpressionParser extends LValParser {
  9214. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  9215. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  9216. return;
  9217. }
  9218. const key = prop.key;
  9219. const name = key.type === "Identifier" ? key.name : key.value;
  9220. if (name === "__proto__") {
  9221. if (isRecord) {
  9222. this.raise(key.start, ErrorMessages.RecordNoProto);
  9223. return;
  9224. }
  9225. if (protoRef.used) {
  9226. if (refExpressionErrors) {
  9227. if (refExpressionErrors.doubleProto === -1) {
  9228. refExpressionErrors.doubleProto = key.start;
  9229. }
  9230. } else {
  9231. this.raise(key.start, ErrorMessages.DuplicateProto);
  9232. }
  9233. }
  9234. protoRef.used = true;
  9235. }
  9236. }
  9237. shouldExitDescending(expr, potentialArrowAt) {
  9238. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  9239. }
  9240. getExpression() {
  9241. this.enterInitialScopes();
  9242. this.nextToken();
  9243. const expr = this.parseExpression();
  9244. if (!this.match(129)) {
  9245. this.unexpected();
  9246. }
  9247. this.finalizeRemainingComments();
  9248. expr.comments = this.state.comments;
  9249. expr.errors = this.state.errors;
  9250. if (this.options.tokens) {
  9251. expr.tokens = this.tokens;
  9252. }
  9253. return expr;
  9254. }
  9255. parseExpression(disallowIn, refExpressionErrors) {
  9256. if (disallowIn) {
  9257. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  9258. }
  9259. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  9260. }
  9261. parseExpressionBase(refExpressionErrors) {
  9262. const startPos = this.state.start;
  9263. const startLoc = this.state.startLoc;
  9264. const expr = this.parseMaybeAssign(refExpressionErrors);
  9265. if (this.match(12)) {
  9266. const node = this.startNodeAt(startPos, startLoc);
  9267. node.expressions = [expr];
  9268. while (this.eat(12)) {
  9269. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  9270. }
  9271. this.toReferencedList(node.expressions);
  9272. return this.finishNode(node, "SequenceExpression");
  9273. }
  9274. return expr;
  9275. }
  9276. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  9277. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  9278. }
  9279. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  9280. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  9281. }
  9282. setOptionalParametersError(refExpressionErrors, resultError) {
  9283. var _resultError$pos;
  9284. refExpressionErrors.optionalParameters = (_resultError$pos = resultError == null ? void 0 : resultError.pos) != null ? _resultError$pos : this.state.start;
  9285. }
  9286. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9287. const startPos = this.state.start;
  9288. const startLoc = this.state.startLoc;
  9289. if (this.isContextual(99)) {
  9290. if (this.prodParam.hasYield) {
  9291. let left = this.parseYield();
  9292. if (afterLeftParse) {
  9293. left = afterLeftParse.call(this, left, startPos, startLoc);
  9294. }
  9295. return left;
  9296. }
  9297. }
  9298. let ownExpressionErrors;
  9299. if (refExpressionErrors) {
  9300. ownExpressionErrors = false;
  9301. } else {
  9302. refExpressionErrors = new ExpressionErrors();
  9303. ownExpressionErrors = true;
  9304. }
  9305. const {
  9306. type
  9307. } = this.state;
  9308. if (type === 10 || tokenIsIdentifier(type)) {
  9309. this.state.potentialArrowAt = this.state.start;
  9310. }
  9311. let left = this.parseMaybeConditional(refExpressionErrors);
  9312. if (afterLeftParse) {
  9313. left = afterLeftParse.call(this, left, startPos, startLoc);
  9314. }
  9315. if (tokenIsAssignment(this.state.type)) {
  9316. const node = this.startNodeAt(startPos, startLoc);
  9317. const operator = this.state.value;
  9318. node.operator = operator;
  9319. if (this.match(27)) {
  9320. node.left = this.toAssignable(left, true);
  9321. if (refExpressionErrors.doubleProto >= startPos) {
  9322. refExpressionErrors.doubleProto = -1;
  9323. }
  9324. if (refExpressionErrors.shorthandAssign >= startPos) {
  9325. refExpressionErrors.shorthandAssign = -1;
  9326. }
  9327. } else {
  9328. node.left = left;
  9329. }
  9330. this.checkLVal(left, "assignment expression");
  9331. this.next();
  9332. node.right = this.parseMaybeAssign();
  9333. return this.finishNode(node, "AssignmentExpression");
  9334. } else if (ownExpressionErrors) {
  9335. this.checkExpressionErrors(refExpressionErrors, true);
  9336. }
  9337. return left;
  9338. }
  9339. parseMaybeConditional(refExpressionErrors) {
  9340. const startPos = this.state.start;
  9341. const startLoc = this.state.startLoc;
  9342. const potentialArrowAt = this.state.potentialArrowAt;
  9343. const expr = this.parseExprOps(refExpressionErrors);
  9344. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  9345. return expr;
  9346. }
  9347. return this.parseConditional(expr, startPos, startLoc, refExpressionErrors);
  9348. }
  9349. parseConditional(expr, startPos, startLoc, refExpressionErrors) {
  9350. if (this.eat(17)) {
  9351. const node = this.startNodeAt(startPos, startLoc);
  9352. node.test = expr;
  9353. node.consequent = this.parseMaybeAssignAllowIn();
  9354. this.expect(14);
  9355. node.alternate = this.parseMaybeAssign();
  9356. return this.finishNode(node, "ConditionalExpression");
  9357. }
  9358. return expr;
  9359. }
  9360. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  9361. return this.match(128) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  9362. }
  9363. parseExprOps(refExpressionErrors) {
  9364. const startPos = this.state.start;
  9365. const startLoc = this.state.startLoc;
  9366. const potentialArrowAt = this.state.potentialArrowAt;
  9367. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  9368. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  9369. return expr;
  9370. }
  9371. return this.parseExprOp(expr, startPos, startLoc, -1);
  9372. }
  9373. parseExprOp(left, leftStartPos, leftStartLoc, minPrec) {
  9374. if (this.isPrivateName(left)) {
  9375. const value = this.getPrivateNameSV(left);
  9376. const {
  9377. start
  9378. } = left;
  9379. if (minPrec >= tokenOperatorPrecedence(52) || !this.prodParam.hasIn || !this.match(52)) {
  9380. this.raise(start, ErrorMessages.PrivateInExpectedIn, value);
  9381. }
  9382. this.classScope.usePrivateName(value, start);
  9383. }
  9384. const op = this.state.type;
  9385. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(52))) {
  9386. let prec = tokenOperatorPrecedence(op);
  9387. if (prec > minPrec) {
  9388. if (op === 35) {
  9389. this.expectPlugin("pipelineOperator");
  9390. if (this.state.inFSharpPipelineDirectBody) {
  9391. return left;
  9392. }
  9393. this.checkPipelineAtInfixOperator(left, leftStartPos);
  9394. }
  9395. const node = this.startNodeAt(leftStartPos, leftStartLoc);
  9396. node.left = left;
  9397. node.operator = this.state.value;
  9398. const logical = op === 37 || op === 38;
  9399. const coalesce = op === 36;
  9400. if (coalesce) {
  9401. prec = tokenOperatorPrecedence(38);
  9402. }
  9403. this.next();
  9404. if (op === 35 && this.getPluginOption("pipelineOperator", "proposal") === "minimal") {
  9405. if (this.state.type === 90 && this.prodParam.hasAwait) {
  9406. throw this.raise(this.state.start, ErrorMessages.UnexpectedAwaitAfterPipelineBody);
  9407. }
  9408. }
  9409. node.right = this.parseExprOpRightExpr(op, prec);
  9410. this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  9411. const nextOp = this.state.type;
  9412. if (coalesce && (nextOp === 37 || nextOp === 38) || logical && nextOp === 36) {
  9413. throw this.raise(this.state.start, ErrorMessages.MixingCoalesceWithLogical);
  9414. }
  9415. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec);
  9416. }
  9417. }
  9418. return left;
  9419. }
  9420. parseExprOpRightExpr(op, prec) {
  9421. const startPos = this.state.start;
  9422. const startLoc = this.state.startLoc;
  9423. switch (op) {
  9424. case 35:
  9425. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  9426. case "hack":
  9427. return this.withTopicBindingContext(() => {
  9428. return this.parseHackPipeBody();
  9429. });
  9430. case "smart":
  9431. return this.withTopicBindingContext(() => {
  9432. if (this.prodParam.hasYield && this.isContextual(99)) {
  9433. throw this.raise(this.state.start, ErrorMessages.PipeBodyIsTighter, this.state.value);
  9434. }
  9435. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startPos, startLoc);
  9436. });
  9437. case "fsharp":
  9438. return this.withSoloAwaitPermittingContext(() => {
  9439. return this.parseFSharpPipelineBody(prec);
  9440. });
  9441. }
  9442. default:
  9443. return this.parseExprOpBaseRightExpr(op, prec);
  9444. }
  9445. }
  9446. parseExprOpBaseRightExpr(op, prec) {
  9447. const startPos = this.state.start;
  9448. const startLoc = this.state.startLoc;
  9449. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startPos, startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  9450. }
  9451. parseHackPipeBody() {
  9452. var _body$extra;
  9453. const {
  9454. start
  9455. } = this.state;
  9456. const body = this.parseMaybeAssign();
  9457. if (invalidHackPipeBodies.has(body.type) && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  9458. this.raise(start, ErrorMessages.PipeUnparenthesizedBody, invalidHackPipeBodies.get(body.type));
  9459. }
  9460. if (!this.topicReferenceWasUsedInCurrentContext()) {
  9461. this.raise(start, ErrorMessages.PipeTopicUnused);
  9462. }
  9463. return body;
  9464. }
  9465. checkExponentialAfterUnary(node) {
  9466. if (this.match(51)) {
  9467. this.raise(node.argument.start, ErrorMessages.UnexpectedTokenUnaryExponentiation);
  9468. }
  9469. }
  9470. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9471. const startPos = this.state.start;
  9472. const startLoc = this.state.startLoc;
  9473. const isAwait = this.isContextual(90);
  9474. if (isAwait && this.isAwaitAllowed()) {
  9475. this.next();
  9476. const expr = this.parseAwait(startPos, startLoc);
  9477. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  9478. return expr;
  9479. }
  9480. const update = this.match(32);
  9481. const node = this.startNode();
  9482. if (tokenIsPrefix(this.state.type)) {
  9483. node.operator = this.state.value;
  9484. node.prefix = true;
  9485. if (this.match(66)) {
  9486. this.expectPlugin("throwExpressions");
  9487. }
  9488. const isDelete = this.match(83);
  9489. this.next();
  9490. node.argument = this.parseMaybeUnary(null, true);
  9491. this.checkExpressionErrors(refExpressionErrors, true);
  9492. if (this.state.strict && isDelete) {
  9493. const arg = node.argument;
  9494. if (arg.type === "Identifier") {
  9495. this.raise(node.start, ErrorMessages.StrictDelete);
  9496. } else if (this.hasPropertyAsPrivateName(arg)) {
  9497. this.raise(node.start, ErrorMessages.DeletePrivateField);
  9498. }
  9499. }
  9500. if (!update) {
  9501. if (!sawUnary) this.checkExponentialAfterUnary(node);
  9502. return this.finishNode(node, "UnaryExpression");
  9503. }
  9504. }
  9505. const expr = this.parseUpdate(node, update, refExpressionErrors);
  9506. if (isAwait) {
  9507. const {
  9508. type
  9509. } = this.state;
  9510. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(48);
  9511. if (startsExpr && !this.isAmbiguousAwait()) {
  9512. this.raiseOverwrite(startPos, ErrorMessages.AwaitNotInAsyncContext);
  9513. return this.parseAwait(startPos, startLoc);
  9514. }
  9515. }
  9516. return expr;
  9517. }
  9518. parseUpdate(node, update, refExpressionErrors) {
  9519. if (update) {
  9520. this.checkLVal(node.argument, "prefix operation");
  9521. return this.finishNode(node, "UpdateExpression");
  9522. }
  9523. const startPos = this.state.start;
  9524. const startLoc = this.state.startLoc;
  9525. let expr = this.parseExprSubscripts(refExpressionErrors);
  9526. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  9527. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  9528. const node = this.startNodeAt(startPos, startLoc);
  9529. node.operator = this.state.value;
  9530. node.prefix = false;
  9531. node.argument = expr;
  9532. this.checkLVal(expr, "postfix operation");
  9533. this.next();
  9534. expr = this.finishNode(node, "UpdateExpression");
  9535. }
  9536. return expr;
  9537. }
  9538. parseExprSubscripts(refExpressionErrors) {
  9539. const startPos = this.state.start;
  9540. const startLoc = this.state.startLoc;
  9541. const potentialArrowAt = this.state.potentialArrowAt;
  9542. const expr = this.parseExprAtom(refExpressionErrors);
  9543. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  9544. return expr;
  9545. }
  9546. return this.parseSubscripts(expr, startPos, startLoc);
  9547. }
  9548. parseSubscripts(base, startPos, startLoc, noCalls) {
  9549. const state = {
  9550. optionalChainMember: false,
  9551. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  9552. stop: false
  9553. };
  9554. do {
  9555. base = this.parseSubscript(base, startPos, startLoc, noCalls, state);
  9556. state.maybeAsyncArrow = false;
  9557. } while (!state.stop);
  9558. return base;
  9559. }
  9560. parseSubscript(base, startPos, startLoc, noCalls, state) {
  9561. if (!noCalls && this.eat(15)) {
  9562. return this.parseBind(base, startPos, startLoc, noCalls, state);
  9563. } else if (this.match(22)) {
  9564. return this.parseTaggedTemplateExpression(base, startPos, startLoc, state);
  9565. }
  9566. let optional = false;
  9567. if (this.match(18)) {
  9568. if (noCalls && this.lookaheadCharCode() === 40) {
  9569. state.stop = true;
  9570. return base;
  9571. }
  9572. state.optionalChainMember = optional = true;
  9573. this.next();
  9574. }
  9575. if (!noCalls && this.match(10)) {
  9576. return this.parseCoverCallAndAsyncArrowHead(base, startPos, startLoc, state, optional);
  9577. } else {
  9578. const computed = this.eat(0);
  9579. if (computed || optional || this.eat(16)) {
  9580. return this.parseMember(base, startPos, startLoc, state, computed, optional);
  9581. } else {
  9582. state.stop = true;
  9583. return base;
  9584. }
  9585. }
  9586. }
  9587. parseMember(base, startPos, startLoc, state, computed, optional) {
  9588. const node = this.startNodeAt(startPos, startLoc);
  9589. node.object = base;
  9590. node.computed = computed;
  9591. const privateName = !computed && this.match(128) && this.state.value;
  9592. const property = computed ? this.parseExpression() : privateName ? this.parsePrivateName() : this.parseIdentifier(true);
  9593. if (privateName !== false) {
  9594. if (node.object.type === "Super") {
  9595. this.raise(startPos, ErrorMessages.SuperPrivateField);
  9596. }
  9597. this.classScope.usePrivateName(privateName, property.start);
  9598. }
  9599. node.property = property;
  9600. if (computed) {
  9601. this.expect(3);
  9602. }
  9603. if (state.optionalChainMember) {
  9604. node.optional = optional;
  9605. return this.finishNode(node, "OptionalMemberExpression");
  9606. } else {
  9607. return this.finishNode(node, "MemberExpression");
  9608. }
  9609. }
  9610. parseBind(base, startPos, startLoc, noCalls, state) {
  9611. const node = this.startNodeAt(startPos, startLoc);
  9612. node.object = base;
  9613. node.callee = this.parseNoCallExpr();
  9614. state.stop = true;
  9615. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startPos, startLoc, noCalls);
  9616. }
  9617. parseCoverCallAndAsyncArrowHead(base, startPos, startLoc, state, optional) {
  9618. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9619. let refExpressionErrors = null;
  9620. this.state.maybeInArrowParameters = true;
  9621. this.next();
  9622. let node = this.startNodeAt(startPos, startLoc);
  9623. node.callee = base;
  9624. if (state.maybeAsyncArrow) {
  9625. this.expressionScope.enter(newAsyncArrowScope());
  9626. refExpressionErrors = new ExpressionErrors();
  9627. }
  9628. if (state.optionalChainMember) {
  9629. node.optional = optional;
  9630. }
  9631. if (optional) {
  9632. node.arguments = this.parseCallExpressionArguments(11);
  9633. } else {
  9634. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  9635. }
  9636. this.finishCallExpression(node, state.optionalChainMember);
  9637. if (state.maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  9638. state.stop = true;
  9639. this.expressionScope.validateAsPattern();
  9640. this.expressionScope.exit();
  9641. node = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node);
  9642. } else {
  9643. if (state.maybeAsyncArrow) {
  9644. this.checkExpressionErrors(refExpressionErrors, true);
  9645. this.expressionScope.exit();
  9646. }
  9647. this.toReferencedArguments(node);
  9648. }
  9649. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9650. return node;
  9651. }
  9652. toReferencedArguments(node, isParenthesizedExpr) {
  9653. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  9654. }
  9655. parseTaggedTemplateExpression(base, startPos, startLoc, state) {
  9656. const node = this.startNodeAt(startPos, startLoc);
  9657. node.tag = base;
  9658. node.quasi = this.parseTemplate(true);
  9659. if (state.optionalChainMember) {
  9660. this.raise(startPos, ErrorMessages.OptionalChainingNoTemplate);
  9661. }
  9662. return this.finishNode(node, "TaggedTemplateExpression");
  9663. }
  9664. atPossibleAsyncArrow(base) {
  9665. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.state.potentialArrowAt;
  9666. }
  9667. finishCallExpression(node, optional) {
  9668. if (node.callee.type === "Import") {
  9669. if (node.arguments.length === 2) {
  9670. {
  9671. if (!this.hasPlugin("moduleAttributes")) {
  9672. this.expectPlugin("importAssertions");
  9673. }
  9674. }
  9675. }
  9676. if (node.arguments.length === 0 || node.arguments.length > 2) {
  9677. this.raise(node.start, ErrorMessages.ImportCallArity, this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? "one or two arguments" : "one argument");
  9678. } else {
  9679. for (const arg of node.arguments) {
  9680. if (arg.type === "SpreadElement") {
  9681. this.raise(arg.start, ErrorMessages.ImportCallSpreadArgument);
  9682. }
  9683. }
  9684. }
  9685. }
  9686. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  9687. }
  9688. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  9689. const elts = [];
  9690. let first = true;
  9691. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  9692. this.state.inFSharpPipelineDirectBody = false;
  9693. while (!this.eat(close)) {
  9694. if (first) {
  9695. first = false;
  9696. } else {
  9697. this.expect(12);
  9698. if (this.match(close)) {
  9699. if (dynamicImport && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  9700. this.raise(this.state.lastTokStart, ErrorMessages.ImportCallArgumentTrailingComma);
  9701. }
  9702. if (nodeForExtra) {
  9703. this.addExtra(nodeForExtra, "trailingComma", this.state.lastTokStart);
  9704. }
  9705. this.next();
  9706. break;
  9707. }
  9708. }
  9709. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  9710. }
  9711. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  9712. return elts;
  9713. }
  9714. shouldParseAsyncArrow() {
  9715. return this.match(19) && !this.canInsertSemicolon();
  9716. }
  9717. parseAsyncArrowFromCallExpression(node, call) {
  9718. var _call$extra;
  9719. this.resetPreviousNodeTrailingComments(call);
  9720. this.expect(19);
  9721. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingComma);
  9722. if (call.innerComments) {
  9723. setInnerComments(node, call.innerComments);
  9724. }
  9725. if (call.callee.trailingComments) {
  9726. setInnerComments(node, call.callee.trailingComments);
  9727. }
  9728. return node;
  9729. }
  9730. parseNoCallExpr() {
  9731. const startPos = this.state.start;
  9732. const startLoc = this.state.startLoc;
  9733. return this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  9734. }
  9735. parseExprAtom(refExpressionErrors) {
  9736. let node;
  9737. const {
  9738. type
  9739. } = this.state;
  9740. switch (type) {
  9741. case 73:
  9742. return this.parseSuper();
  9743. case 77:
  9744. node = this.startNode();
  9745. this.next();
  9746. if (this.match(16)) {
  9747. return this.parseImportMetaProperty(node);
  9748. }
  9749. if (!this.match(10)) {
  9750. this.raise(this.state.lastTokStart, ErrorMessages.UnsupportedImport);
  9751. }
  9752. return this.finishNode(node, "Import");
  9753. case 72:
  9754. node = this.startNode();
  9755. this.next();
  9756. return this.finishNode(node, "ThisExpression");
  9757. case 84:
  9758. {
  9759. return this.parseDo(this.startNode(), false);
  9760. }
  9761. case 50:
  9762. case 29:
  9763. {
  9764. this.readRegexp();
  9765. return this.parseRegExpLiteral(this.state.value);
  9766. }
  9767. case 124:
  9768. return this.parseNumericLiteral(this.state.value);
  9769. case 125:
  9770. return this.parseBigIntLiteral(this.state.value);
  9771. case 126:
  9772. return this.parseDecimalLiteral(this.state.value);
  9773. case 123:
  9774. return this.parseStringLiteral(this.state.value);
  9775. case 78:
  9776. return this.parseNullLiteral();
  9777. case 79:
  9778. return this.parseBooleanLiteral(true);
  9779. case 80:
  9780. return this.parseBooleanLiteral(false);
  9781. case 10:
  9782. {
  9783. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  9784. return this.parseParenAndDistinguishExpression(canBeArrow);
  9785. }
  9786. case 2:
  9787. case 1:
  9788. {
  9789. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  9790. }
  9791. case 0:
  9792. {
  9793. return this.parseArrayLike(3, true, false, refExpressionErrors);
  9794. }
  9795. case 6:
  9796. case 7:
  9797. {
  9798. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  9799. }
  9800. case 5:
  9801. {
  9802. return this.parseObjectLike(8, false, false, refExpressionErrors);
  9803. }
  9804. case 62:
  9805. return this.parseFunctionOrFunctionSent();
  9806. case 24:
  9807. this.parseDecorators();
  9808. case 74:
  9809. node = this.startNode();
  9810. this.takeDecorators(node);
  9811. return this.parseClass(node, false);
  9812. case 71:
  9813. return this.parseNewOrNewTarget();
  9814. case 22:
  9815. return this.parseTemplate(false);
  9816. case 15:
  9817. {
  9818. node = this.startNode();
  9819. this.next();
  9820. node.object = null;
  9821. const callee = node.callee = this.parseNoCallExpr();
  9822. if (callee.type === "MemberExpression") {
  9823. return this.finishNode(node, "BindExpression");
  9824. } else {
  9825. throw this.raise(callee.start, ErrorMessages.UnsupportedBind);
  9826. }
  9827. }
  9828. case 128:
  9829. {
  9830. this.raise(this.state.start, ErrorMessages.PrivateInExpectedIn, this.state.value);
  9831. return this.parsePrivateName();
  9832. }
  9833. case 31:
  9834. {
  9835. return this.parseTopicReferenceThenEqualsSign(48, "%");
  9836. }
  9837. case 30:
  9838. {
  9839. return this.parseTopicReferenceThenEqualsSign(40, "^");
  9840. }
  9841. case 40:
  9842. case 48:
  9843. case 25:
  9844. {
  9845. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  9846. if (pipeProposal) {
  9847. return this.parseTopicReference(pipeProposal);
  9848. } else {
  9849. throw this.unexpected();
  9850. }
  9851. }
  9852. case 43:
  9853. {
  9854. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  9855. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  9856. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  9857. break;
  9858. } else {
  9859. throw this.unexpected();
  9860. }
  9861. }
  9862. default:
  9863. if (tokenIsIdentifier(type)) {
  9864. if (this.isContextual(117) && this.lookaheadCharCode() === 123 && !this.hasFollowingLineBreak()) {
  9865. return this.parseModuleExpression();
  9866. }
  9867. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  9868. const containsEsc = this.state.containsEsc;
  9869. const id = this.parseIdentifier();
  9870. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  9871. const {
  9872. type
  9873. } = this.state;
  9874. if (type === 62) {
  9875. this.resetPreviousNodeTrailingComments(id);
  9876. this.next();
  9877. return this.parseFunction(this.startNodeAtNode(id), undefined, true);
  9878. } else if (tokenIsIdentifier(type)) {
  9879. if (this.lookaheadCharCode() === 61) {
  9880. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  9881. } else {
  9882. return id;
  9883. }
  9884. } else if (type === 84) {
  9885. this.resetPreviousNodeTrailingComments(id);
  9886. return this.parseDo(this.startNodeAtNode(id), true);
  9887. }
  9888. }
  9889. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  9890. this.next();
  9891. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  9892. }
  9893. return id;
  9894. } else {
  9895. throw this.unexpected();
  9896. }
  9897. }
  9898. }
  9899. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  9900. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  9901. if (pipeProposal) {
  9902. this.state.type = topicTokenType;
  9903. this.state.value = topicTokenValue;
  9904. this.state.pos--;
  9905. this.state.end--;
  9906. this.state.endLoc.column--;
  9907. return this.parseTopicReference(pipeProposal);
  9908. } else {
  9909. throw this.unexpected();
  9910. }
  9911. }
  9912. parseTopicReference(pipeProposal) {
  9913. const node = this.startNode();
  9914. const start = this.state.start;
  9915. const tokenType = this.state.type;
  9916. this.next();
  9917. return this.finishTopicReference(node, start, pipeProposal, tokenType);
  9918. }
  9919. finishTopicReference(node, start, pipeProposal, tokenType) {
  9920. if (this.testTopicReferenceConfiguration(pipeProposal, start, tokenType)) {
  9921. let nodeType;
  9922. if (pipeProposal === "smart") {
  9923. nodeType = "PipelinePrimaryTopicReference";
  9924. } else {
  9925. nodeType = "TopicReference";
  9926. }
  9927. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  9928. if (pipeProposal === "smart") {
  9929. this.raise(start, ErrorMessages.PrimaryTopicNotAllowed);
  9930. } else {
  9931. this.raise(start, ErrorMessages.PipeTopicUnbound);
  9932. }
  9933. }
  9934. this.registerTopicReference();
  9935. return this.finishNode(node, nodeType);
  9936. } else {
  9937. throw this.raise(start, ErrorMessages.PipeTopicUnconfiguredToken, tokenLabelName(tokenType));
  9938. }
  9939. }
  9940. testTopicReferenceConfiguration(pipeProposal, start, tokenType) {
  9941. switch (pipeProposal) {
  9942. case "hack":
  9943. {
  9944. const pluginTopicToken = this.getPluginOption("pipelineOperator", "topicToken");
  9945. return tokenLabelName(tokenType) === pluginTopicToken;
  9946. }
  9947. case "smart":
  9948. return tokenType === 25;
  9949. default:
  9950. throw this.raise(start, ErrorMessages.PipeTopicRequiresHackPipes);
  9951. }
  9952. }
  9953. parseAsyncArrowUnaryFunction(node) {
  9954. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  9955. const params = [this.parseIdentifier()];
  9956. this.prodParam.exit();
  9957. if (this.hasPrecedingLineBreak()) {
  9958. this.raise(this.state.pos, ErrorMessages.LineTerminatorBeforeArrow);
  9959. }
  9960. this.expect(19);
  9961. this.parseArrowExpression(node, params, true);
  9962. return node;
  9963. }
  9964. parseDo(node, isAsync) {
  9965. this.expectPlugin("doExpressions");
  9966. if (isAsync) {
  9967. this.expectPlugin("asyncDoExpressions");
  9968. }
  9969. node.async = isAsync;
  9970. this.next();
  9971. const oldLabels = this.state.labels;
  9972. this.state.labels = [];
  9973. if (isAsync) {
  9974. this.prodParam.enter(PARAM_AWAIT);
  9975. node.body = this.parseBlock();
  9976. this.prodParam.exit();
  9977. } else {
  9978. node.body = this.parseBlock();
  9979. }
  9980. this.state.labels = oldLabels;
  9981. return this.finishNode(node, "DoExpression");
  9982. }
  9983. parseSuper() {
  9984. const node = this.startNode();
  9985. this.next();
  9986. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  9987. this.raise(node.start, ErrorMessages.SuperNotAllowed);
  9988. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  9989. this.raise(node.start, ErrorMessages.UnexpectedSuper);
  9990. }
  9991. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  9992. this.raise(node.start, ErrorMessages.UnsupportedSuper);
  9993. }
  9994. return this.finishNode(node, "Super");
  9995. }
  9996. parsePrivateName() {
  9997. const node = this.startNode();
  9998. const id = this.startNodeAt(this.state.start + 1, new Position(this.state.curLine, this.state.start + 1 - this.state.lineStart));
  9999. const name = this.state.value;
  10000. this.next();
  10001. node.id = this.createIdentifier(id, name);
  10002. return this.finishNode(node, "PrivateName");
  10003. }
  10004. parseFunctionOrFunctionSent() {
  10005. const node = this.startNode();
  10006. this.next();
  10007. if (this.prodParam.hasYield && this.match(16)) {
  10008. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  10009. this.next();
  10010. if (this.match(96)) {
  10011. this.expectPlugin("functionSent");
  10012. } else if (!this.hasPlugin("functionSent")) {
  10013. this.unexpected();
  10014. }
  10015. return this.parseMetaProperty(node, meta, "sent");
  10016. }
  10017. return this.parseFunction(node);
  10018. }
  10019. parseMetaProperty(node, meta, propertyName) {
  10020. node.meta = meta;
  10021. const containsEsc = this.state.containsEsc;
  10022. node.property = this.parseIdentifier(true);
  10023. if (node.property.name !== propertyName || containsEsc) {
  10024. this.raise(node.property.start, ErrorMessages.UnsupportedMetaProperty, meta.name, propertyName);
  10025. }
  10026. return this.finishNode(node, "MetaProperty");
  10027. }
  10028. parseImportMetaProperty(node) {
  10029. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  10030. this.next();
  10031. if (this.isContextual(94)) {
  10032. if (!this.inModule) {
  10033. this.raise(id.start, SourceTypeModuleErrorMessages.ImportMetaOutsideModule);
  10034. }
  10035. this.sawUnambiguousESM = true;
  10036. }
  10037. return this.parseMetaProperty(node, id, "meta");
  10038. }
  10039. parseLiteralAtNode(value, type, node) {
  10040. this.addExtra(node, "rawValue", value);
  10041. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  10042. node.value = value;
  10043. this.next();
  10044. return this.finishNode(node, type);
  10045. }
  10046. parseLiteral(value, type) {
  10047. const node = this.startNode();
  10048. return this.parseLiteralAtNode(value, type, node);
  10049. }
  10050. parseStringLiteral(value) {
  10051. return this.parseLiteral(value, "StringLiteral");
  10052. }
  10053. parseNumericLiteral(value) {
  10054. return this.parseLiteral(value, "NumericLiteral");
  10055. }
  10056. parseBigIntLiteral(value) {
  10057. return this.parseLiteral(value, "BigIntLiteral");
  10058. }
  10059. parseDecimalLiteral(value) {
  10060. return this.parseLiteral(value, "DecimalLiteral");
  10061. }
  10062. parseRegExpLiteral(value) {
  10063. const node = this.parseLiteral(value.value, "RegExpLiteral");
  10064. node.pattern = value.pattern;
  10065. node.flags = value.flags;
  10066. return node;
  10067. }
  10068. parseBooleanLiteral(value) {
  10069. const node = this.startNode();
  10070. node.value = value;
  10071. this.next();
  10072. return this.finishNode(node, "BooleanLiteral");
  10073. }
  10074. parseNullLiteral() {
  10075. const node = this.startNode();
  10076. this.next();
  10077. return this.finishNode(node, "NullLiteral");
  10078. }
  10079. parseParenAndDistinguishExpression(canBeArrow) {
  10080. const startPos = this.state.start;
  10081. const startLoc = this.state.startLoc;
  10082. let val;
  10083. this.next();
  10084. this.expressionScope.enter(newArrowHeadScope());
  10085. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10086. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10087. this.state.maybeInArrowParameters = true;
  10088. this.state.inFSharpPipelineDirectBody = false;
  10089. const innerStartPos = this.state.start;
  10090. const innerStartLoc = this.state.startLoc;
  10091. const exprList = [];
  10092. const refExpressionErrors = new ExpressionErrors();
  10093. let first = true;
  10094. let spreadStart;
  10095. let optionalCommaStart;
  10096. while (!this.match(11)) {
  10097. if (first) {
  10098. first = false;
  10099. } else {
  10100. this.expect(12, refExpressionErrors.optionalParameters === -1 ? null : refExpressionErrors.optionalParameters);
  10101. if (this.match(11)) {
  10102. optionalCommaStart = this.state.start;
  10103. break;
  10104. }
  10105. }
  10106. if (this.match(21)) {
  10107. const spreadNodeStartPos = this.state.start;
  10108. const spreadNodeStartLoc = this.state.startLoc;
  10109. spreadStart = this.state.start;
  10110. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartPos, spreadNodeStartLoc));
  10111. this.checkCommaAfterRest(41);
  10112. break;
  10113. } else {
  10114. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  10115. }
  10116. }
  10117. const innerEndPos = this.state.lastTokEnd;
  10118. const innerEndLoc = this.state.lastTokEndLoc;
  10119. this.expect(11);
  10120. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10121. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  10122. let arrowNode = this.startNodeAt(startPos, startLoc);
  10123. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  10124. this.expressionScope.validateAsPattern();
  10125. this.expressionScope.exit();
  10126. this.parseArrowExpression(arrowNode, exprList, false);
  10127. return arrowNode;
  10128. }
  10129. this.expressionScope.exit();
  10130. if (!exprList.length) {
  10131. this.unexpected(this.state.lastTokStart);
  10132. }
  10133. if (optionalCommaStart) this.unexpected(optionalCommaStart);
  10134. if (spreadStart) this.unexpected(spreadStart);
  10135. this.checkExpressionErrors(refExpressionErrors, true);
  10136. this.toReferencedListDeep(exprList, true);
  10137. if (exprList.length > 1) {
  10138. val = this.startNodeAt(innerStartPos, innerStartLoc);
  10139. val.expressions = exprList;
  10140. this.finishNode(val, "SequenceExpression");
  10141. this.resetEndLocation(val, innerEndPos, innerEndLoc);
  10142. } else {
  10143. val = exprList[0];
  10144. }
  10145. if (!this.options.createParenthesizedExpressions) {
  10146. this.addExtra(val, "parenthesized", true);
  10147. this.addExtra(val, "parenStart", startPos);
  10148. this.takeSurroundingComments(val, startPos, this.state.lastTokEnd);
  10149. return val;
  10150. }
  10151. const parenExpression = this.startNodeAt(startPos, startLoc);
  10152. parenExpression.expression = val;
  10153. this.finishNode(parenExpression, "ParenthesizedExpression");
  10154. return parenExpression;
  10155. }
  10156. shouldParseArrow(params) {
  10157. return !this.canInsertSemicolon();
  10158. }
  10159. parseArrow(node) {
  10160. if (this.eat(19)) {
  10161. return node;
  10162. }
  10163. }
  10164. parseParenItem(node, startPos, startLoc) {
  10165. return node;
  10166. }
  10167. parseNewOrNewTarget() {
  10168. const node = this.startNode();
  10169. this.next();
  10170. if (this.match(16)) {
  10171. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  10172. this.next();
  10173. const metaProp = this.parseMetaProperty(node, meta, "target");
  10174. if (!this.scope.inNonArrowFunction && !this.scope.inClass) {
  10175. this.raise(metaProp.start, ErrorMessages.UnexpectedNewTarget);
  10176. }
  10177. return metaProp;
  10178. }
  10179. return this.parseNew(node);
  10180. }
  10181. parseNew(node) {
  10182. node.callee = this.parseNoCallExpr();
  10183. if (node.callee.type === "Import") {
  10184. this.raise(node.callee.start, ErrorMessages.ImportCallNotNewExpression);
  10185. } else if (this.isOptionalChain(node.callee)) {
  10186. this.raise(this.state.lastTokEnd, ErrorMessages.OptionalChainingNoNew);
  10187. } else if (this.eat(18)) {
  10188. this.raise(this.state.start, ErrorMessages.OptionalChainingNoNew);
  10189. }
  10190. this.parseNewArguments(node);
  10191. return this.finishNode(node, "NewExpression");
  10192. }
  10193. parseNewArguments(node) {
  10194. if (this.eat(10)) {
  10195. const args = this.parseExprList(11);
  10196. this.toReferencedList(args);
  10197. node.arguments = args;
  10198. } else {
  10199. node.arguments = [];
  10200. }
  10201. }
  10202. parseTemplateElement(isTagged) {
  10203. const elem = this.startNode();
  10204. if (this.state.value === null) {
  10205. if (!isTagged) {
  10206. this.raise(this.state.start + 1, ErrorMessages.InvalidEscapeSequenceTemplate);
  10207. }
  10208. }
  10209. elem.value = {
  10210. raw: this.input.slice(this.state.start, this.state.end).replace(/\r\n?/g, "\n"),
  10211. cooked: this.state.value
  10212. };
  10213. this.next();
  10214. elem.tail = this.match(22);
  10215. return this.finishNode(elem, "TemplateElement");
  10216. }
  10217. parseTemplate(isTagged) {
  10218. const node = this.startNode();
  10219. this.next();
  10220. node.expressions = [];
  10221. let curElt = this.parseTemplateElement(isTagged);
  10222. node.quasis = [curElt];
  10223. while (!curElt.tail) {
  10224. this.expect(23);
  10225. node.expressions.push(this.parseTemplateSubstitution());
  10226. this.expect(8);
  10227. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  10228. }
  10229. this.next();
  10230. return this.finishNode(node, "TemplateLiteral");
  10231. }
  10232. parseTemplateSubstitution() {
  10233. return this.parseExpression();
  10234. }
  10235. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  10236. if (isRecord) {
  10237. this.expectPlugin("recordAndTuple");
  10238. }
  10239. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10240. this.state.inFSharpPipelineDirectBody = false;
  10241. const propHash = Object.create(null);
  10242. let first = true;
  10243. const node = this.startNode();
  10244. node.properties = [];
  10245. this.next();
  10246. while (!this.match(close)) {
  10247. if (first) {
  10248. first = false;
  10249. } else {
  10250. this.expect(12);
  10251. if (this.match(close)) {
  10252. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  10253. break;
  10254. }
  10255. }
  10256. let prop;
  10257. if (isPattern) {
  10258. prop = this.parseBindingProperty();
  10259. } else {
  10260. prop = this.parsePropertyDefinition(refExpressionErrors);
  10261. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  10262. }
  10263. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  10264. this.raise(prop.start, ErrorMessages.InvalidRecordProperty);
  10265. }
  10266. if (prop.shorthand) {
  10267. this.addExtra(prop, "shorthand", true);
  10268. }
  10269. node.properties.push(prop);
  10270. }
  10271. this.next();
  10272. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  10273. let type = "ObjectExpression";
  10274. if (isPattern) {
  10275. type = "ObjectPattern";
  10276. } else if (isRecord) {
  10277. type = "RecordExpression";
  10278. }
  10279. return this.finishNode(node, type);
  10280. }
  10281. maybeAsyncOrAccessorProp(prop) {
  10282. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(49));
  10283. }
  10284. parsePropertyDefinition(refExpressionErrors) {
  10285. let decorators = [];
  10286. if (this.match(24)) {
  10287. if (this.hasPlugin("decorators")) {
  10288. this.raise(this.state.start, ErrorMessages.UnsupportedPropertyDecorator);
  10289. }
  10290. while (this.match(24)) {
  10291. decorators.push(this.parseDecorator());
  10292. }
  10293. }
  10294. const prop = this.startNode();
  10295. let isAsync = false;
  10296. let isAccessor = false;
  10297. let startPos;
  10298. let startLoc;
  10299. if (this.match(21)) {
  10300. if (decorators.length) this.unexpected();
  10301. return this.parseSpread();
  10302. }
  10303. if (decorators.length) {
  10304. prop.decorators = decorators;
  10305. decorators = [];
  10306. }
  10307. prop.method = false;
  10308. if (refExpressionErrors) {
  10309. startPos = this.state.start;
  10310. startLoc = this.state.startLoc;
  10311. }
  10312. let isGenerator = this.eat(49);
  10313. this.parsePropertyNamePrefixOperator(prop);
  10314. const containsEsc = this.state.containsEsc;
  10315. const key = this.parsePropertyName(prop);
  10316. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  10317. const keyName = key.name;
  10318. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  10319. isAsync = true;
  10320. this.resetPreviousNodeTrailingComments(key);
  10321. isGenerator = this.eat(49);
  10322. this.parsePropertyName(prop);
  10323. }
  10324. if (keyName === "get" || keyName === "set") {
  10325. isAccessor = true;
  10326. this.resetPreviousNodeTrailingComments(key);
  10327. prop.kind = keyName;
  10328. if (this.match(49)) {
  10329. isGenerator = true;
  10330. this.raise(this.state.pos, ErrorMessages.AccessorIsGenerator, keyName);
  10331. this.next();
  10332. }
  10333. this.parsePropertyName(prop);
  10334. }
  10335. }
  10336. this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  10337. return prop;
  10338. }
  10339. getGetterSetterExpectedParamCount(method) {
  10340. return method.kind === "get" ? 0 : 1;
  10341. }
  10342. getObjectOrClassMethodParams(method) {
  10343. return method.params;
  10344. }
  10345. checkGetterSetterParams(method) {
  10346. var _params;
  10347. const paramCount = this.getGetterSetterExpectedParamCount(method);
  10348. const params = this.getObjectOrClassMethodParams(method);
  10349. const start = method.start;
  10350. if (params.length !== paramCount) {
  10351. if (method.kind === "get") {
  10352. this.raise(start, ErrorMessages.BadGetterArity);
  10353. } else {
  10354. this.raise(start, ErrorMessages.BadSetterArity);
  10355. }
  10356. }
  10357. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  10358. this.raise(start, ErrorMessages.BadSetterRestParameter);
  10359. }
  10360. }
  10361. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  10362. if (isAccessor) {
  10363. this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  10364. this.checkGetterSetterParams(prop);
  10365. return prop;
  10366. }
  10367. if (isAsync || isGenerator || this.match(10)) {
  10368. if (isPattern) this.unexpected();
  10369. prop.kind = "method";
  10370. prop.method = true;
  10371. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  10372. }
  10373. }
  10374. parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors) {
  10375. prop.shorthand = false;
  10376. if (this.eat(14)) {
  10377. prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  10378. return this.finishNode(prop, "ObjectProperty");
  10379. }
  10380. if (!prop.computed && prop.key.type === "Identifier") {
  10381. this.checkReservedWord(prop.key.name, prop.key.start, true, false);
  10382. if (isPattern) {
  10383. prop.value = this.parseMaybeDefault(startPos, startLoc, cloneIdentifier(prop.key));
  10384. } else if (this.match(27) && refExpressionErrors) {
  10385. if (refExpressionErrors.shorthandAssign === -1) {
  10386. refExpressionErrors.shorthandAssign = this.state.start;
  10387. }
  10388. prop.value = this.parseMaybeDefault(startPos, startLoc, cloneIdentifier(prop.key));
  10389. } else {
  10390. prop.value = cloneIdentifier(prop.key);
  10391. }
  10392. prop.shorthand = true;
  10393. return this.finishNode(prop, "ObjectProperty");
  10394. }
  10395. }
  10396. parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  10397. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startPos, startLoc, isPattern, refExpressionErrors);
  10398. if (!node) this.unexpected();
  10399. return node;
  10400. }
  10401. parsePropertyName(prop) {
  10402. if (this.eat(0)) {
  10403. prop.computed = true;
  10404. prop.key = this.parseMaybeAssignAllowIn();
  10405. this.expect(3);
  10406. } else {
  10407. const {
  10408. type,
  10409. value
  10410. } = this.state;
  10411. let key;
  10412. if (tokenIsKeywordOrIdentifier(type)) {
  10413. key = this.parseIdentifier(true);
  10414. } else {
  10415. switch (type) {
  10416. case 124:
  10417. key = this.parseNumericLiteral(value);
  10418. break;
  10419. case 123:
  10420. key = this.parseStringLiteral(value);
  10421. break;
  10422. case 125:
  10423. key = this.parseBigIntLiteral(value);
  10424. break;
  10425. case 126:
  10426. key = this.parseDecimalLiteral(value);
  10427. break;
  10428. case 128:
  10429. {
  10430. const privateKeyPos = this.state.start + 1;
  10431. this.raise(privateKeyPos, ErrorMessages.UnexpectedPrivateField);
  10432. key = this.parsePrivateName();
  10433. break;
  10434. }
  10435. default:
  10436. throw this.unexpected();
  10437. }
  10438. }
  10439. prop.key = key;
  10440. if (type !== 128) {
  10441. prop.computed = false;
  10442. }
  10443. }
  10444. return prop.key;
  10445. }
  10446. initFunction(node, isAsync) {
  10447. node.id = null;
  10448. node.generator = false;
  10449. node.async = !!isAsync;
  10450. }
  10451. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  10452. this.initFunction(node, isAsync);
  10453. node.generator = !!isGenerator;
  10454. const allowModifiers = isConstructor;
  10455. this.scope.enter(SCOPE_FUNCTION | SCOPE_SUPER | (inClassScope ? SCOPE_CLASS : 0) | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  10456. this.prodParam.enter(functionFlags(isAsync, node.generator));
  10457. this.parseFunctionParams(node, allowModifiers);
  10458. this.parseFunctionBodyAndFinish(node, type, true);
  10459. this.prodParam.exit();
  10460. this.scope.exit();
  10461. return node;
  10462. }
  10463. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  10464. if (isTuple) {
  10465. this.expectPlugin("recordAndTuple");
  10466. }
  10467. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10468. this.state.inFSharpPipelineDirectBody = false;
  10469. const node = this.startNode();
  10470. this.next();
  10471. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  10472. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  10473. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  10474. }
  10475. parseArrowExpression(node, params, isAsync, trailingCommaPos) {
  10476. this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
  10477. let flags = functionFlags(isAsync, false);
  10478. if (!this.match(0) && this.prodParam.hasIn) {
  10479. flags |= PARAM_IN;
  10480. }
  10481. this.prodParam.enter(flags);
  10482. this.initFunction(node, isAsync);
  10483. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10484. if (params) {
  10485. this.state.maybeInArrowParameters = true;
  10486. this.setArrowFunctionParameters(node, params, trailingCommaPos);
  10487. }
  10488. this.state.maybeInArrowParameters = false;
  10489. this.parseFunctionBody(node, true);
  10490. this.prodParam.exit();
  10491. this.scope.exit();
  10492. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10493. return this.finishNode(node, "ArrowFunctionExpression");
  10494. }
  10495. setArrowFunctionParameters(node, params, trailingCommaPos) {
  10496. node.params = this.toAssignableList(params, trailingCommaPos, false);
  10497. }
  10498. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  10499. this.parseFunctionBody(node, false, isMethod);
  10500. this.finishNode(node, type);
  10501. }
  10502. parseFunctionBody(node, allowExpression, isMethod = false) {
  10503. const isExpression = allowExpression && !this.match(5);
  10504. this.expressionScope.enter(newExpressionScope());
  10505. if (isExpression) {
  10506. node.body = this.parseMaybeAssign();
  10507. this.checkParams(node, false, allowExpression, false);
  10508. } else {
  10509. const oldStrict = this.state.strict;
  10510. const oldLabels = this.state.labels;
  10511. this.state.labels = [];
  10512. this.prodParam.enter(this.prodParam.currentFlags() | PARAM_RETURN);
  10513. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  10514. const nonSimple = !this.isSimpleParamList(node.params);
  10515. if (hasStrictModeDirective && nonSimple) {
  10516. const errorPos = (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.end : node.start;
  10517. this.raise(errorPos, ErrorMessages.IllegalLanguageModeDirective);
  10518. }
  10519. const strictModeChanged = !oldStrict && this.state.strict;
  10520. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  10521. if (this.state.strict && node.id) {
  10522. this.checkLVal(node.id, "function name", BIND_OUTSIDE, undefined, undefined, strictModeChanged);
  10523. }
  10524. });
  10525. this.prodParam.exit();
  10526. this.state.labels = oldLabels;
  10527. }
  10528. this.expressionScope.exit();
  10529. }
  10530. isSimpleParamList(params) {
  10531. for (let i = 0, len = params.length; i < len; i++) {
  10532. if (params[i].type !== "Identifier") return false;
  10533. }
  10534. return true;
  10535. }
  10536. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  10537. const checkClashes = new Set();
  10538. for (const param of node.params) {
  10539. this.checkLVal(param, "function parameter list", BIND_VAR, allowDuplicates ? null : checkClashes, undefined, strictModeChanged);
  10540. }
  10541. }
  10542. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  10543. const elts = [];
  10544. let first = true;
  10545. while (!this.eat(close)) {
  10546. if (first) {
  10547. first = false;
  10548. } else {
  10549. this.expect(12);
  10550. if (this.match(close)) {
  10551. if (nodeForExtra) {
  10552. this.addExtra(nodeForExtra, "trailingComma", this.state.lastTokStart);
  10553. }
  10554. this.next();
  10555. break;
  10556. }
  10557. }
  10558. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  10559. }
  10560. return elts;
  10561. }
  10562. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  10563. let elt;
  10564. if (this.match(12)) {
  10565. if (!allowEmpty) {
  10566. this.raise(this.state.pos, ErrorMessages.UnexpectedToken, ",");
  10567. }
  10568. elt = null;
  10569. } else if (this.match(21)) {
  10570. const spreadNodeStartPos = this.state.start;
  10571. const spreadNodeStartLoc = this.state.startLoc;
  10572. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartPos, spreadNodeStartLoc);
  10573. } else if (this.match(17)) {
  10574. this.expectPlugin("partialApplication");
  10575. if (!allowPlaceholder) {
  10576. this.raise(this.state.start, ErrorMessages.UnexpectedArgumentPlaceholder);
  10577. }
  10578. const node = this.startNode();
  10579. this.next();
  10580. elt = this.finishNode(node, "ArgumentPlaceholder");
  10581. } else {
  10582. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  10583. }
  10584. return elt;
  10585. }
  10586. parseIdentifier(liberal) {
  10587. const node = this.startNode();
  10588. const name = this.parseIdentifierName(node.start, liberal);
  10589. return this.createIdentifier(node, name);
  10590. }
  10591. createIdentifier(node, name) {
  10592. node.name = name;
  10593. node.loc.identifierName = name;
  10594. return this.finishNode(node, "Identifier");
  10595. }
  10596. parseIdentifierName(pos, liberal) {
  10597. let name;
  10598. const {
  10599. start,
  10600. type
  10601. } = this.state;
  10602. if (tokenIsKeywordOrIdentifier(type)) {
  10603. name = this.state.value;
  10604. } else {
  10605. throw this.unexpected();
  10606. }
  10607. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  10608. if (liberal) {
  10609. if (tokenIsKeyword) {
  10610. this.replaceToken(122);
  10611. }
  10612. } else {
  10613. this.checkReservedWord(name, start, tokenIsKeyword, false);
  10614. }
  10615. this.next();
  10616. return name;
  10617. }
  10618. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10619. if (word.length > 10) {
  10620. return;
  10621. }
  10622. if (!canBeReservedWord(word)) {
  10623. return;
  10624. }
  10625. if (word === "yield") {
  10626. if (this.prodParam.hasYield) {
  10627. this.raise(startLoc, ErrorMessages.YieldBindingIdentifier);
  10628. return;
  10629. }
  10630. } else if (word === "await") {
  10631. if (this.prodParam.hasAwait) {
  10632. this.raise(startLoc, ErrorMessages.AwaitBindingIdentifier);
  10633. return;
  10634. } else if (this.scope.inStaticBlock) {
  10635. this.raise(startLoc, ErrorMessages.AwaitBindingIdentifierInStaticBlock);
  10636. return;
  10637. } else {
  10638. this.expressionScope.recordAsyncArrowParametersError(startLoc, ErrorMessages.AwaitBindingIdentifier);
  10639. }
  10640. } else if (word === "arguments") {
  10641. if (this.scope.inClassAndNotInNonArrowFunction) {
  10642. this.raise(startLoc, ErrorMessages.ArgumentsInClass);
  10643. return;
  10644. }
  10645. }
  10646. if (checkKeywords && isKeyword(word)) {
  10647. this.raise(startLoc, ErrorMessages.UnexpectedKeyword, word);
  10648. return;
  10649. }
  10650. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  10651. if (reservedTest(word, this.inModule)) {
  10652. this.raise(startLoc, ErrorMessages.UnexpectedReservedWord, word);
  10653. }
  10654. }
  10655. isAwaitAllowed() {
  10656. if (this.prodParam.hasAwait) return true;
  10657. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  10658. return true;
  10659. }
  10660. return false;
  10661. }
  10662. parseAwait(startPos, startLoc) {
  10663. const node = this.startNodeAt(startPos, startLoc);
  10664. this.expressionScope.recordParameterInitializerError(node.start, ErrorMessages.AwaitExpressionFormalParameter);
  10665. if (this.eat(49)) {
  10666. this.raise(node.start, ErrorMessages.ObsoleteAwaitStar);
  10667. }
  10668. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  10669. if (this.isAmbiguousAwait()) {
  10670. this.ambiguousScriptDifferentAst = true;
  10671. } else {
  10672. this.sawUnambiguousESM = true;
  10673. }
  10674. }
  10675. if (!this.state.soloAwait) {
  10676. node.argument = this.parseMaybeUnary(null, true);
  10677. }
  10678. return this.finishNode(node, "AwaitExpression");
  10679. }
  10680. isAmbiguousAwait() {
  10681. return this.hasPrecedingLineBreak() || this.match(47) || this.match(10) || this.match(0) || this.match(22) || this.match(127) || this.match(50) || this.hasPlugin("v8intrinsic") && this.match(48);
  10682. }
  10683. parseYield() {
  10684. const node = this.startNode();
  10685. this.expressionScope.recordParameterInitializerError(node.start, ErrorMessages.YieldInParameter);
  10686. this.next();
  10687. let delegating = false;
  10688. let argument = null;
  10689. if (!this.hasPrecedingLineBreak()) {
  10690. delegating = this.eat(49);
  10691. switch (this.state.type) {
  10692. case 13:
  10693. case 129:
  10694. case 8:
  10695. case 11:
  10696. case 3:
  10697. case 9:
  10698. case 14:
  10699. case 12:
  10700. if (!delegating) break;
  10701. default:
  10702. argument = this.parseMaybeAssign();
  10703. }
  10704. }
  10705. node.delegate = delegating;
  10706. node.argument = argument;
  10707. return this.finishNode(node, "YieldExpression");
  10708. }
  10709. checkPipelineAtInfixOperator(left, leftStartPos) {
  10710. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  10711. if (left.type === "SequenceExpression") {
  10712. this.raise(leftStartPos, ErrorMessages.PipelineHeadSequenceExpression);
  10713. }
  10714. }
  10715. }
  10716. checkHackPipeBodyEarlyErrors(startPos) {
  10717. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10718. this.raise(startPos, ErrorMessages.PipeTopicUnused);
  10719. }
  10720. }
  10721. parseSmartPipelineBodyInStyle(childExpr, startPos, startLoc) {
  10722. const bodyNode = this.startNodeAt(startPos, startLoc);
  10723. if (this.isSimpleReference(childExpr)) {
  10724. bodyNode.callee = childExpr;
  10725. return this.finishNode(bodyNode, "PipelineBareFunction");
  10726. } else {
  10727. this.checkSmartPipeTopicBodyEarlyErrors(startPos);
  10728. bodyNode.expression = childExpr;
  10729. return this.finishNode(bodyNode, "PipelineTopicExpression");
  10730. }
  10731. }
  10732. isSimpleReference(expression) {
  10733. switch (expression.type) {
  10734. case "MemberExpression":
  10735. return !expression.computed && this.isSimpleReference(expression.object);
  10736. case "Identifier":
  10737. return true;
  10738. default:
  10739. return false;
  10740. }
  10741. }
  10742. checkSmartPipeTopicBodyEarlyErrors(startPos) {
  10743. if (this.match(19)) {
  10744. throw this.raise(this.state.start, ErrorMessages.PipelineBodyNoArrow);
  10745. } else if (!this.topicReferenceWasUsedInCurrentContext()) {
  10746. this.raise(startPos, ErrorMessages.PipelineTopicUnused);
  10747. }
  10748. }
  10749. withTopicBindingContext(callback) {
  10750. const outerContextTopicState = this.state.topicContext;
  10751. this.state.topicContext = {
  10752. maxNumOfResolvableTopics: 1,
  10753. maxTopicIndex: null
  10754. };
  10755. try {
  10756. return callback();
  10757. } finally {
  10758. this.state.topicContext = outerContextTopicState;
  10759. }
  10760. }
  10761. withSmartMixTopicForbiddingContext(callback) {
  10762. const proposal = this.getPluginOption("pipelineOperator", "proposal");
  10763. if (proposal === "smart") {
  10764. const outerContextTopicState = this.state.topicContext;
  10765. this.state.topicContext = {
  10766. maxNumOfResolvableTopics: 0,
  10767. maxTopicIndex: null
  10768. };
  10769. try {
  10770. return callback();
  10771. } finally {
  10772. this.state.topicContext = outerContextTopicState;
  10773. }
  10774. } else {
  10775. return callback();
  10776. }
  10777. }
  10778. withSoloAwaitPermittingContext(callback) {
  10779. const outerContextSoloAwaitState = this.state.soloAwait;
  10780. this.state.soloAwait = true;
  10781. try {
  10782. return callback();
  10783. } finally {
  10784. this.state.soloAwait = outerContextSoloAwaitState;
  10785. }
  10786. }
  10787. allowInAnd(callback) {
  10788. const flags = this.prodParam.currentFlags();
  10789. const prodParamToSet = PARAM_IN & ~flags;
  10790. if (prodParamToSet) {
  10791. this.prodParam.enter(flags | PARAM_IN);
  10792. try {
  10793. return callback();
  10794. } finally {
  10795. this.prodParam.exit();
  10796. }
  10797. }
  10798. return callback();
  10799. }
  10800. disallowInAnd(callback) {
  10801. const flags = this.prodParam.currentFlags();
  10802. const prodParamToClear = PARAM_IN & flags;
  10803. if (prodParamToClear) {
  10804. this.prodParam.enter(flags & ~PARAM_IN);
  10805. try {
  10806. return callback();
  10807. } finally {
  10808. this.prodParam.exit();
  10809. }
  10810. }
  10811. return callback();
  10812. }
  10813. registerTopicReference() {
  10814. this.state.topicContext.maxTopicIndex = 0;
  10815. }
  10816. topicReferenceIsAllowedInCurrentContext() {
  10817. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  10818. }
  10819. topicReferenceWasUsedInCurrentContext() {
  10820. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  10821. }
  10822. parseFSharpPipelineBody(prec) {
  10823. const startPos = this.state.start;
  10824. const startLoc = this.state.startLoc;
  10825. this.state.potentialArrowAt = this.state.start;
  10826. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10827. this.state.inFSharpPipelineDirectBody = true;
  10828. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startPos, startLoc, prec);
  10829. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  10830. return ret;
  10831. }
  10832. parseModuleExpression() {
  10833. this.expectPlugin("moduleBlocks");
  10834. const node = this.startNode();
  10835. this.next();
  10836. this.eat(5);
  10837. const revertScopes = this.initializeScopes(true);
  10838. this.enterInitialScopes();
  10839. const program = this.startNode();
  10840. try {
  10841. node.body = this.parseProgram(program, 8, "module");
  10842. } finally {
  10843. revertScopes();
  10844. }
  10845. this.eat(8);
  10846. return this.finishNode(node, "ModuleExpression");
  10847. }
  10848. parsePropertyNamePrefixOperator(prop) {}
  10849. }
  10850. const loopLabel = {
  10851. kind: "loop"
  10852. },
  10853. switchLabel = {
  10854. kind: "switch"
  10855. };
  10856. const FUNC_NO_FLAGS = 0b000,
  10857. FUNC_STATEMENT = 0b001,
  10858. FUNC_HANGING_STATEMENT = 0b010,
  10859. FUNC_NULLABLE_ID = 0b100;
  10860. const loneSurrogate = /[\uD800-\uDFFF]/u;
  10861. const keywordRelationalOperator = /in(?:stanceof)?/y;
  10862. function babel7CompatTokens(tokens) {
  10863. for (let i = 0; i < tokens.length; i++) {
  10864. const token = tokens[i];
  10865. const {
  10866. type
  10867. } = token;
  10868. if (type === 128) {
  10869. {
  10870. const {
  10871. loc,
  10872. start,
  10873. value,
  10874. end
  10875. } = token;
  10876. const hashEndPos = start + 1;
  10877. const hashEndLoc = new Position(loc.start.line, loc.start.column + 1);
  10878. tokens.splice(i, 1, new Token({
  10879. type: getExportedToken(25),
  10880. value: "#",
  10881. start: start,
  10882. end: hashEndPos,
  10883. startLoc: loc.start,
  10884. endLoc: hashEndLoc
  10885. }), new Token({
  10886. type: getExportedToken(122),
  10887. value: value,
  10888. start: hashEndPos,
  10889. end: end,
  10890. startLoc: hashEndLoc,
  10891. endLoc: loc.end
  10892. }));
  10893. i++;
  10894. continue;
  10895. }
  10896. }
  10897. if (typeof type === "number") {
  10898. token.type = getExportedToken(type);
  10899. }
  10900. }
  10901. return tokens;
  10902. }
  10903. class StatementParser extends ExpressionParser {
  10904. parseTopLevel(file, program) {
  10905. file.program = this.parseProgram(program);
  10906. file.comments = this.state.comments;
  10907. if (this.options.tokens) file.tokens = babel7CompatTokens(this.tokens);
  10908. return this.finishNode(file, "File");
  10909. }
  10910. parseProgram(program, end = 129, sourceType = this.options.sourceType) {
  10911. program.sourceType = sourceType;
  10912. program.interpreter = this.parseInterpreterDirective();
  10913. this.parseBlockBody(program, true, true, end);
  10914. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  10915. for (const [name] of Array.from(this.scope.undefinedExports)) {
  10916. const pos = this.scope.undefinedExports.get(name);
  10917. this.raise(pos, ErrorMessages.ModuleExportUndefined, name);
  10918. }
  10919. }
  10920. return this.finishNode(program, "Program");
  10921. }
  10922. stmtToDirective(stmt) {
  10923. const directive = stmt;
  10924. directive.type = "Directive";
  10925. directive.value = directive.expression;
  10926. delete directive.expression;
  10927. const directiveLiteral = directive.value;
  10928. const expressionValue = directiveLiteral.value;
  10929. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  10930. const val = directiveLiteral.value = raw.slice(1, -1);
  10931. this.addExtra(directiveLiteral, "raw", raw);
  10932. this.addExtra(directiveLiteral, "rawValue", val);
  10933. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  10934. directiveLiteral.type = "DirectiveLiteral";
  10935. return directive;
  10936. }
  10937. parseInterpreterDirective() {
  10938. if (!this.match(26)) {
  10939. return null;
  10940. }
  10941. const node = this.startNode();
  10942. node.value = this.state.value;
  10943. this.next();
  10944. return this.finishNode(node, "InterpreterDirective");
  10945. }
  10946. isLet(context) {
  10947. if (!this.isContextual(93)) {
  10948. return false;
  10949. }
  10950. return this.isLetKeyword(context);
  10951. }
  10952. isLetKeyword(context) {
  10953. const next = this.nextTokenStart();
  10954. const nextCh = this.codePointAtPos(next);
  10955. if (nextCh === 92 || nextCh === 91) {
  10956. return true;
  10957. }
  10958. if (context) return false;
  10959. if (nextCh === 123) return true;
  10960. if (isIdentifierStart(nextCh)) {
  10961. keywordRelationalOperator.lastIndex = next;
  10962. if (keywordRelationalOperator.test(this.input)) {
  10963. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  10964. if (!isIdentifierChar(endCh) && endCh !== 92) {
  10965. return false;
  10966. }
  10967. }
  10968. return true;
  10969. }
  10970. return false;
  10971. }
  10972. parseStatement(context, topLevel) {
  10973. if (this.match(24)) {
  10974. this.parseDecorators(true);
  10975. }
  10976. return this.parseStatementContent(context, topLevel);
  10977. }
  10978. parseStatementContent(context, topLevel) {
  10979. let starttype = this.state.type;
  10980. const node = this.startNode();
  10981. let kind;
  10982. if (this.isLet(context)) {
  10983. starttype = 68;
  10984. kind = "let";
  10985. }
  10986. switch (starttype) {
  10987. case 54:
  10988. return this.parseBreakContinueStatement(node, true);
  10989. case 57:
  10990. return this.parseBreakContinueStatement(node, false);
  10991. case 58:
  10992. return this.parseDebuggerStatement(node);
  10993. case 84:
  10994. return this.parseDoStatement(node);
  10995. case 85:
  10996. return this.parseForStatement(node);
  10997. case 62:
  10998. if (this.lookaheadCharCode() === 46) break;
  10999. if (context) {
  11000. if (this.state.strict) {
  11001. this.raise(this.state.start, ErrorMessages.StrictFunction);
  11002. } else if (context !== "if" && context !== "label") {
  11003. this.raise(this.state.start, ErrorMessages.SloppyFunction);
  11004. }
  11005. }
  11006. return this.parseFunctionStatement(node, false, !context);
  11007. case 74:
  11008. if (context) this.unexpected();
  11009. return this.parseClass(node, true);
  11010. case 63:
  11011. return this.parseIfStatement(node);
  11012. case 64:
  11013. return this.parseReturnStatement(node);
  11014. case 65:
  11015. return this.parseSwitchStatement(node);
  11016. case 66:
  11017. return this.parseThrowStatement(node);
  11018. case 67:
  11019. return this.parseTryStatement(node);
  11020. case 69:
  11021. case 68:
  11022. kind = kind || this.state.value;
  11023. if (context && kind !== "var") {
  11024. this.raise(this.state.start, ErrorMessages.UnexpectedLexicalDeclaration);
  11025. }
  11026. return this.parseVarStatement(node, kind);
  11027. case 86:
  11028. return this.parseWhileStatement(node);
  11029. case 70:
  11030. return this.parseWithStatement(node);
  11031. case 5:
  11032. return this.parseBlock();
  11033. case 13:
  11034. return this.parseEmptyStatement(node);
  11035. case 77:
  11036. {
  11037. const nextTokenCharCode = this.lookaheadCharCode();
  11038. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  11039. break;
  11040. }
  11041. }
  11042. case 76:
  11043. {
  11044. if (!this.options.allowImportExportEverywhere && !topLevel) {
  11045. this.raise(this.state.start, ErrorMessages.UnexpectedImportExport);
  11046. }
  11047. this.next();
  11048. let result;
  11049. if (starttype === 77) {
  11050. result = this.parseImport(node);
  11051. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  11052. this.sawUnambiguousESM = true;
  11053. }
  11054. } else {
  11055. result = this.parseExport(node);
  11056. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  11057. this.sawUnambiguousESM = true;
  11058. }
  11059. }
  11060. this.assertModuleNodeAllowed(node);
  11061. return result;
  11062. }
  11063. default:
  11064. {
  11065. if (this.isAsyncFunction()) {
  11066. if (context) {
  11067. this.raise(this.state.start, ErrorMessages.AsyncFunctionInSingleStatementContext);
  11068. }
  11069. this.next();
  11070. return this.parseFunctionStatement(node, true, !context);
  11071. }
  11072. }
  11073. }
  11074. const maybeName = this.state.value;
  11075. const expr = this.parseExpression();
  11076. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  11077. return this.parseLabeledStatement(node, maybeName, expr, context);
  11078. } else {
  11079. return this.parseExpressionStatement(node, expr);
  11080. }
  11081. }
  11082. assertModuleNodeAllowed(node) {
  11083. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  11084. this.raise(node.start, SourceTypeModuleErrorMessages.ImportOutsideModule);
  11085. }
  11086. }
  11087. takeDecorators(node) {
  11088. const decorators = this.state.decoratorStack[this.state.decoratorStack.length - 1];
  11089. if (decorators.length) {
  11090. node.decorators = decorators;
  11091. this.resetStartLocationFromNode(node, decorators[0]);
  11092. this.state.decoratorStack[this.state.decoratorStack.length - 1] = [];
  11093. }
  11094. }
  11095. canHaveLeadingDecorator() {
  11096. return this.match(74);
  11097. }
  11098. parseDecorators(allowExport) {
  11099. const currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1];
  11100. while (this.match(24)) {
  11101. const decorator = this.parseDecorator();
  11102. currentContextDecorators.push(decorator);
  11103. }
  11104. if (this.match(76)) {
  11105. if (!allowExport) {
  11106. this.unexpected();
  11107. }
  11108. if (this.hasPlugin("decorators") && !this.getPluginOption("decorators", "decoratorsBeforeExport")) {
  11109. this.raise(this.state.start, ErrorMessages.DecoratorExportClass);
  11110. }
  11111. } else if (!this.canHaveLeadingDecorator()) {
  11112. throw this.raise(this.state.start, ErrorMessages.UnexpectedLeadingDecorator);
  11113. }
  11114. }
  11115. parseDecorator() {
  11116. this.expectOnePlugin(["decorators-legacy", "decorators"]);
  11117. const node = this.startNode();
  11118. this.next();
  11119. if (this.hasPlugin("decorators")) {
  11120. this.state.decoratorStack.push([]);
  11121. const startPos = this.state.start;
  11122. const startLoc = this.state.startLoc;
  11123. let expr;
  11124. if (this.eat(10)) {
  11125. expr = this.parseExpression();
  11126. this.expect(11);
  11127. } else {
  11128. expr = this.parseIdentifier(false);
  11129. while (this.eat(16)) {
  11130. const node = this.startNodeAt(startPos, startLoc);
  11131. node.object = expr;
  11132. node.property = this.parseIdentifier(true);
  11133. node.computed = false;
  11134. expr = this.finishNode(node, "MemberExpression");
  11135. }
  11136. }
  11137. node.expression = this.parseMaybeDecoratorArguments(expr);
  11138. this.state.decoratorStack.pop();
  11139. } else {
  11140. node.expression = this.parseExprSubscripts();
  11141. }
  11142. return this.finishNode(node, "Decorator");
  11143. }
  11144. parseMaybeDecoratorArguments(expr) {
  11145. if (this.eat(10)) {
  11146. const node = this.startNodeAtNode(expr);
  11147. node.callee = expr;
  11148. node.arguments = this.parseCallExpressionArguments(11, false);
  11149. this.toReferencedList(node.arguments);
  11150. return this.finishNode(node, "CallExpression");
  11151. }
  11152. return expr;
  11153. }
  11154. parseBreakContinueStatement(node, isBreak) {
  11155. this.next();
  11156. if (this.isLineTerminator()) {
  11157. node.label = null;
  11158. } else {
  11159. node.label = this.parseIdentifier();
  11160. this.semicolon();
  11161. }
  11162. this.verifyBreakContinue(node, isBreak);
  11163. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  11164. }
  11165. verifyBreakContinue(node, isBreak) {
  11166. let i;
  11167. for (i = 0; i < this.state.labels.length; ++i) {
  11168. const lab = this.state.labels[i];
  11169. if (node.label == null || lab.name === node.label.name) {
  11170. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  11171. if (node.label && isBreak) break;
  11172. }
  11173. }
  11174. if (i === this.state.labels.length) {
  11175. this.raise(node.start, ErrorMessages.IllegalBreakContinue, isBreak ? "break" : "continue");
  11176. }
  11177. }
  11178. parseDebuggerStatement(node) {
  11179. this.next();
  11180. this.semicolon();
  11181. return this.finishNode(node, "DebuggerStatement");
  11182. }
  11183. parseHeaderExpression() {
  11184. this.expect(10);
  11185. const val = this.parseExpression();
  11186. this.expect(11);
  11187. return val;
  11188. }
  11189. parseDoStatement(node) {
  11190. this.next();
  11191. this.state.labels.push(loopLabel);
  11192. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("do"));
  11193. this.state.labels.pop();
  11194. this.expect(86);
  11195. node.test = this.parseHeaderExpression();
  11196. this.eat(13);
  11197. return this.finishNode(node, "DoWhileStatement");
  11198. }
  11199. parseForStatement(node) {
  11200. this.next();
  11201. this.state.labels.push(loopLabel);
  11202. let awaitAt = -1;
  11203. if (this.isAwaitAllowed() && this.eatContextual(90)) {
  11204. awaitAt = this.state.lastTokStart;
  11205. }
  11206. this.scope.enter(SCOPE_OTHER);
  11207. this.expect(10);
  11208. if (this.match(13)) {
  11209. if (awaitAt > -1) {
  11210. this.unexpected(awaitAt);
  11211. }
  11212. return this.parseFor(node, null);
  11213. }
  11214. const startsWithLet = this.isContextual(93);
  11215. const isLet = startsWithLet && this.isLetKeyword();
  11216. if (this.match(68) || this.match(69) || isLet) {
  11217. const init = this.startNode();
  11218. const kind = isLet ? "let" : this.state.value;
  11219. this.next();
  11220. this.parseVar(init, true, kind);
  11221. this.finishNode(init, "VariableDeclaration");
  11222. if ((this.match(52) || this.isContextual(95)) && init.declarations.length === 1) {
  11223. return this.parseForIn(node, init, awaitAt);
  11224. }
  11225. if (awaitAt > -1) {
  11226. this.unexpected(awaitAt);
  11227. }
  11228. return this.parseFor(node, init);
  11229. }
  11230. const startsWithAsync = this.isContextual(89);
  11231. const refExpressionErrors = new ExpressionErrors();
  11232. const init = this.parseExpression(true, refExpressionErrors);
  11233. const isForOf = this.isContextual(95);
  11234. if (isForOf) {
  11235. if (startsWithLet) {
  11236. this.raise(init.start, ErrorMessages.ForOfLet);
  11237. } else if (awaitAt === -1 && startsWithAsync && init.type === "Identifier") {
  11238. this.raise(init.start, ErrorMessages.ForOfAsync);
  11239. }
  11240. }
  11241. if (isForOf || this.match(52)) {
  11242. this.toAssignable(init, true);
  11243. const description = isForOf ? "for-of statement" : "for-in statement";
  11244. this.checkLVal(init, description);
  11245. return this.parseForIn(node, init, awaitAt);
  11246. } else {
  11247. this.checkExpressionErrors(refExpressionErrors, true);
  11248. }
  11249. if (awaitAt > -1) {
  11250. this.unexpected(awaitAt);
  11251. }
  11252. return this.parseFor(node, init);
  11253. }
  11254. parseFunctionStatement(node, isAsync, declarationPosition) {
  11255. this.next();
  11256. return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), isAsync);
  11257. }
  11258. parseIfStatement(node) {
  11259. this.next();
  11260. node.test = this.parseHeaderExpression();
  11261. node.consequent = this.parseStatement("if");
  11262. node.alternate = this.eat(60) ? this.parseStatement("if") : null;
  11263. return this.finishNode(node, "IfStatement");
  11264. }
  11265. parseReturnStatement(node) {
  11266. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  11267. this.raise(this.state.start, ErrorMessages.IllegalReturn);
  11268. }
  11269. this.next();
  11270. if (this.isLineTerminator()) {
  11271. node.argument = null;
  11272. } else {
  11273. node.argument = this.parseExpression();
  11274. this.semicolon();
  11275. }
  11276. return this.finishNode(node, "ReturnStatement");
  11277. }
  11278. parseSwitchStatement(node) {
  11279. this.next();
  11280. node.discriminant = this.parseHeaderExpression();
  11281. const cases = node.cases = [];
  11282. this.expect(5);
  11283. this.state.labels.push(switchLabel);
  11284. this.scope.enter(SCOPE_OTHER);
  11285. let cur;
  11286. for (let sawDefault; !this.match(8);) {
  11287. if (this.match(55) || this.match(59)) {
  11288. const isCase = this.match(55);
  11289. if (cur) this.finishNode(cur, "SwitchCase");
  11290. cases.push(cur = this.startNode());
  11291. cur.consequent = [];
  11292. this.next();
  11293. if (isCase) {
  11294. cur.test = this.parseExpression();
  11295. } else {
  11296. if (sawDefault) {
  11297. this.raise(this.state.lastTokStart, ErrorMessages.MultipleDefaultsInSwitch);
  11298. }
  11299. sawDefault = true;
  11300. cur.test = null;
  11301. }
  11302. this.expect(14);
  11303. } else {
  11304. if (cur) {
  11305. cur.consequent.push(this.parseStatement(null));
  11306. } else {
  11307. this.unexpected();
  11308. }
  11309. }
  11310. }
  11311. this.scope.exit();
  11312. if (cur) this.finishNode(cur, "SwitchCase");
  11313. this.next();
  11314. this.state.labels.pop();
  11315. return this.finishNode(node, "SwitchStatement");
  11316. }
  11317. parseThrowStatement(node) {
  11318. this.next();
  11319. if (this.hasPrecedingLineBreak()) {
  11320. this.raise(this.state.lastTokEnd, ErrorMessages.NewlineAfterThrow);
  11321. }
  11322. node.argument = this.parseExpression();
  11323. this.semicolon();
  11324. return this.finishNode(node, "ThrowStatement");
  11325. }
  11326. parseCatchClauseParam() {
  11327. const param = this.parseBindingAtom();
  11328. const simple = param.type === "Identifier";
  11329. this.scope.enter(simple ? SCOPE_SIMPLE_CATCH : 0);
  11330. this.checkLVal(param, "catch clause", BIND_LEXICAL);
  11331. return param;
  11332. }
  11333. parseTryStatement(node) {
  11334. this.next();
  11335. node.block = this.parseBlock();
  11336. node.handler = null;
  11337. if (this.match(56)) {
  11338. const clause = this.startNode();
  11339. this.next();
  11340. if (this.match(10)) {
  11341. this.expect(10);
  11342. clause.param = this.parseCatchClauseParam();
  11343. this.expect(11);
  11344. } else {
  11345. clause.param = null;
  11346. this.scope.enter(SCOPE_OTHER);
  11347. }
  11348. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  11349. this.scope.exit();
  11350. node.handler = this.finishNode(clause, "CatchClause");
  11351. }
  11352. node.finalizer = this.eat(61) ? this.parseBlock() : null;
  11353. if (!node.handler && !node.finalizer) {
  11354. this.raise(node.start, ErrorMessages.NoCatchOrFinally);
  11355. }
  11356. return this.finishNode(node, "TryStatement");
  11357. }
  11358. parseVarStatement(node, kind) {
  11359. this.next();
  11360. this.parseVar(node, false, kind);
  11361. this.semicolon();
  11362. return this.finishNode(node, "VariableDeclaration");
  11363. }
  11364. parseWhileStatement(node) {
  11365. this.next();
  11366. node.test = this.parseHeaderExpression();
  11367. this.state.labels.push(loopLabel);
  11368. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("while"));
  11369. this.state.labels.pop();
  11370. return this.finishNode(node, "WhileStatement");
  11371. }
  11372. parseWithStatement(node) {
  11373. if (this.state.strict) {
  11374. this.raise(this.state.start, ErrorMessages.StrictWith);
  11375. }
  11376. this.next();
  11377. node.object = this.parseHeaderExpression();
  11378. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("with"));
  11379. return this.finishNode(node, "WithStatement");
  11380. }
  11381. parseEmptyStatement(node) {
  11382. this.next();
  11383. return this.finishNode(node, "EmptyStatement");
  11384. }
  11385. parseLabeledStatement(node, maybeName, expr, context) {
  11386. for (const label of this.state.labels) {
  11387. if (label.name === maybeName) {
  11388. this.raise(expr.start, ErrorMessages.LabelRedeclaration, maybeName);
  11389. }
  11390. }
  11391. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(65) ? "switch" : null;
  11392. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  11393. const label = this.state.labels[i];
  11394. if (label.statementStart === node.start) {
  11395. label.statementStart = this.state.start;
  11396. label.kind = kind;
  11397. } else {
  11398. break;
  11399. }
  11400. }
  11401. this.state.labels.push({
  11402. name: maybeName,
  11403. kind: kind,
  11404. statementStart: this.state.start
  11405. });
  11406. node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
  11407. this.state.labels.pop();
  11408. node.label = expr;
  11409. return this.finishNode(node, "LabeledStatement");
  11410. }
  11411. parseExpressionStatement(node, expr) {
  11412. node.expression = expr;
  11413. this.semicolon();
  11414. return this.finishNode(node, "ExpressionStatement");
  11415. }
  11416. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  11417. const node = this.startNode();
  11418. if (allowDirectives) {
  11419. this.state.strictErrors.clear();
  11420. }
  11421. this.expect(5);
  11422. if (createNewLexicalScope) {
  11423. this.scope.enter(SCOPE_OTHER);
  11424. }
  11425. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  11426. if (createNewLexicalScope) {
  11427. this.scope.exit();
  11428. }
  11429. return this.finishNode(node, "BlockStatement");
  11430. }
  11431. isValidDirective(stmt) {
  11432. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  11433. }
  11434. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  11435. const body = node.body = [];
  11436. const directives = node.directives = [];
  11437. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  11438. }
  11439. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  11440. const oldStrict = this.state.strict;
  11441. let hasStrictModeDirective = false;
  11442. let parsedNonDirective = false;
  11443. while (!this.match(end)) {
  11444. const stmt = this.parseStatement(null, topLevel);
  11445. if (directives && !parsedNonDirective) {
  11446. if (this.isValidDirective(stmt)) {
  11447. const directive = this.stmtToDirective(stmt);
  11448. directives.push(directive);
  11449. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  11450. hasStrictModeDirective = true;
  11451. this.setStrict(true);
  11452. }
  11453. continue;
  11454. }
  11455. parsedNonDirective = true;
  11456. this.state.strictErrors.clear();
  11457. }
  11458. body.push(stmt);
  11459. }
  11460. if (afterBlockParse) {
  11461. afterBlockParse.call(this, hasStrictModeDirective);
  11462. }
  11463. if (!oldStrict) {
  11464. this.setStrict(false);
  11465. }
  11466. this.next();
  11467. }
  11468. parseFor(node, init) {
  11469. node.init = init;
  11470. this.semicolon(false);
  11471. node.test = this.match(13) ? null : this.parseExpression();
  11472. this.semicolon(false);
  11473. node.update = this.match(11) ? null : this.parseExpression();
  11474. this.expect(11);
  11475. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("for"));
  11476. this.scope.exit();
  11477. this.state.labels.pop();
  11478. return this.finishNode(node, "ForStatement");
  11479. }
  11480. parseForIn(node, init, awaitAt) {
  11481. const isForIn = this.match(52);
  11482. this.next();
  11483. if (isForIn) {
  11484. if (awaitAt > -1) this.unexpected(awaitAt);
  11485. } else {
  11486. node.await = awaitAt > -1;
  11487. }
  11488. if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) {
  11489. this.raise(init.start, ErrorMessages.ForInOfLoopInitializer, isForIn ? "for-in" : "for-of");
  11490. } else if (init.type === "AssignmentPattern") {
  11491. this.raise(init.start, ErrorMessages.InvalidLhs, "for-loop");
  11492. }
  11493. node.left = init;
  11494. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  11495. this.expect(11);
  11496. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement("for"));
  11497. this.scope.exit();
  11498. this.state.labels.pop();
  11499. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  11500. }
  11501. parseVar(node, isFor, kind) {
  11502. const declarations = node.declarations = [];
  11503. const isTypescript = this.hasPlugin("typescript");
  11504. node.kind = kind;
  11505. for (;;) {
  11506. const decl = this.startNode();
  11507. this.parseVarId(decl, kind);
  11508. if (this.eat(27)) {
  11509. decl.init = isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  11510. } else {
  11511. if (kind === "const" && !(this.match(52) || this.isContextual(95))) {
  11512. if (!isTypescript) {
  11513. this.raise(this.state.lastTokEnd, ErrorMessages.DeclarationMissingInitializer, "Const declarations");
  11514. }
  11515. } else if (decl.id.type !== "Identifier" && !(isFor && (this.match(52) || this.isContextual(95)))) {
  11516. this.raise(this.state.lastTokEnd, ErrorMessages.DeclarationMissingInitializer, "Complex binding patterns");
  11517. }
  11518. decl.init = null;
  11519. }
  11520. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  11521. if (!this.eat(12)) break;
  11522. }
  11523. return node;
  11524. }
  11525. parseVarId(decl, kind) {
  11526. decl.id = this.parseBindingAtom();
  11527. this.checkLVal(decl.id, "variable declaration", kind === "var" ? BIND_VAR : BIND_LEXICAL, undefined, kind !== "var");
  11528. }
  11529. parseFunction(node, statement = FUNC_NO_FLAGS, isAsync = false) {
  11530. const isStatement = statement & FUNC_STATEMENT;
  11531. const isHangingStatement = statement & FUNC_HANGING_STATEMENT;
  11532. const requireId = !!isStatement && !(statement & FUNC_NULLABLE_ID);
  11533. this.initFunction(node, isAsync);
  11534. if (this.match(49) && isHangingStatement) {
  11535. this.raise(this.state.start, ErrorMessages.GeneratorInSingleStatementContext);
  11536. }
  11537. node.generator = this.eat(49);
  11538. if (isStatement) {
  11539. node.id = this.parseFunctionId(requireId);
  11540. }
  11541. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11542. this.state.maybeInArrowParameters = false;
  11543. this.scope.enter(SCOPE_FUNCTION);
  11544. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11545. if (!isStatement) {
  11546. node.id = this.parseFunctionId();
  11547. }
  11548. this.parseFunctionParams(node, false);
  11549. this.withSmartMixTopicForbiddingContext(() => {
  11550. this.parseFunctionBodyAndFinish(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
  11551. });
  11552. this.prodParam.exit();
  11553. this.scope.exit();
  11554. if (isStatement && !isHangingStatement) {
  11555. this.registerFunctionStatementId(node);
  11556. }
  11557. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11558. return node;
  11559. }
  11560. parseFunctionId(requireId) {
  11561. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  11562. }
  11563. parseFunctionParams(node, allowModifiers) {
  11564. this.expect(10);
  11565. this.expressionScope.enter(newParameterDeclarationScope());
  11566. node.params = this.parseBindingList(11, 41, false, allowModifiers);
  11567. this.expressionScope.exit();
  11568. }
  11569. registerFunctionStatementId(node) {
  11570. if (!node.id) return;
  11571. this.scope.declareName(node.id.name, this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION, node.id.start);
  11572. }
  11573. parseClass(node, isStatement, optionalId) {
  11574. this.next();
  11575. this.takeDecorators(node);
  11576. const oldStrict = this.state.strict;
  11577. this.state.strict = true;
  11578. this.parseClassId(node, isStatement, optionalId);
  11579. this.parseClassSuper(node);
  11580. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  11581. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  11582. }
  11583. isClassProperty() {
  11584. return this.match(27) || this.match(13) || this.match(8);
  11585. }
  11586. isClassMethod() {
  11587. return this.match(10);
  11588. }
  11589. isNonstaticConstructor(method) {
  11590. return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
  11591. }
  11592. parseClassBody(hadSuperClass, oldStrict) {
  11593. this.classScope.enter();
  11594. const state = {
  11595. hadConstructor: false,
  11596. hadSuperClass
  11597. };
  11598. let decorators = [];
  11599. const classBody = this.startNode();
  11600. classBody.body = [];
  11601. this.expect(5);
  11602. this.withSmartMixTopicForbiddingContext(() => {
  11603. while (!this.match(8)) {
  11604. if (this.eat(13)) {
  11605. if (decorators.length > 0) {
  11606. throw this.raise(this.state.lastTokEnd, ErrorMessages.DecoratorSemicolon);
  11607. }
  11608. continue;
  11609. }
  11610. if (this.match(24)) {
  11611. decorators.push(this.parseDecorator());
  11612. continue;
  11613. }
  11614. const member = this.startNode();
  11615. if (decorators.length) {
  11616. member.decorators = decorators;
  11617. this.resetStartLocationFromNode(member, decorators[0]);
  11618. decorators = [];
  11619. }
  11620. this.parseClassMember(classBody, member, state);
  11621. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  11622. this.raise(member.start, ErrorMessages.DecoratorConstructor);
  11623. }
  11624. }
  11625. });
  11626. this.state.strict = oldStrict;
  11627. this.next();
  11628. if (decorators.length) {
  11629. throw this.raise(this.state.start, ErrorMessages.TrailingDecorator);
  11630. }
  11631. this.classScope.exit();
  11632. return this.finishNode(classBody, "ClassBody");
  11633. }
  11634. parseClassMemberFromModifier(classBody, member) {
  11635. const key = this.parseIdentifier(true);
  11636. if (this.isClassMethod()) {
  11637. const method = member;
  11638. method.kind = "method";
  11639. method.computed = false;
  11640. method.key = key;
  11641. method.static = false;
  11642. this.pushClassMethod(classBody, method, false, false, false, false);
  11643. return true;
  11644. } else if (this.isClassProperty()) {
  11645. const prop = member;
  11646. prop.computed = false;
  11647. prop.key = key;
  11648. prop.static = false;
  11649. classBody.body.push(this.parseClassProperty(prop));
  11650. return true;
  11651. }
  11652. this.resetPreviousNodeTrailingComments(key);
  11653. return false;
  11654. }
  11655. parseClassMember(classBody, member, state) {
  11656. const isStatic = this.isContextual(98);
  11657. if (isStatic) {
  11658. if (this.parseClassMemberFromModifier(classBody, member)) {
  11659. return;
  11660. }
  11661. if (this.eat(5)) {
  11662. this.parseClassStaticBlock(classBody, member);
  11663. return;
  11664. }
  11665. }
  11666. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  11667. }
  11668. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  11669. const publicMethod = member;
  11670. const privateMethod = member;
  11671. const publicProp = member;
  11672. const privateProp = member;
  11673. const method = publicMethod;
  11674. const publicMember = publicMethod;
  11675. member.static = isStatic;
  11676. this.parsePropertyNamePrefixOperator(member);
  11677. if (this.eat(49)) {
  11678. method.kind = "method";
  11679. const isPrivateName = this.match(128);
  11680. this.parseClassElementName(method);
  11681. if (isPrivateName) {
  11682. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  11683. return;
  11684. }
  11685. if (this.isNonstaticConstructor(publicMethod)) {
  11686. this.raise(publicMethod.key.start, ErrorMessages.ConstructorIsGenerator);
  11687. }
  11688. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  11689. return;
  11690. }
  11691. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  11692. const isPrivate = this.match(128);
  11693. const key = this.parseClassElementName(member);
  11694. const maybeQuestionTokenStart = this.state.start;
  11695. this.parsePostMemberNameModifiers(publicMember);
  11696. if (this.isClassMethod()) {
  11697. method.kind = "method";
  11698. if (isPrivate) {
  11699. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  11700. return;
  11701. }
  11702. const isConstructor = this.isNonstaticConstructor(publicMethod);
  11703. let allowsDirectSuper = false;
  11704. if (isConstructor) {
  11705. publicMethod.kind = "constructor";
  11706. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  11707. this.raise(key.start, ErrorMessages.DuplicateConstructor);
  11708. }
  11709. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  11710. this.raise(key.start, ErrorMessages.OverrideOnConstructor);
  11711. }
  11712. state.hadConstructor = true;
  11713. allowsDirectSuper = state.hadSuperClass;
  11714. }
  11715. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  11716. } else if (this.isClassProperty()) {
  11717. if (isPrivate) {
  11718. this.pushClassPrivateProperty(classBody, privateProp);
  11719. } else {
  11720. this.pushClassProperty(classBody, publicProp);
  11721. }
  11722. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  11723. this.resetPreviousNodeTrailingComments(key);
  11724. const isGenerator = this.eat(49);
  11725. if (publicMember.optional) {
  11726. this.unexpected(maybeQuestionTokenStart);
  11727. }
  11728. method.kind = "method";
  11729. const isPrivate = this.match(128);
  11730. this.parseClassElementName(method);
  11731. this.parsePostMemberNameModifiers(publicMember);
  11732. if (isPrivate) {
  11733. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  11734. } else {
  11735. if (this.isNonstaticConstructor(publicMethod)) {
  11736. this.raise(publicMethod.key.start, ErrorMessages.ConstructorIsAsync);
  11737. }
  11738. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  11739. }
  11740. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(49) && this.isLineTerminator())) {
  11741. this.resetPreviousNodeTrailingComments(key);
  11742. method.kind = key.name;
  11743. const isPrivate = this.match(128);
  11744. this.parseClassElementName(publicMethod);
  11745. if (isPrivate) {
  11746. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  11747. } else {
  11748. if (this.isNonstaticConstructor(publicMethod)) {
  11749. this.raise(publicMethod.key.start, ErrorMessages.ConstructorIsAccessor);
  11750. }
  11751. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  11752. }
  11753. this.checkGetterSetterParams(publicMethod);
  11754. } else if (this.isLineTerminator()) {
  11755. if (isPrivate) {
  11756. this.pushClassPrivateProperty(classBody, privateProp);
  11757. } else {
  11758. this.pushClassProperty(classBody, publicProp);
  11759. }
  11760. } else {
  11761. this.unexpected();
  11762. }
  11763. }
  11764. parseClassElementName(member) {
  11765. const {
  11766. type,
  11767. value,
  11768. start
  11769. } = this.state;
  11770. if ((type === 122 || type === 123) && member.static && value === "prototype") {
  11771. this.raise(start, ErrorMessages.StaticPrototype);
  11772. }
  11773. if (type === 128) {
  11774. if (value === "constructor") {
  11775. this.raise(start, ErrorMessages.ConstructorClassPrivateField);
  11776. }
  11777. const key = this.parsePrivateName();
  11778. member.key = key;
  11779. return key;
  11780. }
  11781. return this.parsePropertyName(member);
  11782. }
  11783. parseClassStaticBlock(classBody, member) {
  11784. var _member$decorators;
  11785. this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER);
  11786. const oldLabels = this.state.labels;
  11787. this.state.labels = [];
  11788. this.prodParam.enter(PARAM);
  11789. const body = member.body = [];
  11790. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  11791. this.prodParam.exit();
  11792. this.scope.exit();
  11793. this.state.labels = oldLabels;
  11794. classBody.body.push(this.finishNode(member, "StaticBlock"));
  11795. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  11796. this.raise(member.start, ErrorMessages.DecoratorStaticBlock);
  11797. }
  11798. }
  11799. pushClassProperty(classBody, prop) {
  11800. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  11801. this.raise(prop.key.start, ErrorMessages.ConstructorClassField);
  11802. }
  11803. classBody.body.push(this.parseClassProperty(prop));
  11804. }
  11805. pushClassPrivateProperty(classBody, prop) {
  11806. const node = this.parseClassPrivateProperty(prop);
  11807. classBody.body.push(node);
  11808. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), CLASS_ELEMENT_OTHER, node.key.start);
  11809. }
  11810. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  11811. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  11812. }
  11813. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  11814. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  11815. classBody.body.push(node);
  11816. 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;
  11817. this.declareClassPrivateMethodInScope(node, kind);
  11818. }
  11819. declareClassPrivateMethodInScope(node, kind) {
  11820. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.start);
  11821. }
  11822. parsePostMemberNameModifiers(methodOrProp) {}
  11823. parseClassPrivateProperty(node) {
  11824. this.parseInitializer(node);
  11825. this.semicolon();
  11826. return this.finishNode(node, "ClassPrivateProperty");
  11827. }
  11828. parseClassProperty(node) {
  11829. this.parseInitializer(node);
  11830. this.semicolon();
  11831. return this.finishNode(node, "ClassProperty");
  11832. }
  11833. parseInitializer(node) {
  11834. this.scope.enter(SCOPE_CLASS | SCOPE_SUPER);
  11835. this.expressionScope.enter(newExpressionScope());
  11836. this.prodParam.enter(PARAM);
  11837. node.value = this.eat(27) ? this.parseMaybeAssignAllowIn() : null;
  11838. this.expressionScope.exit();
  11839. this.prodParam.exit();
  11840. this.scope.exit();
  11841. }
  11842. parseClassId(node, isStatement, optionalId, bindingType = BIND_CLASS) {
  11843. if (tokenIsIdentifier(this.state.type)) {
  11844. node.id = this.parseIdentifier();
  11845. if (isStatement) {
  11846. this.checkLVal(node.id, "class name", bindingType);
  11847. }
  11848. } else {
  11849. if (optionalId || !isStatement) {
  11850. node.id = null;
  11851. } else {
  11852. this.unexpected(null, ErrorMessages.MissingClassName);
  11853. }
  11854. }
  11855. }
  11856. parseClassSuper(node) {
  11857. node.superClass = this.eat(75) ? this.parseExprSubscripts() : null;
  11858. }
  11859. parseExport(node) {
  11860. const hasDefault = this.maybeParseExportDefaultSpecifier(node);
  11861. const parseAfterDefault = !hasDefault || this.eat(12);
  11862. const hasStar = parseAfterDefault && this.eatExportStar(node);
  11863. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  11864. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  11865. const isFromRequired = hasDefault || hasStar;
  11866. if (hasStar && !hasNamespace) {
  11867. if (hasDefault) this.unexpected();
  11868. this.parseExportFrom(node, true);
  11869. return this.finishNode(node, "ExportAllDeclaration");
  11870. }
  11871. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  11872. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers || hasNamespace && parseAfterNamespace && !hasSpecifiers) {
  11873. throw this.unexpected(null, 5);
  11874. }
  11875. let hasDeclaration;
  11876. if (isFromRequired || hasSpecifiers) {
  11877. hasDeclaration = false;
  11878. this.parseExportFrom(node, isFromRequired);
  11879. } else {
  11880. hasDeclaration = this.maybeParseExportDeclaration(node);
  11881. }
  11882. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  11883. this.checkExport(node, true, false, !!node.source);
  11884. return this.finishNode(node, "ExportNamedDeclaration");
  11885. }
  11886. if (this.eat(59)) {
  11887. node.declaration = this.parseExportDefaultExpression();
  11888. this.checkExport(node, true, true);
  11889. return this.finishNode(node, "ExportDefaultDeclaration");
  11890. }
  11891. throw this.unexpected(null, 5);
  11892. }
  11893. eatExportStar(node) {
  11894. return this.eat(49);
  11895. }
  11896. maybeParseExportDefaultSpecifier(node) {
  11897. if (this.isExportDefaultSpecifier()) {
  11898. this.expectPlugin("exportDefaultFrom");
  11899. const specifier = this.startNode();
  11900. specifier.exported = this.parseIdentifier(true);
  11901. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  11902. return true;
  11903. }
  11904. return false;
  11905. }
  11906. maybeParseExportNamespaceSpecifier(node) {
  11907. if (this.isContextual(87)) {
  11908. if (!node.specifiers) node.specifiers = [];
  11909. const specifier = this.startNodeAt(this.state.lastTokStart, this.state.lastTokStartLoc);
  11910. this.next();
  11911. specifier.exported = this.parseModuleExportName();
  11912. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  11913. return true;
  11914. }
  11915. return false;
  11916. }
  11917. maybeParseExportNamedSpecifiers(node) {
  11918. if (this.match(5)) {
  11919. if (!node.specifiers) node.specifiers = [];
  11920. const isTypeExport = node.exportKind === "type";
  11921. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  11922. node.source = null;
  11923. node.declaration = null;
  11924. if (this.hasPlugin("importAssertions")) {
  11925. node.assertions = [];
  11926. }
  11927. return true;
  11928. }
  11929. return false;
  11930. }
  11931. maybeParseExportDeclaration(node) {
  11932. if (this.shouldParseExportDeclaration()) {
  11933. node.specifiers = [];
  11934. node.source = null;
  11935. if (this.hasPlugin("importAssertions")) {
  11936. node.assertions = [];
  11937. }
  11938. node.declaration = this.parseExportDeclaration(node);
  11939. return true;
  11940. }
  11941. return false;
  11942. }
  11943. isAsyncFunction() {
  11944. if (!this.isContextual(89)) return false;
  11945. const next = this.nextTokenStart();
  11946. return !lineBreak.test(this.input.slice(this.state.pos, next)) && this.isUnparsedContextual(next, "function");
  11947. }
  11948. parseExportDefaultExpression() {
  11949. const expr = this.startNode();
  11950. const isAsync = this.isAsyncFunction();
  11951. if (this.match(62) || isAsync) {
  11952. this.next();
  11953. if (isAsync) {
  11954. this.next();
  11955. }
  11956. return this.parseFunction(expr, FUNC_STATEMENT | FUNC_NULLABLE_ID, isAsync);
  11957. } else if (this.match(74)) {
  11958. return this.parseClass(expr, true, true);
  11959. } else if (this.match(24)) {
  11960. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport")) {
  11961. this.raise(this.state.start, ErrorMessages.DecoratorBeforeExport);
  11962. }
  11963. this.parseDecorators(false);
  11964. return this.parseClass(expr, true, true);
  11965. } else if (this.match(69) || this.match(68) || this.isLet()) {
  11966. throw this.raise(this.state.start, ErrorMessages.UnsupportedDefaultExport);
  11967. } else {
  11968. const res = this.parseMaybeAssignAllowIn();
  11969. this.semicolon();
  11970. return res;
  11971. }
  11972. }
  11973. parseExportDeclaration(node) {
  11974. return this.parseStatement(null);
  11975. }
  11976. isExportDefaultSpecifier() {
  11977. const {
  11978. type
  11979. } = this.state;
  11980. if (tokenIsIdentifier(type)) {
  11981. if (type === 89 && !this.state.containsEsc || type === 93) {
  11982. return false;
  11983. }
  11984. if ((type === 120 || type === 119) && !this.state.containsEsc) {
  11985. const {
  11986. type: nextType
  11987. } = this.lookahead();
  11988. if (tokenIsIdentifier(nextType) && nextType !== 91 || nextType === 5) {
  11989. this.expectOnePlugin(["flow", "typescript"]);
  11990. return false;
  11991. }
  11992. }
  11993. } else if (!this.match(59)) {
  11994. return false;
  11995. }
  11996. const next = this.nextTokenStart();
  11997. const hasFrom = this.isUnparsedContextual(next, "from");
  11998. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  11999. return true;
  12000. }
  12001. if (this.match(59) && hasFrom) {
  12002. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  12003. return nextAfterFrom === 34 || nextAfterFrom === 39;
  12004. }
  12005. return false;
  12006. }
  12007. parseExportFrom(node, expect) {
  12008. if (this.eatContextual(91)) {
  12009. node.source = this.parseImportSource();
  12010. this.checkExport(node);
  12011. const assertions = this.maybeParseImportAssertions();
  12012. if (assertions) {
  12013. node.assertions = assertions;
  12014. }
  12015. } else if (expect) {
  12016. this.unexpected();
  12017. }
  12018. this.semicolon();
  12019. }
  12020. shouldParseExportDeclaration() {
  12021. const {
  12022. type
  12023. } = this.state;
  12024. if (type === 24) {
  12025. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12026. if (this.hasPlugin("decorators")) {
  12027. if (this.getPluginOption("decorators", "decoratorsBeforeExport")) {
  12028. this.unexpected(this.state.start, ErrorMessages.DecoratorBeforeExport);
  12029. } else {
  12030. return true;
  12031. }
  12032. }
  12033. }
  12034. return type === 68 || type === 69 || type === 62 || type === 74 || this.isLet() || this.isAsyncFunction();
  12035. }
  12036. checkExport(node, checkNames, isDefault, isFrom) {
  12037. if (checkNames) {
  12038. if (isDefault) {
  12039. this.checkDuplicateExports(node, "default");
  12040. if (this.hasPlugin("exportDefaultFrom")) {
  12041. var _declaration$extra;
  12042. const declaration = node.declaration;
  12043. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  12044. this.raise(declaration.start, ErrorMessages.ExportDefaultFromAsIdentifier);
  12045. }
  12046. }
  12047. } else if (node.specifiers && node.specifiers.length) {
  12048. for (const specifier of node.specifiers) {
  12049. const {
  12050. exported
  12051. } = specifier;
  12052. const exportedName = exported.type === "Identifier" ? exported.name : exported.value;
  12053. this.checkDuplicateExports(specifier, exportedName);
  12054. if (!isFrom && specifier.local) {
  12055. const {
  12056. local
  12057. } = specifier;
  12058. if (local.type !== "Identifier") {
  12059. this.raise(specifier.start, ErrorMessages.ExportBindingIsString, local.value, exportedName);
  12060. } else {
  12061. this.checkReservedWord(local.name, local.start, true, false);
  12062. this.scope.checkLocalExport(local);
  12063. }
  12064. }
  12065. }
  12066. } else if (node.declaration) {
  12067. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  12068. const id = node.declaration.id;
  12069. if (!id) throw new Error("Assertion failure");
  12070. this.checkDuplicateExports(node, id.name);
  12071. } else if (node.declaration.type === "VariableDeclaration") {
  12072. for (const declaration of node.declaration.declarations) {
  12073. this.checkDeclaration(declaration.id);
  12074. }
  12075. }
  12076. }
  12077. }
  12078. const currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1];
  12079. if (currentContextDecorators.length) {
  12080. throw this.raise(node.start, ErrorMessages.UnsupportedDecoratorExport);
  12081. }
  12082. }
  12083. checkDeclaration(node) {
  12084. if (node.type === "Identifier") {
  12085. this.checkDuplicateExports(node, node.name);
  12086. } else if (node.type === "ObjectPattern") {
  12087. for (const prop of node.properties) {
  12088. this.checkDeclaration(prop);
  12089. }
  12090. } else if (node.type === "ArrayPattern") {
  12091. for (const elem of node.elements) {
  12092. if (elem) {
  12093. this.checkDeclaration(elem);
  12094. }
  12095. }
  12096. } else if (node.type === "ObjectProperty") {
  12097. this.checkDeclaration(node.value);
  12098. } else if (node.type === "RestElement") {
  12099. this.checkDeclaration(node.argument);
  12100. } else if (node.type === "AssignmentPattern") {
  12101. this.checkDeclaration(node.left);
  12102. }
  12103. }
  12104. checkDuplicateExports(node, name) {
  12105. if (this.exportedIdentifiers.has(name)) {
  12106. this.raise(node.start, name === "default" ? ErrorMessages.DuplicateDefaultExport : ErrorMessages.DuplicateExport, name);
  12107. }
  12108. this.exportedIdentifiers.add(name);
  12109. }
  12110. parseExportSpecifiers(isInTypeExport) {
  12111. const nodes = [];
  12112. let first = true;
  12113. this.expect(5);
  12114. while (!this.eat(8)) {
  12115. if (first) {
  12116. first = false;
  12117. } else {
  12118. this.expect(12);
  12119. if (this.eat(8)) break;
  12120. }
  12121. const isMaybeTypeOnly = this.isContextual(120);
  12122. const isString = this.match(123);
  12123. const node = this.startNode();
  12124. node.local = this.parseModuleExportName();
  12125. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  12126. }
  12127. return nodes;
  12128. }
  12129. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  12130. if (this.eatContextual(87)) {
  12131. node.exported = this.parseModuleExportName();
  12132. } else if (isString) {
  12133. node.exported = cloneStringLiteral(node.local);
  12134. } else if (!node.exported) {
  12135. node.exported = cloneIdentifier(node.local);
  12136. }
  12137. return this.finishNode(node, "ExportSpecifier");
  12138. }
  12139. parseModuleExportName() {
  12140. if (this.match(123)) {
  12141. const result = this.parseStringLiteral(this.state.value);
  12142. const surrogate = result.value.match(loneSurrogate);
  12143. if (surrogate) {
  12144. this.raise(result.start, ErrorMessages.ModuleExportNameHasLoneSurrogate, surrogate[0].charCodeAt(0).toString(16));
  12145. }
  12146. return result;
  12147. }
  12148. return this.parseIdentifier(true);
  12149. }
  12150. parseImport(node) {
  12151. node.specifiers = [];
  12152. if (!this.match(123)) {
  12153. const hasDefault = this.maybeParseDefaultImportSpecifier(node);
  12154. const parseNext = !hasDefault || this.eat(12);
  12155. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  12156. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  12157. this.expectContextual(91);
  12158. }
  12159. node.source = this.parseImportSource();
  12160. const assertions = this.maybeParseImportAssertions();
  12161. if (assertions) {
  12162. node.assertions = assertions;
  12163. } else {
  12164. const attributes = this.maybeParseModuleAttributes();
  12165. if (attributes) {
  12166. node.attributes = attributes;
  12167. }
  12168. }
  12169. this.semicolon();
  12170. return this.finishNode(node, "ImportDeclaration");
  12171. }
  12172. parseImportSource() {
  12173. if (!this.match(123)) this.unexpected();
  12174. return this.parseExprAtom();
  12175. }
  12176. shouldParseDefaultImport(node) {
  12177. return tokenIsIdentifier(this.state.type);
  12178. }
  12179. parseImportSpecifierLocal(node, specifier, type, contextDescription) {
  12180. specifier.local = this.parseIdentifier();
  12181. this.checkLVal(specifier.local, contextDescription, BIND_LEXICAL);
  12182. node.specifiers.push(this.finishNode(specifier, type));
  12183. }
  12184. parseAssertEntries() {
  12185. const attrs = [];
  12186. const attrNames = new Set();
  12187. do {
  12188. if (this.match(8)) {
  12189. break;
  12190. }
  12191. const node = this.startNode();
  12192. const keyName = this.state.value;
  12193. if (attrNames.has(keyName)) {
  12194. this.raise(this.state.start, ErrorMessages.ModuleAttributesWithDuplicateKeys, keyName);
  12195. }
  12196. attrNames.add(keyName);
  12197. if (this.match(123)) {
  12198. node.key = this.parseStringLiteral(keyName);
  12199. } else {
  12200. node.key = this.parseIdentifier(true);
  12201. }
  12202. this.expect(14);
  12203. if (!this.match(123)) {
  12204. throw this.unexpected(this.state.start, ErrorMessages.ModuleAttributeInvalidValue);
  12205. }
  12206. node.value = this.parseStringLiteral(this.state.value);
  12207. this.finishNode(node, "ImportAttribute");
  12208. attrs.push(node);
  12209. } while (this.eat(12));
  12210. return attrs;
  12211. }
  12212. maybeParseModuleAttributes() {
  12213. if (this.match(70) && !this.hasPrecedingLineBreak()) {
  12214. this.expectPlugin("moduleAttributes");
  12215. this.next();
  12216. } else {
  12217. if (this.hasPlugin("moduleAttributes")) return [];
  12218. return null;
  12219. }
  12220. const attrs = [];
  12221. const attributes = new Set();
  12222. do {
  12223. const node = this.startNode();
  12224. node.key = this.parseIdentifier(true);
  12225. if (node.key.name !== "type") {
  12226. this.raise(node.key.start, ErrorMessages.ModuleAttributeDifferentFromType, node.key.name);
  12227. }
  12228. if (attributes.has(node.key.name)) {
  12229. this.raise(node.key.start, ErrorMessages.ModuleAttributesWithDuplicateKeys, node.key.name);
  12230. }
  12231. attributes.add(node.key.name);
  12232. this.expect(14);
  12233. if (!this.match(123)) {
  12234. throw this.unexpected(this.state.start, ErrorMessages.ModuleAttributeInvalidValue);
  12235. }
  12236. node.value = this.parseStringLiteral(this.state.value);
  12237. this.finishNode(node, "ImportAttribute");
  12238. attrs.push(node);
  12239. } while (this.eat(12));
  12240. return attrs;
  12241. }
  12242. maybeParseImportAssertions() {
  12243. if (this.isContextual(88) && !this.hasPrecedingLineBreak()) {
  12244. this.expectPlugin("importAssertions");
  12245. this.next();
  12246. } else {
  12247. if (this.hasPlugin("importAssertions")) return [];
  12248. return null;
  12249. }
  12250. this.eat(5);
  12251. const attrs = this.parseAssertEntries();
  12252. this.eat(8);
  12253. return attrs;
  12254. }
  12255. maybeParseDefaultImportSpecifier(node) {
  12256. if (this.shouldParseDefaultImport(node)) {
  12257. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier", "default import specifier");
  12258. return true;
  12259. }
  12260. return false;
  12261. }
  12262. maybeParseStarImportSpecifier(node) {
  12263. if (this.match(49)) {
  12264. const specifier = this.startNode();
  12265. this.next();
  12266. this.expectContextual(87);
  12267. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier", "import namespace specifier");
  12268. return true;
  12269. }
  12270. return false;
  12271. }
  12272. parseNamedImportSpecifiers(node) {
  12273. let first = true;
  12274. this.expect(5);
  12275. while (!this.eat(8)) {
  12276. if (first) {
  12277. first = false;
  12278. } else {
  12279. if (this.eat(14)) {
  12280. throw this.raise(this.state.start, ErrorMessages.DestructureNamedImport);
  12281. }
  12282. this.expect(12);
  12283. if (this.eat(8)) break;
  12284. }
  12285. const specifier = this.startNode();
  12286. const importedIsString = this.match(123);
  12287. const isMaybeTypeOnly = this.isContextual(120);
  12288. specifier.imported = this.parseModuleExportName();
  12289. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly);
  12290. node.specifiers.push(importSpecifier);
  12291. }
  12292. }
  12293. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly) {
  12294. if (this.eatContextual(87)) {
  12295. specifier.local = this.parseIdentifier();
  12296. } else {
  12297. const {
  12298. imported
  12299. } = specifier;
  12300. if (importedIsString) {
  12301. throw this.raise(specifier.start, ErrorMessages.ImportBindingIsString, imported.value);
  12302. }
  12303. this.checkReservedWord(imported.name, specifier.start, true, true);
  12304. if (!specifier.local) {
  12305. specifier.local = cloneIdentifier(imported);
  12306. }
  12307. }
  12308. this.checkLVal(specifier.local, "import specifier", BIND_LEXICAL);
  12309. return this.finishNode(specifier, "ImportSpecifier");
  12310. }
  12311. isThisParam(param) {
  12312. return param.type === "Identifier" && param.name === "this";
  12313. }
  12314. }
  12315. class Parser extends StatementParser {
  12316. constructor(options, input) {
  12317. options = getOptions(options);
  12318. super(options, input);
  12319. this.options = options;
  12320. this.initializeScopes();
  12321. this.plugins = pluginsMap(this.options.plugins);
  12322. this.filename = options.sourceFilename;
  12323. }
  12324. getScopeHandler() {
  12325. return ScopeHandler;
  12326. }
  12327. parse() {
  12328. this.enterInitialScopes();
  12329. const file = this.startNode();
  12330. const program = this.startNode();
  12331. this.nextToken();
  12332. file.errors = null;
  12333. this.parseTopLevel(file, program);
  12334. file.errors = this.state.errors;
  12335. return file;
  12336. }
  12337. }
  12338. function pluginsMap(plugins) {
  12339. const pluginMap = new Map();
  12340. for (const plugin of plugins) {
  12341. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  12342. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  12343. }
  12344. return pluginMap;
  12345. }
  12346. function parse(input, options) {
  12347. var _options;
  12348. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  12349. options = Object.assign({}, options);
  12350. try {
  12351. options.sourceType = "module";
  12352. const parser = getParser(options, input);
  12353. const ast = parser.parse();
  12354. if (parser.sawUnambiguousESM) {
  12355. return ast;
  12356. }
  12357. if (parser.ambiguousScriptDifferentAst) {
  12358. try {
  12359. options.sourceType = "script";
  12360. return getParser(options, input).parse();
  12361. } catch (_unused) {}
  12362. } else {
  12363. ast.program.sourceType = "script";
  12364. }
  12365. return ast;
  12366. } catch (moduleError) {
  12367. try {
  12368. options.sourceType = "script";
  12369. return getParser(options, input).parse();
  12370. } catch (_unused2) {}
  12371. throw moduleError;
  12372. }
  12373. } else {
  12374. return getParser(options, input).parse();
  12375. }
  12376. }
  12377. function parseExpression(input, options) {
  12378. const parser = getParser(options, input);
  12379. if (parser.options.strictMode) {
  12380. parser.state.strict = true;
  12381. }
  12382. return parser.getExpression();
  12383. }
  12384. function generateExportedTokenTypes(internalTokenTypes) {
  12385. const tokenTypes = {};
  12386. for (const typeName of Object.keys(internalTokenTypes)) {
  12387. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  12388. }
  12389. return tokenTypes;
  12390. }
  12391. const tokTypes = generateExportedTokenTypes(tt);
  12392. function getParser(options, input) {
  12393. let cls = Parser;
  12394. if (options != null && options.plugins) {
  12395. validatePlugins(options.plugins);
  12396. cls = getParserClass(options.plugins);
  12397. }
  12398. return new cls(options, input);
  12399. }
  12400. const parserClassCache = {};
  12401. function getParserClass(pluginsFromOptions) {
  12402. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  12403. const key = pluginList.join("/");
  12404. let cls = parserClassCache[key];
  12405. if (!cls) {
  12406. cls = Parser;
  12407. for (const plugin of pluginList) {
  12408. cls = mixinPlugins[plugin](cls);
  12409. }
  12410. parserClassCache[key] = cls;
  12411. }
  12412. return cls;
  12413. }
  12414. exports.parse = parse;
  12415. exports.parseExpression = parseExpression;
  12416. exports.tokTypes = tokTypes;
  12417. //# sourceMappingURL=index.js.map