acorn.js 213 KB

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