chunk-vite-node-utils.473cd0b2.mjs 243 KB

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