acorn.js 236 KB

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