acorn.mjs 221 KB

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