acorn.mjs 226 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266
  1. // This file was generated. Do not modify manually!
  2. var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 78, 5, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  3. // This file was generated. Do not modify manually!
  4. var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 7, 25, 39, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 57, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 261, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489];
  5. // This file was generated. Do not modify manually!
  6. var 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\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1add\u1ae0-\u1aeb\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
  7. // This file was generated. Do not modify manually!
  8. var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088f\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5c\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdc-\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7dc\ua7f1-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  9. // These are a run-length and offset encoded representation of the
  10. // >0xffff code points that are a valid part of identifiers. The
  11. // offset starts at 0x10000, and each pair of numbers represents an
  12. // offset to the next range, and then a size of the range.
  13. // Reserved word lists for various dialects of the language
  14. var reservedWords = {
  15. 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
  16. 5: "class enum extends super const export import",
  17. 6: "enum",
  18. strict: "implements interface let package private protected public static yield",
  19. strictBind: "eval arguments"
  20. };
  21. // And the keywords
  22. var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
  23. var keywords$1 = {
  24. 5: ecma5AndLessKeywords,
  25. "5module": ecma5AndLessKeywords + " export import",
  26. 6: ecma5AndLessKeywords + " const class extends export import super"
  27. };
  28. var keywordRelationalOperator = /^in(stanceof)?$/;
  29. // ## Character categories
  30. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  31. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  32. // This has a complexity linear to the value of the code. The
  33. // assumption is that looking up astral identifier characters is
  34. // rare.
  35. function isInAstralSet(code, set) {
  36. var pos = 0x10000;
  37. for (var i = 0; i < set.length; i += 2) {
  38. pos += set[i];
  39. if (pos > code) { return false }
  40. pos += set[i + 1];
  41. if (pos >= code) { return true }
  42. }
  43. return false
  44. }
  45. // Test whether a given character code starts an identifier.
  46. function isIdentifierStart(code, astral) {
  47. if (code < 65) { return code === 36 }
  48. if (code < 91) { return true }
  49. if (code < 97) { return code === 95 }
  50. if (code < 123) { return true }
  51. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  52. if (astral === false) { return false }
  53. return isInAstralSet(code, astralIdentifierStartCodes)
  54. }
  55. // Test whether a given character is part of an identifier.
  56. function isIdentifierChar(code, astral) {
  57. if (code < 48) { return code === 36 }
  58. if (code < 58) { return true }
  59. if (code < 65) { return false }
  60. if (code < 91) { return true }
  61. if (code < 97) { return code === 95 }
  62. if (code < 123) { return true }
  63. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  64. if (astral === false) { return false }
  65. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  66. }
  67. // ## Token types
  68. // The assignment of fine-grained, information-carrying type objects
  69. // allows the tokenizer to store the information it has about a
  70. // token in a way that is very cheap for the parser to look up.
  71. // All token type variables start with an underscore, to make them
  72. // easy to recognize.
  73. // The `beforeExpr` property is used to disambiguate between regular
  74. // expressions and divisions. It is set on all token types that can
  75. // be followed by an expression (thus, a slash after them would be a
  76. // regular expression).
  77. //
  78. // The `startsExpr` property is used to check if the token ends a
  79. // `yield` expression. It is set on all token types that either can
  80. // directly start an expression (like a quotation mark) or can
  81. // continue an expression (like the body of a string).
  82. //
  83. // `isLoop` marks a keyword as starting a loop, which is important
  84. // to know when parsing a label, in order to allow or disallow
  85. // continue jumps to that label.
  86. var TokenType = function TokenType(label, conf) {
  87. if ( conf === void 0 ) conf = {};
  88. this.label = label;
  89. this.keyword = conf.keyword;
  90. this.beforeExpr = !!conf.beforeExpr;
  91. this.startsExpr = !!conf.startsExpr;
  92. this.isLoop = !!conf.isLoop;
  93. this.isAssign = !!conf.isAssign;
  94. this.prefix = !!conf.prefix;
  95. this.postfix = !!conf.postfix;
  96. this.binop = conf.binop || null;
  97. this.updateContext = null;
  98. };
  99. function binop(name, prec) {
  100. return new TokenType(name, {beforeExpr: true, binop: prec})
  101. }
  102. var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
  103. // Map keyword names to token types.
  104. var keywords = {};
  105. // Succinct definitions of keyword token types
  106. function kw(name, options) {
  107. if ( options === void 0 ) options = {};
  108. options.keyword = name;
  109. return keywords[name] = new TokenType(name, options)
  110. }
  111. var types$1 = {
  112. num: new TokenType("num", startsExpr),
  113. regexp: new TokenType("regexp", startsExpr),
  114. string: new TokenType("string", startsExpr),
  115. name: new TokenType("name", startsExpr),
  116. privateId: new TokenType("privateId", startsExpr),
  117. eof: new TokenType("eof"),
  118. // Punctuation token types.
  119. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  120. bracketR: new TokenType("]"),
  121. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  122. braceR: new TokenType("}"),
  123. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  124. parenR: new TokenType(")"),
  125. comma: new TokenType(",", beforeExpr),
  126. semi: new TokenType(";", beforeExpr),
  127. colon: new TokenType(":", beforeExpr),
  128. dot: new TokenType("."),
  129. question: new TokenType("?", beforeExpr),
  130. questionDot: new TokenType("?."),
  131. arrow: new TokenType("=>", beforeExpr),
  132. template: new TokenType("template"),
  133. invalidTemplate: new TokenType("invalidTemplate"),
  134. ellipsis: new TokenType("...", beforeExpr),
  135. backQuote: new TokenType("`", startsExpr),
  136. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  137. // Operators. These carry several kinds of properties to help the
  138. // parser use them properly (the presence of these properties is
  139. // what categorizes them as operators).
  140. //
  141. // `binop`, when present, specifies that this operator is a binary
  142. // operator, and will refer to its precedence.
  143. //
  144. // `prefix` and `postfix` mark the operator as a prefix or postfix
  145. // unary operator.
  146. //
  147. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  148. // binary operators with a very low precedence, that should result
  149. // in AssignmentExpression nodes.
  150. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  151. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  152. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  153. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  154. logicalOR: binop("||", 1),
  155. logicalAND: binop("&&", 2),
  156. bitwiseOR: binop("|", 3),
  157. bitwiseXOR: binop("^", 4),
  158. bitwiseAND: binop("&", 5),
  159. equality: binop("==/!=/===/!==", 6),
  160. relational: binop("</>/<=/>=", 7),
  161. bitShift: binop("<</>>/>>>", 8),
  162. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  163. modulo: binop("%", 10),
  164. star: binop("*", 10),
  165. slash: binop("/", 10),
  166. starstar: new TokenType("**", {beforeExpr: true}),
  167. coalesce: binop("??", 1),
  168. // Keyword token types.
  169. _break: kw("break"),
  170. _case: kw("case", beforeExpr),
  171. _catch: kw("catch"),
  172. _continue: kw("continue"),
  173. _debugger: kw("debugger"),
  174. _default: kw("default", beforeExpr),
  175. _do: kw("do", {isLoop: true, beforeExpr: true}),
  176. _else: kw("else", beforeExpr),
  177. _finally: kw("finally"),
  178. _for: kw("for", {isLoop: true}),
  179. _function: kw("function", startsExpr),
  180. _if: kw("if"),
  181. _return: kw("return", beforeExpr),
  182. _switch: kw("switch"),
  183. _throw: kw("throw", beforeExpr),
  184. _try: kw("try"),
  185. _var: kw("var"),
  186. _const: kw("const"),
  187. _while: kw("while", {isLoop: true}),
  188. _with: kw("with"),
  189. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  190. _this: kw("this", startsExpr),
  191. _super: kw("super", startsExpr),
  192. _class: kw("class", startsExpr),
  193. _extends: kw("extends", beforeExpr),
  194. _export: kw("export"),
  195. _import: kw("import", startsExpr),
  196. _null: kw("null", startsExpr),
  197. _true: kw("true", startsExpr),
  198. _false: kw("false", startsExpr),
  199. _in: kw("in", {beforeExpr: true, binop: 7}),
  200. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  201. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  202. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  203. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  204. };
  205. // Matches a whole line break (where CRLF is considered a single
  206. // line break). Used to count lines.
  207. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  208. var lineBreakG = new RegExp(lineBreak.source, "g");
  209. function isNewLine(code) {
  210. return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
  211. }
  212. function nextLineBreak(code, from, end) {
  213. if ( end === void 0 ) end = code.length;
  214. for (var i = from; i < end; i++) {
  215. var next = code.charCodeAt(i);
  216. if (isNewLine(next))
  217. { return i < end - 1 && next === 13 && code.charCodeAt(i + 1) === 10 ? i + 2 : i + 1 }
  218. }
  219. return -1
  220. }
  221. var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  222. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  223. var ref = Object.prototype;
  224. var hasOwnProperty = ref.hasOwnProperty;
  225. var toString = ref.toString;
  226. var hasOwn = Object.hasOwn || (function (obj, propName) { return (
  227. hasOwnProperty.call(obj, propName)
  228. ); });
  229. var isArray = Array.isArray || (function (obj) { return (
  230. toString.call(obj) === "[object Array]"
  231. ); });
  232. var regexpCache = Object.create(null);
  233. function wordsRegexp(words) {
  234. return regexpCache[words] || (regexpCache[words] = new RegExp("^(?:" + words.replace(/ /g, "|") + ")$"))
  235. }
  236. function codePointToString(code) {
  237. // UTF-16 Decoding
  238. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  239. code -= 0x10000;
  240. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  241. }
  242. var loneSurrogate = /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/;
  243. // These are used when `options.locations` is on, for the
  244. // `startLoc` and `endLoc` properties.
  245. var Position = function Position(line, col) {
  246. this.line = line;
  247. this.column = col;
  248. };
  249. Position.prototype.offset = function offset (n) {
  250. return new Position(this.line, this.column + n)
  251. };
  252. var SourceLocation = function SourceLocation(p, start, end) {
  253. this.start = start;
  254. this.end = end;
  255. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  256. };
  257. // The `getLineInfo` function is mostly useful when the
  258. // `locations` option is off (for performance reasons) and you
  259. // want to find the line/column position for a given character
  260. // offset. `input` should be the code string that the offset refers
  261. // into.
  262. function getLineInfo(input, offset) {
  263. for (var line = 1, cur = 0;;) {
  264. var nextBreak = nextLineBreak(input, cur, offset);
  265. if (nextBreak < 0) { return new Position(line, offset - cur) }
  266. ++line;
  267. cur = nextBreak;
  268. }
  269. }
  270. // A second argument must be given to configure the parser process.
  271. // These options are recognized (only `ecmaVersion` is required):
  272. var defaultOptions = {
  273. // `ecmaVersion` indicates the ECMAScript version to parse. Must be
  274. // either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
  275. // (2019), 11 (2020), 12 (2021), 13 (2022), 14 (2023), or `"latest"`
  276. // (the latest version the library supports). This influences
  277. // support for strict mode, the set of reserved words, and support
  278. // for new syntax features.
  279. ecmaVersion: null,
  280. // `sourceType` indicates the mode the code should be parsed in.
  281. // Can be either `"script"`, `"module"` or `"commonjs"`. This influences global
  282. // strict mode and parsing of `import` and `export` declarations.
  283. sourceType: "script",
  284. // `onInsertedSemicolon` can be a callback that will be called when
  285. // a semicolon is automatically inserted. It will be passed the
  286. // position of the inserted semicolon as an offset, and if
  287. // `locations` is enabled, it is given the location as a `{line,
  288. // column}` object as second argument.
  289. onInsertedSemicolon: null,
  290. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  291. // trailing commas.
  292. onTrailingComma: null,
  293. // By default, reserved words are only enforced if ecmaVersion >= 5.
  294. // Set `allowReserved` to a boolean value to explicitly turn this on
  295. // an off. When this option has the value "never", reserved words
  296. // and keywords can also not be used as property names.
  297. allowReserved: null,
  298. // When enabled, a return at the top level is not considered an
  299. // error.
  300. allowReturnOutsideFunction: false,
  301. // When enabled, import/export statements are not constrained to
  302. // appearing at the top of the program, and an import.meta expression
  303. // in a script isn't considered an error.
  304. allowImportExportEverywhere: false,
  305. // By default, await identifiers are allowed to appear at the top-level scope only if ecmaVersion >= 2022.
  306. // When enabled, await identifiers are allowed to appear at the top-level scope,
  307. // but they are still not allowed in non-async functions.
  308. allowAwaitOutsideFunction: null,
  309. // When enabled, super identifiers are not constrained to
  310. // appearing in methods and do not raise an error when they appear elsewhere.
  311. allowSuperOutsideMethod: null,
  312. // When enabled, hashbang directive in the beginning of file is
  313. // allowed and treated as a line comment. Enabled by default when
  314. // `ecmaVersion` >= 2023.
  315. allowHashBang: false,
  316. // By default, the parser will verify that private properties are
  317. // only used in places where they are valid and have been declared.
  318. // Set this to false to turn such checks off.
  319. checkPrivateFields: true,
  320. // When `locations` is on, `loc` properties holding objects with
  321. // `start` and `end` properties in `{line, column}` form (with
  322. // line being 1-based and column 0-based) will be attached to the
  323. // nodes.
  324. locations: false,
  325. // A function can be passed as `onToken` option, which will
  326. // cause Acorn to call that function with object in the same
  327. // format as tokens returned from `tokenizer().getToken()`. Note
  328. // that you are not allowed to call the parser from the
  329. // callback—that will corrupt its internal state.
  330. onToken: null,
  331. // A function can be passed as `onComment` option, which will
  332. // cause Acorn to call that function with `(block, text, start,
  333. // end)` parameters whenever a comment is skipped. `block` is a
  334. // boolean indicating whether this is a block (`/* */`) comment,
  335. // `text` is the content of the comment, and `start` and `end` are
  336. // character offsets that denote the start and end of the comment.
  337. // When the `locations` option is on, two more parameters are
  338. // passed, the full `{line, column}` locations of the start and
  339. // end of the comments. Note that you are not allowed to call the
  340. // parser from the callback—that will corrupt its internal state.
  341. // When this option has an array as value, objects representing the
  342. // comments are pushed to it.
  343. onComment: null,
  344. // Nodes have their start and end characters offsets recorded in
  345. // `start` and `end` properties (directly on the node, rather than
  346. // the `loc` object, which holds line/column data. To also add a
  347. // [semi-standardized][range] `range` property holding a `[start,
  348. // end]` array with the same numbers, set the `ranges` option to
  349. // `true`.
  350. //
  351. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  352. ranges: false,
  353. // It is possible to parse multiple files into a single AST by
  354. // passing the tree produced by parsing the first file as
  355. // `program` option in subsequent parses. This will add the
  356. // toplevel forms of the parsed file to the `Program` (top) node
  357. // of an existing parse tree.
  358. program: null,
  359. // When `locations` is on, you can pass this to record the source
  360. // file in every node's `loc` object.
  361. sourceFile: null,
  362. // This value, if given, is stored in every node, whether
  363. // `locations` is on or off.
  364. directSourceFile: null,
  365. // When enabled, parenthesized expressions are represented by
  366. // (non-standard) ParenthesizedExpression nodes
  367. preserveParens: false
  368. };
  369. // Interpret and default an options object
  370. var warnedAboutEcmaVersion = false;
  371. function getOptions(opts) {
  372. var options = {};
  373. for (var opt in defaultOptions)
  374. { options[opt] = opts && hasOwn(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  375. if (options.ecmaVersion === "latest") {
  376. options.ecmaVersion = 1e8;
  377. } else if (options.ecmaVersion == null) {
  378. if (!warnedAboutEcmaVersion && typeof console === "object" && console.warn) {
  379. warnedAboutEcmaVersion = true;
  380. console.warn("Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.");
  381. }
  382. options.ecmaVersion = 11;
  383. } else if (options.ecmaVersion >= 2015) {
  384. options.ecmaVersion -= 2009;
  385. }
  386. if (options.allowReserved == null)
  387. { options.allowReserved = options.ecmaVersion < 5; }
  388. if (!opts || opts.allowHashBang == null)
  389. { options.allowHashBang = options.ecmaVersion >= 14; }
  390. if (isArray(options.onToken)) {
  391. var tokens = options.onToken;
  392. options.onToken = function (token) { return tokens.push(token); };
  393. }
  394. if (isArray(options.onComment))
  395. { options.onComment = pushComment(options, options.onComment); }
  396. if (options.sourceType === "commonjs" && options.allowAwaitOutsideFunction)
  397. { throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs") }
  398. return options
  399. }
  400. function pushComment(options, array) {
  401. return function(block, text, start, end, startLoc, endLoc) {
  402. var comment = {
  403. type: block ? "Block" : "Line",
  404. value: text,
  405. start: start,
  406. end: end
  407. };
  408. if (options.locations)
  409. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  410. if (options.ranges)
  411. { comment.range = [start, end]; }
  412. array.push(comment);
  413. }
  414. }
  415. // Each scope gets a bitset that may contain these flags
  416. var
  417. SCOPE_TOP = 1,
  418. SCOPE_FUNCTION = 2,
  419. SCOPE_ASYNC = 4,
  420. SCOPE_GENERATOR = 8,
  421. SCOPE_ARROW = 16,
  422. SCOPE_SIMPLE_CATCH = 32,
  423. SCOPE_SUPER = 64,
  424. SCOPE_DIRECT_SUPER = 128,
  425. SCOPE_CLASS_STATIC_BLOCK = 256,
  426. SCOPE_CLASS_FIELD_INIT = 512,
  427. SCOPE_SWITCH = 1024,
  428. SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;
  429. function functionFlags(async, generator) {
  430. return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
  431. }
  432. // Used in checkLVal* and declareName to determine the type of a binding
  433. var
  434. BIND_NONE = 0, // Not a binding
  435. BIND_VAR = 1, // Var-style binding
  436. BIND_LEXICAL = 2, // Let- or const-style binding
  437. BIND_FUNCTION = 3, // Function declaration
  438. BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
  439. BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
  440. var Parser = function Parser(options, input, startPos) {
  441. this.options = options = getOptions(options);
  442. this.sourceFile = options.sourceFile;
  443. this.keywords = wordsRegexp(keywords$1[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
  444. var reserved = "";
  445. if (options.allowReserved !== true) {
  446. reserved = reservedWords[options.ecmaVersion >= 6 ? 6 : options.ecmaVersion === 5 ? 5 : 3];
  447. if (options.sourceType === "module") { reserved += " await"; }
  448. }
  449. this.reservedWords = wordsRegexp(reserved);
  450. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  451. this.reservedWordsStrict = wordsRegexp(reservedStrict);
  452. this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
  453. this.input = String(input);
  454. // Used to signal to callers of `readWord1` whether the word
  455. // contained any escape sequences. This is needed because words with
  456. // escape sequences must not be interpreted as keywords.
  457. this.containsEsc = false;
  458. // Set up token state
  459. // The current position of the tokenizer in the input.
  460. if (startPos) {
  461. this.pos = startPos;
  462. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  463. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  464. } else {
  465. this.pos = this.lineStart = 0;
  466. this.curLine = 1;
  467. }
  468. // Properties of the current token:
  469. // Its type
  470. this.type = types$1.eof;
  471. // For tokens that include more information than their type, the value
  472. this.value = null;
  473. // Its start and end offset
  474. this.start = this.end = this.pos;
  475. // And, if locations are used, the {line, column} object
  476. // corresponding to those offsets
  477. this.startLoc = this.endLoc = this.curPosition();
  478. // Position information for the previous token
  479. this.lastTokEndLoc = this.lastTokStartLoc = null;
  480. this.lastTokStart = this.lastTokEnd = this.pos;
  481. // The context stack is used to superficially track syntactic
  482. // context to predict whether a regular expression is allowed in a
  483. // given position.
  484. this.context = this.initialContext();
  485. this.exprAllowed = true;
  486. // Figure out if it's a module code.
  487. this.inModule = options.sourceType === "module";
  488. this.strict = this.inModule || this.strictDirective(this.pos);
  489. // Used to signify the start of a potential arrow function
  490. this.potentialArrowAt = -1;
  491. this.potentialArrowInForAwait = false;
  492. // Positions to delayed-check that yield/await does not exist in default parameters.
  493. this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
  494. // Labels in scope.
  495. this.labels = [];
  496. // Thus-far undefined exports.
  497. this.undefinedExports = Object.create(null);
  498. // If enabled, skip leading hashbang line.
  499. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  500. { this.skipLineComment(2); }
  501. // Scope tracking for duplicate variable names (see scope.js)
  502. this.scopeStack = [];
  503. this.enterScope(
  504. this.options.sourceType === "commonjs"
  505. // In commonjs, the top-level scope behaves like a function scope
  506. ? SCOPE_FUNCTION
  507. : SCOPE_TOP
  508. );
  509. // For RegExp validation
  510. this.regexpState = null;
  511. // The stack of private names.
  512. // Each element has two properties: 'declared' and 'used'.
  513. // When it exited from the outermost class definition, all used private names must be declared.
  514. this.privateNameStack = [];
  515. };
  516. var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },canAwait: { configurable: true },allowReturn: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true },allowNewDotTarget: { configurable: true },allowUsing: { configurable: true },inClassStaticBlock: { configurable: true } };
  517. Parser.prototype.parse = function parse () {
  518. var node = this.options.program || this.startNode();
  519. this.nextToken();
  520. return this.parseTopLevel(node)
  521. };
  522. prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
  523. prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 };
  524. prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 };
  525. prototypeAccessors.canAwait.get = function () {
  526. for (var i = this.scopeStack.length - 1; i >= 0; i--) {
  527. var ref = this.scopeStack[i];
  528. var flags = ref.flags;
  529. if (flags & (SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT)) { return false }
  530. if (flags & SCOPE_FUNCTION) { return (flags & SCOPE_ASYNC) > 0 }
  531. }
  532. return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction
  533. };
  534. prototypeAccessors.allowReturn.get = function () {
  535. if (this.inFunction) { return true }
  536. if (this.options.allowReturnOutsideFunction && this.currentVarScope().flags & SCOPE_TOP) { return true }
  537. return false
  538. };
  539. prototypeAccessors.allowSuper.get = function () {
  540. var ref = this.currentThisScope();
  541. var flags = ref.flags;
  542. return (flags & SCOPE_SUPER) > 0 || this.options.allowSuperOutsideMethod
  543. };
  544. prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
  545. prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
  546. prototypeAccessors.allowNewDotTarget.get = function () {
  547. for (var i = this.scopeStack.length - 1; i >= 0; i--) {
  548. var ref = this.scopeStack[i];
  549. var flags = ref.flags;
  550. if (flags & (SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT) ||
  551. ((flags & SCOPE_FUNCTION) && !(flags & SCOPE_ARROW))) { return true }
  552. }
  553. return false
  554. };
  555. prototypeAccessors.allowUsing.get = function () {
  556. var ref = this.currentScope();
  557. var flags = ref.flags;
  558. if (flags & SCOPE_SWITCH) { return false }
  559. if (!this.inModule && flags & SCOPE_TOP) { return false }
  560. return true
  561. };
  562. prototypeAccessors.inClassStaticBlock.get = function () {
  563. return (this.currentVarScope().flags & SCOPE_CLASS_STATIC_BLOCK) > 0
  564. };
  565. Parser.extend = function extend () {
  566. var plugins = [], len = arguments.length;
  567. while ( len-- ) plugins[ len ] = arguments[ len ];
  568. var cls = this;
  569. for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
  570. return cls
  571. };
  572. Parser.parse = function parse (input, options) {
  573. return new this(options, input).parse()
  574. };
  575. Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
  576. var parser = new this(options, input, pos);
  577. parser.nextToken();
  578. return parser.parseExpression()
  579. };
  580. Parser.tokenizer = function tokenizer (input, options) {
  581. return new this(options, input)
  582. };
  583. Object.defineProperties( Parser.prototype, prototypeAccessors );
  584. var pp$9 = Parser.prototype;
  585. // ## Parser utilities
  586. var literal = /^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;
  587. pp$9.strictDirective = function(start) {
  588. if (this.options.ecmaVersion < 5) { return false }
  589. for (;;) {
  590. // Try to find string literal.
  591. skipWhiteSpace.lastIndex = start;
  592. start += skipWhiteSpace.exec(this.input)[0].length;
  593. var match = literal.exec(this.input.slice(start));
  594. if (!match) { return false }
  595. if ((match[1] || match[2]) === "use strict") {
  596. skipWhiteSpace.lastIndex = start + match[0].length;
  597. var spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length;
  598. var next = this.input.charAt(end);
  599. return next === ";" || next === "}" ||
  600. (lineBreak.test(spaceAfter[0]) &&
  601. !(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "="))
  602. }
  603. start += match[0].length;
  604. // Skip semicolon, if any.
  605. skipWhiteSpace.lastIndex = start;
  606. start += skipWhiteSpace.exec(this.input)[0].length;
  607. if (this.input[start] === ";")
  608. { start++; }
  609. }
  610. };
  611. // Predicate that tests whether the next token is of the given
  612. // type, and if yes, consumes it as a side effect.
  613. pp$9.eat = function(type) {
  614. if (this.type === type) {
  615. this.next();
  616. return true
  617. } else {
  618. return false
  619. }
  620. };
  621. // Tests whether parsed token is a contextual keyword.
  622. pp$9.isContextual = function(name) {
  623. return this.type === types$1.name && this.value === name && !this.containsEsc
  624. };
  625. // Consumes contextual keyword if possible.
  626. pp$9.eatContextual = function(name) {
  627. if (!this.isContextual(name)) { return false }
  628. this.next();
  629. return true
  630. };
  631. // Asserts that following token is given contextual keyword.
  632. pp$9.expectContextual = function(name) {
  633. if (!this.eatContextual(name)) { this.unexpected(); }
  634. };
  635. // Test whether a semicolon can be inserted at the current position.
  636. pp$9.canInsertSemicolon = function() {
  637. return this.type === types$1.eof ||
  638. this.type === types$1.braceR ||
  639. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  640. };
  641. pp$9.insertSemicolon = function() {
  642. if (this.canInsertSemicolon()) {
  643. if (this.options.onInsertedSemicolon)
  644. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  645. return true
  646. }
  647. };
  648. // Consume a semicolon, or, failing that, see if we are allowed to
  649. // pretend that there is a semicolon at this position.
  650. pp$9.semicolon = function() {
  651. if (!this.eat(types$1.semi) && !this.insertSemicolon()) { this.unexpected(); }
  652. };
  653. pp$9.afterTrailingComma = function(tokType, notNext) {
  654. if (this.type === tokType) {
  655. if (this.options.onTrailingComma)
  656. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  657. if (!notNext)
  658. { this.next(); }
  659. return true
  660. }
  661. };
  662. // Expect a token of a given type. If found, consume it, otherwise,
  663. // raise an unexpected token error.
  664. pp$9.expect = function(type) {
  665. this.eat(type) || this.unexpected();
  666. };
  667. // Raise an unexpected token error.
  668. pp$9.unexpected = function(pos) {
  669. this.raise(pos != null ? pos : this.start, "Unexpected token");
  670. };
  671. var DestructuringErrors = function DestructuringErrors() {
  672. this.shorthandAssign =
  673. this.trailingComma =
  674. this.parenthesizedAssign =
  675. this.parenthesizedBind =
  676. this.doubleProto =
  677. -1;
  678. };
  679. pp$9.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  680. if (!refDestructuringErrors) { return }
  681. if (refDestructuringErrors.trailingComma > -1)
  682. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  683. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  684. if (parens > -1) { this.raiseRecoverable(parens, isAssign ? "Assigning to rvalue" : "Parenthesized pattern"); }
  685. };
  686. pp$9.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  687. if (!refDestructuringErrors) { return false }
  688. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  689. var doubleProto = refDestructuringErrors.doubleProto;
  690. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  691. if (shorthandAssign >= 0)
  692. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  693. if (doubleProto >= 0)
  694. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  695. };
  696. pp$9.checkYieldAwaitInDefaultParams = function() {
  697. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  698. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  699. if (this.awaitPos)
  700. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  701. };
  702. pp$9.isSimpleAssignTarget = function(expr) {
  703. if (expr.type === "ParenthesizedExpression")
  704. { return this.isSimpleAssignTarget(expr.expression) }
  705. return expr.type === "Identifier" || expr.type === "MemberExpression"
  706. };
  707. var pp$8 = Parser.prototype;
  708. // ### Statement parsing
  709. // Parse a program. Initializes the parser, reads any number of
  710. // statements, and wraps them in a Program node. Optionally takes a
  711. // `program` argument. If present, the statements will be appended
  712. // to its body instead of creating a new node.
  713. pp$8.parseTopLevel = function(node) {
  714. var exports = Object.create(null);
  715. if (!node.body) { node.body = []; }
  716. while (this.type !== types$1.eof) {
  717. var stmt = this.parseStatement(null, true, exports);
  718. node.body.push(stmt);
  719. }
  720. if (this.inModule)
  721. { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
  722. {
  723. var name = list[i];
  724. this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
  725. } }
  726. this.adaptDirectivePrologue(node.body);
  727. this.next();
  728. node.sourceType = this.options.sourceType === "commonjs" ? "script" : this.options.sourceType;
  729. return this.finishNode(node, "Program")
  730. };
  731. var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
  732. pp$8.isLet = function(context) {
  733. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  734. skipWhiteSpace.lastIndex = this.pos;
  735. var skip = skipWhiteSpace.exec(this.input);
  736. var next = this.pos + skip[0].length, nextCh = this.fullCharCodeAt(next);
  737. // For ambiguous cases, determine if a LexicalDeclaration (or only a
  738. // Statement) is allowed here. If context is not empty then only a Statement
  739. // is allowed. However, `let [` is an explicit negative lookahead for
  740. // ExpressionStatement, so special-case it first.
  741. if (nextCh === 91 || nextCh === 92) { return true } // '[', '\'
  742. if (context) { return false }
  743. if (nextCh === 123) { return true } // '{'
  744. if (isIdentifierStart(nextCh)) {
  745. var start = next;
  746. do { next += nextCh <= 0xffff ? 1 : 2; }
  747. while (isIdentifierChar(nextCh = this.fullCharCodeAt(next)))
  748. if (nextCh === 92) { return true }
  749. var ident = this.input.slice(start, next);
  750. if (!keywordRelationalOperator.test(ident)) { return true }
  751. }
  752. return false
  753. };
  754. // check 'async [no LineTerminator here] function'
  755. // - 'async /*foo*/ function' is OK.
  756. // - 'async /*\n*/ function' is invalid.
  757. pp$8.isAsyncFunction = function() {
  758. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  759. { return false }
  760. skipWhiteSpace.lastIndex = this.pos;
  761. var skip = skipWhiteSpace.exec(this.input);
  762. var next = this.pos + skip[0].length, after;
  763. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  764. this.input.slice(next, next + 8) === "function" &&
  765. (next + 8 === this.input.length ||
  766. !(isIdentifierChar(after = this.fullCharCodeAt(next + 8)) || after === 92 /* '\' */))
  767. };
  768. pp$8.isUsingKeyword = function(isAwaitUsing, isFor) {
  769. if (this.options.ecmaVersion < 17 || !this.isContextual(isAwaitUsing ? "await" : "using"))
  770. { return false }
  771. skipWhiteSpace.lastIndex = this.pos;
  772. var skip = skipWhiteSpace.exec(this.input);
  773. var next = this.pos + skip[0].length;
  774. if (lineBreak.test(this.input.slice(this.pos, next))) { return false }
  775. if (isAwaitUsing) {
  776. var usingEndPos = next + 5 /* using */, after;
  777. if (this.input.slice(next, usingEndPos) !== "using" ||
  778. usingEndPos === this.input.length ||
  779. isIdentifierChar(after = this.fullCharCodeAt(usingEndPos)) ||
  780. after === 92 /* '\' */
  781. ) { return false }
  782. skipWhiteSpace.lastIndex = usingEndPos;
  783. var skipAfterUsing = skipWhiteSpace.exec(this.input);
  784. next = usingEndPos + skipAfterUsing[0].length;
  785. if (skipAfterUsing && lineBreak.test(this.input.slice(usingEndPos, next))) { return false }
  786. }
  787. var ch = this.fullCharCodeAt(next);
  788. if (!isIdentifierStart(ch) && ch !== 92 /* '\' */) { return false }
  789. var idStart = next;
  790. do { next += ch <= 0xffff ? 1 : 2; }
  791. while (isIdentifierChar(ch = this.fullCharCodeAt(next)))
  792. if (ch === 92) { return true }
  793. var id = this.input.slice(idStart, next);
  794. if (keywordRelationalOperator.test(id) || isFor && id === "of") { return false }
  795. return true
  796. };
  797. pp$8.isAwaitUsing = function(isFor) {
  798. return this.isUsingKeyword(true, isFor)
  799. };
  800. pp$8.isUsing = function(isFor) {
  801. return this.isUsingKeyword(false, isFor)
  802. };
  803. // Parse a single statement.
  804. //
  805. // If expecting a statement and finding a slash operator, parse a
  806. // regular expression literal. This is to handle cases like
  807. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  808. // does not help.
  809. pp$8.parseStatement = function(context, topLevel, exports) {
  810. var starttype = this.type, node = this.startNode(), kind;
  811. if (this.isLet(context)) {
  812. starttype = types$1._var;
  813. kind = "let";
  814. }
  815. // Most types of statements are recognized by the keyword they
  816. // start with. Many are trivial to parse, some require a bit of
  817. // complexity.
  818. switch (starttype) {
  819. case types$1._break: case types$1._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  820. case types$1._debugger: return this.parseDebuggerStatement(node)
  821. case types$1._do: return this.parseDoStatement(node)
  822. case types$1._for: return this.parseForStatement(node)
  823. case types$1._function:
  824. // Function as sole body of either an if statement or a labeled statement
  825. // works, but not when it is part of a labeled statement that is the sole
  826. // body of an if statement.
  827. if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
  828. return this.parseFunctionStatement(node, false, !context)
  829. case types$1._class:
  830. if (context) { this.unexpected(); }
  831. return this.parseClass(node, true)
  832. case types$1._if: return this.parseIfStatement(node)
  833. case types$1._return: return this.parseReturnStatement(node)
  834. case types$1._switch: return this.parseSwitchStatement(node)
  835. case types$1._throw: return this.parseThrowStatement(node)
  836. case types$1._try: return this.parseTryStatement(node)
  837. case types$1._const: case types$1._var:
  838. kind = kind || this.value;
  839. if (context && kind !== "var") { this.unexpected(); }
  840. return this.parseVarStatement(node, kind)
  841. case types$1._while: return this.parseWhileStatement(node)
  842. case types$1._with: return this.parseWithStatement(node)
  843. case types$1.braceL: return this.parseBlock(true, node)
  844. case types$1.semi: return this.parseEmptyStatement(node)
  845. case types$1._export:
  846. case types$1._import:
  847. if (this.options.ecmaVersion > 10 && starttype === types$1._import) {
  848. skipWhiteSpace.lastIndex = this.pos;
  849. var skip = skipWhiteSpace.exec(this.input);
  850. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  851. if (nextCh === 40 || nextCh === 46) // '(' or '.'
  852. { return this.parseExpressionStatement(node, this.parseExpression()) }
  853. }
  854. if (!this.options.allowImportExportEverywhere) {
  855. if (!topLevel)
  856. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  857. if (!this.inModule)
  858. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  859. }
  860. return starttype === types$1._import ? this.parseImport(node) : this.parseExport(node, exports)
  861. // If the statement does not start with a statement keyword or a
  862. // brace, it's an ExpressionStatement or LabeledStatement. We
  863. // simply start parsing an expression, and afterwards, if the
  864. // next token is a colon and the expression was a simple
  865. // Identifier node, we switch to interpreting it as a label.
  866. default:
  867. if (this.isAsyncFunction()) {
  868. if (context) { this.unexpected(); }
  869. this.next();
  870. return this.parseFunctionStatement(node, true, !context)
  871. }
  872. var usingKind = this.isAwaitUsing(false) ? "await using" : this.isUsing(false) ? "using" : null;
  873. if (usingKind) {
  874. if (!this.allowUsing) {
  875. this.raise(this.start, "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement");
  876. }
  877. if (usingKind === "await using") {
  878. if (!this.canAwait) {
  879. this.raise(this.start, "Await using cannot appear outside of async function");
  880. }
  881. this.next();
  882. }
  883. this.next();
  884. this.parseVar(node, false, usingKind);
  885. this.semicolon();
  886. return this.finishNode(node, "VariableDeclaration")
  887. }
  888. var maybeName = this.value, expr = this.parseExpression();
  889. if (starttype === types$1.name && expr.type === "Identifier" && this.eat(types$1.colon))
  890. { return this.parseLabeledStatement(node, maybeName, expr, context) }
  891. else { return this.parseExpressionStatement(node, expr) }
  892. }
  893. };
  894. pp$8.parseBreakContinueStatement = function(node, keyword) {
  895. var isBreak = keyword === "break";
  896. this.next();
  897. if (this.eat(types$1.semi) || this.insertSemicolon()) { node.label = null; }
  898. else if (this.type !== types$1.name) { this.unexpected(); }
  899. else {
  900. node.label = this.parseIdent();
  901. this.semicolon();
  902. }
  903. // Verify that there is an actual destination to break or
  904. // continue to.
  905. var i = 0;
  906. for (; i < this.labels.length; ++i) {
  907. var lab = this.labels[i];
  908. if (node.label == null || lab.name === node.label.name) {
  909. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  910. if (node.label && isBreak) { break }
  911. }
  912. }
  913. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  914. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  915. };
  916. pp$8.parseDebuggerStatement = function(node) {
  917. this.next();
  918. this.semicolon();
  919. return this.finishNode(node, "DebuggerStatement")
  920. };
  921. pp$8.parseDoStatement = function(node) {
  922. this.next();
  923. this.labels.push(loopLabel);
  924. node.body = this.parseStatement("do");
  925. this.labels.pop();
  926. this.expect(types$1._while);
  927. node.test = this.parseParenExpression();
  928. if (this.options.ecmaVersion >= 6)
  929. { this.eat(types$1.semi); }
  930. else
  931. { this.semicolon(); }
  932. return this.finishNode(node, "DoWhileStatement")
  933. };
  934. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  935. // loop is non-trivial. Basically, we have to parse the init `var`
  936. // statement or expression, disallowing the `in` operator (see
  937. // the second parameter to `parseExpression`), and then check
  938. // whether the next token is `in` or `of`. When there is no init
  939. // part (semicolon immediately after the opening parenthesis), it
  940. // is a regular `for` loop.
  941. pp$8.parseForStatement = function(node) {
  942. this.next();
  943. var awaitAt = (this.options.ecmaVersion >= 9 && this.canAwait && this.eatContextual("await")) ? this.lastTokStart : -1;
  944. this.labels.push(loopLabel);
  945. this.enterScope(0);
  946. this.expect(types$1.parenL);
  947. if (this.type === types$1.semi) {
  948. if (awaitAt > -1) { this.unexpected(awaitAt); }
  949. return this.parseFor(node, null)
  950. }
  951. var isLet = this.isLet();
  952. if (this.type === types$1._var || this.type === types$1._const || isLet) {
  953. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  954. this.next();
  955. this.parseVar(init$1, true, kind);
  956. this.finishNode(init$1, "VariableDeclaration");
  957. return this.parseForAfterInit(node, init$1, awaitAt)
  958. }
  959. var startsWithLet = this.isContextual("let"), isForOf = false;
  960. var usingKind = this.isUsing(true) ? "using" : this.isAwaitUsing(true) ? "await using" : null;
  961. if (usingKind) {
  962. var init$2 = this.startNode();
  963. this.next();
  964. if (usingKind === "await using") {
  965. if (!this.canAwait) {
  966. this.raise(this.start, "Await using cannot appear outside of async function");
  967. }
  968. this.next();
  969. }
  970. this.parseVar(init$2, true, usingKind);
  971. this.finishNode(init$2, "VariableDeclaration");
  972. return this.parseForAfterInit(node, init$2, awaitAt)
  973. }
  974. var containsEsc = this.containsEsc;
  975. var refDestructuringErrors = new DestructuringErrors;
  976. var initPos = this.start;
  977. var init = awaitAt > -1
  978. ? this.parseExprSubscripts(refDestructuringErrors, "await")
  979. : this.parseExpression(true, refDestructuringErrors);
  980. if (this.type === types$1._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  981. if (awaitAt > -1) { // implies `ecmaVersion >= 9` (see declaration of awaitAt)
  982. if (this.type === types$1._in) { this.unexpected(awaitAt); }
  983. node.await = true;
  984. } else if (isForOf && this.options.ecmaVersion >= 8) {
  985. if (init.start === initPos && !containsEsc && init.type === "Identifier" && init.name === "async") { this.unexpected(); }
  986. else if (this.options.ecmaVersion >= 9) { node.await = false; }
  987. }
  988. if (startsWithLet && isForOf) { this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); }
  989. this.toAssignable(init, false, refDestructuringErrors);
  990. this.checkLValPattern(init);
  991. return this.parseForIn(node, init)
  992. } else {
  993. this.checkExpressionErrors(refDestructuringErrors, true);
  994. }
  995. if (awaitAt > -1) { this.unexpected(awaitAt); }
  996. return this.parseFor(node, init)
  997. };
  998. // Helper method to parse for loop after variable initialization
  999. pp$8.parseForAfterInit = function(node, init, awaitAt) {
  1000. if ((this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init.declarations.length === 1) {
  1001. if (this.options.ecmaVersion >= 9) {
  1002. if (this.type === types$1._in) {
  1003. if (awaitAt > -1) { this.unexpected(awaitAt); }
  1004. } else { node.await = awaitAt > -1; }
  1005. }
  1006. return this.parseForIn(node, init)
  1007. }
  1008. if (awaitAt > -1) { this.unexpected(awaitAt); }
  1009. return this.parseFor(node, init)
  1010. };
  1011. pp$8.parseFunctionStatement = function(node, isAsync, declarationPosition) {
  1012. this.next();
  1013. return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
  1014. };
  1015. pp$8.parseIfStatement = function(node) {
  1016. this.next();
  1017. node.test = this.parseParenExpression();
  1018. // allow function declarations in branches, but only in non-strict mode
  1019. node.consequent = this.parseStatement("if");
  1020. node.alternate = this.eat(types$1._else) ? this.parseStatement("if") : null;
  1021. return this.finishNode(node, "IfStatement")
  1022. };
  1023. pp$8.parseReturnStatement = function(node) {
  1024. if (!this.allowReturn)
  1025. { this.raise(this.start, "'return' outside of function"); }
  1026. this.next();
  1027. // In `return` (and `break`/`continue`), the keywords with
  1028. // optional arguments, we eagerly look for a semicolon or the
  1029. // possibility to insert one.
  1030. if (this.eat(types$1.semi) || this.insertSemicolon()) { node.argument = null; }
  1031. else { node.argument = this.parseExpression(); this.semicolon(); }
  1032. return this.finishNode(node, "ReturnStatement")
  1033. };
  1034. pp$8.parseSwitchStatement = function(node) {
  1035. this.next();
  1036. node.discriminant = this.parseParenExpression();
  1037. node.cases = [];
  1038. this.expect(types$1.braceL);
  1039. this.labels.push(switchLabel);
  1040. this.enterScope(SCOPE_SWITCH);
  1041. // Statements under must be grouped (by label) in SwitchCase
  1042. // nodes. `cur` is used to keep the node that we are currently
  1043. // adding statements to.
  1044. var cur;
  1045. for (var sawDefault = false; this.type !== types$1.braceR;) {
  1046. if (this.type === types$1._case || this.type === types$1._default) {
  1047. var isCase = this.type === types$1._case;
  1048. if (cur) { this.finishNode(cur, "SwitchCase"); }
  1049. node.cases.push(cur = this.startNode());
  1050. cur.consequent = [];
  1051. this.next();
  1052. if (isCase) {
  1053. cur.test = this.parseExpression();
  1054. } else {
  1055. if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
  1056. sawDefault = true;
  1057. cur.test = null;
  1058. }
  1059. this.expect(types$1.colon);
  1060. } else {
  1061. if (!cur) { this.unexpected(); }
  1062. cur.consequent.push(this.parseStatement(null));
  1063. }
  1064. }
  1065. this.exitScope();
  1066. if (cur) { this.finishNode(cur, "SwitchCase"); }
  1067. this.next(); // Closing brace
  1068. this.labels.pop();
  1069. return this.finishNode(node, "SwitchStatement")
  1070. };
  1071. pp$8.parseThrowStatement = function(node) {
  1072. this.next();
  1073. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  1074. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  1075. node.argument = this.parseExpression();
  1076. this.semicolon();
  1077. return this.finishNode(node, "ThrowStatement")
  1078. };
  1079. // Reused empty array added for node fields that are always empty.
  1080. var empty$1 = [];
  1081. pp$8.parseCatchClauseParam = function() {
  1082. var param = this.parseBindingAtom();
  1083. var simple = param.type === "Identifier";
  1084. this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
  1085. this.checkLValPattern(param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
  1086. this.expect(types$1.parenR);
  1087. return param
  1088. };
  1089. pp$8.parseTryStatement = function(node) {
  1090. this.next();
  1091. node.block = this.parseBlock();
  1092. node.handler = null;
  1093. if (this.type === types$1._catch) {
  1094. var clause = this.startNode();
  1095. this.next();
  1096. if (this.eat(types$1.parenL)) {
  1097. clause.param = this.parseCatchClauseParam();
  1098. } else {
  1099. if (this.options.ecmaVersion < 10) { this.unexpected(); }
  1100. clause.param = null;
  1101. this.enterScope(0);
  1102. }
  1103. clause.body = this.parseBlock(false);
  1104. this.exitScope();
  1105. node.handler = this.finishNode(clause, "CatchClause");
  1106. }
  1107. node.finalizer = this.eat(types$1._finally) ? this.parseBlock() : null;
  1108. if (!node.handler && !node.finalizer)
  1109. { this.raise(node.start, "Missing catch or finally clause"); }
  1110. return this.finishNode(node, "TryStatement")
  1111. };
  1112. pp$8.parseVarStatement = function(node, kind, allowMissingInitializer) {
  1113. this.next();
  1114. this.parseVar(node, false, kind, allowMissingInitializer);
  1115. this.semicolon();
  1116. return this.finishNode(node, "VariableDeclaration")
  1117. };
  1118. pp$8.parseWhileStatement = function(node) {
  1119. this.next();
  1120. node.test = this.parseParenExpression();
  1121. this.labels.push(loopLabel);
  1122. node.body = this.parseStatement("while");
  1123. this.labels.pop();
  1124. return this.finishNode(node, "WhileStatement")
  1125. };
  1126. pp$8.parseWithStatement = function(node) {
  1127. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  1128. this.next();
  1129. node.object = this.parseParenExpression();
  1130. node.body = this.parseStatement("with");
  1131. return this.finishNode(node, "WithStatement")
  1132. };
  1133. pp$8.parseEmptyStatement = function(node) {
  1134. this.next();
  1135. return this.finishNode(node, "EmptyStatement")
  1136. };
  1137. pp$8.parseLabeledStatement = function(node, maybeName, expr, context) {
  1138. for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
  1139. {
  1140. var label = list[i$1];
  1141. if (label.name === maybeName)
  1142. { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
  1143. } }
  1144. var kind = this.type.isLoop ? "loop" : this.type === types$1._switch ? "switch" : null;
  1145. for (var i = this.labels.length - 1; i >= 0; i--) {
  1146. var label$1 = this.labels[i];
  1147. if (label$1.statementStart === node.start) {
  1148. // Update information about previous labels on this node
  1149. label$1.statementStart = this.start;
  1150. label$1.kind = kind;
  1151. } else { break }
  1152. }
  1153. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  1154. node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
  1155. this.labels.pop();
  1156. node.label = expr;
  1157. return this.finishNode(node, "LabeledStatement")
  1158. };
  1159. pp$8.parseExpressionStatement = function(node, expr) {
  1160. node.expression = expr;
  1161. this.semicolon();
  1162. return this.finishNode(node, "ExpressionStatement")
  1163. };
  1164. // Parse a semicolon-enclosed block of statements, handling `"use
  1165. // strict"` declarations when `allowStrict` is true (used for
  1166. // function bodies).
  1167. pp$8.parseBlock = function(createNewLexicalScope, node, exitStrict) {
  1168. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  1169. if ( node === void 0 ) node = this.startNode();
  1170. node.body = [];
  1171. this.expect(types$1.braceL);
  1172. if (createNewLexicalScope) { this.enterScope(0); }
  1173. while (this.type !== types$1.braceR) {
  1174. var stmt = this.parseStatement(null);
  1175. node.body.push(stmt);
  1176. }
  1177. if (exitStrict) { this.strict = false; }
  1178. this.next();
  1179. if (createNewLexicalScope) { this.exitScope(); }
  1180. return this.finishNode(node, "BlockStatement")
  1181. };
  1182. // Parse a regular `for` loop. The disambiguation code in
  1183. // `parseStatement` will already have parsed the init statement or
  1184. // expression.
  1185. pp$8.parseFor = function(node, init) {
  1186. node.init = init;
  1187. this.expect(types$1.semi);
  1188. node.test = this.type === types$1.semi ? null : this.parseExpression();
  1189. this.expect(types$1.semi);
  1190. node.update = this.type === types$1.parenR ? null : this.parseExpression();
  1191. this.expect(types$1.parenR);
  1192. node.body = this.parseStatement("for");
  1193. this.exitScope();
  1194. this.labels.pop();
  1195. return this.finishNode(node, "ForStatement")
  1196. };
  1197. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  1198. // same from parser's perspective.
  1199. pp$8.parseForIn = function(node, init) {
  1200. var isForIn = this.type === types$1._in;
  1201. this.next();
  1202. if (
  1203. init.type === "VariableDeclaration" &&
  1204. init.declarations[0].init != null &&
  1205. (
  1206. !isForIn ||
  1207. this.options.ecmaVersion < 8 ||
  1208. this.strict ||
  1209. init.kind !== "var" ||
  1210. init.declarations[0].id.type !== "Identifier"
  1211. )
  1212. ) {
  1213. this.raise(
  1214. init.start,
  1215. ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
  1216. );
  1217. }
  1218. node.left = init;
  1219. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
  1220. this.expect(types$1.parenR);
  1221. node.body = this.parseStatement("for");
  1222. this.exitScope();
  1223. this.labels.pop();
  1224. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
  1225. };
  1226. // Parse a list of variable declarations.
  1227. pp$8.parseVar = function(node, isFor, kind, allowMissingInitializer) {
  1228. node.declarations = [];
  1229. node.kind = kind;
  1230. for (;;) {
  1231. var decl = this.startNode();
  1232. this.parseVarId(decl, kind);
  1233. if (this.eat(types$1.eq)) {
  1234. decl.init = this.parseMaybeAssign(isFor);
  1235. } else if (!allowMissingInitializer && kind === "const" && !(this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
  1236. this.unexpected();
  1237. } else if (!allowMissingInitializer && (kind === "using" || kind === "await using") && this.options.ecmaVersion >= 17 && this.type !== types$1._in && !this.isContextual("of")) {
  1238. this.raise(this.lastTokEnd, ("Missing initializer in " + kind + " declaration"));
  1239. } else if (!allowMissingInitializer && decl.id.type !== "Identifier" && !(isFor && (this.type === types$1._in || this.isContextual("of")))) {
  1240. this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
  1241. } else {
  1242. decl.init = null;
  1243. }
  1244. node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
  1245. if (!this.eat(types$1.comma)) { break }
  1246. }
  1247. return node
  1248. };
  1249. pp$8.parseVarId = function(decl, kind) {
  1250. decl.id = kind === "using" || kind === "await using"
  1251. ? this.parseIdent()
  1252. : this.parseBindingAtom();
  1253. this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
  1254. };
  1255. var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
  1256. // Parse a function declaration or literal (depending on the
  1257. // `statement & FUNC_STATEMENT`).
  1258. // Remove `allowExpressionBody` for 7.0.0, as it is only called with false
  1259. pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, forInit) {
  1260. this.initFunction(node);
  1261. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
  1262. if (this.type === types$1.star && (statement & FUNC_HANGING_STATEMENT))
  1263. { this.unexpected(); }
  1264. node.generator = this.eat(types$1.star);
  1265. }
  1266. if (this.options.ecmaVersion >= 8)
  1267. { node.async = !!isAsync; }
  1268. if (statement & FUNC_STATEMENT) {
  1269. node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types$1.name ? null : this.parseIdent();
  1270. if (node.id && !(statement & FUNC_HANGING_STATEMENT))
  1271. // If it is a regular function declaration in sloppy mode, then it is
  1272. // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
  1273. // mode depends on properties of the current scope (see
  1274. // treatFunctionsAsVar).
  1275. { this.checkLValSimple(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
  1276. }
  1277. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  1278. this.yieldPos = 0;
  1279. this.awaitPos = 0;
  1280. this.awaitIdentPos = 0;
  1281. this.enterScope(functionFlags(node.async, node.generator));
  1282. if (!(statement & FUNC_STATEMENT))
  1283. { node.id = this.type === types$1.name ? this.parseIdent() : null; }
  1284. this.parseFunctionParams(node);
  1285. this.parseFunctionBody(node, allowExpressionBody, false, forInit);
  1286. this.yieldPos = oldYieldPos;
  1287. this.awaitPos = oldAwaitPos;
  1288. this.awaitIdentPos = oldAwaitIdentPos;
  1289. return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
  1290. };
  1291. pp$8.parseFunctionParams = function(node) {
  1292. this.expect(types$1.parenL);
  1293. node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8);
  1294. this.checkYieldAwaitInDefaultParams();
  1295. };
  1296. // Parse a class declaration or literal (depending on the
  1297. // `isStatement` parameter).
  1298. pp$8.parseClass = function(node, isStatement) {
  1299. this.next();
  1300. // ecma-262 14.6 Class Definitions
  1301. // A class definition is always strict mode code.
  1302. var oldStrict = this.strict;
  1303. this.strict = true;
  1304. this.parseClassId(node, isStatement);
  1305. this.parseClassSuper(node);
  1306. var privateNameMap = this.enterClassBody();
  1307. var classBody = this.startNode();
  1308. var hadConstructor = false;
  1309. classBody.body = [];
  1310. this.expect(types$1.braceL);
  1311. while (this.type !== types$1.braceR) {
  1312. var element = this.parseClassElement(node.superClass !== null);
  1313. if (element) {
  1314. classBody.body.push(element);
  1315. if (element.type === "MethodDefinition" && element.kind === "constructor") {
  1316. if (hadConstructor) { this.raiseRecoverable(element.start, "Duplicate constructor in the same class"); }
  1317. hadConstructor = true;
  1318. } else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) {
  1319. this.raiseRecoverable(element.key.start, ("Identifier '#" + (element.key.name) + "' has already been declared"));
  1320. }
  1321. }
  1322. }
  1323. this.strict = oldStrict;
  1324. this.next();
  1325. node.body = this.finishNode(classBody, "ClassBody");
  1326. this.exitClassBody();
  1327. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1328. };
  1329. pp$8.parseClassElement = function(constructorAllowsSuper) {
  1330. if (this.eat(types$1.semi)) { return null }
  1331. var ecmaVersion = this.options.ecmaVersion;
  1332. var node = this.startNode();
  1333. var keyName = "";
  1334. var isGenerator = false;
  1335. var isAsync = false;
  1336. var kind = "method";
  1337. var isStatic = false;
  1338. if (this.eatContextual("static")) {
  1339. // Parse static init block
  1340. if (ecmaVersion >= 13 && this.eat(types$1.braceL)) {
  1341. this.parseClassStaticBlock(node);
  1342. return node
  1343. }
  1344. if (this.isClassElementNameStart() || this.type === types$1.star) {
  1345. isStatic = true;
  1346. } else {
  1347. keyName = "static";
  1348. }
  1349. }
  1350. node.static = isStatic;
  1351. if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) {
  1352. if ((this.isClassElementNameStart() || this.type === types$1.star) && !this.canInsertSemicolon()) {
  1353. isAsync = true;
  1354. } else {
  1355. keyName = "async";
  1356. }
  1357. }
  1358. if (!keyName && (ecmaVersion >= 9 || !isAsync) && this.eat(types$1.star)) {
  1359. isGenerator = true;
  1360. }
  1361. if (!keyName && !isAsync && !isGenerator) {
  1362. var lastValue = this.value;
  1363. if (this.eatContextual("get") || this.eatContextual("set")) {
  1364. if (this.isClassElementNameStart()) {
  1365. kind = lastValue;
  1366. } else {
  1367. keyName = lastValue;
  1368. }
  1369. }
  1370. }
  1371. // Parse element name
  1372. if (keyName) {
  1373. // 'async', 'get', 'set', or 'static' were not a keyword contextually.
  1374. // The last token is any of those. Make it the element name.
  1375. node.computed = false;
  1376. node.key = this.startNodeAt(this.lastTokStart, this.lastTokStartLoc);
  1377. node.key.name = keyName;
  1378. this.finishNode(node.key, "Identifier");
  1379. } else {
  1380. this.parseClassElementName(node);
  1381. }
  1382. // Parse element value
  1383. if (ecmaVersion < 13 || this.type === types$1.parenL || kind !== "method" || isGenerator || isAsync) {
  1384. var isConstructor = !node.static && checkKeyName(node, "constructor");
  1385. var allowsDirectSuper = isConstructor && constructorAllowsSuper;
  1386. // Couldn't move this check into the 'parseClassMethod' method for backward compatibility.
  1387. if (isConstructor && kind !== "method") { this.raise(node.key.start, "Constructor can't have get/set modifier"); }
  1388. node.kind = isConstructor ? "constructor" : kind;
  1389. this.parseClassMethod(node, isGenerator, isAsync, allowsDirectSuper);
  1390. } else {
  1391. this.parseClassField(node);
  1392. }
  1393. return node
  1394. };
  1395. pp$8.isClassElementNameStart = function() {
  1396. return (
  1397. this.type === types$1.name ||
  1398. this.type === types$1.privateId ||
  1399. this.type === types$1.num ||
  1400. this.type === types$1.string ||
  1401. this.type === types$1.bracketL ||
  1402. this.type.keyword
  1403. )
  1404. };
  1405. pp$8.parseClassElementName = function(element) {
  1406. if (this.type === types$1.privateId) {
  1407. if (this.value === "constructor") {
  1408. this.raise(this.start, "Classes can't have an element named '#constructor'");
  1409. }
  1410. element.computed = false;
  1411. element.key = this.parsePrivateIdent();
  1412. } else {
  1413. this.parsePropertyName(element);
  1414. }
  1415. };
  1416. pp$8.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
  1417. // Check key and flags
  1418. var key = method.key;
  1419. if (method.kind === "constructor") {
  1420. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1421. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1422. } else if (method.static && checkKeyName(method, "prototype")) {
  1423. this.raise(key.start, "Classes may not have a static property named prototype");
  1424. }
  1425. // Parse value
  1426. var value = method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
  1427. // Check value
  1428. if (method.kind === "get" && value.params.length !== 0)
  1429. { this.raiseRecoverable(value.start, "getter should have no params"); }
  1430. if (method.kind === "set" && value.params.length !== 1)
  1431. { this.raiseRecoverable(value.start, "setter should have exactly one param"); }
  1432. if (method.kind === "set" && value.params[0].type === "RestElement")
  1433. { this.raiseRecoverable(value.params[0].start, "Setter cannot use rest params"); }
  1434. return this.finishNode(method, "MethodDefinition")
  1435. };
  1436. pp$8.parseClassField = function(field) {
  1437. if (checkKeyName(field, "constructor")) {
  1438. this.raise(field.key.start, "Classes can't have a field named 'constructor'");
  1439. } else if (field.static && checkKeyName(field, "prototype")) {
  1440. this.raise(field.key.start, "Classes can't have a static field named 'prototype'");
  1441. }
  1442. if (this.eat(types$1.eq)) {
  1443. // To raise SyntaxError if 'arguments' exists in the initializer.
  1444. this.enterScope(SCOPE_CLASS_FIELD_INIT | SCOPE_SUPER);
  1445. field.value = this.parseMaybeAssign();
  1446. this.exitScope();
  1447. } else {
  1448. field.value = null;
  1449. }
  1450. this.semicolon();
  1451. return this.finishNode(field, "PropertyDefinition")
  1452. };
  1453. pp$8.parseClassStaticBlock = function(node) {
  1454. node.body = [];
  1455. var oldLabels = this.labels;
  1456. this.labels = [];
  1457. this.enterScope(SCOPE_CLASS_STATIC_BLOCK | SCOPE_SUPER);
  1458. while (this.type !== types$1.braceR) {
  1459. var stmt = this.parseStatement(null);
  1460. node.body.push(stmt);
  1461. }
  1462. this.next();
  1463. this.exitScope();
  1464. this.labels = oldLabels;
  1465. return this.finishNode(node, "StaticBlock")
  1466. };
  1467. pp$8.parseClassId = function(node, isStatement) {
  1468. if (this.type === types$1.name) {
  1469. node.id = this.parseIdent();
  1470. if (isStatement)
  1471. { this.checkLValSimple(node.id, BIND_LEXICAL, false); }
  1472. } else {
  1473. if (isStatement === true)
  1474. { this.unexpected(); }
  1475. node.id = null;
  1476. }
  1477. };
  1478. pp$8.parseClassSuper = function(node) {
  1479. node.superClass = this.eat(types$1._extends) ? this.parseExprSubscripts(null, false) : null;
  1480. };
  1481. pp$8.enterClassBody = function() {
  1482. var element = {declared: Object.create(null), used: []};
  1483. this.privateNameStack.push(element);
  1484. return element.declared
  1485. };
  1486. pp$8.exitClassBody = function() {
  1487. var ref = this.privateNameStack.pop();
  1488. var declared = ref.declared;
  1489. var used = ref.used;
  1490. if (!this.options.checkPrivateFields) { return }
  1491. var len = this.privateNameStack.length;
  1492. var parent = len === 0 ? null : this.privateNameStack[len - 1];
  1493. for (var i = 0; i < used.length; ++i) {
  1494. var id = used[i];
  1495. if (!hasOwn(declared, id.name)) {
  1496. if (parent) {
  1497. parent.used.push(id);
  1498. } else {
  1499. this.raiseRecoverable(id.start, ("Private field '#" + (id.name) + "' must be declared in an enclosing class"));
  1500. }
  1501. }
  1502. }
  1503. };
  1504. function isPrivateNameConflicted(privateNameMap, element) {
  1505. var name = element.key.name;
  1506. var curr = privateNameMap[name];
  1507. var next = "true";
  1508. if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) {
  1509. next = (element.static ? "s" : "i") + element.kind;
  1510. }
  1511. // `class { get #a(){}; static set #a(_){} }` is also conflict.
  1512. if (
  1513. curr === "iget" && next === "iset" ||
  1514. curr === "iset" && next === "iget" ||
  1515. curr === "sget" && next === "sset" ||
  1516. curr === "sset" && next === "sget"
  1517. ) {
  1518. privateNameMap[name] = "true";
  1519. return false
  1520. } else if (!curr) {
  1521. privateNameMap[name] = next;
  1522. return false
  1523. } else {
  1524. return true
  1525. }
  1526. }
  1527. function checkKeyName(node, name) {
  1528. var computed = node.computed;
  1529. var key = node.key;
  1530. return !computed && (
  1531. key.type === "Identifier" && key.name === name ||
  1532. key.type === "Literal" && key.value === name
  1533. )
  1534. }
  1535. // Parses module export declaration.
  1536. pp$8.parseExportAllDeclaration = function(node, exports) {
  1537. if (this.options.ecmaVersion >= 11) {
  1538. if (this.eatContextual("as")) {
  1539. node.exported = this.parseModuleExportName();
  1540. this.checkExport(exports, node.exported, this.lastTokStart);
  1541. } else {
  1542. node.exported = null;
  1543. }
  1544. }
  1545. this.expectContextual("from");
  1546. if (this.type !== types$1.string) { this.unexpected(); }
  1547. node.source = this.parseExprAtom();
  1548. if (this.options.ecmaVersion >= 16)
  1549. { node.attributes = this.parseWithClause(); }
  1550. this.semicolon();
  1551. return this.finishNode(node, "ExportAllDeclaration")
  1552. };
  1553. pp$8.parseExport = function(node, exports) {
  1554. this.next();
  1555. // export * from '...'
  1556. if (this.eat(types$1.star)) {
  1557. return this.parseExportAllDeclaration(node, exports)
  1558. }
  1559. if (this.eat(types$1._default)) { // export default ...
  1560. this.checkExport(exports, "default", this.lastTokStart);
  1561. node.declaration = this.parseExportDefaultDeclaration();
  1562. return this.finishNode(node, "ExportDefaultDeclaration")
  1563. }
  1564. // export var|const|let|function|class ...
  1565. if (this.shouldParseExportStatement()) {
  1566. node.declaration = this.parseExportDeclaration(node);
  1567. if (node.declaration.type === "VariableDeclaration")
  1568. { this.checkVariableExport(exports, node.declaration.declarations); }
  1569. else
  1570. { this.checkExport(exports, node.declaration.id, node.declaration.id.start); }
  1571. node.specifiers = [];
  1572. node.source = null;
  1573. if (this.options.ecmaVersion >= 16)
  1574. { node.attributes = []; }
  1575. } else { // export { x, y as z } [from '...']
  1576. node.declaration = null;
  1577. node.specifiers = this.parseExportSpecifiers(exports);
  1578. if (this.eatContextual("from")) {
  1579. if (this.type !== types$1.string) { this.unexpected(); }
  1580. node.source = this.parseExprAtom();
  1581. if (this.options.ecmaVersion >= 16)
  1582. { node.attributes = this.parseWithClause(); }
  1583. } else {
  1584. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1585. // check for keywords used as local names
  1586. var spec = list[i];
  1587. this.checkUnreserved(spec.local);
  1588. // check if export is defined
  1589. this.checkLocalExport(spec.local);
  1590. if (spec.local.type === "Literal") {
  1591. this.raise(spec.local.start, "A string literal cannot be used as an exported binding without `from`.");
  1592. }
  1593. }
  1594. node.source = null;
  1595. if (this.options.ecmaVersion >= 16)
  1596. { node.attributes = []; }
  1597. }
  1598. this.semicolon();
  1599. }
  1600. return this.finishNode(node, "ExportNamedDeclaration")
  1601. };
  1602. pp$8.parseExportDeclaration = function(node) {
  1603. return this.parseStatement(null)
  1604. };
  1605. pp$8.parseExportDefaultDeclaration = function() {
  1606. var isAsync;
  1607. if (this.type === types$1._function || (isAsync = this.isAsyncFunction())) {
  1608. var fNode = this.startNode();
  1609. this.next();
  1610. if (isAsync) { this.next(); }
  1611. return this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync)
  1612. } else if (this.type === types$1._class) {
  1613. var cNode = this.startNode();
  1614. return this.parseClass(cNode, "nullableID")
  1615. } else {
  1616. var declaration = this.parseMaybeAssign();
  1617. this.semicolon();
  1618. return declaration
  1619. }
  1620. };
  1621. pp$8.checkExport = function(exports, name, pos) {
  1622. if (!exports) { return }
  1623. if (typeof name !== "string")
  1624. { name = name.type === "Identifier" ? name.name : name.value; }
  1625. if (hasOwn(exports, name))
  1626. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1627. exports[name] = true;
  1628. };
  1629. pp$8.checkPatternExport = function(exports, pat) {
  1630. var type = pat.type;
  1631. if (type === "Identifier")
  1632. { this.checkExport(exports, pat, pat.start); }
  1633. else if (type === "ObjectPattern")
  1634. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1635. {
  1636. var prop = list[i];
  1637. this.checkPatternExport(exports, prop);
  1638. } }
  1639. else if (type === "ArrayPattern")
  1640. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1641. var elt = list$1[i$1];
  1642. if (elt) { this.checkPatternExport(exports, elt); }
  1643. } }
  1644. else if (type === "Property")
  1645. { this.checkPatternExport(exports, pat.value); }
  1646. else if (type === "AssignmentPattern")
  1647. { this.checkPatternExport(exports, pat.left); }
  1648. else if (type === "RestElement")
  1649. { this.checkPatternExport(exports, pat.argument); }
  1650. };
  1651. pp$8.checkVariableExport = function(exports, decls) {
  1652. if (!exports) { return }
  1653. for (var i = 0, list = decls; i < list.length; i += 1)
  1654. {
  1655. var decl = list[i];
  1656. this.checkPatternExport(exports, decl.id);
  1657. }
  1658. };
  1659. pp$8.shouldParseExportStatement = function() {
  1660. return this.type.keyword === "var" ||
  1661. this.type.keyword === "const" ||
  1662. this.type.keyword === "class" ||
  1663. this.type.keyword === "function" ||
  1664. this.isLet() ||
  1665. this.isAsyncFunction()
  1666. };
  1667. // Parses a comma-separated list of module exports.
  1668. pp$8.parseExportSpecifier = function(exports) {
  1669. var node = this.startNode();
  1670. node.local = this.parseModuleExportName();
  1671. node.exported = this.eatContextual("as") ? this.parseModuleExportName() : node.local;
  1672. this.checkExport(
  1673. exports,
  1674. node.exported,
  1675. node.exported.start
  1676. );
  1677. return this.finishNode(node, "ExportSpecifier")
  1678. };
  1679. pp$8.parseExportSpecifiers = function(exports) {
  1680. var nodes = [], first = true;
  1681. // export { x, y as z } [from '...']
  1682. this.expect(types$1.braceL);
  1683. while (!this.eat(types$1.braceR)) {
  1684. if (!first) {
  1685. this.expect(types$1.comma);
  1686. if (this.afterTrailingComma(types$1.braceR)) { break }
  1687. } else { first = false; }
  1688. nodes.push(this.parseExportSpecifier(exports));
  1689. }
  1690. return nodes
  1691. };
  1692. // Parses import declaration.
  1693. pp$8.parseImport = function(node) {
  1694. this.next();
  1695. // import '...'
  1696. if (this.type === types$1.string) {
  1697. node.specifiers = empty$1;
  1698. node.source = this.parseExprAtom();
  1699. } else {
  1700. node.specifiers = this.parseImportSpecifiers();
  1701. this.expectContextual("from");
  1702. node.source = this.type === types$1.string ? this.parseExprAtom() : this.unexpected();
  1703. }
  1704. if (this.options.ecmaVersion >= 16)
  1705. { node.attributes = this.parseWithClause(); }
  1706. this.semicolon();
  1707. return this.finishNode(node, "ImportDeclaration")
  1708. };
  1709. // Parses a comma-separated list of module imports.
  1710. pp$8.parseImportSpecifier = function() {
  1711. var node = this.startNode();
  1712. node.imported = this.parseModuleExportName();
  1713. if (this.eatContextual("as")) {
  1714. node.local = this.parseIdent();
  1715. } else {
  1716. this.checkUnreserved(node.imported);
  1717. node.local = node.imported;
  1718. }
  1719. this.checkLValSimple(node.local, BIND_LEXICAL);
  1720. return this.finishNode(node, "ImportSpecifier")
  1721. };
  1722. pp$8.parseImportDefaultSpecifier = function() {
  1723. // import defaultObj, { x, y as z } from '...'
  1724. var node = this.startNode();
  1725. node.local = this.parseIdent();
  1726. this.checkLValSimple(node.local, BIND_LEXICAL);
  1727. return this.finishNode(node, "ImportDefaultSpecifier")
  1728. };
  1729. pp$8.parseImportNamespaceSpecifier = function() {
  1730. var node = this.startNode();
  1731. this.next();
  1732. this.expectContextual("as");
  1733. node.local = this.parseIdent();
  1734. this.checkLValSimple(node.local, BIND_LEXICAL);
  1735. return this.finishNode(node, "ImportNamespaceSpecifier")
  1736. };
  1737. pp$8.parseImportSpecifiers = function() {
  1738. var nodes = [], first = true;
  1739. if (this.type === types$1.name) {
  1740. nodes.push(this.parseImportDefaultSpecifier());
  1741. if (!this.eat(types$1.comma)) { return nodes }
  1742. }
  1743. if (this.type === types$1.star) {
  1744. nodes.push(this.parseImportNamespaceSpecifier());
  1745. return nodes
  1746. }
  1747. this.expect(types$1.braceL);
  1748. while (!this.eat(types$1.braceR)) {
  1749. if (!first) {
  1750. this.expect(types$1.comma);
  1751. if (this.afterTrailingComma(types$1.braceR)) { break }
  1752. } else { first = false; }
  1753. nodes.push(this.parseImportSpecifier());
  1754. }
  1755. return nodes
  1756. };
  1757. pp$8.parseWithClause = function() {
  1758. var nodes = [];
  1759. if (!this.eat(types$1._with)) {
  1760. return nodes
  1761. }
  1762. this.expect(types$1.braceL);
  1763. var attributeKeys = {};
  1764. var first = true;
  1765. while (!this.eat(types$1.braceR)) {
  1766. if (!first) {
  1767. this.expect(types$1.comma);
  1768. if (this.afterTrailingComma(types$1.braceR)) { break }
  1769. } else { first = false; }
  1770. var attr = this.parseImportAttribute();
  1771. var keyName = attr.key.type === "Identifier" ? attr.key.name : attr.key.value;
  1772. if (hasOwn(attributeKeys, keyName))
  1773. { this.raiseRecoverable(attr.key.start, "Duplicate attribute key '" + keyName + "'"); }
  1774. attributeKeys[keyName] = true;
  1775. nodes.push(attr);
  1776. }
  1777. return nodes
  1778. };
  1779. pp$8.parseImportAttribute = function() {
  1780. var node = this.startNode();
  1781. node.key = this.type === types$1.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never");
  1782. this.expect(types$1.colon);
  1783. if (this.type !== types$1.string) {
  1784. this.unexpected();
  1785. }
  1786. node.value = this.parseExprAtom();
  1787. return this.finishNode(node, "ImportAttribute")
  1788. };
  1789. pp$8.parseModuleExportName = function() {
  1790. if (this.options.ecmaVersion >= 13 && this.type === types$1.string) {
  1791. var stringLiteral = this.parseLiteral(this.value);
  1792. if (loneSurrogate.test(stringLiteral.value)) {
  1793. this.raise(stringLiteral.start, "An export name cannot include a lone surrogate.");
  1794. }
  1795. return stringLiteral
  1796. }
  1797. return this.parseIdent(true)
  1798. };
  1799. // Set `ExpressionStatement#directive` property for directive prologues.
  1800. pp$8.adaptDirectivePrologue = function(statements) {
  1801. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1802. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1803. }
  1804. };
  1805. pp$8.isDirectiveCandidate = function(statement) {
  1806. return (
  1807. this.options.ecmaVersion >= 5 &&
  1808. statement.type === "ExpressionStatement" &&
  1809. statement.expression.type === "Literal" &&
  1810. typeof statement.expression.value === "string" &&
  1811. // Reject parenthesized strings.
  1812. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1813. )
  1814. };
  1815. var pp$7 = Parser.prototype;
  1816. // Convert existing expression atom to assignable pattern
  1817. // if possible.
  1818. pp$7.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1819. if (this.options.ecmaVersion >= 6 && node) {
  1820. switch (node.type) {
  1821. case "Identifier":
  1822. if (this.inAsync && node.name === "await")
  1823. { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
  1824. break
  1825. case "ObjectPattern":
  1826. case "ArrayPattern":
  1827. case "AssignmentPattern":
  1828. case "RestElement":
  1829. break
  1830. case "ObjectExpression":
  1831. node.type = "ObjectPattern";
  1832. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1833. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1834. var prop = list[i];
  1835. this.toAssignable(prop, isBinding);
  1836. // Early error:
  1837. // AssignmentRestProperty[Yield, Await] :
  1838. // `...` DestructuringAssignmentTarget[Yield, Await]
  1839. //
  1840. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1841. if (
  1842. prop.type === "RestElement" &&
  1843. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1844. ) {
  1845. this.raise(prop.argument.start, "Unexpected token");
  1846. }
  1847. }
  1848. break
  1849. case "Property":
  1850. // AssignmentProperty has type === "Property"
  1851. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1852. this.toAssignable(node.value, isBinding);
  1853. break
  1854. case "ArrayExpression":
  1855. node.type = "ArrayPattern";
  1856. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1857. this.toAssignableList(node.elements, isBinding);
  1858. break
  1859. case "SpreadElement":
  1860. node.type = "RestElement";
  1861. this.toAssignable(node.argument, isBinding);
  1862. if (node.argument.type === "AssignmentPattern")
  1863. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1864. break
  1865. case "AssignmentExpression":
  1866. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1867. node.type = "AssignmentPattern";
  1868. delete node.operator;
  1869. this.toAssignable(node.left, isBinding);
  1870. break
  1871. case "ParenthesizedExpression":
  1872. this.toAssignable(node.expression, isBinding, refDestructuringErrors);
  1873. break
  1874. case "ChainExpression":
  1875. this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side");
  1876. break
  1877. case "MemberExpression":
  1878. if (!isBinding) { break }
  1879. default:
  1880. this.raise(node.start, "Assigning to rvalue");
  1881. }
  1882. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1883. return node
  1884. };
  1885. // Convert list of expression atoms to binding list.
  1886. pp$7.toAssignableList = function(exprList, isBinding) {
  1887. var end = exprList.length;
  1888. for (var i = 0; i < end; i++) {
  1889. var elt = exprList[i];
  1890. if (elt) { this.toAssignable(elt, isBinding); }
  1891. }
  1892. if (end) {
  1893. var last = exprList[end - 1];
  1894. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1895. { this.unexpected(last.argument.start); }
  1896. }
  1897. return exprList
  1898. };
  1899. // Parses spread element.
  1900. pp$7.parseSpread = function(refDestructuringErrors) {
  1901. var node = this.startNode();
  1902. this.next();
  1903. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1904. return this.finishNode(node, "SpreadElement")
  1905. };
  1906. pp$7.parseRestBinding = function() {
  1907. var node = this.startNode();
  1908. this.next();
  1909. // RestElement inside of a function parameter must be an identifier
  1910. if (this.options.ecmaVersion === 6 && this.type !== types$1.name)
  1911. { this.unexpected(); }
  1912. node.argument = this.parseBindingAtom();
  1913. return this.finishNode(node, "RestElement")
  1914. };
  1915. // Parses lvalue (assignable) atom.
  1916. pp$7.parseBindingAtom = function() {
  1917. if (this.options.ecmaVersion >= 6) {
  1918. switch (this.type) {
  1919. case types$1.bracketL:
  1920. var node = this.startNode();
  1921. this.next();
  1922. node.elements = this.parseBindingList(types$1.bracketR, true, true);
  1923. return this.finishNode(node, "ArrayPattern")
  1924. case types$1.braceL:
  1925. return this.parseObj(true)
  1926. }
  1927. }
  1928. return this.parseIdent()
  1929. };
  1930. pp$7.parseBindingList = function(close, allowEmpty, allowTrailingComma, allowModifiers) {
  1931. var elts = [], first = true;
  1932. while (!this.eat(close)) {
  1933. if (first) { first = false; }
  1934. else { this.expect(types$1.comma); }
  1935. if (allowEmpty && this.type === types$1.comma) {
  1936. elts.push(null);
  1937. } else if (allowTrailingComma && this.afterTrailingComma(close)) {
  1938. break
  1939. } else if (this.type === types$1.ellipsis) {
  1940. var rest = this.parseRestBinding();
  1941. this.parseBindingListItem(rest);
  1942. elts.push(rest);
  1943. if (this.type === types$1.comma) { this.raiseRecoverable(this.start, "Comma is not permitted after the rest element"); }
  1944. this.expect(close);
  1945. break
  1946. } else {
  1947. elts.push(this.parseAssignableListItem(allowModifiers));
  1948. }
  1949. }
  1950. return elts
  1951. };
  1952. pp$7.parseAssignableListItem = function(allowModifiers) {
  1953. var elem = this.parseMaybeDefault(this.start, this.startLoc);
  1954. this.parseBindingListItem(elem);
  1955. return elem
  1956. };
  1957. pp$7.parseBindingListItem = function(param) {
  1958. return param
  1959. };
  1960. // Parses assignment pattern around given atom if possible.
  1961. pp$7.parseMaybeDefault = function(startPos, startLoc, left) {
  1962. left = left || this.parseBindingAtom();
  1963. if (this.options.ecmaVersion < 6 || !this.eat(types$1.eq)) { return left }
  1964. var node = this.startNodeAt(startPos, startLoc);
  1965. node.left = left;
  1966. node.right = this.parseMaybeAssign();
  1967. return this.finishNode(node, "AssignmentPattern")
  1968. };
  1969. // The following three functions all verify that a node is an lvalue —
  1970. // something that can be bound, or assigned to. In order to do so, they perform
  1971. // a variety of checks:
  1972. //
  1973. // - Check that none of the bound/assigned-to identifiers are reserved words.
  1974. // - Record name declarations for bindings in the appropriate scope.
  1975. // - Check duplicate argument names, if checkClashes is set.
  1976. //
  1977. // If a complex binding pattern is encountered (e.g., object and array
  1978. // destructuring), the entire pattern is recursively checked.
  1979. //
  1980. // There are three versions of checkLVal*() appropriate for different
  1981. // circumstances:
  1982. //
  1983. // - checkLValSimple() shall be used if the syntactic construct supports
  1984. // nothing other than identifiers and member expressions. Parenthesized
  1985. // expressions are also correctly handled. This is generally appropriate for
  1986. // constructs for which the spec says
  1987. //
  1988. // > It is a Syntax Error if AssignmentTargetType of [the production] is not
  1989. // > simple.
  1990. //
  1991. // It is also appropriate for checking if an identifier is valid and not
  1992. // defined elsewhere, like import declarations or function/class identifiers.
  1993. //
  1994. // Examples where this is used include:
  1995. // a += …;
  1996. // import a from '…';
  1997. // where a is the node to be checked.
  1998. //
  1999. // - checkLValPattern() shall be used if the syntactic construct supports
  2000. // anything checkLValSimple() supports, as well as object and array
  2001. // destructuring patterns. This is generally appropriate for constructs for
  2002. // which the spec says
  2003. //
  2004. // > It is a Syntax Error if [the production] is neither an ObjectLiteral nor
  2005. // > an ArrayLiteral and AssignmentTargetType of [the production] is not
  2006. // > simple.
  2007. //
  2008. // Examples where this is used include:
  2009. // (a = …);
  2010. // const a = …;
  2011. // try { … } catch (a) { … }
  2012. // where a is the node to be checked.
  2013. //
  2014. // - checkLValInnerPattern() shall be used if the syntactic construct supports
  2015. // anything checkLValPattern() supports, as well as default assignment
  2016. // patterns, rest elements, and other constructs that may appear within an
  2017. // object or array destructuring pattern.
  2018. //
  2019. // As a special case, function parameters also use checkLValInnerPattern(),
  2020. // as they also support defaults and rest constructs.
  2021. //
  2022. // These functions deliberately support both assignment and binding constructs,
  2023. // as the logic for both is exceedingly similar. If the node is the target of
  2024. // an assignment, then bindingType should be set to BIND_NONE. Otherwise, it
  2025. // should be set to the appropriate BIND_* constant, like BIND_VAR or
  2026. // BIND_LEXICAL.
  2027. //
  2028. // If the function is called with a non-BIND_NONE bindingType, then
  2029. // additionally a checkClashes object may be specified to allow checking for
  2030. // duplicate argument names. checkClashes is ignored if the provided construct
  2031. // is an assignment (i.e., bindingType is BIND_NONE).
  2032. pp$7.checkLValSimple = function(expr, bindingType, checkClashes) {
  2033. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  2034. var isBind = bindingType !== BIND_NONE;
  2035. switch (expr.type) {
  2036. case "Identifier":
  2037. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  2038. { this.raiseRecoverable(expr.start, (isBind ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  2039. if (isBind) {
  2040. if (bindingType === BIND_LEXICAL && expr.name === "let")
  2041. { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
  2042. if (checkClashes) {
  2043. if (hasOwn(checkClashes, expr.name))
  2044. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  2045. checkClashes[expr.name] = true;
  2046. }
  2047. if (bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
  2048. }
  2049. break
  2050. case "ChainExpression":
  2051. this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side");
  2052. break
  2053. case "MemberExpression":
  2054. if (isBind) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  2055. break
  2056. case "ParenthesizedExpression":
  2057. if (isBind) { this.raiseRecoverable(expr.start, "Binding parenthesized expression"); }
  2058. return this.checkLValSimple(expr.expression, bindingType, checkClashes)
  2059. default:
  2060. this.raise(expr.start, (isBind ? "Binding" : "Assigning to") + " rvalue");
  2061. }
  2062. };
  2063. pp$7.checkLValPattern = function(expr, bindingType, checkClashes) {
  2064. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  2065. switch (expr.type) {
  2066. case "ObjectPattern":
  2067. for (var i = 0, list = expr.properties; i < list.length; i += 1) {
  2068. var prop = list[i];
  2069. this.checkLValInnerPattern(prop, bindingType, checkClashes);
  2070. }
  2071. break
  2072. case "ArrayPattern":
  2073. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  2074. var elem = list$1[i$1];
  2075. if (elem) { this.checkLValInnerPattern(elem, bindingType, checkClashes); }
  2076. }
  2077. break
  2078. default:
  2079. this.checkLValSimple(expr, bindingType, checkClashes);
  2080. }
  2081. };
  2082. pp$7.checkLValInnerPattern = function(expr, bindingType, checkClashes) {
  2083. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  2084. switch (expr.type) {
  2085. case "Property":
  2086. // AssignmentProperty has type === "Property"
  2087. this.checkLValInnerPattern(expr.value, bindingType, checkClashes);
  2088. break
  2089. case "AssignmentPattern":
  2090. this.checkLValPattern(expr.left, bindingType, checkClashes);
  2091. break
  2092. case "RestElement":
  2093. this.checkLValPattern(expr.argument, bindingType, checkClashes);
  2094. break
  2095. default:
  2096. this.checkLValPattern(expr, bindingType, checkClashes);
  2097. }
  2098. };
  2099. // The algorithm used to determine whether a regexp can appear at a
  2100. // given point in the program is loosely based on sweet.js' approach.
  2101. // See https://github.com/mozilla/sweet.js/wiki/design
  2102. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2103. this.token = token;
  2104. this.isExpr = !!isExpr;
  2105. this.preserveSpace = !!preserveSpace;
  2106. this.override = override;
  2107. this.generator = !!generator;
  2108. };
  2109. var types = {
  2110. b_stat: new TokContext("{", false),
  2111. b_expr: new TokContext("{", true),
  2112. b_tmpl: new TokContext("${", false),
  2113. p_stat: new TokContext("(", false),
  2114. p_expr: new TokContext("(", true),
  2115. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2116. f_stat: new TokContext("function", false),
  2117. f_expr: new TokContext("function", true),
  2118. f_expr_gen: new TokContext("function", true, false, null, true),
  2119. f_gen: new TokContext("function", false, false, null, true)
  2120. };
  2121. var pp$6 = Parser.prototype;
  2122. pp$6.initialContext = function() {
  2123. return [types.b_stat]
  2124. };
  2125. pp$6.curContext = function() {
  2126. return this.context[this.context.length - 1]
  2127. };
  2128. pp$6.braceIsBlock = function(prevType) {
  2129. var parent = this.curContext();
  2130. if (parent === types.f_expr || parent === types.f_stat)
  2131. { return true }
  2132. if (prevType === types$1.colon && (parent === types.b_stat || parent === types.b_expr))
  2133. { return !parent.isExpr }
  2134. // The check for `tt.name && exprAllowed` detects whether we are
  2135. // after a `yield` or `of` construct. See the `updateContext` for
  2136. // `tt.name`.
  2137. if (prevType === types$1._return || prevType === types$1.name && this.exprAllowed)
  2138. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2139. if (prevType === types$1._else || prevType === types$1.semi || prevType === types$1.eof || prevType === types$1.parenR || prevType === types$1.arrow)
  2140. { return true }
  2141. if (prevType === types$1.braceL)
  2142. { return parent === types.b_stat }
  2143. if (prevType === types$1._var || prevType === types$1._const || prevType === types$1.name)
  2144. { return false }
  2145. return !this.exprAllowed
  2146. };
  2147. pp$6.inGeneratorContext = function() {
  2148. for (var i = this.context.length - 1; i >= 1; i--) {
  2149. var context = this.context[i];
  2150. if (context.token === "function")
  2151. { return context.generator }
  2152. }
  2153. return false
  2154. };
  2155. pp$6.updateContext = function(prevType) {
  2156. var update, type = this.type;
  2157. if (type.keyword && prevType === types$1.dot)
  2158. { this.exprAllowed = false; }
  2159. else if (update = type.updateContext)
  2160. { update.call(this, prevType); }
  2161. else
  2162. { this.exprAllowed = type.beforeExpr; }
  2163. };
  2164. // Used to handle edge cases when token context could not be inferred correctly during tokenization phase
  2165. pp$6.overrideContext = function(tokenCtx) {
  2166. if (this.curContext() !== tokenCtx) {
  2167. this.context[this.context.length - 1] = tokenCtx;
  2168. }
  2169. };
  2170. // Token-specific context update code
  2171. types$1.parenR.updateContext = types$1.braceR.updateContext = function() {
  2172. if (this.context.length === 1) {
  2173. this.exprAllowed = true;
  2174. return
  2175. }
  2176. var out = this.context.pop();
  2177. if (out === types.b_stat && this.curContext().token === "function") {
  2178. out = this.context.pop();
  2179. }
  2180. this.exprAllowed = !out.isExpr;
  2181. };
  2182. types$1.braceL.updateContext = function(prevType) {
  2183. this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
  2184. this.exprAllowed = true;
  2185. };
  2186. types$1.dollarBraceL.updateContext = function() {
  2187. this.context.push(types.b_tmpl);
  2188. this.exprAllowed = true;
  2189. };
  2190. types$1.parenL.updateContext = function(prevType) {
  2191. var statementParens = prevType === types$1._if || prevType === types$1._for || prevType === types$1._with || prevType === types$1._while;
  2192. this.context.push(statementParens ? types.p_stat : types.p_expr);
  2193. this.exprAllowed = true;
  2194. };
  2195. types$1.incDec.updateContext = function() {
  2196. // tokExprAllowed stays unchanged
  2197. };
  2198. types$1._function.updateContext = types$1._class.updateContext = function(prevType) {
  2199. if (prevType.beforeExpr && prevType !== types$1._else &&
  2200. !(prevType === types$1.semi && this.curContext() !== types.p_stat) &&
  2201. !(prevType === types$1._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
  2202. !((prevType === types$1.colon || prevType === types$1.braceL) && this.curContext() === types.b_stat))
  2203. { this.context.push(types.f_expr); }
  2204. else
  2205. { this.context.push(types.f_stat); }
  2206. this.exprAllowed = false;
  2207. };
  2208. types$1.colon.updateContext = function() {
  2209. if (this.curContext().token === "function") { this.context.pop(); }
  2210. this.exprAllowed = true;
  2211. };
  2212. types$1.backQuote.updateContext = function() {
  2213. if (this.curContext() === types.q_tmpl)
  2214. { this.context.pop(); }
  2215. else
  2216. { this.context.push(types.q_tmpl); }
  2217. this.exprAllowed = false;
  2218. };
  2219. types$1.star.updateContext = function(prevType) {
  2220. if (prevType === types$1._function) {
  2221. var index = this.context.length - 1;
  2222. if (this.context[index] === types.f_expr)
  2223. { this.context[index] = types.f_expr_gen; }
  2224. else
  2225. { this.context[index] = types.f_gen; }
  2226. }
  2227. this.exprAllowed = true;
  2228. };
  2229. types$1.name.updateContext = function(prevType) {
  2230. var allowed = false;
  2231. if (this.options.ecmaVersion >= 6 && prevType !== types$1.dot) {
  2232. if (this.value === "of" && !this.exprAllowed ||
  2233. this.value === "yield" && this.inGeneratorContext())
  2234. { allowed = true; }
  2235. }
  2236. this.exprAllowed = allowed;
  2237. };
  2238. // A recursive descent parser operates by defining functions for all
  2239. // syntactic elements, and recursively calling those, each function
  2240. // advancing the input stream and returning an AST node. Precedence
  2241. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  2242. // instead of `(!x)[1]` is handled by the fact that the parser
  2243. // function that parses unary prefix operators is called first, and
  2244. // in turn calls the function that parses `[]` subscripts — that
  2245. // way, it'll receive the node for `x[1]` already parsed, and wraps
  2246. // *that* in the unary operator node.
  2247. //
  2248. // Acorn uses an [operator precedence parser][opp] to handle binary
  2249. // operator precedence, because it is much more compact than using
  2250. // the technique outlined above, which uses different, nesting
  2251. // functions to specify precedence, for all of the ten binary
  2252. // precedence levels that JavaScript defines.
  2253. //
  2254. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  2255. var pp$5 = Parser.prototype;
  2256. // Check if property name clashes with already added.
  2257. // Object/class getters and setters are not allowed to clash —
  2258. // either with each other or with an init property — and in
  2259. // strict mode, init properties are also not allowed to be repeated.
  2260. pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  2261. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  2262. { return }
  2263. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  2264. { return }
  2265. var key = prop.key;
  2266. var name;
  2267. switch (key.type) {
  2268. case "Identifier": name = key.name; break
  2269. case "Literal": name = String(key.value); break
  2270. default: return
  2271. }
  2272. var kind = prop.kind;
  2273. if (this.options.ecmaVersion >= 6) {
  2274. if (name === "__proto__" && kind === "init") {
  2275. if (propHash.proto) {
  2276. if (refDestructuringErrors) {
  2277. if (refDestructuringErrors.doubleProto < 0) {
  2278. refDestructuringErrors.doubleProto = key.start;
  2279. }
  2280. } else {
  2281. this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
  2282. }
  2283. }
  2284. propHash.proto = true;
  2285. }
  2286. return
  2287. }
  2288. name = "$" + name;
  2289. var other = propHash[name];
  2290. if (other) {
  2291. var redefinition;
  2292. if (kind === "init") {
  2293. redefinition = this.strict && other.init || other.get || other.set;
  2294. } else {
  2295. redefinition = other.init || other[kind];
  2296. }
  2297. if (redefinition)
  2298. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  2299. } else {
  2300. other = propHash[name] = {
  2301. init: false,
  2302. get: false,
  2303. set: false
  2304. };
  2305. }
  2306. other[kind] = true;
  2307. };
  2308. // ### Expression parsing
  2309. // These nest, from the most general expression type at the top to
  2310. // 'atomic', nondivisible expression types at the bottom. Most of
  2311. // the functions will simply let the function(s) below them parse,
  2312. // and, *if* the syntactic construct they handle is present, wrap
  2313. // the AST node that the inner parser gave them in another node.
  2314. // Parse a full expression. The optional arguments are used to
  2315. // forbid the `in` operator (in for loops initalization expressions)
  2316. // and provide reference for storing '=' operator inside shorthand
  2317. // property assignment in contexts where both object expression
  2318. // and object pattern might appear (so it's possible to raise
  2319. // delayed syntax error at correct position).
  2320. pp$5.parseExpression = function(forInit, refDestructuringErrors) {
  2321. var startPos = this.start, startLoc = this.startLoc;
  2322. var expr = this.parseMaybeAssign(forInit, refDestructuringErrors);
  2323. if (this.type === types$1.comma) {
  2324. var node = this.startNodeAt(startPos, startLoc);
  2325. node.expressions = [expr];
  2326. while (this.eat(types$1.comma)) { node.expressions.push(this.parseMaybeAssign(forInit, refDestructuringErrors)); }
  2327. return this.finishNode(node, "SequenceExpression")
  2328. }
  2329. return expr
  2330. };
  2331. // Parse an assignment expression. This includes applications of
  2332. // operators like `+=`.
  2333. pp$5.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) {
  2334. if (this.isContextual("yield")) {
  2335. if (this.inGenerator) { return this.parseYield(forInit) }
  2336. // The tokenizer will assume an expression is allowed after
  2337. // `yield`, but this isn't that kind of yield
  2338. else { this.exprAllowed = false; }
  2339. }
  2340. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldDoubleProto = -1;
  2341. if (refDestructuringErrors) {
  2342. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  2343. oldTrailingComma = refDestructuringErrors.trailingComma;
  2344. oldDoubleProto = refDestructuringErrors.doubleProto;
  2345. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  2346. } else {
  2347. refDestructuringErrors = new DestructuringErrors;
  2348. ownDestructuringErrors = true;
  2349. }
  2350. var startPos = this.start, startLoc = this.startLoc;
  2351. if (this.type === types$1.parenL || this.type === types$1.name) {
  2352. this.potentialArrowAt = this.start;
  2353. this.potentialArrowInForAwait = forInit === "await";
  2354. }
  2355. var left = this.parseMaybeConditional(forInit, refDestructuringErrors);
  2356. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  2357. if (this.type.isAssign) {
  2358. var node = this.startNodeAt(startPos, startLoc);
  2359. node.operator = this.value;
  2360. if (this.type === types$1.eq)
  2361. { left = this.toAssignable(left, false, refDestructuringErrors); }
  2362. if (!ownDestructuringErrors) {
  2363. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1;
  2364. }
  2365. if (refDestructuringErrors.shorthandAssign >= left.start)
  2366. { refDestructuringErrors.shorthandAssign = -1; } // reset because shorthand default was used correctly
  2367. if (this.type === types$1.eq)
  2368. { this.checkLValPattern(left); }
  2369. else
  2370. { this.checkLValSimple(left); }
  2371. node.left = left;
  2372. this.next();
  2373. node.right = this.parseMaybeAssign(forInit);
  2374. if (oldDoubleProto > -1) { refDestructuringErrors.doubleProto = oldDoubleProto; }
  2375. return this.finishNode(node, "AssignmentExpression")
  2376. } else {
  2377. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  2378. }
  2379. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  2380. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  2381. return left
  2382. };
  2383. // Parse a ternary conditional (`?:`) operator.
  2384. pp$5.parseMaybeConditional = function(forInit, refDestructuringErrors) {
  2385. var startPos = this.start, startLoc = this.startLoc;
  2386. var expr = this.parseExprOps(forInit, refDestructuringErrors);
  2387. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2388. if (this.eat(types$1.question)) {
  2389. var node = this.startNodeAt(startPos, startLoc);
  2390. node.test = expr;
  2391. node.consequent = this.parseMaybeAssign();
  2392. this.expect(types$1.colon);
  2393. node.alternate = this.parseMaybeAssign(forInit);
  2394. return this.finishNode(node, "ConditionalExpression")
  2395. }
  2396. return expr
  2397. };
  2398. // Start the precedence parser.
  2399. pp$5.parseExprOps = function(forInit, refDestructuringErrors) {
  2400. var startPos = this.start, startLoc = this.startLoc;
  2401. var expr = this.parseMaybeUnary(refDestructuringErrors, false, false, forInit);
  2402. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2403. return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, forInit)
  2404. };
  2405. // Parse binary operators with the operator precedence parsing
  2406. // algorithm. `left` is the left-hand side of the operator.
  2407. // `minPrec` provides context that allows the function to stop and
  2408. // defer further parser to one of its callers when it encounters an
  2409. // operator that has a lower precedence than the set it is parsing.
  2410. pp$5.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) {
  2411. var prec = this.type.binop;
  2412. if (prec != null && (!forInit || this.type !== types$1._in)) {
  2413. if (prec > minPrec) {
  2414. var logical = this.type === types$1.logicalOR || this.type === types$1.logicalAND;
  2415. var coalesce = this.type === types$1.coalesce;
  2416. if (coalesce) {
  2417. // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions.
  2418. // In other words, `node.right` shouldn't contain logical expressions in order to check the mixed error.
  2419. prec = types$1.logicalAND.binop;
  2420. }
  2421. var op = this.value;
  2422. this.next();
  2423. var startPos = this.start, startLoc = this.startLoc;
  2424. var right = this.parseExprOp(this.parseMaybeUnary(null, false, false, forInit), startPos, startLoc, prec, forInit);
  2425. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce);
  2426. if ((logical && this.type === types$1.coalesce) || (coalesce && (this.type === types$1.logicalOR || this.type === types$1.logicalAND))) {
  2427. this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses");
  2428. }
  2429. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, forInit)
  2430. }
  2431. }
  2432. return left
  2433. };
  2434. pp$5.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  2435. if (right.type === "PrivateIdentifier") { this.raise(right.start, "Private identifier can only be left side of binary expression"); }
  2436. var node = this.startNodeAt(startPos, startLoc);
  2437. node.left = left;
  2438. node.operator = op;
  2439. node.right = right;
  2440. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  2441. };
  2442. // Parse unary operators, both prefix and postfix.
  2443. pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit) {
  2444. var startPos = this.start, startLoc = this.startLoc, expr;
  2445. if (this.isContextual("await") && this.canAwait) {
  2446. expr = this.parseAwait(forInit);
  2447. sawUnary = true;
  2448. } else if (this.type.prefix) {
  2449. var node = this.startNode(), update = this.type === types$1.incDec;
  2450. node.operator = this.value;
  2451. node.prefix = true;
  2452. this.next();
  2453. node.argument = this.parseMaybeUnary(null, true, update, forInit);
  2454. this.checkExpressionErrors(refDestructuringErrors, true);
  2455. if (update) { this.checkLValSimple(node.argument); }
  2456. else if (this.strict && node.operator === "delete" && isLocalVariableAccess(node.argument))
  2457. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  2458. else if (node.operator === "delete" && isPrivateFieldAccess(node.argument))
  2459. { this.raiseRecoverable(node.start, "Private fields can not be deleted"); }
  2460. else { sawUnary = true; }
  2461. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  2462. } else if (!sawUnary && this.type === types$1.privateId) {
  2463. if ((forInit || this.privateNameStack.length === 0) && this.options.checkPrivateFields) { this.unexpected(); }
  2464. expr = this.parsePrivateIdent();
  2465. // only could be private fields in 'in', such as #x in obj
  2466. if (this.type !== types$1._in) { this.unexpected(); }
  2467. } else {
  2468. expr = this.parseExprSubscripts(refDestructuringErrors, forInit);
  2469. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2470. while (this.type.postfix && !this.canInsertSemicolon()) {
  2471. var node$1 = this.startNodeAt(startPos, startLoc);
  2472. node$1.operator = this.value;
  2473. node$1.prefix = false;
  2474. node$1.argument = expr;
  2475. this.checkLValSimple(expr);
  2476. this.next();
  2477. expr = this.finishNode(node$1, "UpdateExpression");
  2478. }
  2479. }
  2480. if (!incDec && this.eat(types$1.starstar)) {
  2481. if (sawUnary)
  2482. { this.unexpected(this.lastTokStart); }
  2483. else
  2484. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false) }
  2485. } else {
  2486. return expr
  2487. }
  2488. };
  2489. function isLocalVariableAccess(node) {
  2490. return (
  2491. node.type === "Identifier" ||
  2492. node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression)
  2493. )
  2494. }
  2495. function isPrivateFieldAccess(node) {
  2496. return (
  2497. node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" ||
  2498. node.type === "ChainExpression" && isPrivateFieldAccess(node.expression) ||
  2499. node.type === "ParenthesizedExpression" && isPrivateFieldAccess(node.expression)
  2500. )
  2501. }
  2502. // Parse call, dot, and `[]`-subscript expressions.
  2503. pp$5.parseExprSubscripts = function(refDestructuringErrors, forInit) {
  2504. var startPos = this.start, startLoc = this.startLoc;
  2505. var expr = this.parseExprAtom(refDestructuringErrors, forInit);
  2506. if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
  2507. { return expr }
  2508. var result = this.parseSubscripts(expr, startPos, startLoc, false, forInit);
  2509. if (refDestructuringErrors && result.type === "MemberExpression") {
  2510. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  2511. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  2512. if (refDestructuringErrors.trailingComma >= result.start) { refDestructuringErrors.trailingComma = -1; }
  2513. }
  2514. return result
  2515. };
  2516. pp$5.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit) {
  2517. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  2518. this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 &&
  2519. this.potentialArrowAt === base.start;
  2520. var optionalChained = false;
  2521. while (true) {
  2522. var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
  2523. if (element.optional) { optionalChained = true; }
  2524. if (element === base || element.type === "ArrowFunctionExpression") {
  2525. if (optionalChained) {
  2526. var chainNode = this.startNodeAt(startPos, startLoc);
  2527. chainNode.expression = element;
  2528. element = this.finishNode(chainNode, "ChainExpression");
  2529. }
  2530. return element
  2531. }
  2532. base = element;
  2533. }
  2534. };
  2535. pp$5.shouldParseAsyncArrow = function() {
  2536. return !this.canInsertSemicolon() && this.eat(types$1.arrow)
  2537. };
  2538. pp$5.parseSubscriptAsyncArrow = function(startPos, startLoc, exprList, forInit) {
  2539. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true, forInit)
  2540. };
  2541. pp$5.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) {
  2542. var optionalSupported = this.options.ecmaVersion >= 11;
  2543. var optional = optionalSupported && this.eat(types$1.questionDot);
  2544. if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); }
  2545. var computed = this.eat(types$1.bracketL);
  2546. if (computed || (optional && this.type !== types$1.parenL && this.type !== types$1.backQuote) || this.eat(types$1.dot)) {
  2547. var node = this.startNodeAt(startPos, startLoc);
  2548. node.object = base;
  2549. if (computed) {
  2550. node.property = this.parseExpression();
  2551. this.expect(types$1.bracketR);
  2552. } else if (this.type === types$1.privateId && base.type !== "Super") {
  2553. node.property = this.parsePrivateIdent();
  2554. } else {
  2555. node.property = this.parseIdent(this.options.allowReserved !== "never");
  2556. }
  2557. node.computed = !!computed;
  2558. if (optionalSupported) {
  2559. node.optional = optional;
  2560. }
  2561. base = this.finishNode(node, "MemberExpression");
  2562. } else if (!noCalls && this.eat(types$1.parenL)) {
  2563. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2564. this.yieldPos = 0;
  2565. this.awaitPos = 0;
  2566. this.awaitIdentPos = 0;
  2567. var exprList = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors);
  2568. if (maybeAsyncArrow && !optional && this.shouldParseAsyncArrow()) {
  2569. this.checkPatternErrors(refDestructuringErrors, false);
  2570. this.checkYieldAwaitInDefaultParams();
  2571. if (this.awaitIdentPos > 0)
  2572. { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
  2573. this.yieldPos = oldYieldPos;
  2574. this.awaitPos = oldAwaitPos;
  2575. this.awaitIdentPos = oldAwaitIdentPos;
  2576. return this.parseSubscriptAsyncArrow(startPos, startLoc, exprList, forInit)
  2577. }
  2578. this.checkExpressionErrors(refDestructuringErrors, true);
  2579. this.yieldPos = oldYieldPos || this.yieldPos;
  2580. this.awaitPos = oldAwaitPos || this.awaitPos;
  2581. this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
  2582. var node$1 = this.startNodeAt(startPos, startLoc);
  2583. node$1.callee = base;
  2584. node$1.arguments = exprList;
  2585. if (optionalSupported) {
  2586. node$1.optional = optional;
  2587. }
  2588. base = this.finishNode(node$1, "CallExpression");
  2589. } else if (this.type === types$1.backQuote) {
  2590. if (optional || optionalChained) {
  2591. this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions");
  2592. }
  2593. var node$2 = this.startNodeAt(startPos, startLoc);
  2594. node$2.tag = base;
  2595. node$2.quasi = this.parseTemplate({isTagged: true});
  2596. base = this.finishNode(node$2, "TaggedTemplateExpression");
  2597. }
  2598. return base
  2599. };
  2600. // Parse an atomic expression — either a single token that is an
  2601. // expression, an expression started by a keyword like `function` or
  2602. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  2603. // or `{}`.
  2604. pp$5.parseExprAtom = function(refDestructuringErrors, forInit, forNew) {
  2605. // If a division operator appears in an expression position, the
  2606. // tokenizer got confused, and we force it to read a regexp instead.
  2607. if (this.type === types$1.slash) { this.readRegexp(); }
  2608. var node, canBeArrow = this.potentialArrowAt === this.start;
  2609. switch (this.type) {
  2610. case types$1._super:
  2611. if (!this.allowSuper)
  2612. { this.raise(this.start, "'super' keyword outside a method"); }
  2613. node = this.startNode();
  2614. this.next();
  2615. if (this.type === types$1.parenL && !this.allowDirectSuper)
  2616. { this.raise(node.start, "super() call outside constructor of a subclass"); }
  2617. // The `super` keyword can appear at below:
  2618. // SuperProperty:
  2619. // super [ Expression ]
  2620. // super . IdentifierName
  2621. // SuperCall:
  2622. // super ( Arguments )
  2623. if (this.type !== types$1.dot && this.type !== types$1.bracketL && this.type !== types$1.parenL)
  2624. { this.unexpected(); }
  2625. return this.finishNode(node, "Super")
  2626. case types$1._this:
  2627. node = this.startNode();
  2628. this.next();
  2629. return this.finishNode(node, "ThisExpression")
  2630. case types$1.name:
  2631. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  2632. var id = this.parseIdent(false);
  2633. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types$1._function)) {
  2634. this.overrideContext(types.f_expr);
  2635. return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true, forInit)
  2636. }
  2637. if (canBeArrow && !this.canInsertSemicolon()) {
  2638. if (this.eat(types$1.arrow))
  2639. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false, forInit) }
  2640. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types$1.name && !containsEsc &&
  2641. (!this.potentialArrowInForAwait || this.value !== "of" || this.containsEsc)) {
  2642. id = this.parseIdent(false);
  2643. if (this.canInsertSemicolon() || !this.eat(types$1.arrow))
  2644. { this.unexpected(); }
  2645. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true, forInit)
  2646. }
  2647. }
  2648. return id
  2649. case types$1.regexp:
  2650. var value = this.value;
  2651. node = this.parseLiteral(value.value);
  2652. node.regex = {pattern: value.pattern, flags: value.flags};
  2653. return node
  2654. case types$1.num: case types$1.string:
  2655. return this.parseLiteral(this.value)
  2656. case types$1._null: case types$1._true: case types$1._false:
  2657. node = this.startNode();
  2658. node.value = this.type === types$1._null ? null : this.type === types$1._true;
  2659. node.raw = this.type.keyword;
  2660. this.next();
  2661. return this.finishNode(node, "Literal")
  2662. case types$1.parenL:
  2663. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit);
  2664. if (refDestructuringErrors) {
  2665. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  2666. { refDestructuringErrors.parenthesizedAssign = start; }
  2667. if (refDestructuringErrors.parenthesizedBind < 0)
  2668. { refDestructuringErrors.parenthesizedBind = start; }
  2669. }
  2670. return expr
  2671. case types$1.bracketL:
  2672. node = this.startNode();
  2673. this.next();
  2674. node.elements = this.parseExprList(types$1.bracketR, true, true, refDestructuringErrors);
  2675. return this.finishNode(node, "ArrayExpression")
  2676. case types$1.braceL:
  2677. this.overrideContext(types.b_expr);
  2678. return this.parseObj(false, refDestructuringErrors)
  2679. case types$1._function:
  2680. node = this.startNode();
  2681. this.next();
  2682. return this.parseFunction(node, 0)
  2683. case types$1._class:
  2684. return this.parseClass(this.startNode(), false)
  2685. case types$1._new:
  2686. return this.parseNew()
  2687. case types$1.backQuote:
  2688. return this.parseTemplate()
  2689. case types$1._import:
  2690. if (this.options.ecmaVersion >= 11) {
  2691. return this.parseExprImport(forNew)
  2692. } else {
  2693. return this.unexpected()
  2694. }
  2695. default:
  2696. return this.parseExprAtomDefault()
  2697. }
  2698. };
  2699. pp$5.parseExprAtomDefault = function() {
  2700. this.unexpected();
  2701. };
  2702. pp$5.parseExprImport = function(forNew) {
  2703. var node = this.startNode();
  2704. // Consume `import` as an identifier for `import.meta`.
  2705. // Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`.
  2706. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword import"); }
  2707. this.next();
  2708. if (this.type === types$1.parenL && !forNew) {
  2709. return this.parseDynamicImport(node)
  2710. } else if (this.type === types$1.dot) {
  2711. var meta = this.startNodeAt(node.start, node.loc && node.loc.start);
  2712. meta.name = "import";
  2713. node.meta = this.finishNode(meta, "Identifier");
  2714. return this.parseImportMeta(node)
  2715. } else {
  2716. this.unexpected();
  2717. }
  2718. };
  2719. pp$5.parseDynamicImport = function(node) {
  2720. this.next(); // skip `(`
  2721. // Parse node.source.
  2722. node.source = this.parseMaybeAssign();
  2723. if (this.options.ecmaVersion >= 16) {
  2724. if (!this.eat(types$1.parenR)) {
  2725. this.expect(types$1.comma);
  2726. if (!this.afterTrailingComma(types$1.parenR)) {
  2727. node.options = this.parseMaybeAssign();
  2728. if (!this.eat(types$1.parenR)) {
  2729. this.expect(types$1.comma);
  2730. if (!this.afterTrailingComma(types$1.parenR)) {
  2731. this.unexpected();
  2732. }
  2733. }
  2734. } else {
  2735. node.options = null;
  2736. }
  2737. } else {
  2738. node.options = null;
  2739. }
  2740. } else {
  2741. // Verify ending.
  2742. if (!this.eat(types$1.parenR)) {
  2743. var errorPos = this.start;
  2744. if (this.eat(types$1.comma) && this.eat(types$1.parenR)) {
  2745. this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
  2746. } else {
  2747. this.unexpected(errorPos);
  2748. }
  2749. }
  2750. }
  2751. return this.finishNode(node, "ImportExpression")
  2752. };
  2753. pp$5.parseImportMeta = function(node) {
  2754. this.next(); // skip `.`
  2755. var containsEsc = this.containsEsc;
  2756. node.property = this.parseIdent(true);
  2757. if (node.property.name !== "meta")
  2758. { this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); }
  2759. if (containsEsc)
  2760. { this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); }
  2761. if (this.options.sourceType !== "module" && !this.options.allowImportExportEverywhere)
  2762. { this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); }
  2763. return this.finishNode(node, "MetaProperty")
  2764. };
  2765. pp$5.parseLiteral = function(value) {
  2766. var node = this.startNode();
  2767. node.value = value;
  2768. node.raw = this.input.slice(this.start, this.end);
  2769. if (node.raw.charCodeAt(node.raw.length - 1) === 110)
  2770. { node.bigint = node.value != null ? node.value.toString() : node.raw.slice(0, -1).replace(/_/g, ""); }
  2771. this.next();
  2772. return this.finishNode(node, "Literal")
  2773. };
  2774. pp$5.parseParenExpression = function() {
  2775. this.expect(types$1.parenL);
  2776. var val = this.parseExpression();
  2777. this.expect(types$1.parenR);
  2778. return val
  2779. };
  2780. pp$5.shouldParseArrow = function(exprList) {
  2781. return !this.canInsertSemicolon()
  2782. };
  2783. pp$5.parseParenAndDistinguishExpression = function(canBeArrow, forInit) {
  2784. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  2785. if (this.options.ecmaVersion >= 6) {
  2786. this.next();
  2787. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  2788. var exprList = [], first = true, lastIsComma = false;
  2789. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  2790. this.yieldPos = 0;
  2791. this.awaitPos = 0;
  2792. // Do not save awaitIdentPos to allow checking awaits nested in parameters
  2793. while (this.type !== types$1.parenR) {
  2794. first ? first = false : this.expect(types$1.comma);
  2795. if (allowTrailingComma && this.afterTrailingComma(types$1.parenR, true)) {
  2796. lastIsComma = true;
  2797. break
  2798. } else if (this.type === types$1.ellipsis) {
  2799. spreadStart = this.start;
  2800. exprList.push(this.parseParenItem(this.parseRestBinding()));
  2801. if (this.type === types$1.comma) {
  2802. this.raiseRecoverable(
  2803. this.start,
  2804. "Comma is not permitted after the rest element"
  2805. );
  2806. }
  2807. break
  2808. } else {
  2809. exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
  2810. }
  2811. }
  2812. var innerEndPos = this.lastTokEnd, innerEndLoc = this.lastTokEndLoc;
  2813. this.expect(types$1.parenR);
  2814. if (canBeArrow && this.shouldParseArrow(exprList) && this.eat(types$1.arrow)) {
  2815. this.checkPatternErrors(refDestructuringErrors, false);
  2816. this.checkYieldAwaitInDefaultParams();
  2817. this.yieldPos = oldYieldPos;
  2818. this.awaitPos = oldAwaitPos;
  2819. return this.parseParenArrowList(startPos, startLoc, exprList, forInit)
  2820. }
  2821. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  2822. if (spreadStart) { this.unexpected(spreadStart); }
  2823. this.checkExpressionErrors(refDestructuringErrors, true);
  2824. this.yieldPos = oldYieldPos || this.yieldPos;
  2825. this.awaitPos = oldAwaitPos || this.awaitPos;
  2826. if (exprList.length > 1) {
  2827. val = this.startNodeAt(innerStartPos, innerStartLoc);
  2828. val.expressions = exprList;
  2829. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  2830. } else {
  2831. val = exprList[0];
  2832. }
  2833. } else {
  2834. val = this.parseParenExpression();
  2835. }
  2836. if (this.options.preserveParens) {
  2837. var par = this.startNodeAt(startPos, startLoc);
  2838. par.expression = val;
  2839. return this.finishNode(par, "ParenthesizedExpression")
  2840. } else {
  2841. return val
  2842. }
  2843. };
  2844. pp$5.parseParenItem = function(item) {
  2845. return item
  2846. };
  2847. pp$5.parseParenArrowList = function(startPos, startLoc, exprList, forInit) {
  2848. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, false, forInit)
  2849. };
  2850. // New's precedence is slightly tricky. It must allow its argument to
  2851. // be a `[]` or dot subscript expression, but not a call — at least,
  2852. // not without wrapping it in parentheses. Thus, it uses the noCalls
  2853. // argument to parseSubscripts to prevent it from consuming the
  2854. // argument list.
  2855. var empty = [];
  2856. pp$5.parseNew = function() {
  2857. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); }
  2858. var node = this.startNode();
  2859. this.next();
  2860. if (this.options.ecmaVersion >= 6 && this.type === types$1.dot) {
  2861. var meta = this.startNodeAt(node.start, node.loc && node.loc.start);
  2862. meta.name = "new";
  2863. node.meta = this.finishNode(meta, "Identifier");
  2864. this.next();
  2865. var containsEsc = this.containsEsc;
  2866. node.property = this.parseIdent(true);
  2867. if (node.property.name !== "target")
  2868. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); }
  2869. if (containsEsc)
  2870. { this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); }
  2871. if (!this.allowNewDotTarget)
  2872. { this.raiseRecoverable(node.start, "'new.target' can only be used in functions and class static block"); }
  2873. return this.finishNode(node, "MetaProperty")
  2874. }
  2875. var startPos = this.start, startLoc = this.startLoc;
  2876. node.callee = this.parseSubscripts(this.parseExprAtom(null, false, true), startPos, startLoc, true, false);
  2877. if (this.eat(types$1.parenL)) { node.arguments = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false); }
  2878. else { node.arguments = empty; }
  2879. return this.finishNode(node, "NewExpression")
  2880. };
  2881. // Parse template expression.
  2882. pp$5.parseTemplateElement = function(ref) {
  2883. var isTagged = ref.isTagged;
  2884. var elem = this.startNode();
  2885. if (this.type === types$1.invalidTemplate) {
  2886. if (!isTagged) {
  2887. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2888. }
  2889. elem.value = {
  2890. raw: this.value.replace(/\r\n?/g, "\n"),
  2891. cooked: null
  2892. };
  2893. } else {
  2894. elem.value = {
  2895. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2896. cooked: this.value
  2897. };
  2898. }
  2899. this.next();
  2900. elem.tail = this.type === types$1.backQuote;
  2901. return this.finishNode(elem, "TemplateElement")
  2902. };
  2903. pp$5.parseTemplate = function(ref) {
  2904. if ( ref === void 0 ) ref = {};
  2905. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2906. var node = this.startNode();
  2907. this.next();
  2908. node.expressions = [];
  2909. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2910. node.quasis = [curElt];
  2911. while (!curElt.tail) {
  2912. if (this.type === types$1.eof) { this.raise(this.pos, "Unterminated template literal"); }
  2913. this.expect(types$1.dollarBraceL);
  2914. node.expressions.push(this.parseExpression());
  2915. this.expect(types$1.braceR);
  2916. node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
  2917. }
  2918. this.next();
  2919. return this.finishNode(node, "TemplateLiteral")
  2920. };
  2921. pp$5.isAsyncProp = function(prop) {
  2922. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2923. (this.type === types$1.name || this.type === types$1.num || this.type === types$1.string || this.type === types$1.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types$1.star)) &&
  2924. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2925. };
  2926. // Parse an object literal or binding pattern.
  2927. pp$5.parseObj = function(isPattern, refDestructuringErrors) {
  2928. var node = this.startNode(), first = true, propHash = {};
  2929. node.properties = [];
  2930. this.next();
  2931. while (!this.eat(types$1.braceR)) {
  2932. if (!first) {
  2933. this.expect(types$1.comma);
  2934. if (this.options.ecmaVersion >= 5 && this.afterTrailingComma(types$1.braceR)) { break }
  2935. } else { first = false; }
  2936. var prop = this.parseProperty(isPattern, refDestructuringErrors);
  2937. if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
  2938. node.properties.push(prop);
  2939. }
  2940. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2941. };
  2942. pp$5.parseProperty = function(isPattern, refDestructuringErrors) {
  2943. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2944. if (this.options.ecmaVersion >= 9 && this.eat(types$1.ellipsis)) {
  2945. if (isPattern) {
  2946. prop.argument = this.parseIdent(false);
  2947. if (this.type === types$1.comma) {
  2948. this.raiseRecoverable(this.start, "Comma is not permitted after the rest element");
  2949. }
  2950. return this.finishNode(prop, "RestElement")
  2951. }
  2952. // Parse argument.
  2953. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2954. // To disallow trailing comma via `this.toAssignable()`.
  2955. if (this.type === types$1.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2956. refDestructuringErrors.trailingComma = this.start;
  2957. }
  2958. // Finish
  2959. return this.finishNode(prop, "SpreadElement")
  2960. }
  2961. if (this.options.ecmaVersion >= 6) {
  2962. prop.method = false;
  2963. prop.shorthand = false;
  2964. if (isPattern || refDestructuringErrors) {
  2965. startPos = this.start;
  2966. startLoc = this.startLoc;
  2967. }
  2968. if (!isPattern)
  2969. { isGenerator = this.eat(types$1.star); }
  2970. }
  2971. var containsEsc = this.containsEsc;
  2972. this.parsePropertyName(prop);
  2973. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2974. isAsync = true;
  2975. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types$1.star);
  2976. this.parsePropertyName(prop);
  2977. } else {
  2978. isAsync = false;
  2979. }
  2980. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2981. return this.finishNode(prop, "Property")
  2982. };
  2983. pp$5.parseGetterSetter = function(prop) {
  2984. var kind = prop.key.name;
  2985. this.parsePropertyName(prop);
  2986. prop.value = this.parseMethod(false);
  2987. prop.kind = kind;
  2988. var paramCount = prop.kind === "get" ? 0 : 1;
  2989. if (prop.value.params.length !== paramCount) {
  2990. var start = prop.value.start;
  2991. if (prop.kind === "get")
  2992. { this.raiseRecoverable(start, "getter should have no params"); }
  2993. else
  2994. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2995. } else {
  2996. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2997. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2998. }
  2999. };
  3000. pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  3001. if ((isGenerator || isAsync) && this.type === types$1.colon)
  3002. { this.unexpected(); }
  3003. if (this.eat(types$1.colon)) {
  3004. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  3005. prop.kind = "init";
  3006. } else if (this.options.ecmaVersion >= 6 && this.type === types$1.parenL) {
  3007. if (isPattern) { this.unexpected(); }
  3008. prop.method = true;
  3009. prop.value = this.parseMethod(isGenerator, isAsync);
  3010. prop.kind = "init";
  3011. } else if (!isPattern && !containsEsc &&
  3012. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  3013. (prop.key.name === "get" || prop.key.name === "set") &&
  3014. (this.type !== types$1.comma && this.type !== types$1.braceR && this.type !== types$1.eq)) {
  3015. if (isGenerator || isAsync) { this.unexpected(); }
  3016. this.parseGetterSetter(prop);
  3017. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  3018. if (isGenerator || isAsync) { this.unexpected(); }
  3019. this.checkUnreserved(prop.key);
  3020. if (prop.key.name === "await" && !this.awaitIdentPos)
  3021. { this.awaitIdentPos = startPos; }
  3022. if (isPattern) {
  3023. prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
  3024. } else if (this.type === types$1.eq && refDestructuringErrors) {
  3025. if (refDestructuringErrors.shorthandAssign < 0)
  3026. { refDestructuringErrors.shorthandAssign = this.start; }
  3027. prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
  3028. } else {
  3029. prop.value = this.copyNode(prop.key);
  3030. }
  3031. prop.kind = "init";
  3032. prop.shorthand = true;
  3033. } else { this.unexpected(); }
  3034. };
  3035. pp$5.parsePropertyName = function(prop) {
  3036. if (this.options.ecmaVersion >= 6) {
  3037. if (this.eat(types$1.bracketL)) {
  3038. prop.computed = true;
  3039. prop.key = this.parseMaybeAssign();
  3040. this.expect(types$1.bracketR);
  3041. return prop.key
  3042. } else {
  3043. prop.computed = false;
  3044. }
  3045. }
  3046. return prop.key = this.type === types$1.num || this.type === types$1.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
  3047. };
  3048. // Initialize empty function node.
  3049. pp$5.initFunction = function(node) {
  3050. node.id = null;
  3051. if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
  3052. if (this.options.ecmaVersion >= 8) { node.async = false; }
  3053. };
  3054. // Parse object or class method.
  3055. pp$5.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
  3056. var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  3057. this.initFunction(node);
  3058. if (this.options.ecmaVersion >= 6)
  3059. { node.generator = isGenerator; }
  3060. if (this.options.ecmaVersion >= 8)
  3061. { node.async = !!isAsync; }
  3062. this.yieldPos = 0;
  3063. this.awaitPos = 0;
  3064. this.awaitIdentPos = 0;
  3065. this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  3066. this.expect(types$1.parenL);
  3067. node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8);
  3068. this.checkYieldAwaitInDefaultParams();
  3069. this.parseFunctionBody(node, false, true, false);
  3070. this.yieldPos = oldYieldPos;
  3071. this.awaitPos = oldAwaitPos;
  3072. this.awaitIdentPos = oldAwaitIdentPos;
  3073. return this.finishNode(node, "FunctionExpression")
  3074. };
  3075. // Parse arrow function expression with given parameters.
  3076. pp$5.parseArrowExpression = function(node, params, isAsync, forInit) {
  3077. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  3078. this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
  3079. this.initFunction(node);
  3080. if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
  3081. this.yieldPos = 0;
  3082. this.awaitPos = 0;
  3083. this.awaitIdentPos = 0;
  3084. node.params = this.toAssignableList(params, true);
  3085. this.parseFunctionBody(node, true, false, forInit);
  3086. this.yieldPos = oldYieldPos;
  3087. this.awaitPos = oldAwaitPos;
  3088. this.awaitIdentPos = oldAwaitIdentPos;
  3089. return this.finishNode(node, "ArrowFunctionExpression")
  3090. };
  3091. // Parse function body and check parameters.
  3092. pp$5.parseFunctionBody = function(node, isArrowFunction, isMethod, forInit) {
  3093. var isExpression = isArrowFunction && this.type !== types$1.braceL;
  3094. var oldStrict = this.strict, useStrict = false;
  3095. if (isExpression) {
  3096. node.body = this.parseMaybeAssign(forInit);
  3097. node.expression = true;
  3098. this.checkParams(node, false);
  3099. } else {
  3100. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  3101. if (!oldStrict || nonSimple) {
  3102. useStrict = this.strictDirective(this.end);
  3103. // If this is a strict mode function, verify that argument names
  3104. // are not repeated, and it does not try to bind the words `eval`
  3105. // or `arguments`.
  3106. if (useStrict && nonSimple)
  3107. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  3108. }
  3109. // Start a new scope with regard to labels and the `inFunction`
  3110. // flag (restore them to their old value afterwards).
  3111. var oldLabels = this.labels;
  3112. this.labels = [];
  3113. if (useStrict) { this.strict = true; }
  3114. // Add the params to varDeclaredNames to ensure that an error is thrown
  3115. // if a let/const declaration in the function clashes with one of the params.
  3116. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
  3117. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  3118. if (this.strict && node.id) { this.checkLValSimple(node.id, BIND_OUTSIDE); }
  3119. node.body = this.parseBlock(false, undefined, useStrict && !oldStrict);
  3120. node.expression = false;
  3121. this.adaptDirectivePrologue(node.body.body);
  3122. this.labels = oldLabels;
  3123. }
  3124. this.exitScope();
  3125. };
  3126. pp$5.isSimpleParamList = function(params) {
  3127. for (var i = 0, list = params; i < list.length; i += 1)
  3128. {
  3129. var param = list[i];
  3130. if (param.type !== "Identifier") { return false
  3131. } }
  3132. return true
  3133. };
  3134. // Checks function params for various disallowed patterns such as using "eval"
  3135. // or "arguments" and duplicate parameters.
  3136. pp$5.checkParams = function(node, allowDuplicates) {
  3137. var nameHash = Object.create(null);
  3138. for (var i = 0, list = node.params; i < list.length; i += 1)
  3139. {
  3140. var param = list[i];
  3141. this.checkLValInnerPattern(param, BIND_VAR, allowDuplicates ? null : nameHash);
  3142. }
  3143. };
  3144. // Parses a comma-separated list of expressions, and returns them as
  3145. // an array. `close` is the token type that ends the list, and
  3146. // `allowEmpty` can be turned on to allow subsequent commas with
  3147. // nothing in between them to be parsed as `null` (which is needed
  3148. // for array literals).
  3149. pp$5.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  3150. var elts = [], first = true;
  3151. while (!this.eat(close)) {
  3152. if (!first) {
  3153. this.expect(types$1.comma);
  3154. if (allowTrailingComma && this.afterTrailingComma(close)) { break }
  3155. } else { first = false; }
  3156. var elt = (void 0);
  3157. if (allowEmpty && this.type === types$1.comma)
  3158. { elt = null; }
  3159. else if (this.type === types$1.ellipsis) {
  3160. elt = this.parseSpread(refDestructuringErrors);
  3161. if (refDestructuringErrors && this.type === types$1.comma && refDestructuringErrors.trailingComma < 0)
  3162. { refDestructuringErrors.trailingComma = this.start; }
  3163. } else {
  3164. elt = this.parseMaybeAssign(false, refDestructuringErrors);
  3165. }
  3166. elts.push(elt);
  3167. }
  3168. return elts
  3169. };
  3170. pp$5.checkUnreserved = function(ref) {
  3171. var start = ref.start;
  3172. var end = ref.end;
  3173. var name = ref.name;
  3174. if (this.inGenerator && name === "yield")
  3175. { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
  3176. if (this.inAsync && name === "await")
  3177. { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
  3178. if (!(this.currentThisScope().flags & SCOPE_VAR) && name === "arguments")
  3179. { this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer"); }
  3180. if (this.inClassStaticBlock && (name === "arguments" || name === "await"))
  3181. { this.raise(start, ("Cannot use " + name + " in class static initialization block")); }
  3182. if (this.keywords.test(name))
  3183. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  3184. if (this.options.ecmaVersion < 6 &&
  3185. this.input.slice(start, end).indexOf("\\") !== -1) { return }
  3186. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  3187. if (re.test(name)) {
  3188. if (!this.inAsync && name === "await")
  3189. { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
  3190. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  3191. }
  3192. };
  3193. // Parse the next token as an identifier. If `liberal` is true (used
  3194. // when parsing properties), it will also convert keywords into
  3195. // identifiers.
  3196. pp$5.parseIdent = function(liberal) {
  3197. var node = this.parseIdentNode();
  3198. this.next(!!liberal);
  3199. this.finishNode(node, "Identifier");
  3200. if (!liberal) {
  3201. this.checkUnreserved(node);
  3202. if (node.name === "await" && !this.awaitIdentPos)
  3203. { this.awaitIdentPos = node.start; }
  3204. }
  3205. return node
  3206. };
  3207. pp$5.parseIdentNode = function() {
  3208. var node = this.startNode();
  3209. if (this.type === types$1.name) {
  3210. node.name = this.value;
  3211. } else if (this.type.keyword) {
  3212. node.name = this.type.keyword;
  3213. // To fix https://github.com/acornjs/acorn/issues/575
  3214. // `class` and `function` keywords push new context into this.context.
  3215. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  3216. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  3217. if ((node.name === "class" || node.name === "function") &&
  3218. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  3219. this.context.pop();
  3220. }
  3221. this.type = types$1.name;
  3222. } else {
  3223. this.unexpected();
  3224. }
  3225. return node
  3226. };
  3227. pp$5.parsePrivateIdent = function() {
  3228. var node = this.startNode();
  3229. if (this.type === types$1.privateId) {
  3230. node.name = this.value;
  3231. } else {
  3232. this.unexpected();
  3233. }
  3234. this.next();
  3235. this.finishNode(node, "PrivateIdentifier");
  3236. // For validating existence
  3237. if (this.options.checkPrivateFields) {
  3238. if (this.privateNameStack.length === 0) {
  3239. this.raise(node.start, ("Private field '#" + (node.name) + "' must be declared in an enclosing class"));
  3240. } else {
  3241. this.privateNameStack[this.privateNameStack.length - 1].used.push(node);
  3242. }
  3243. }
  3244. return node
  3245. };
  3246. // Parses yield expression inside generator.
  3247. pp$5.parseYield = function(forInit) {
  3248. if (!this.yieldPos) { this.yieldPos = this.start; }
  3249. var node = this.startNode();
  3250. this.next();
  3251. if (this.type === types$1.semi || this.canInsertSemicolon() || (this.type !== types$1.star && !this.type.startsExpr)) {
  3252. node.delegate = false;
  3253. node.argument = null;
  3254. } else {
  3255. node.delegate = this.eat(types$1.star);
  3256. node.argument = this.parseMaybeAssign(forInit);
  3257. }
  3258. return this.finishNode(node, "YieldExpression")
  3259. };
  3260. pp$5.parseAwait = function(forInit) {
  3261. if (!this.awaitPos) { this.awaitPos = this.start; }
  3262. var node = this.startNode();
  3263. this.next();
  3264. node.argument = this.parseMaybeUnary(null, true, false, forInit);
  3265. return this.finishNode(node, "AwaitExpression")
  3266. };
  3267. var pp$4 = Parser.prototype;
  3268. // This function is used to raise exceptions on parse errors. It
  3269. // takes an offset integer (into the current `input`) to indicate
  3270. // the location of the error, attaches the position to the end
  3271. // of the error message, and then raises a `SyntaxError` with that
  3272. // message.
  3273. pp$4.raise = function(pos, message) {
  3274. var loc = getLineInfo(this.input, pos);
  3275. message += " (" + loc.line + ":" + loc.column + ")";
  3276. if (this.sourceFile) {
  3277. message += " in " + this.sourceFile;
  3278. }
  3279. var err = new SyntaxError(message);
  3280. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  3281. throw err
  3282. };
  3283. pp$4.raiseRecoverable = pp$4.raise;
  3284. pp$4.curPosition = function() {
  3285. if (this.options.locations) {
  3286. return new Position(this.curLine, this.pos - this.lineStart)
  3287. }
  3288. };
  3289. var pp$3 = Parser.prototype;
  3290. var Scope = function Scope(flags) {
  3291. this.flags = flags;
  3292. // A list of var-declared names in the current lexical scope
  3293. this.var = [];
  3294. // A list of lexically-declared names in the current lexical scope
  3295. this.lexical = [];
  3296. // A list of lexically-declared FunctionDeclaration names in the current lexical scope
  3297. this.functions = [];
  3298. };
  3299. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  3300. pp$3.enterScope = function(flags) {
  3301. this.scopeStack.push(new Scope(flags));
  3302. };
  3303. pp$3.exitScope = function() {
  3304. this.scopeStack.pop();
  3305. };
  3306. // The spec says:
  3307. // > At the top level of a function, or script, function declarations are
  3308. // > treated like var declarations rather than like lexical declarations.
  3309. pp$3.treatFunctionsAsVarInScope = function(scope) {
  3310. return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
  3311. };
  3312. pp$3.declareName = function(name, bindingType, pos) {
  3313. var redeclared = false;
  3314. if (bindingType === BIND_LEXICAL) {
  3315. var scope = this.currentScope();
  3316. redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
  3317. scope.lexical.push(name);
  3318. if (this.inModule && (scope.flags & SCOPE_TOP))
  3319. { delete this.undefinedExports[name]; }
  3320. } else if (bindingType === BIND_SIMPLE_CATCH) {
  3321. var scope$1 = this.currentScope();
  3322. scope$1.lexical.push(name);
  3323. } else if (bindingType === BIND_FUNCTION) {
  3324. var scope$2 = this.currentScope();
  3325. if (this.treatFunctionsAsVar)
  3326. { redeclared = scope$2.lexical.indexOf(name) > -1; }
  3327. else
  3328. { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
  3329. scope$2.functions.push(name);
  3330. } else {
  3331. for (var i = this.scopeStack.length - 1; i >= 0; --i) {
  3332. var scope$3 = this.scopeStack[i];
  3333. if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
  3334. !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
  3335. redeclared = true;
  3336. break
  3337. }
  3338. scope$3.var.push(name);
  3339. if (this.inModule && (scope$3.flags & SCOPE_TOP))
  3340. { delete this.undefinedExports[name]; }
  3341. if (scope$3.flags & SCOPE_VAR) { break }
  3342. }
  3343. }
  3344. if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
  3345. };
  3346. pp$3.checkLocalExport = function(id) {
  3347. // scope.functions must be empty as Module code is always strict.
  3348. if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
  3349. this.scopeStack[0].var.indexOf(id.name) === -1) {
  3350. this.undefinedExports[id.name] = id;
  3351. }
  3352. };
  3353. pp$3.currentScope = function() {
  3354. return this.scopeStack[this.scopeStack.length - 1]
  3355. };
  3356. pp$3.currentVarScope = function() {
  3357. for (var i = this.scopeStack.length - 1;; i--) {
  3358. var scope = this.scopeStack[i];
  3359. if (scope.flags & (SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK)) { return scope }
  3360. }
  3361. };
  3362. // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
  3363. pp$3.currentThisScope = function() {
  3364. for (var i = this.scopeStack.length - 1;; i--) {
  3365. var scope = this.scopeStack[i];
  3366. if (scope.flags & (SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK) &&
  3367. !(scope.flags & SCOPE_ARROW)) { return scope }
  3368. }
  3369. };
  3370. var Node = function Node(parser, pos, loc) {
  3371. this.type = "";
  3372. this.start = pos;
  3373. this.end = 0;
  3374. if (parser.options.locations)
  3375. { this.loc = new SourceLocation(parser, loc); }
  3376. if (parser.options.directSourceFile)
  3377. { this.sourceFile = parser.options.directSourceFile; }
  3378. if (parser.options.ranges)
  3379. { this.range = [pos, 0]; }
  3380. };
  3381. // Start an AST node, attaching a start offset.
  3382. var pp$2 = Parser.prototype;
  3383. pp$2.startNode = function() {
  3384. return new Node(this, this.start, this.startLoc)
  3385. };
  3386. pp$2.startNodeAt = function(pos, loc) {
  3387. return new Node(this, pos, loc)
  3388. };
  3389. // Finish an AST node, adding `type` and `end` properties.
  3390. function finishNodeAt(node, type, pos, loc) {
  3391. node.type = type;
  3392. node.end = pos;
  3393. if (this.options.locations)
  3394. { node.loc.end = loc; }
  3395. if (this.options.ranges)
  3396. { node.range[1] = pos; }
  3397. return node
  3398. }
  3399. pp$2.finishNode = function(node, type) {
  3400. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  3401. };
  3402. // Finish node at given position
  3403. pp$2.finishNodeAt = function(node, type, pos, loc) {
  3404. return finishNodeAt.call(this, node, type, pos, loc)
  3405. };
  3406. pp$2.copyNode = function(node) {
  3407. var newNode = new Node(this, node.start, this.startLoc);
  3408. for (var prop in node) { newNode[prop] = node[prop]; }
  3409. return newNode
  3410. };
  3411. // This file was generated by "bin/generate-unicode-script-values.js". Do not modify manually!
  3412. var scriptValuesAddedInUnicode = "Berf Beria_Erfe Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sidetic Sidt Sunu Sunuwar Tai_Yo Tayo Todhri Todr Tolong_Siki Tols Tulu_Tigalari Tutg Unknown Zzzz";
  3413. // This file contains Unicode properties extracted from the ECMAScript specification.
  3414. // The lists are extracted like so:
  3415. // $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
  3416. // #table-binary-unicode-properties
  3417. var ecma9BinaryProperties = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS";
  3418. var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
  3419. var ecma11BinaryProperties = ecma10BinaryProperties;
  3420. var ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict";
  3421. var ecma13BinaryProperties = ecma12BinaryProperties;
  3422. var ecma14BinaryProperties = ecma13BinaryProperties;
  3423. var unicodeBinaryProperties = {
  3424. 9: ecma9BinaryProperties,
  3425. 10: ecma10BinaryProperties,
  3426. 11: ecma11BinaryProperties,
  3427. 12: ecma12BinaryProperties,
  3428. 13: ecma13BinaryProperties,
  3429. 14: ecma14BinaryProperties
  3430. };
  3431. // #table-binary-unicode-properties-of-strings
  3432. var ecma14BinaryPropertiesOfStrings = "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji";
  3433. var unicodeBinaryPropertiesOfStrings = {
  3434. 9: "",
  3435. 10: "",
  3436. 11: "",
  3437. 12: "",
  3438. 13: "",
  3439. 14: ecma14BinaryPropertiesOfStrings
  3440. };
  3441. // #table-unicode-general-category-values
  3442. var unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu";
  3443. // #table-unicode-script-values
  3444. var ecma9ScriptValues = "Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb";
  3445. var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
  3446. var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
  3447. var ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi";
  3448. var ecma13ScriptValues = ecma12ScriptValues + " Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith";
  3449. var ecma14ScriptValues = ecma13ScriptValues + " " + scriptValuesAddedInUnicode;
  3450. var unicodeScriptValues = {
  3451. 9: ecma9ScriptValues,
  3452. 10: ecma10ScriptValues,
  3453. 11: ecma11ScriptValues,
  3454. 12: ecma12ScriptValues,
  3455. 13: ecma13ScriptValues,
  3456. 14: ecma14ScriptValues
  3457. };
  3458. var data = {};
  3459. function buildUnicodeData(ecmaVersion) {
  3460. var d = data[ecmaVersion] = {
  3461. binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
  3462. binaryOfStrings: wordsRegexp(unicodeBinaryPropertiesOfStrings[ecmaVersion]),
  3463. nonBinary: {
  3464. General_Category: wordsRegexp(unicodeGeneralCategoryValues),
  3465. Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
  3466. }
  3467. };
  3468. d.nonBinary.Script_Extensions = d.nonBinary.Script;
  3469. d.nonBinary.gc = d.nonBinary.General_Category;
  3470. d.nonBinary.sc = d.nonBinary.Script;
  3471. d.nonBinary.scx = d.nonBinary.Script_Extensions;
  3472. }
  3473. for (var i = 0, list = [9, 10, 11, 12, 13, 14]; i < list.length; i += 1) {
  3474. var ecmaVersion = list[i];
  3475. buildUnicodeData(ecmaVersion);
  3476. }
  3477. var pp$1 = Parser.prototype;
  3478. // Track disjunction structure to determine whether a duplicate
  3479. // capture group name is allowed because it is in a separate branch.
  3480. var BranchID = function BranchID(parent, base) {
  3481. // Parent disjunction branch
  3482. this.parent = parent;
  3483. // Identifies this set of sibling branches
  3484. this.base = base || this;
  3485. };
  3486. BranchID.prototype.separatedFrom = function separatedFrom (alt) {
  3487. // A branch is separate from another branch if they or any of
  3488. // their parents are siblings in a given disjunction
  3489. for (var self = this; self; self = self.parent) {
  3490. for (var other = alt; other; other = other.parent) {
  3491. if (self.base === other.base && self !== other) { return true }
  3492. }
  3493. }
  3494. return false
  3495. };
  3496. BranchID.prototype.sibling = function sibling () {
  3497. return new BranchID(this.parent, this.base)
  3498. };
  3499. var RegExpValidationState = function RegExpValidationState(parser) {
  3500. this.parser = parser;
  3501. this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "") + (parser.options.ecmaVersion >= 13 ? "d" : "") + (parser.options.ecmaVersion >= 15 ? "v" : "");
  3502. this.unicodeProperties = data[parser.options.ecmaVersion >= 14 ? 14 : parser.options.ecmaVersion];
  3503. this.source = "";
  3504. this.flags = "";
  3505. this.start = 0;
  3506. this.switchU = false;
  3507. this.switchV = false;
  3508. this.switchN = false;
  3509. this.pos = 0;
  3510. this.lastIntValue = 0;
  3511. this.lastStringValue = "";
  3512. this.lastAssertionIsQuantifiable = false;
  3513. this.numCapturingParens = 0;
  3514. this.maxBackReference = 0;
  3515. this.groupNames = Object.create(null);
  3516. this.backReferenceNames = [];
  3517. this.branchID = null;
  3518. };
  3519. RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
  3520. var unicodeSets = flags.indexOf("v") !== -1;
  3521. var unicode = flags.indexOf("u") !== -1;
  3522. this.start = start | 0;
  3523. this.source = pattern + "";
  3524. this.flags = flags;
  3525. if (unicodeSets && this.parser.options.ecmaVersion >= 15) {
  3526. this.switchU = true;
  3527. this.switchV = true;
  3528. this.switchN = true;
  3529. } else {
  3530. this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
  3531. this.switchV = false;
  3532. this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
  3533. }
  3534. };
  3535. RegExpValidationState.prototype.raise = function raise (message) {
  3536. this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
  3537. };
  3538. // If u flag is given, this returns the code point at the index (it combines a surrogate pair).
  3539. // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
  3540. RegExpValidationState.prototype.at = function at (i, forceU) {
  3541. if ( forceU === void 0 ) forceU = false;
  3542. var s = this.source;
  3543. var l = s.length;
  3544. if (i >= l) {
  3545. return -1
  3546. }
  3547. var c = s.charCodeAt(i);
  3548. if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3549. return c
  3550. }
  3551. var next = s.charCodeAt(i + 1);
  3552. return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
  3553. };
  3554. RegExpValidationState.prototype.nextIndex = function nextIndex (i, forceU) {
  3555. if ( forceU === void 0 ) forceU = false;
  3556. var s = this.source;
  3557. var l = s.length;
  3558. if (i >= l) {
  3559. return l
  3560. }
  3561. var c = s.charCodeAt(i), next;
  3562. if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
  3563. (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
  3564. return i + 1
  3565. }
  3566. return i + 2
  3567. };
  3568. RegExpValidationState.prototype.current = function current (forceU) {
  3569. if ( forceU === void 0 ) forceU = false;
  3570. return this.at(this.pos, forceU)
  3571. };
  3572. RegExpValidationState.prototype.lookahead = function lookahead (forceU) {
  3573. if ( forceU === void 0 ) forceU = false;
  3574. return this.at(this.nextIndex(this.pos, forceU), forceU)
  3575. };
  3576. RegExpValidationState.prototype.advance = function advance (forceU) {
  3577. if ( forceU === void 0 ) forceU = false;
  3578. this.pos = this.nextIndex(this.pos, forceU);
  3579. };
  3580. RegExpValidationState.prototype.eat = function eat (ch, forceU) {
  3581. if ( forceU === void 0 ) forceU = false;
  3582. if (this.current(forceU) === ch) {
  3583. this.advance(forceU);
  3584. return true
  3585. }
  3586. return false
  3587. };
  3588. RegExpValidationState.prototype.eatChars = function eatChars (chs, forceU) {
  3589. if ( forceU === void 0 ) forceU = false;
  3590. var pos = this.pos;
  3591. for (var i = 0, list = chs; i < list.length; i += 1) {
  3592. var ch = list[i];
  3593. var current = this.at(pos, forceU);
  3594. if (current === -1 || current !== ch) {
  3595. return false
  3596. }
  3597. pos = this.nextIndex(pos, forceU);
  3598. }
  3599. this.pos = pos;
  3600. return true
  3601. };
  3602. /**
  3603. * Validate the flags part of a given RegExpLiteral.
  3604. *
  3605. * @param {RegExpValidationState} state The state to validate RegExp.
  3606. * @returns {void}
  3607. */
  3608. pp$1.validateRegExpFlags = function(state) {
  3609. var validFlags = state.validFlags;
  3610. var flags = state.flags;
  3611. var u = false;
  3612. var v = false;
  3613. for (var i = 0; i < flags.length; i++) {
  3614. var flag = flags.charAt(i);
  3615. if (validFlags.indexOf(flag) === -1) {
  3616. this.raise(state.start, "Invalid regular expression flag");
  3617. }
  3618. if (flags.indexOf(flag, i + 1) > -1) {
  3619. this.raise(state.start, "Duplicate regular expression flag");
  3620. }
  3621. if (flag === "u") { u = true; }
  3622. if (flag === "v") { v = true; }
  3623. }
  3624. if (this.options.ecmaVersion >= 15 && u && v) {
  3625. this.raise(state.start, "Invalid regular expression flag");
  3626. }
  3627. };
  3628. function hasProp(obj) {
  3629. for (var _ in obj) { return true }
  3630. return false
  3631. }
  3632. /**
  3633. * Validate the pattern part of a given RegExpLiteral.
  3634. *
  3635. * @param {RegExpValidationState} state The state to validate RegExp.
  3636. * @returns {void}
  3637. */
  3638. pp$1.validateRegExpPattern = function(state) {
  3639. this.regexp_pattern(state);
  3640. // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
  3641. // parsing contains a |GroupName|, reparse with the goal symbol
  3642. // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
  3643. // exception if _P_ did not conform to the grammar, if any elements of _P_
  3644. // were not matched by the parse, or if any Early Error conditions exist.
  3645. if (!state.switchN && this.options.ecmaVersion >= 9 && hasProp(state.groupNames)) {
  3646. state.switchN = true;
  3647. this.regexp_pattern(state);
  3648. }
  3649. };
  3650. // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
  3651. pp$1.regexp_pattern = function(state) {
  3652. state.pos = 0;
  3653. state.lastIntValue = 0;
  3654. state.lastStringValue = "";
  3655. state.lastAssertionIsQuantifiable = false;
  3656. state.numCapturingParens = 0;
  3657. state.maxBackReference = 0;
  3658. state.groupNames = Object.create(null);
  3659. state.backReferenceNames.length = 0;
  3660. state.branchID = null;
  3661. this.regexp_disjunction(state);
  3662. if (state.pos !== state.source.length) {
  3663. // Make the same messages as V8.
  3664. if (state.eat(0x29 /* ) */)) {
  3665. state.raise("Unmatched ')'");
  3666. }
  3667. if (state.eat(0x5D /* ] */) || state.eat(0x7D /* } */)) {
  3668. state.raise("Lone quantifier brackets");
  3669. }
  3670. }
  3671. if (state.maxBackReference > state.numCapturingParens) {
  3672. state.raise("Invalid escape");
  3673. }
  3674. for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
  3675. var name = list[i];
  3676. if (!state.groupNames[name]) {
  3677. state.raise("Invalid named capture referenced");
  3678. }
  3679. }
  3680. };
  3681. // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
  3682. pp$1.regexp_disjunction = function(state) {
  3683. var trackDisjunction = this.options.ecmaVersion >= 16;
  3684. if (trackDisjunction) { state.branchID = new BranchID(state.branchID, null); }
  3685. this.regexp_alternative(state);
  3686. while (state.eat(0x7C /* | */)) {
  3687. if (trackDisjunction) { state.branchID = state.branchID.sibling(); }
  3688. this.regexp_alternative(state);
  3689. }
  3690. if (trackDisjunction) { state.branchID = state.branchID.parent; }
  3691. // Make the same message as V8.
  3692. if (this.regexp_eatQuantifier(state, true)) {
  3693. state.raise("Nothing to repeat");
  3694. }
  3695. if (state.eat(0x7B /* { */)) {
  3696. state.raise("Lone quantifier brackets");
  3697. }
  3698. };
  3699. // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
  3700. pp$1.regexp_alternative = function(state) {
  3701. while (state.pos < state.source.length && this.regexp_eatTerm(state)) {}
  3702. };
  3703. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
  3704. pp$1.regexp_eatTerm = function(state) {
  3705. if (this.regexp_eatAssertion(state)) {
  3706. // Handle `QuantifiableAssertion Quantifier` alternative.
  3707. // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
  3708. // is a QuantifiableAssertion.
  3709. if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
  3710. // Make the same message as V8.
  3711. if (state.switchU) {
  3712. state.raise("Invalid quantifier");
  3713. }
  3714. }
  3715. return true
  3716. }
  3717. if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
  3718. this.regexp_eatQuantifier(state);
  3719. return true
  3720. }
  3721. return false
  3722. };
  3723. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
  3724. pp$1.regexp_eatAssertion = function(state) {
  3725. var start = state.pos;
  3726. state.lastAssertionIsQuantifiable = false;
  3727. // ^, $
  3728. if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
  3729. return true
  3730. }
  3731. // \b \B
  3732. if (state.eat(0x5C /* \ */)) {
  3733. if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
  3734. return true
  3735. }
  3736. state.pos = start;
  3737. }
  3738. // Lookahead / Lookbehind
  3739. if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
  3740. var lookbehind = false;
  3741. if (this.options.ecmaVersion >= 9) {
  3742. lookbehind = state.eat(0x3C /* < */);
  3743. }
  3744. if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
  3745. this.regexp_disjunction(state);
  3746. if (!state.eat(0x29 /* ) */)) {
  3747. state.raise("Unterminated group");
  3748. }
  3749. state.lastAssertionIsQuantifiable = !lookbehind;
  3750. return true
  3751. }
  3752. }
  3753. state.pos = start;
  3754. return false
  3755. };
  3756. // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
  3757. pp$1.regexp_eatQuantifier = function(state, noError) {
  3758. if ( noError === void 0 ) noError = false;
  3759. if (this.regexp_eatQuantifierPrefix(state, noError)) {
  3760. state.eat(0x3F /* ? */);
  3761. return true
  3762. }
  3763. return false
  3764. };
  3765. // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
  3766. pp$1.regexp_eatQuantifierPrefix = function(state, noError) {
  3767. return (
  3768. state.eat(0x2A /* * */) ||
  3769. state.eat(0x2B /* + */) ||
  3770. state.eat(0x3F /* ? */) ||
  3771. this.regexp_eatBracedQuantifier(state, noError)
  3772. )
  3773. };
  3774. pp$1.regexp_eatBracedQuantifier = function(state, noError) {
  3775. var start = state.pos;
  3776. if (state.eat(0x7B /* { */)) {
  3777. var min = 0, max = -1;
  3778. if (this.regexp_eatDecimalDigits(state)) {
  3779. min = state.lastIntValue;
  3780. if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
  3781. max = state.lastIntValue;
  3782. }
  3783. if (state.eat(0x7D /* } */)) {
  3784. // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
  3785. if (max !== -1 && max < min && !noError) {
  3786. state.raise("numbers out of order in {} quantifier");
  3787. }
  3788. return true
  3789. }
  3790. }
  3791. if (state.switchU && !noError) {
  3792. state.raise("Incomplete quantifier");
  3793. }
  3794. state.pos = start;
  3795. }
  3796. return false
  3797. };
  3798. // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
  3799. pp$1.regexp_eatAtom = function(state) {
  3800. return (
  3801. this.regexp_eatPatternCharacters(state) ||
  3802. state.eat(0x2E /* . */) ||
  3803. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3804. this.regexp_eatCharacterClass(state) ||
  3805. this.regexp_eatUncapturingGroup(state) ||
  3806. this.regexp_eatCapturingGroup(state)
  3807. )
  3808. };
  3809. pp$1.regexp_eatReverseSolidusAtomEscape = function(state) {
  3810. var start = state.pos;
  3811. if (state.eat(0x5C /* \ */)) {
  3812. if (this.regexp_eatAtomEscape(state)) {
  3813. return true
  3814. }
  3815. state.pos = start;
  3816. }
  3817. return false
  3818. };
  3819. pp$1.regexp_eatUncapturingGroup = function(state) {
  3820. var start = state.pos;
  3821. if (state.eat(0x28 /* ( */)) {
  3822. if (state.eat(0x3F /* ? */)) {
  3823. if (this.options.ecmaVersion >= 16) {
  3824. var addModifiers = this.regexp_eatModifiers(state);
  3825. var hasHyphen = state.eat(0x2D /* - */);
  3826. if (addModifiers || hasHyphen) {
  3827. for (var i = 0; i < addModifiers.length; i++) {
  3828. var modifier = addModifiers.charAt(i);
  3829. if (addModifiers.indexOf(modifier, i + 1) > -1) {
  3830. state.raise("Duplicate regular expression modifiers");
  3831. }
  3832. }
  3833. if (hasHyphen) {
  3834. var removeModifiers = this.regexp_eatModifiers(state);
  3835. if (!addModifiers && !removeModifiers && state.current() === 0x3A /* : */) {
  3836. state.raise("Invalid regular expression modifiers");
  3837. }
  3838. for (var i$1 = 0; i$1 < removeModifiers.length; i$1++) {
  3839. var modifier$1 = removeModifiers.charAt(i$1);
  3840. if (
  3841. removeModifiers.indexOf(modifier$1, i$1 + 1) > -1 ||
  3842. addModifiers.indexOf(modifier$1) > -1
  3843. ) {
  3844. state.raise("Duplicate regular expression modifiers");
  3845. }
  3846. }
  3847. }
  3848. }
  3849. }
  3850. if (state.eat(0x3A /* : */)) {
  3851. this.regexp_disjunction(state);
  3852. if (state.eat(0x29 /* ) */)) {
  3853. return true
  3854. }
  3855. state.raise("Unterminated group");
  3856. }
  3857. }
  3858. state.pos = start;
  3859. }
  3860. return false
  3861. };
  3862. pp$1.regexp_eatCapturingGroup = function(state) {
  3863. if (state.eat(0x28 /* ( */)) {
  3864. if (this.options.ecmaVersion >= 9) {
  3865. this.regexp_groupSpecifier(state);
  3866. } else if (state.current() === 0x3F /* ? */) {
  3867. state.raise("Invalid group");
  3868. }
  3869. this.regexp_disjunction(state);
  3870. if (state.eat(0x29 /* ) */)) {
  3871. state.numCapturingParens += 1;
  3872. return true
  3873. }
  3874. state.raise("Unterminated group");
  3875. }
  3876. return false
  3877. };
  3878. // RegularExpressionModifiers ::
  3879. // [empty]
  3880. // RegularExpressionModifiers RegularExpressionModifier
  3881. pp$1.regexp_eatModifiers = function(state) {
  3882. var modifiers = "";
  3883. var ch = 0;
  3884. while ((ch = state.current()) !== -1 && isRegularExpressionModifier(ch)) {
  3885. modifiers += codePointToString(ch);
  3886. state.advance();
  3887. }
  3888. return modifiers
  3889. };
  3890. // RegularExpressionModifier :: one of
  3891. // `i` `m` `s`
  3892. function isRegularExpressionModifier(ch) {
  3893. return ch === 0x69 /* i */ || ch === 0x6d /* m */ || ch === 0x73 /* s */
  3894. }
  3895. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
  3896. pp$1.regexp_eatExtendedAtom = function(state) {
  3897. return (
  3898. state.eat(0x2E /* . */) ||
  3899. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3900. this.regexp_eatCharacterClass(state) ||
  3901. this.regexp_eatUncapturingGroup(state) ||
  3902. this.regexp_eatCapturingGroup(state) ||
  3903. this.regexp_eatInvalidBracedQuantifier(state) ||
  3904. this.regexp_eatExtendedPatternCharacter(state)
  3905. )
  3906. };
  3907. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
  3908. pp$1.regexp_eatInvalidBracedQuantifier = function(state) {
  3909. if (this.regexp_eatBracedQuantifier(state, true)) {
  3910. state.raise("Nothing to repeat");
  3911. }
  3912. return false
  3913. };
  3914. // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
  3915. pp$1.regexp_eatSyntaxCharacter = function(state) {
  3916. var ch = state.current();
  3917. if (isSyntaxCharacter(ch)) {
  3918. state.lastIntValue = ch;
  3919. state.advance();
  3920. return true
  3921. }
  3922. return false
  3923. };
  3924. function isSyntaxCharacter(ch) {
  3925. return (
  3926. ch === 0x24 /* $ */ ||
  3927. ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
  3928. ch === 0x2E /* . */ ||
  3929. ch === 0x3F /* ? */ ||
  3930. ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
  3931. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  3932. )
  3933. }
  3934. // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
  3935. // But eat eager.
  3936. pp$1.regexp_eatPatternCharacters = function(state) {
  3937. var start = state.pos;
  3938. var ch = 0;
  3939. while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
  3940. state.advance();
  3941. }
  3942. return state.pos !== start
  3943. };
  3944. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
  3945. pp$1.regexp_eatExtendedPatternCharacter = function(state) {
  3946. var ch = state.current();
  3947. if (
  3948. ch !== -1 &&
  3949. ch !== 0x24 /* $ */ &&
  3950. !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
  3951. ch !== 0x2E /* . */ &&
  3952. ch !== 0x3F /* ? */ &&
  3953. ch !== 0x5B /* [ */ &&
  3954. ch !== 0x5E /* ^ */ &&
  3955. ch !== 0x7C /* | */
  3956. ) {
  3957. state.advance();
  3958. return true
  3959. }
  3960. return false
  3961. };
  3962. // GroupSpecifier ::
  3963. // [empty]
  3964. // `?` GroupName
  3965. pp$1.regexp_groupSpecifier = function(state) {
  3966. if (state.eat(0x3F /* ? */)) {
  3967. if (!this.regexp_eatGroupName(state)) { state.raise("Invalid group"); }
  3968. var trackDisjunction = this.options.ecmaVersion >= 16;
  3969. var known = state.groupNames[state.lastStringValue];
  3970. if (known) {
  3971. if (trackDisjunction) {
  3972. for (var i = 0, list = known; i < list.length; i += 1) {
  3973. var altID = list[i];
  3974. if (!altID.separatedFrom(state.branchID))
  3975. { state.raise("Duplicate capture group name"); }
  3976. }
  3977. } else {
  3978. state.raise("Duplicate capture group name");
  3979. }
  3980. }
  3981. if (trackDisjunction) {
  3982. (known || (state.groupNames[state.lastStringValue] = [])).push(state.branchID);
  3983. } else {
  3984. state.groupNames[state.lastStringValue] = true;
  3985. }
  3986. }
  3987. };
  3988. // GroupName ::
  3989. // `<` RegExpIdentifierName `>`
  3990. // Note: this updates `state.lastStringValue` property with the eaten name.
  3991. pp$1.regexp_eatGroupName = function(state) {
  3992. state.lastStringValue = "";
  3993. if (state.eat(0x3C /* < */)) {
  3994. if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
  3995. return true
  3996. }
  3997. state.raise("Invalid capture group name");
  3998. }
  3999. return false
  4000. };
  4001. // RegExpIdentifierName ::
  4002. // RegExpIdentifierStart
  4003. // RegExpIdentifierName RegExpIdentifierPart
  4004. // Note: this updates `state.lastStringValue` property with the eaten name.
  4005. pp$1.regexp_eatRegExpIdentifierName = function(state) {
  4006. state.lastStringValue = "";
  4007. if (this.regexp_eatRegExpIdentifierStart(state)) {
  4008. state.lastStringValue += codePointToString(state.lastIntValue);
  4009. while (this.regexp_eatRegExpIdentifierPart(state)) {
  4010. state.lastStringValue += codePointToString(state.lastIntValue);
  4011. }
  4012. return true
  4013. }
  4014. return false
  4015. };
  4016. // RegExpIdentifierStart ::
  4017. // UnicodeIDStart
  4018. // `$`
  4019. // `_`
  4020. // `\` RegExpUnicodeEscapeSequence[+U]
  4021. pp$1.regexp_eatRegExpIdentifierStart = function(state) {
  4022. var start = state.pos;
  4023. var forceU = this.options.ecmaVersion >= 11;
  4024. var ch = state.current(forceU);
  4025. state.advance(forceU);
  4026. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
  4027. ch = state.lastIntValue;
  4028. }
  4029. if (isRegExpIdentifierStart(ch)) {
  4030. state.lastIntValue = ch;
  4031. return true
  4032. }
  4033. state.pos = start;
  4034. return false
  4035. };
  4036. function isRegExpIdentifierStart(ch) {
  4037. return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
  4038. }
  4039. // RegExpIdentifierPart ::
  4040. // UnicodeIDContinue
  4041. // `$`
  4042. // `_`
  4043. // `\` RegExpUnicodeEscapeSequence[+U]
  4044. // <ZWNJ>
  4045. // <ZWJ>
  4046. pp$1.regexp_eatRegExpIdentifierPart = function(state) {
  4047. var start = state.pos;
  4048. var forceU = this.options.ecmaVersion >= 11;
  4049. var ch = state.current(forceU);
  4050. state.advance(forceU);
  4051. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
  4052. ch = state.lastIntValue;
  4053. }
  4054. if (isRegExpIdentifierPart(ch)) {
  4055. state.lastIntValue = ch;
  4056. return true
  4057. }
  4058. state.pos = start;
  4059. return false
  4060. };
  4061. function isRegExpIdentifierPart(ch) {
  4062. return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
  4063. }
  4064. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
  4065. pp$1.regexp_eatAtomEscape = function(state) {
  4066. if (
  4067. this.regexp_eatBackReference(state) ||
  4068. this.regexp_eatCharacterClassEscape(state) ||
  4069. this.regexp_eatCharacterEscape(state) ||
  4070. (state.switchN && this.regexp_eatKGroupName(state))
  4071. ) {
  4072. return true
  4073. }
  4074. if (state.switchU) {
  4075. // Make the same message as V8.
  4076. if (state.current() === 0x63 /* c */) {
  4077. state.raise("Invalid unicode escape");
  4078. }
  4079. state.raise("Invalid escape");
  4080. }
  4081. return false
  4082. };
  4083. pp$1.regexp_eatBackReference = function(state) {
  4084. var start = state.pos;
  4085. if (this.regexp_eatDecimalEscape(state)) {
  4086. var n = state.lastIntValue;
  4087. if (state.switchU) {
  4088. // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
  4089. if (n > state.maxBackReference) {
  4090. state.maxBackReference = n;
  4091. }
  4092. return true
  4093. }
  4094. if (n <= state.numCapturingParens) {
  4095. return true
  4096. }
  4097. state.pos = start;
  4098. }
  4099. return false
  4100. };
  4101. pp$1.regexp_eatKGroupName = function(state) {
  4102. if (state.eat(0x6B /* k */)) {
  4103. if (this.regexp_eatGroupName(state)) {
  4104. state.backReferenceNames.push(state.lastStringValue);
  4105. return true
  4106. }
  4107. state.raise("Invalid named reference");
  4108. }
  4109. return false
  4110. };
  4111. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
  4112. pp$1.regexp_eatCharacterEscape = function(state) {
  4113. return (
  4114. this.regexp_eatControlEscape(state) ||
  4115. this.regexp_eatCControlLetter(state) ||
  4116. this.regexp_eatZero(state) ||
  4117. this.regexp_eatHexEscapeSequence(state) ||
  4118. this.regexp_eatRegExpUnicodeEscapeSequence(state, false) ||
  4119. (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
  4120. this.regexp_eatIdentityEscape(state)
  4121. )
  4122. };
  4123. pp$1.regexp_eatCControlLetter = function(state) {
  4124. var start = state.pos;
  4125. if (state.eat(0x63 /* c */)) {
  4126. if (this.regexp_eatControlLetter(state)) {
  4127. return true
  4128. }
  4129. state.pos = start;
  4130. }
  4131. return false
  4132. };
  4133. pp$1.regexp_eatZero = function(state) {
  4134. if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
  4135. state.lastIntValue = 0;
  4136. state.advance();
  4137. return true
  4138. }
  4139. return false
  4140. };
  4141. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
  4142. pp$1.regexp_eatControlEscape = function(state) {
  4143. var ch = state.current();
  4144. if (ch === 0x74 /* t */) {
  4145. state.lastIntValue = 0x09; /* \t */
  4146. state.advance();
  4147. return true
  4148. }
  4149. if (ch === 0x6E /* n */) {
  4150. state.lastIntValue = 0x0A; /* \n */
  4151. state.advance();
  4152. return true
  4153. }
  4154. if (ch === 0x76 /* v */) {
  4155. state.lastIntValue = 0x0B; /* \v */
  4156. state.advance();
  4157. return true
  4158. }
  4159. if (ch === 0x66 /* f */) {
  4160. state.lastIntValue = 0x0C; /* \f */
  4161. state.advance();
  4162. return true
  4163. }
  4164. if (ch === 0x72 /* r */) {
  4165. state.lastIntValue = 0x0D; /* \r */
  4166. state.advance();
  4167. return true
  4168. }
  4169. return false
  4170. };
  4171. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
  4172. pp$1.regexp_eatControlLetter = function(state) {
  4173. var ch = state.current();
  4174. if (isControlLetter(ch)) {
  4175. state.lastIntValue = ch % 0x20;
  4176. state.advance();
  4177. return true
  4178. }
  4179. return false
  4180. };
  4181. function isControlLetter(ch) {
  4182. return (
  4183. (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
  4184. (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
  4185. )
  4186. }
  4187. // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
  4188. pp$1.regexp_eatRegExpUnicodeEscapeSequence = function(state, forceU) {
  4189. if ( forceU === void 0 ) forceU = false;
  4190. var start = state.pos;
  4191. var switchU = forceU || state.switchU;
  4192. if (state.eat(0x75 /* u */)) {
  4193. if (this.regexp_eatFixedHexDigits(state, 4)) {
  4194. var lead = state.lastIntValue;
  4195. if (switchU && lead >= 0xD800 && lead <= 0xDBFF) {
  4196. var leadSurrogateEnd = state.pos;
  4197. if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
  4198. var trail = state.lastIntValue;
  4199. if (trail >= 0xDC00 && trail <= 0xDFFF) {
  4200. state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  4201. return true
  4202. }
  4203. }
  4204. state.pos = leadSurrogateEnd;
  4205. state.lastIntValue = lead;
  4206. }
  4207. return true
  4208. }
  4209. if (
  4210. switchU &&
  4211. state.eat(0x7B /* { */) &&
  4212. this.regexp_eatHexDigits(state) &&
  4213. state.eat(0x7D /* } */) &&
  4214. isValidUnicode(state.lastIntValue)
  4215. ) {
  4216. return true
  4217. }
  4218. if (switchU) {
  4219. state.raise("Invalid unicode escape");
  4220. }
  4221. state.pos = start;
  4222. }
  4223. return false
  4224. };
  4225. function isValidUnicode(ch) {
  4226. return ch >= 0 && ch <= 0x10FFFF
  4227. }
  4228. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
  4229. pp$1.regexp_eatIdentityEscape = function(state) {
  4230. if (state.switchU) {
  4231. if (this.regexp_eatSyntaxCharacter(state)) {
  4232. return true
  4233. }
  4234. if (state.eat(0x2F /* / */)) {
  4235. state.lastIntValue = 0x2F; /* / */
  4236. return true
  4237. }
  4238. return false
  4239. }
  4240. var ch = state.current();
  4241. if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
  4242. state.lastIntValue = ch;
  4243. state.advance();
  4244. return true
  4245. }
  4246. return false
  4247. };
  4248. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
  4249. pp$1.regexp_eatDecimalEscape = function(state) {
  4250. state.lastIntValue = 0;
  4251. var ch = state.current();
  4252. if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
  4253. do {
  4254. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  4255. state.advance();
  4256. } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
  4257. return true
  4258. }
  4259. return false
  4260. };
  4261. // Return values used by character set parsing methods, needed to
  4262. // forbid negation of sets that can match strings.
  4263. var CharSetNone = 0; // Nothing parsed
  4264. var CharSetOk = 1; // Construct parsed, cannot contain strings
  4265. var CharSetString = 2; // Construct parsed, can contain strings
  4266. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
  4267. pp$1.regexp_eatCharacterClassEscape = function(state) {
  4268. var ch = state.current();
  4269. if (isCharacterClassEscape(ch)) {
  4270. state.lastIntValue = -1;
  4271. state.advance();
  4272. return CharSetOk
  4273. }
  4274. var negate = false;
  4275. if (
  4276. state.switchU &&
  4277. this.options.ecmaVersion >= 9 &&
  4278. ((negate = ch === 0x50 /* P */) || ch === 0x70 /* p */)
  4279. ) {
  4280. state.lastIntValue = -1;
  4281. state.advance();
  4282. var result;
  4283. if (
  4284. state.eat(0x7B /* { */) &&
  4285. (result = this.regexp_eatUnicodePropertyValueExpression(state)) &&
  4286. state.eat(0x7D /* } */)
  4287. ) {
  4288. if (negate && result === CharSetString) { state.raise("Invalid property name"); }
  4289. return result
  4290. }
  4291. state.raise("Invalid property name");
  4292. }
  4293. return CharSetNone
  4294. };
  4295. function isCharacterClassEscape(ch) {
  4296. return (
  4297. ch === 0x64 /* d */ ||
  4298. ch === 0x44 /* D */ ||
  4299. ch === 0x73 /* s */ ||
  4300. ch === 0x53 /* S */ ||
  4301. ch === 0x77 /* w */ ||
  4302. ch === 0x57 /* W */
  4303. )
  4304. }
  4305. // UnicodePropertyValueExpression ::
  4306. // UnicodePropertyName `=` UnicodePropertyValue
  4307. // LoneUnicodePropertyNameOrValue
  4308. pp$1.regexp_eatUnicodePropertyValueExpression = function(state) {
  4309. var start = state.pos;
  4310. // UnicodePropertyName `=` UnicodePropertyValue
  4311. if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
  4312. var name = state.lastStringValue;
  4313. if (this.regexp_eatUnicodePropertyValue(state)) {
  4314. var value = state.lastStringValue;
  4315. this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
  4316. return CharSetOk
  4317. }
  4318. }
  4319. state.pos = start;
  4320. // LoneUnicodePropertyNameOrValue
  4321. if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
  4322. var nameOrValue = state.lastStringValue;
  4323. return this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue)
  4324. }
  4325. return CharSetNone
  4326. };
  4327. pp$1.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
  4328. if (!hasOwn(state.unicodeProperties.nonBinary, name))
  4329. { state.raise("Invalid property name"); }
  4330. if (!state.unicodeProperties.nonBinary[name].test(value))
  4331. { state.raise("Invalid property value"); }
  4332. };
  4333. pp$1.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
  4334. if (state.unicodeProperties.binary.test(nameOrValue)) { return CharSetOk }
  4335. if (state.switchV && state.unicodeProperties.binaryOfStrings.test(nameOrValue)) { return CharSetString }
  4336. state.raise("Invalid property name");
  4337. };
  4338. // UnicodePropertyName ::
  4339. // UnicodePropertyNameCharacters
  4340. pp$1.regexp_eatUnicodePropertyName = function(state) {
  4341. var ch = 0;
  4342. state.lastStringValue = "";
  4343. while (isUnicodePropertyNameCharacter(ch = state.current())) {
  4344. state.lastStringValue += codePointToString(ch);
  4345. state.advance();
  4346. }
  4347. return state.lastStringValue !== ""
  4348. };
  4349. function isUnicodePropertyNameCharacter(ch) {
  4350. return isControlLetter(ch) || ch === 0x5F /* _ */
  4351. }
  4352. // UnicodePropertyValue ::
  4353. // UnicodePropertyValueCharacters
  4354. pp$1.regexp_eatUnicodePropertyValue = function(state) {
  4355. var ch = 0;
  4356. state.lastStringValue = "";
  4357. while (isUnicodePropertyValueCharacter(ch = state.current())) {
  4358. state.lastStringValue += codePointToString(ch);
  4359. state.advance();
  4360. }
  4361. return state.lastStringValue !== ""
  4362. };
  4363. function isUnicodePropertyValueCharacter(ch) {
  4364. return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
  4365. }
  4366. // LoneUnicodePropertyNameOrValue ::
  4367. // UnicodePropertyValueCharacters
  4368. pp$1.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
  4369. return this.regexp_eatUnicodePropertyValue(state)
  4370. };
  4371. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
  4372. pp$1.regexp_eatCharacterClass = function(state) {
  4373. if (state.eat(0x5B /* [ */)) {
  4374. var negate = state.eat(0x5E /* ^ */);
  4375. var result = this.regexp_classContents(state);
  4376. if (!state.eat(0x5D /* ] */))
  4377. { state.raise("Unterminated character class"); }
  4378. if (negate && result === CharSetString)
  4379. { state.raise("Negated character class may contain strings"); }
  4380. return true
  4381. }
  4382. return false
  4383. };
  4384. // https://tc39.es/ecma262/#prod-ClassContents
  4385. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
  4386. pp$1.regexp_classContents = function(state) {
  4387. if (state.current() === 0x5D /* ] */) { return CharSetOk }
  4388. if (state.switchV) { return this.regexp_classSetExpression(state) }
  4389. this.regexp_nonEmptyClassRanges(state);
  4390. return CharSetOk
  4391. };
  4392. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
  4393. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
  4394. pp$1.regexp_nonEmptyClassRanges = function(state) {
  4395. while (this.regexp_eatClassAtom(state)) {
  4396. var left = state.lastIntValue;
  4397. if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) {
  4398. var right = state.lastIntValue;
  4399. if (state.switchU && (left === -1 || right === -1)) {
  4400. state.raise("Invalid character class");
  4401. }
  4402. if (left !== -1 && right !== -1 && left > right) {
  4403. state.raise("Range out of order in character class");
  4404. }
  4405. }
  4406. }
  4407. };
  4408. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
  4409. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
  4410. pp$1.regexp_eatClassAtom = function(state) {
  4411. var start = state.pos;
  4412. if (state.eat(0x5C /* \ */)) {
  4413. if (this.regexp_eatClassEscape(state)) {
  4414. return true
  4415. }
  4416. if (state.switchU) {
  4417. // Make the same message as V8.
  4418. var ch$1 = state.current();
  4419. if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
  4420. state.raise("Invalid class escape");
  4421. }
  4422. state.raise("Invalid escape");
  4423. }
  4424. state.pos = start;
  4425. }
  4426. var ch = state.current();
  4427. if (ch !== 0x5D /* ] */) {
  4428. state.lastIntValue = ch;
  4429. state.advance();
  4430. return true
  4431. }
  4432. return false
  4433. };
  4434. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
  4435. pp$1.regexp_eatClassEscape = function(state) {
  4436. var start = state.pos;
  4437. if (state.eat(0x62 /* b */)) {
  4438. state.lastIntValue = 0x08; /* <BS> */
  4439. return true
  4440. }
  4441. if (state.switchU && state.eat(0x2D /* - */)) {
  4442. state.lastIntValue = 0x2D; /* - */
  4443. return true
  4444. }
  4445. if (!state.switchU && state.eat(0x63 /* c */)) {
  4446. if (this.regexp_eatClassControlLetter(state)) {
  4447. return true
  4448. }
  4449. state.pos = start;
  4450. }
  4451. return (
  4452. this.regexp_eatCharacterClassEscape(state) ||
  4453. this.regexp_eatCharacterEscape(state)
  4454. )
  4455. };
  4456. // https://tc39.es/ecma262/#prod-ClassSetExpression
  4457. // https://tc39.es/ecma262/#prod-ClassUnion
  4458. // https://tc39.es/ecma262/#prod-ClassIntersection
  4459. // https://tc39.es/ecma262/#prod-ClassSubtraction
  4460. pp$1.regexp_classSetExpression = function(state) {
  4461. var result = CharSetOk, subResult;
  4462. if (this.regexp_eatClassSetRange(state)) ; else if (subResult = this.regexp_eatClassSetOperand(state)) {
  4463. if (subResult === CharSetString) { result = CharSetString; }
  4464. // https://tc39.es/ecma262/#prod-ClassIntersection
  4465. var start = state.pos;
  4466. while (state.eatChars([0x26, 0x26] /* && */)) {
  4467. if (
  4468. state.current() !== 0x26 /* & */ &&
  4469. (subResult = this.regexp_eatClassSetOperand(state))
  4470. ) {
  4471. if (subResult !== CharSetString) { result = CharSetOk; }
  4472. continue
  4473. }
  4474. state.raise("Invalid character in character class");
  4475. }
  4476. if (start !== state.pos) { return result }
  4477. // https://tc39.es/ecma262/#prod-ClassSubtraction
  4478. while (state.eatChars([0x2D, 0x2D] /* -- */)) {
  4479. if (this.regexp_eatClassSetOperand(state)) { continue }
  4480. state.raise("Invalid character in character class");
  4481. }
  4482. if (start !== state.pos) { return result }
  4483. } else {
  4484. state.raise("Invalid character in character class");
  4485. }
  4486. // https://tc39.es/ecma262/#prod-ClassUnion
  4487. for (;;) {
  4488. if (this.regexp_eatClassSetRange(state)) { continue }
  4489. subResult = this.regexp_eatClassSetOperand(state);
  4490. if (!subResult) { return result }
  4491. if (subResult === CharSetString) { result = CharSetString; }
  4492. }
  4493. };
  4494. // https://tc39.es/ecma262/#prod-ClassSetRange
  4495. pp$1.regexp_eatClassSetRange = function(state) {
  4496. var start = state.pos;
  4497. if (this.regexp_eatClassSetCharacter(state)) {
  4498. var left = state.lastIntValue;
  4499. if (state.eat(0x2D /* - */) && this.regexp_eatClassSetCharacter(state)) {
  4500. var right = state.lastIntValue;
  4501. if (left !== -1 && right !== -1 && left > right) {
  4502. state.raise("Range out of order in character class");
  4503. }
  4504. return true
  4505. }
  4506. state.pos = start;
  4507. }
  4508. return false
  4509. };
  4510. // https://tc39.es/ecma262/#prod-ClassSetOperand
  4511. pp$1.regexp_eatClassSetOperand = function(state) {
  4512. if (this.regexp_eatClassSetCharacter(state)) { return CharSetOk }
  4513. return this.regexp_eatClassStringDisjunction(state) || this.regexp_eatNestedClass(state)
  4514. };
  4515. // https://tc39.es/ecma262/#prod-NestedClass
  4516. pp$1.regexp_eatNestedClass = function(state) {
  4517. var start = state.pos;
  4518. if (state.eat(0x5B /* [ */)) {
  4519. var negate = state.eat(0x5E /* ^ */);
  4520. var result = this.regexp_classContents(state);
  4521. if (state.eat(0x5D /* ] */)) {
  4522. if (negate && result === CharSetString) {
  4523. state.raise("Negated character class may contain strings");
  4524. }
  4525. return result
  4526. }
  4527. state.pos = start;
  4528. }
  4529. if (state.eat(0x5C /* \ */)) {
  4530. var result$1 = this.regexp_eatCharacterClassEscape(state);
  4531. if (result$1) {
  4532. return result$1
  4533. }
  4534. state.pos = start;
  4535. }
  4536. return null
  4537. };
  4538. // https://tc39.es/ecma262/#prod-ClassStringDisjunction
  4539. pp$1.regexp_eatClassStringDisjunction = function(state) {
  4540. var start = state.pos;
  4541. if (state.eatChars([0x5C, 0x71] /* \q */)) {
  4542. if (state.eat(0x7B /* { */)) {
  4543. var result = this.regexp_classStringDisjunctionContents(state);
  4544. if (state.eat(0x7D /* } */)) {
  4545. return result
  4546. }
  4547. } else {
  4548. // Make the same message as V8.
  4549. state.raise("Invalid escape");
  4550. }
  4551. state.pos = start;
  4552. }
  4553. return null
  4554. };
  4555. // https://tc39.es/ecma262/#prod-ClassStringDisjunctionContents
  4556. pp$1.regexp_classStringDisjunctionContents = function(state) {
  4557. var result = this.regexp_classString(state);
  4558. while (state.eat(0x7C /* | */)) {
  4559. if (this.regexp_classString(state) === CharSetString) { result = CharSetString; }
  4560. }
  4561. return result
  4562. };
  4563. // https://tc39.es/ecma262/#prod-ClassString
  4564. // https://tc39.es/ecma262/#prod-NonEmptyClassString
  4565. pp$1.regexp_classString = function(state) {
  4566. var count = 0;
  4567. while (this.regexp_eatClassSetCharacter(state)) { count++; }
  4568. return count === 1 ? CharSetOk : CharSetString
  4569. };
  4570. // https://tc39.es/ecma262/#prod-ClassSetCharacter
  4571. pp$1.regexp_eatClassSetCharacter = function(state) {
  4572. var start = state.pos;
  4573. if (state.eat(0x5C /* \ */)) {
  4574. if (
  4575. this.regexp_eatCharacterEscape(state) ||
  4576. this.regexp_eatClassSetReservedPunctuator(state)
  4577. ) {
  4578. return true
  4579. }
  4580. if (state.eat(0x62 /* b */)) {
  4581. state.lastIntValue = 0x08; /* <BS> */
  4582. return true
  4583. }
  4584. state.pos = start;
  4585. return false
  4586. }
  4587. var ch = state.current();
  4588. if (ch < 0 || ch === state.lookahead() && isClassSetReservedDoublePunctuatorCharacter(ch)) { return false }
  4589. if (isClassSetSyntaxCharacter(ch)) { return false }
  4590. state.advance();
  4591. state.lastIntValue = ch;
  4592. return true
  4593. };
  4594. // https://tc39.es/ecma262/#prod-ClassSetReservedDoublePunctuator
  4595. function isClassSetReservedDoublePunctuatorCharacter(ch) {
  4596. return (
  4597. ch === 0x21 /* ! */ ||
  4598. ch >= 0x23 /* # */ && ch <= 0x26 /* & */ ||
  4599. ch >= 0x2A /* * */ && ch <= 0x2C /* , */ ||
  4600. ch === 0x2E /* . */ ||
  4601. ch >= 0x3A /* : */ && ch <= 0x40 /* @ */ ||
  4602. ch === 0x5E /* ^ */ ||
  4603. ch === 0x60 /* ` */ ||
  4604. ch === 0x7E /* ~ */
  4605. )
  4606. }
  4607. // https://tc39.es/ecma262/#prod-ClassSetSyntaxCharacter
  4608. function isClassSetSyntaxCharacter(ch) {
  4609. return (
  4610. ch === 0x28 /* ( */ ||
  4611. ch === 0x29 /* ) */ ||
  4612. ch === 0x2D /* - */ ||
  4613. ch === 0x2F /* / */ ||
  4614. ch >= 0x5B /* [ */ && ch <= 0x5D /* ] */ ||
  4615. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  4616. )
  4617. }
  4618. // https://tc39.es/ecma262/#prod-ClassSetReservedPunctuator
  4619. pp$1.regexp_eatClassSetReservedPunctuator = function(state) {
  4620. var ch = state.current();
  4621. if (isClassSetReservedPunctuator(ch)) {
  4622. state.lastIntValue = ch;
  4623. state.advance();
  4624. return true
  4625. }
  4626. return false
  4627. };
  4628. // https://tc39.es/ecma262/#prod-ClassSetReservedPunctuator
  4629. function isClassSetReservedPunctuator(ch) {
  4630. return (
  4631. ch === 0x21 /* ! */ ||
  4632. ch === 0x23 /* # */ ||
  4633. ch === 0x25 /* % */ ||
  4634. ch === 0x26 /* & */ ||
  4635. ch === 0x2C /* , */ ||
  4636. ch === 0x2D /* - */ ||
  4637. ch >= 0x3A /* : */ && ch <= 0x3E /* > */ ||
  4638. ch === 0x40 /* @ */ ||
  4639. ch === 0x60 /* ` */ ||
  4640. ch === 0x7E /* ~ */
  4641. )
  4642. }
  4643. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
  4644. pp$1.regexp_eatClassControlLetter = function(state) {
  4645. var ch = state.current();
  4646. if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
  4647. state.lastIntValue = ch % 0x20;
  4648. state.advance();
  4649. return true
  4650. }
  4651. return false
  4652. };
  4653. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4654. pp$1.regexp_eatHexEscapeSequence = function(state) {
  4655. var start = state.pos;
  4656. if (state.eat(0x78 /* x */)) {
  4657. if (this.regexp_eatFixedHexDigits(state, 2)) {
  4658. return true
  4659. }
  4660. if (state.switchU) {
  4661. state.raise("Invalid escape");
  4662. }
  4663. state.pos = start;
  4664. }
  4665. return false
  4666. };
  4667. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
  4668. pp$1.regexp_eatDecimalDigits = function(state) {
  4669. var start = state.pos;
  4670. var ch = 0;
  4671. state.lastIntValue = 0;
  4672. while (isDecimalDigit(ch = state.current())) {
  4673. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  4674. state.advance();
  4675. }
  4676. return state.pos !== start
  4677. };
  4678. function isDecimalDigit(ch) {
  4679. return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
  4680. }
  4681. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
  4682. pp$1.regexp_eatHexDigits = function(state) {
  4683. var start = state.pos;
  4684. var ch = 0;
  4685. state.lastIntValue = 0;
  4686. while (isHexDigit(ch = state.current())) {
  4687. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4688. state.advance();
  4689. }
  4690. return state.pos !== start
  4691. };
  4692. function isHexDigit(ch) {
  4693. return (
  4694. (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
  4695. (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
  4696. (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
  4697. )
  4698. }
  4699. function hexToInt(ch) {
  4700. if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
  4701. return 10 + (ch - 0x41 /* A */)
  4702. }
  4703. if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
  4704. return 10 + (ch - 0x61 /* a */)
  4705. }
  4706. return ch - 0x30 /* 0 */
  4707. }
  4708. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
  4709. // Allows only 0-377(octal) i.e. 0-255(decimal).
  4710. pp$1.regexp_eatLegacyOctalEscapeSequence = function(state) {
  4711. if (this.regexp_eatOctalDigit(state)) {
  4712. var n1 = state.lastIntValue;
  4713. if (this.regexp_eatOctalDigit(state)) {
  4714. var n2 = state.lastIntValue;
  4715. if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
  4716. state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
  4717. } else {
  4718. state.lastIntValue = n1 * 8 + n2;
  4719. }
  4720. } else {
  4721. state.lastIntValue = n1;
  4722. }
  4723. return true
  4724. }
  4725. return false
  4726. };
  4727. // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
  4728. pp$1.regexp_eatOctalDigit = function(state) {
  4729. var ch = state.current();
  4730. if (isOctalDigit(ch)) {
  4731. state.lastIntValue = ch - 0x30; /* 0 */
  4732. state.advance();
  4733. return true
  4734. }
  4735. state.lastIntValue = 0;
  4736. return false
  4737. };
  4738. function isOctalDigit(ch) {
  4739. return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
  4740. }
  4741. // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
  4742. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
  4743. // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4744. pp$1.regexp_eatFixedHexDigits = function(state, length) {
  4745. var start = state.pos;
  4746. state.lastIntValue = 0;
  4747. for (var i = 0; i < length; ++i) {
  4748. var ch = state.current();
  4749. if (!isHexDigit(ch)) {
  4750. state.pos = start;
  4751. return false
  4752. }
  4753. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4754. state.advance();
  4755. }
  4756. return true
  4757. };
  4758. // Object type used to represent tokens. Note that normally, tokens
  4759. // simply exist as properties on the parser object. This is only
  4760. // used for the onToken callback and the external tokenizer.
  4761. var Token = function Token(p) {
  4762. this.type = p.type;
  4763. this.value = p.value;
  4764. this.start = p.start;
  4765. this.end = p.end;
  4766. if (p.options.locations)
  4767. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  4768. if (p.options.ranges)
  4769. { this.range = [p.start, p.end]; }
  4770. };
  4771. // ## Tokenizer
  4772. var pp = Parser.prototype;
  4773. // Move to the next token
  4774. pp.next = function(ignoreEscapeSequenceInKeyword) {
  4775. if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc)
  4776. { this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword); }
  4777. if (this.options.onToken)
  4778. { this.options.onToken(new Token(this)); }
  4779. this.lastTokEnd = this.end;
  4780. this.lastTokStart = this.start;
  4781. this.lastTokEndLoc = this.endLoc;
  4782. this.lastTokStartLoc = this.startLoc;
  4783. this.nextToken();
  4784. };
  4785. pp.getToken = function() {
  4786. this.next();
  4787. return new Token(this)
  4788. };
  4789. // If we're in an ES6 environment, make parsers iterable
  4790. if (typeof Symbol !== "undefined")
  4791. { pp[Symbol.iterator] = function() {
  4792. var this$1$1 = this;
  4793. return {
  4794. next: function () {
  4795. var token = this$1$1.getToken();
  4796. return {
  4797. done: token.type === types$1.eof,
  4798. value: token
  4799. }
  4800. }
  4801. }
  4802. }; }
  4803. // Toggle strict mode. Re-reads the next number or string to please
  4804. // pedantic tests (`"use strict"; 010;` should fail).
  4805. // Read a single token, updating the parser object's token-related
  4806. // properties.
  4807. pp.nextToken = function() {
  4808. var curContext = this.curContext();
  4809. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  4810. this.start = this.pos;
  4811. if (this.options.locations) { this.startLoc = this.curPosition(); }
  4812. if (this.pos >= this.input.length) { return this.finishToken(types$1.eof) }
  4813. if (curContext.override) { return curContext.override(this) }
  4814. else { this.readToken(this.fullCharCodeAtPos()); }
  4815. };
  4816. pp.readToken = function(code) {
  4817. // Identifier or keyword. '\uXXXX' sequences are allowed in
  4818. // identifiers, so '\' also dispatches to that.
  4819. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  4820. { return this.readWord() }
  4821. return this.getTokenFromCode(code)
  4822. };
  4823. pp.fullCharCodeAt = function(pos) {
  4824. var code = this.input.charCodeAt(pos);
  4825. if (code <= 0xd7ff || code >= 0xdc00) { return code }
  4826. var next = this.input.charCodeAt(pos + 1);
  4827. return next <= 0xdbff || next >= 0xe000 ? code : (code << 10) + next - 0x35fdc00
  4828. };
  4829. pp.fullCharCodeAtPos = function() {
  4830. return this.fullCharCodeAt(this.pos)
  4831. };
  4832. pp.skipBlockComment = function() {
  4833. var startLoc = this.options.onComment && this.curPosition();
  4834. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  4835. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  4836. this.pos = end + 2;
  4837. if (this.options.locations) {
  4838. for (var nextBreak = (void 0), pos = start; (nextBreak = nextLineBreak(this.input, pos, this.pos)) > -1;) {
  4839. ++this.curLine;
  4840. pos = this.lineStart = nextBreak;
  4841. }
  4842. }
  4843. if (this.options.onComment)
  4844. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  4845. startLoc, this.curPosition()); }
  4846. };
  4847. pp.skipLineComment = function(startSkip) {
  4848. var start = this.pos;
  4849. var startLoc = this.options.onComment && this.curPosition();
  4850. var ch = this.input.charCodeAt(this.pos += startSkip);
  4851. while (this.pos < this.input.length && !isNewLine(ch)) {
  4852. ch = this.input.charCodeAt(++this.pos);
  4853. }
  4854. if (this.options.onComment)
  4855. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  4856. startLoc, this.curPosition()); }
  4857. };
  4858. // Called at the start of the parse and after every token. Skips
  4859. // whitespace and comments, and.
  4860. pp.skipSpace = function() {
  4861. loop: while (this.pos < this.input.length) {
  4862. var ch = this.input.charCodeAt(this.pos);
  4863. switch (ch) {
  4864. case 32: case 160: // ' '
  4865. ++this.pos;
  4866. break
  4867. case 13:
  4868. if (this.input.charCodeAt(this.pos + 1) === 10) {
  4869. ++this.pos;
  4870. }
  4871. case 10: case 8232: case 8233:
  4872. ++this.pos;
  4873. if (this.options.locations) {
  4874. ++this.curLine;
  4875. this.lineStart = this.pos;
  4876. }
  4877. break
  4878. case 47: // '/'
  4879. switch (this.input.charCodeAt(this.pos + 1)) {
  4880. case 42: // '*'
  4881. this.skipBlockComment();
  4882. break
  4883. case 47:
  4884. this.skipLineComment(2);
  4885. break
  4886. default:
  4887. break loop
  4888. }
  4889. break
  4890. default:
  4891. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  4892. ++this.pos;
  4893. } else {
  4894. break loop
  4895. }
  4896. }
  4897. }
  4898. };
  4899. // Called at the end of every token. Sets `end`, `val`, and
  4900. // maintains `context` and `exprAllowed`, and skips the space after
  4901. // the token, so that the next one's `start` will point at the
  4902. // right position.
  4903. pp.finishToken = function(type, val) {
  4904. this.end = this.pos;
  4905. if (this.options.locations) { this.endLoc = this.curPosition(); }
  4906. var prevType = this.type;
  4907. this.type = type;
  4908. this.value = val;
  4909. this.updateContext(prevType);
  4910. };
  4911. // ### Token reading
  4912. // This is the function that is called to fetch the next token. It
  4913. // is somewhat obscure, because it works in character codes rather
  4914. // than characters, and because operator parsing has been inlined
  4915. // into it.
  4916. //
  4917. // All in the name of speed.
  4918. //
  4919. pp.readToken_dot = function() {
  4920. var next = this.input.charCodeAt(this.pos + 1);
  4921. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  4922. var next2 = this.input.charCodeAt(this.pos + 2);
  4923. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  4924. this.pos += 3;
  4925. return this.finishToken(types$1.ellipsis)
  4926. } else {
  4927. ++this.pos;
  4928. return this.finishToken(types$1.dot)
  4929. }
  4930. };
  4931. pp.readToken_slash = function() { // '/'
  4932. var next = this.input.charCodeAt(this.pos + 1);
  4933. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  4934. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4935. return this.finishOp(types$1.slash, 1)
  4936. };
  4937. pp.readToken_mult_modulo_exp = function(code) { // '%*'
  4938. var next = this.input.charCodeAt(this.pos + 1);
  4939. var size = 1;
  4940. var tokentype = code === 42 ? types$1.star : types$1.modulo;
  4941. // exponentiation operator ** and **=
  4942. if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
  4943. ++size;
  4944. tokentype = types$1.starstar;
  4945. next = this.input.charCodeAt(this.pos + 2);
  4946. }
  4947. if (next === 61) { return this.finishOp(types$1.assign, size + 1) }
  4948. return this.finishOp(tokentype, size)
  4949. };
  4950. pp.readToken_pipe_amp = function(code) { // '|&'
  4951. var next = this.input.charCodeAt(this.pos + 1);
  4952. if (next === code) {
  4953. if (this.options.ecmaVersion >= 12) {
  4954. var next2 = this.input.charCodeAt(this.pos + 2);
  4955. if (next2 === 61) { return this.finishOp(types$1.assign, 3) }
  4956. }
  4957. return this.finishOp(code === 124 ? types$1.logicalOR : types$1.logicalAND, 2)
  4958. }
  4959. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4960. return this.finishOp(code === 124 ? types$1.bitwiseOR : types$1.bitwiseAND, 1)
  4961. };
  4962. pp.readToken_caret = function() { // '^'
  4963. var next = this.input.charCodeAt(this.pos + 1);
  4964. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4965. return this.finishOp(types$1.bitwiseXOR, 1)
  4966. };
  4967. pp.readToken_plus_min = function(code) { // '+-'
  4968. var next = this.input.charCodeAt(this.pos + 1);
  4969. if (next === code) {
  4970. if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
  4971. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  4972. // A `-->` line comment
  4973. this.skipLineComment(3);
  4974. this.skipSpace();
  4975. return this.nextToken()
  4976. }
  4977. return this.finishOp(types$1.incDec, 2)
  4978. }
  4979. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4980. return this.finishOp(types$1.plusMin, 1)
  4981. };
  4982. pp.readToken_lt_gt = function(code) { // '<>'
  4983. var next = this.input.charCodeAt(this.pos + 1);
  4984. var size = 1;
  4985. if (next === code) {
  4986. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  4987. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types$1.assign, size + 1) }
  4988. return this.finishOp(types$1.bitShift, size)
  4989. }
  4990. if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
  4991. this.input.charCodeAt(this.pos + 3) === 45) {
  4992. // `<!--`, an XML-style comment that should be interpreted as a line comment
  4993. this.skipLineComment(4);
  4994. this.skipSpace();
  4995. return this.nextToken()
  4996. }
  4997. if (next === 61) { size = 2; }
  4998. return this.finishOp(types$1.relational, size)
  4999. };
  5000. pp.readToken_eq_excl = function(code) { // '=!'
  5001. var next = this.input.charCodeAt(this.pos + 1);
  5002. if (next === 61) { return this.finishOp(types$1.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  5003. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  5004. this.pos += 2;
  5005. return this.finishToken(types$1.arrow)
  5006. }
  5007. return this.finishOp(code === 61 ? types$1.eq : types$1.prefix, 1)
  5008. };
  5009. pp.readToken_question = function() { // '?'
  5010. var ecmaVersion = this.options.ecmaVersion;
  5011. if (ecmaVersion >= 11) {
  5012. var next = this.input.charCodeAt(this.pos + 1);
  5013. if (next === 46) {
  5014. var next2 = this.input.charCodeAt(this.pos + 2);
  5015. if (next2 < 48 || next2 > 57) { return this.finishOp(types$1.questionDot, 2) }
  5016. }
  5017. if (next === 63) {
  5018. if (ecmaVersion >= 12) {
  5019. var next2$1 = this.input.charCodeAt(this.pos + 2);
  5020. if (next2$1 === 61) { return this.finishOp(types$1.assign, 3) }
  5021. }
  5022. return this.finishOp(types$1.coalesce, 2)
  5023. }
  5024. }
  5025. return this.finishOp(types$1.question, 1)
  5026. };
  5027. pp.readToken_numberSign = function() { // '#'
  5028. var ecmaVersion = this.options.ecmaVersion;
  5029. var code = 35; // '#'
  5030. if (ecmaVersion >= 13) {
  5031. ++this.pos;
  5032. code = this.fullCharCodeAtPos();
  5033. if (isIdentifierStart(code, true) || code === 92 /* '\' */) {
  5034. return this.finishToken(types$1.privateId, this.readWord1())
  5035. }
  5036. }
  5037. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  5038. };
  5039. pp.getTokenFromCode = function(code) {
  5040. switch (code) {
  5041. // The interpretation of a dot depends on whether it is followed
  5042. // by a digit or another two dots.
  5043. case 46: // '.'
  5044. return this.readToken_dot()
  5045. // Punctuation tokens.
  5046. case 40: ++this.pos; return this.finishToken(types$1.parenL)
  5047. case 41: ++this.pos; return this.finishToken(types$1.parenR)
  5048. case 59: ++this.pos; return this.finishToken(types$1.semi)
  5049. case 44: ++this.pos; return this.finishToken(types$1.comma)
  5050. case 91: ++this.pos; return this.finishToken(types$1.bracketL)
  5051. case 93: ++this.pos; return this.finishToken(types$1.bracketR)
  5052. case 123: ++this.pos; return this.finishToken(types$1.braceL)
  5053. case 125: ++this.pos; return this.finishToken(types$1.braceR)
  5054. case 58: ++this.pos; return this.finishToken(types$1.colon)
  5055. case 96: // '`'
  5056. if (this.options.ecmaVersion < 6) { break }
  5057. ++this.pos;
  5058. return this.finishToken(types$1.backQuote)
  5059. case 48: // '0'
  5060. var next = this.input.charCodeAt(this.pos + 1);
  5061. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  5062. if (this.options.ecmaVersion >= 6) {
  5063. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  5064. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  5065. }
  5066. // Anything else beginning with a digit is an integer, octal
  5067. // number, or float.
  5068. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  5069. return this.readNumber(false)
  5070. // Quotes produce strings.
  5071. case 34: case 39: // '"', "'"
  5072. return this.readString(code)
  5073. // Operators are parsed inline in tiny state machines. '=' (61) is
  5074. // often referred to. `finishOp` simply skips the amount of
  5075. // characters it is given as second argument, and returns a token
  5076. // of the type given by its first argument.
  5077. case 47: // '/'
  5078. return this.readToken_slash()
  5079. case 37: case 42: // '%*'
  5080. return this.readToken_mult_modulo_exp(code)
  5081. case 124: case 38: // '|&'
  5082. return this.readToken_pipe_amp(code)
  5083. case 94: // '^'
  5084. return this.readToken_caret()
  5085. case 43: case 45: // '+-'
  5086. return this.readToken_plus_min(code)
  5087. case 60: case 62: // '<>'
  5088. return this.readToken_lt_gt(code)
  5089. case 61: case 33: // '=!'
  5090. return this.readToken_eq_excl(code)
  5091. case 63: // '?'
  5092. return this.readToken_question()
  5093. case 126: // '~'
  5094. return this.finishOp(types$1.prefix, 1)
  5095. case 35: // '#'
  5096. return this.readToken_numberSign()
  5097. }
  5098. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  5099. };
  5100. pp.finishOp = function(type, size) {
  5101. var str = this.input.slice(this.pos, this.pos + size);
  5102. this.pos += size;
  5103. return this.finishToken(type, str)
  5104. };
  5105. pp.readRegexp = function() {
  5106. var escaped, inClass, start = this.pos;
  5107. for (;;) {
  5108. if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
  5109. var ch = this.input.charAt(this.pos);
  5110. if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
  5111. if (!escaped) {
  5112. if (ch === "[") { inClass = true; }
  5113. else if (ch === "]" && inClass) { inClass = false; }
  5114. else if (ch === "/" && !inClass) { break }
  5115. escaped = ch === "\\";
  5116. } else { escaped = false; }
  5117. ++this.pos;
  5118. }
  5119. var pattern = this.input.slice(start, this.pos);
  5120. ++this.pos;
  5121. var flagsStart = this.pos;
  5122. var flags = this.readWord1();
  5123. if (this.containsEsc) { this.unexpected(flagsStart); }
  5124. // Validate pattern
  5125. var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
  5126. state.reset(start, pattern, flags);
  5127. this.validateRegExpFlags(state);
  5128. this.validateRegExpPattern(state);
  5129. // Create Literal#value property value.
  5130. var value = null;
  5131. try {
  5132. value = new RegExp(pattern, flags);
  5133. } catch (e) {
  5134. // ESTree requires null if it failed to instantiate RegExp object.
  5135. // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
  5136. }
  5137. return this.finishToken(types$1.regexp, {pattern: pattern, flags: flags, value: value})
  5138. };
  5139. // Read an integer in the given radix. Return null if zero digits
  5140. // were read, the integer value otherwise. When `len` is given, this
  5141. // will return `null` unless the integer has exactly `len` digits.
  5142. pp.readInt = function(radix, len, maybeLegacyOctalNumericLiteral) {
  5143. // `len` is used for character escape sequences. In that case, disallow separators.
  5144. var allowSeparators = this.options.ecmaVersion >= 12 && len === undefined;
  5145. // `maybeLegacyOctalNumericLiteral` is true if it doesn't have prefix (0x,0o,0b)
  5146. // and isn't fraction part nor exponent part. In that case, if the first digit
  5147. // is zero then disallow separators.
  5148. var isLegacyOctalNumericLiteral = maybeLegacyOctalNumericLiteral && this.input.charCodeAt(this.pos) === 48;
  5149. var start = this.pos, total = 0, lastCode = 0;
  5150. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i, ++this.pos) {
  5151. var code = this.input.charCodeAt(this.pos), val = (void 0);
  5152. if (allowSeparators && code === 95) {
  5153. if (isLegacyOctalNumericLiteral) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals"); }
  5154. if (lastCode === 95) { this.raiseRecoverable(this.pos, "Numeric separator must be exactly one underscore"); }
  5155. if (i === 0) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed at the first of digits"); }
  5156. lastCode = code;
  5157. continue
  5158. }
  5159. if (code >= 97) { val = code - 97 + 10; } // a
  5160. else if (code >= 65) { val = code - 65 + 10; } // A
  5161. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  5162. else { val = Infinity; }
  5163. if (val >= radix) { break }
  5164. lastCode = code;
  5165. total = total * radix + val;
  5166. }
  5167. if (allowSeparators && lastCode === 95) { this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits"); }
  5168. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  5169. return total
  5170. };
  5171. function stringToNumber(str, isLegacyOctalNumericLiteral) {
  5172. if (isLegacyOctalNumericLiteral) {
  5173. return parseInt(str, 8)
  5174. }
  5175. // `parseFloat(value)` stops parsing at the first numeric separator then returns a wrong value.
  5176. return parseFloat(str.replace(/_/g, ""))
  5177. }
  5178. function stringToBigInt(str) {
  5179. if (typeof BigInt !== "function") {
  5180. return null
  5181. }
  5182. // `BigInt(value)` throws syntax error if the string contains numeric separators.
  5183. return BigInt(str.replace(/_/g, ""))
  5184. }
  5185. pp.readRadixNumber = function(radix) {
  5186. var start = this.pos;
  5187. this.pos += 2; // 0x
  5188. var val = this.readInt(radix);
  5189. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  5190. if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
  5191. val = stringToBigInt(this.input.slice(start, this.pos));
  5192. ++this.pos;
  5193. } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  5194. return this.finishToken(types$1.num, val)
  5195. };
  5196. // Read an integer, octal integer, or floating-point number.
  5197. pp.readNumber = function(startsWithDot) {
  5198. var start = this.pos;
  5199. if (!startsWithDot && this.readInt(10, undefined, true) === null) { this.raise(start, "Invalid number"); }
  5200. var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  5201. if (octal && this.strict) { this.raise(start, "Invalid number"); }
  5202. var next = this.input.charCodeAt(this.pos);
  5203. if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
  5204. var val$1 = stringToBigInt(this.input.slice(start, this.pos));
  5205. ++this.pos;
  5206. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  5207. return this.finishToken(types$1.num, val$1)
  5208. }
  5209. if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
  5210. if (next === 46 && !octal) { // '.'
  5211. ++this.pos;
  5212. this.readInt(10);
  5213. next = this.input.charCodeAt(this.pos);
  5214. }
  5215. if ((next === 69 || next === 101) && !octal) { // 'eE'
  5216. next = this.input.charCodeAt(++this.pos);
  5217. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  5218. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  5219. }
  5220. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  5221. var val = stringToNumber(this.input.slice(start, this.pos), octal);
  5222. return this.finishToken(types$1.num, val)
  5223. };
  5224. // Read a string value, interpreting backslash-escapes.
  5225. pp.readCodePoint = function() {
  5226. var ch = this.input.charCodeAt(this.pos), code;
  5227. if (ch === 123) { // '{'
  5228. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  5229. var codePos = ++this.pos;
  5230. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  5231. ++this.pos;
  5232. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  5233. } else {
  5234. code = this.readHexChar(4);
  5235. }
  5236. return code
  5237. };
  5238. pp.readString = function(quote) {
  5239. var out = "", chunkStart = ++this.pos;
  5240. for (;;) {
  5241. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
  5242. var ch = this.input.charCodeAt(this.pos);
  5243. if (ch === quote) { break }
  5244. if (ch === 92) { // '\'
  5245. out += this.input.slice(chunkStart, this.pos);
  5246. out += this.readEscapedChar(false);
  5247. chunkStart = this.pos;
  5248. } else if (ch === 0x2028 || ch === 0x2029) {
  5249. if (this.options.ecmaVersion < 10) { this.raise(this.start, "Unterminated string constant"); }
  5250. ++this.pos;
  5251. if (this.options.locations) {
  5252. this.curLine++;
  5253. this.lineStart = this.pos;
  5254. }
  5255. } else {
  5256. if (isNewLine(ch)) { this.raise(this.start, "Unterminated string constant"); }
  5257. ++this.pos;
  5258. }
  5259. }
  5260. out += this.input.slice(chunkStart, this.pos++);
  5261. return this.finishToken(types$1.string, out)
  5262. };
  5263. // Reads template string tokens.
  5264. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  5265. pp.tryReadTemplateToken = function() {
  5266. this.inTemplateElement = true;
  5267. try {
  5268. this.readTmplToken();
  5269. } catch (err) {
  5270. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  5271. this.readInvalidTemplateToken();
  5272. } else {
  5273. throw err
  5274. }
  5275. }
  5276. this.inTemplateElement = false;
  5277. };
  5278. pp.invalidStringToken = function(position, message) {
  5279. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  5280. throw INVALID_TEMPLATE_ESCAPE_ERROR
  5281. } else {
  5282. this.raise(position, message);
  5283. }
  5284. };
  5285. pp.readTmplToken = function() {
  5286. var out = "", chunkStart = this.pos;
  5287. for (;;) {
  5288. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
  5289. var ch = this.input.charCodeAt(this.pos);
  5290. if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { // '`', '${'
  5291. if (this.pos === this.start && (this.type === types$1.template || this.type === types$1.invalidTemplate)) {
  5292. if (ch === 36) {
  5293. this.pos += 2;
  5294. return this.finishToken(types$1.dollarBraceL)
  5295. } else {
  5296. ++this.pos;
  5297. return this.finishToken(types$1.backQuote)
  5298. }
  5299. }
  5300. out += this.input.slice(chunkStart, this.pos);
  5301. return this.finishToken(types$1.template, out)
  5302. }
  5303. if (ch === 92) { // '\'
  5304. out += this.input.slice(chunkStart, this.pos);
  5305. out += this.readEscapedChar(true);
  5306. chunkStart = this.pos;
  5307. } else if (isNewLine(ch)) {
  5308. out += this.input.slice(chunkStart, this.pos);
  5309. ++this.pos;
  5310. switch (ch) {
  5311. case 13:
  5312. if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
  5313. case 10:
  5314. out += "\n";
  5315. break
  5316. default:
  5317. out += String.fromCharCode(ch);
  5318. break
  5319. }
  5320. if (this.options.locations) {
  5321. ++this.curLine;
  5322. this.lineStart = this.pos;
  5323. }
  5324. chunkStart = this.pos;
  5325. } else {
  5326. ++this.pos;
  5327. }
  5328. }
  5329. };
  5330. // Reads a template token to search for the end, without validating any escape sequences
  5331. pp.readInvalidTemplateToken = function() {
  5332. for (; this.pos < this.input.length; this.pos++) {
  5333. switch (this.input[this.pos]) {
  5334. case "\\":
  5335. ++this.pos;
  5336. break
  5337. case "$":
  5338. if (this.input[this.pos + 1] !== "{") { break }
  5339. // fall through
  5340. case "`":
  5341. return this.finishToken(types$1.invalidTemplate, this.input.slice(this.start, this.pos))
  5342. case "\r":
  5343. if (this.input[this.pos + 1] === "\n") { ++this.pos; }
  5344. // fall through
  5345. case "\n": case "\u2028": case "\u2029":
  5346. ++this.curLine;
  5347. this.lineStart = this.pos + 1;
  5348. break
  5349. }
  5350. }
  5351. this.raise(this.start, "Unterminated template");
  5352. };
  5353. // Used to read escaped characters
  5354. pp.readEscapedChar = function(inTemplate) {
  5355. var ch = this.input.charCodeAt(++this.pos);
  5356. ++this.pos;
  5357. switch (ch) {
  5358. case 110: return "\n" // 'n' -> '\n'
  5359. case 114: return "\r" // 'r' -> '\r'
  5360. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  5361. case 117: return codePointToString(this.readCodePoint()) // 'u'
  5362. case 116: return "\t" // 't' -> '\t'
  5363. case 98: return "\b" // 'b' -> '\b'
  5364. case 118: return "\u000b" // 'v' -> '\u000b'
  5365. case 102: return "\f" // 'f' -> '\f'
  5366. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  5367. case 10: // ' \n'
  5368. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  5369. return ""
  5370. case 56:
  5371. case 57:
  5372. if (this.strict) {
  5373. this.invalidStringToken(
  5374. this.pos - 1,
  5375. "Invalid escape sequence"
  5376. );
  5377. }
  5378. if (inTemplate) {
  5379. var codePos = this.pos - 1;
  5380. this.invalidStringToken(
  5381. codePos,
  5382. "Invalid escape sequence in template string"
  5383. );
  5384. }
  5385. default:
  5386. if (ch >= 48 && ch <= 55) {
  5387. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  5388. var octal = parseInt(octalStr, 8);
  5389. if (octal > 255) {
  5390. octalStr = octalStr.slice(0, -1);
  5391. octal = parseInt(octalStr, 8);
  5392. }
  5393. this.pos += octalStr.length - 1;
  5394. ch = this.input.charCodeAt(this.pos);
  5395. if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
  5396. this.invalidStringToken(
  5397. this.pos - 1 - octalStr.length,
  5398. inTemplate
  5399. ? "Octal literal in template string"
  5400. : "Octal literal in strict mode"
  5401. );
  5402. }
  5403. return String.fromCharCode(octal)
  5404. }
  5405. if (isNewLine(ch)) {
  5406. // Unicode new line characters after \ get removed from output in both
  5407. // template literals and strings
  5408. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  5409. return ""
  5410. }
  5411. return String.fromCharCode(ch)
  5412. }
  5413. };
  5414. // Used to read character escape sequences ('\x', '\u', '\U').
  5415. pp.readHexChar = function(len) {
  5416. var codePos = this.pos;
  5417. var n = this.readInt(16, len);
  5418. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  5419. return n
  5420. };
  5421. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  5422. // to whether the word contained a '\u' escape.
  5423. //
  5424. // Incrementally adds only escaped chars, adding other chunks as-is
  5425. // as a micro-optimization.
  5426. pp.readWord1 = function() {
  5427. this.containsEsc = false;
  5428. var word = "", first = true, chunkStart = this.pos;
  5429. var astral = this.options.ecmaVersion >= 6;
  5430. while (this.pos < this.input.length) {
  5431. var ch = this.fullCharCodeAtPos();
  5432. if (isIdentifierChar(ch, astral)) {
  5433. this.pos += ch <= 0xffff ? 1 : 2;
  5434. } else if (ch === 92) { // "\"
  5435. this.containsEsc = true;
  5436. word += this.input.slice(chunkStart, this.pos);
  5437. var escStart = this.pos;
  5438. if (this.input.charCodeAt(++this.pos) !== 117) // "u"
  5439. { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  5440. ++this.pos;
  5441. var esc = this.readCodePoint();
  5442. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  5443. { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
  5444. word += codePointToString(esc);
  5445. chunkStart = this.pos;
  5446. } else {
  5447. break
  5448. }
  5449. first = false;
  5450. }
  5451. return word + this.input.slice(chunkStart, this.pos)
  5452. };
  5453. // Read an identifier or keyword token. Will check for reserved
  5454. // words when necessary.
  5455. pp.readWord = function() {
  5456. var word = this.readWord1();
  5457. var type = types$1.name;
  5458. if (this.keywords.test(word)) {
  5459. type = keywords[word];
  5460. }
  5461. return this.finishToken(type, word)
  5462. };
  5463. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  5464. //
  5465. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  5466. // various contributors and released under an MIT license.
  5467. //
  5468. // Git repositories for Acorn are available at
  5469. //
  5470. // http://marijnhaverbeke.nl/git/acorn
  5471. // https://github.com/acornjs/acorn.git
  5472. //
  5473. // Please use the [github bug tracker][ghbt] to report issues.
  5474. //
  5475. // [ghbt]: https://github.com/acornjs/acorn/issues
  5476. var version = "8.16.0";
  5477. Parser.acorn = {
  5478. Parser: Parser,
  5479. version: version,
  5480. defaultOptions: defaultOptions,
  5481. Position: Position,
  5482. SourceLocation: SourceLocation,
  5483. getLineInfo: getLineInfo,
  5484. Node: Node,
  5485. TokenType: TokenType,
  5486. tokTypes: types$1,
  5487. keywordTypes: keywords,
  5488. TokContext: TokContext,
  5489. tokContexts: types,
  5490. isIdentifierChar: isIdentifierChar,
  5491. isIdentifierStart: isIdentifierStart,
  5492. Token: Token,
  5493. isNewLine: isNewLine,
  5494. lineBreak: lineBreak,
  5495. lineBreakG: lineBreakG,
  5496. nonASCIIwhitespace: nonASCIIwhitespace
  5497. };
  5498. // The main exported interface (under `self.acorn` when in the
  5499. // browser) is a `parse` function that takes a code string and returns
  5500. // an abstract syntax tree as specified by the [ESTree spec][estree].
  5501. //
  5502. // [estree]: https://github.com/estree/estree
  5503. function parse(input, options) {
  5504. return Parser.parse(input, options)
  5505. }
  5506. // This function tries to parse a single expression at a given
  5507. // offset in a string. Useful for parsing mixed-language formats
  5508. // that embed JavaScript expressions.
  5509. function parseExpressionAt(input, pos, options) {
  5510. return Parser.parseExpressionAt(input, pos, options)
  5511. }
  5512. // Acorn is organized as a tokenizer and a recursive-descent parser.
  5513. // The `tokenizer` export provides an interface to the tokenizer.
  5514. function tokenizer(input, options) {
  5515. return Parser.tokenizer(input, options)
  5516. }
  5517. export { Node, Parser, Position, SourceLocation, TokContext, Token, TokenType, defaultOptions, getLineInfo, isIdentifierChar, isIdentifierStart, isNewLine, keywords as keywordTypes, lineBreak, lineBreakG, nonASCIIwhitespace, parse, parseExpressionAt, types as tokContexts, types$1 as tokTypes, tokenizer, version };