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, 81, 2, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 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, 10, 1, 2, 0, 49, 6, 4, 4, 14, 9, 5351, 0, 7, 14, 13835, 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, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 983, 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, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 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, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 4026, 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, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 757, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938, 6, 4191];
  10. // This file was generated. Do not modify manually!
  11. var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\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\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\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. return false
  46. }
  47. // Test whether a given character code starts an identifier.
  48. function isIdentifierStart(code, astral) {
  49. if (code < 65) { return code === 36 }
  50. if (code < 91) { return true }
  51. if (code < 97) { return code === 95 }
  52. if (code < 123) { return true }
  53. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  54. if (astral === false) { return false }
  55. return isInAstralSet(code, astralIdentifierStartCodes)
  56. }
  57. // Test whether a given character is part of an identifier.
  58. function isIdentifierChar(code, astral) {
  59. if (code < 48) { return code === 36 }
  60. if (code < 58) { return true }
  61. if (code < 65) { return false }
  62. if (code < 91) { return true }
  63. if (code < 97) { return code === 95 }
  64. if (code < 123) { return true }
  65. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  66. if (astral === false) { return false }
  67. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  68. }
  69. // ## Token types
  70. // The assignment of fine-grained, information-carrying type objects
  71. // allows the tokenizer to store the information it has about a
  72. // token in a way that is very cheap for the parser to look up.
  73. // All token type variables start with an underscore, to make them
  74. // easy to recognize.
  75. // The `beforeExpr` property is used to disambiguate between regular
  76. // expressions and divisions. It is set on all token types that can
  77. // be followed by an expression (thus, a slash after them would be a
  78. // regular expression).
  79. //
  80. // The `startsExpr` property is used to check if the token ends a
  81. // `yield` expression. It is set on all token types that either can
  82. // directly start an expression (like a quotation mark) or can
  83. // continue an expression (like the body of a string).
  84. //
  85. // `isLoop` marks a keyword as starting a loop, which is important
  86. // to know when parsing a label, in order to allow or disallow
  87. // continue jumps to that label.
  88. var TokenType = function TokenType(label, conf) {
  89. if ( conf === void 0 ) conf = {};
  90. this.label = label;
  91. this.keyword = conf.keyword;
  92. this.beforeExpr = !!conf.beforeExpr;
  93. this.startsExpr = !!conf.startsExpr;
  94. this.isLoop = !!conf.isLoop;
  95. this.isAssign = !!conf.isAssign;
  96. this.prefix = !!conf.prefix;
  97. this.postfix = !!conf.postfix;
  98. this.binop = conf.binop || null;
  99. this.updateContext = null;
  100. };
  101. function binop(name, prec) {
  102. return new TokenType(name, {beforeExpr: true, binop: prec})
  103. }
  104. var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
  105. // Map keyword names to token types.
  106. var keywords = {};
  107. // Succinct definitions of keyword token types
  108. function kw(name, options) {
  109. if ( options === void 0 ) options = {};
  110. options.keyword = name;
  111. return keywords[name] = new TokenType(name, options)
  112. }
  113. var types$1 = {
  114. num: new TokenType("num", startsExpr),
  115. regexp: new TokenType("regexp", startsExpr),
  116. string: new TokenType("string", startsExpr),
  117. name: new TokenType("name", startsExpr),
  118. privateId: new TokenType("privateId", startsExpr),
  119. eof: new TokenType("eof"),
  120. // Punctuation token types.
  121. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  122. bracketR: new TokenType("]"),
  123. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  124. braceR: new TokenType("}"),
  125. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  126. parenR: new TokenType(")"),
  127. comma: new TokenType(",", beforeExpr),
  128. semi: new TokenType(";", beforeExpr),
  129. colon: new TokenType(":", beforeExpr),
  130. dot: new TokenType("."),
  131. question: new TokenType("?", beforeExpr),
  132. questionDot: new TokenType("?."),
  133. arrow: new TokenType("=>", beforeExpr),
  134. template: new TokenType("template"),
  135. invalidTemplate: new TokenType("invalidTemplate"),
  136. ellipsis: new TokenType("...", beforeExpr),
  137. backQuote: new TokenType("`", startsExpr),
  138. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  139. // Operators. These carry several kinds of properties to help the
  140. // parser use them properly (the presence of these properties is
  141. // what categorizes them as operators).
  142. //
  143. // `binop`, when present, specifies that this operator is a binary
  144. // operator, and will refer to its precedence.
  145. //
  146. // `prefix` and `postfix` mark the operator as a prefix or postfix
  147. // unary operator.
  148. //
  149. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  150. // binary operators with a very low precedence, that should result
  151. // in AssignmentExpression nodes.
  152. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  153. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  154. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  155. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  156. logicalOR: binop("||", 1),
  157. logicalAND: binop("&&", 2),
  158. bitwiseOR: binop("|", 3),
  159. bitwiseXOR: binop("^", 4),
  160. bitwiseAND: binop("&", 5),
  161. equality: binop("==/!=/===/!==", 6),
  162. relational: binop("</>/<=/>=", 7),
  163. bitShift: binop("<</>>/>>>", 8),
  164. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  165. modulo: binop("%", 10),
  166. star: binop("*", 10),
  167. slash: binop("/", 10),
  168. starstar: new TokenType("**", {beforeExpr: true}),
  169. coalesce: binop("??", 1),
  170. // Keyword token types.
  171. _break: kw("break"),
  172. _case: kw("case", beforeExpr),
  173. _catch: kw("catch"),
  174. _continue: kw("continue"),
  175. _debugger: kw("debugger"),
  176. _default: kw("default", beforeExpr),
  177. _do: kw("do", {isLoop: true, beforeExpr: true}),
  178. _else: kw("else", beforeExpr),
  179. _finally: kw("finally"),
  180. _for: kw("for", {isLoop: true}),
  181. _function: kw("function", startsExpr),
  182. _if: kw("if"),
  183. _return: kw("return", beforeExpr),
  184. _switch: kw("switch"),
  185. _throw: kw("throw", beforeExpr),
  186. _try: kw("try"),
  187. _var: kw("var"),
  188. _const: kw("const"),
  189. _while: kw("while", {isLoop: true}),
  190. _with: kw("with"),
  191. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  192. _this: kw("this", startsExpr),
  193. _super: kw("super", startsExpr),
  194. _class: kw("class", startsExpr),
  195. _extends: kw("extends", beforeExpr),
  196. _export: kw("export"),
  197. _import: kw("import", startsExpr),
  198. _null: kw("null", startsExpr),
  199. _true: kw("true", startsExpr),
  200. _false: kw("false", startsExpr),
  201. _in: kw("in", {beforeExpr: true, binop: 7}),
  202. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  203. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  204. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  205. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  206. };
  207. // Matches a whole line break (where CRLF is considered a single
  208. // line break). Used to count lines.
  209. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  210. var lineBreakG = new RegExp(lineBreak.source, "g");
  211. function isNewLine(code) {
  212. return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
  213. }
  214. function nextLineBreak(code, from, end) {
  215. if ( end === void 0 ) end = code.length;
  216. for (var i = from; i < end; i++) {
  217. var next = code.charCodeAt(i);
  218. if (isNewLine(next))
  219. { return i < end - 1 && next === 13 && code.charCodeAt(i + 1) === 10 ? i + 2 : i + 1 }
  220. }
  221. return -1
  222. }
  223. var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  224. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  225. var ref = Object.prototype;
  226. var hasOwnProperty = ref.hasOwnProperty;
  227. var toString = ref.toString;
  228. var hasOwn = Object.hasOwn || (function (obj, propName) { return (
  229. hasOwnProperty.call(obj, propName)
  230. ); });
  231. var isArray = Array.isArray || (function (obj) { return (
  232. toString.call(obj) === "[object Array]"
  233. ); });
  234. function wordsRegexp(words) {
  235. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  236. }
  237. function codePointToString(code) {
  238. // UTF-16 Decoding
  239. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  240. code -= 0x10000;
  241. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  242. }
  243. var loneSurrogate = /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/;
  244. // These are used when `options.locations` is on, for the
  245. // `startLoc` and `endLoc` properties.
  246. var Position = function Position(line, col) {
  247. this.line = line;
  248. this.column = col;
  249. };
  250. Position.prototype.offset = function offset (n) {
  251. return new Position(this.line, this.column + n)
  252. };
  253. var SourceLocation = function SourceLocation(p, start, end) {
  254. this.start = start;
  255. this.end = end;
  256. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  257. };
  258. // The `getLineInfo` function is mostly useful when the
  259. // `locations` option is off (for performance reasons) and you
  260. // want to find the line/column position for a given character
  261. // offset. `input` should be the code string that the offset refers
  262. // into.
  263. function getLineInfo(input, offset) {
  264. for (var line = 1, cur = 0;;) {
  265. var nextBreak = nextLineBreak(input, cur, offset);
  266. if (nextBreak < 0) { return new Position(line, offset - cur) }
  267. ++line;
  268. cur = nextBreak;
  269. }
  270. }
  271. // A second argument must be given to configure the parser process.
  272. // These options are recognized (only `ecmaVersion` is required):
  273. var defaultOptions = {
  274. // `ecmaVersion` indicates the ECMAScript version to parse. Must be
  275. // either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
  276. // (2019), 11 (2020), 12 (2021), 13 (2022), 14 (2023), or `"latest"`
  277. // (the latest version the library supports). This influences
  278. // support for strict mode, the set of reserved words, and support
  279. // for new syntax features.
  280. ecmaVersion: null,
  281. // `sourceType` indicates the mode the code should be parsed in.
  282. // Can be either `"script"` or `"module"`. This influences global
  283. // strict mode and parsing of `import` and `export` declarations.
  284. sourceType: "script",
  285. // `onInsertedSemicolon` can be a callback that will be called
  286. // when a semicolon is automatically inserted. It will be passed
  287. // the position of the comma as an offset, and if `locations` is
  288. // enabled, it is given the location as a `{line, column}` object
  289. // as second argument.
  290. onInsertedSemicolon: null,
  291. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  292. // trailing commas.
  293. onTrailingComma: null,
  294. // By default, reserved words are only enforced if ecmaVersion >= 5.
  295. // Set `allowReserved` to a boolean value to explicitly turn this on
  296. // an off. When this option has the value "never", reserved words
  297. // and keywords can also not be used as property names.
  298. allowReserved: null,
  299. // When enabled, a return at the top level is not considered an
  300. // error.
  301. allowReturnOutsideFunction: false,
  302. // When enabled, import/export statements are not constrained to
  303. // appearing at the top of the program, and an import.meta expression
  304. // in a script isn't considered an error.
  305. allowImportExportEverywhere: false,
  306. // By default, await identifiers are allowed to appear at the top-level scope only if ecmaVersion >= 2022.
  307. // When enabled, await identifiers are allowed to appear at the top-level scope,
  308. // but they are still not allowed in non-async functions.
  309. allowAwaitOutsideFunction: null,
  310. // When enabled, super identifiers are not constrained to
  311. // appearing in methods and do not raise an error when they appear elsewhere.
  312. allowSuperOutsideMethod: null,
  313. // When enabled, hashbang directive in the beginning of file is
  314. // allowed and treated as a line comment. Enabled by default when
  315. // `ecmaVersion` >= 2023.
  316. allowHashBang: false,
  317. // When `locations` is on, `loc` properties holding objects with
  318. // `start` and `end` properties in `{line, column}` form (with
  319. // line being 1-based and column 0-based) will be attached to the
  320. // nodes.
  321. locations: false,
  322. // A function can be passed as `onToken` option, which will
  323. // cause Acorn to call that function with object in the same
  324. // format as tokens returned from `tokenizer().getToken()`. Note
  325. // that you are not allowed to call the parser from the
  326. // callback—that will corrupt its internal state.
  327. onToken: null,
  328. // A function can be passed as `onComment` option, which will
  329. // cause Acorn to call that function with `(block, text, start,
  330. // end)` parameters whenever a comment is skipped. `block` is a
  331. // boolean indicating whether this is a block (`/* */`) comment,
  332. // `text` is the content of the comment, and `start` and `end` are
  333. // character offsets that denote the start and end of the comment.
  334. // When the `locations` option is on, two more parameters are
  335. // passed, the full `{line, column}` locations of the start and
  336. // end of the comments. Note that you are not allowed to call the
  337. // parser from the callback—that will corrupt its internal state.
  338. onComment: null,
  339. // Nodes have their start and end characters offsets recorded in
  340. // `start` and `end` properties (directly on the node, rather than
  341. // the `loc` object, which holds line/column data. To also add a
  342. // [semi-standardized][range] `range` property holding a `[start,
  343. // end]` array with the same numbers, set the `ranges` option to
  344. // `true`.
  345. //
  346. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  347. ranges: false,
  348. // It is possible to parse multiple files into a single AST by
  349. // passing the tree produced by parsing the first file as
  350. // `program` option in subsequent parses. This will add the
  351. // toplevel forms of the parsed file to the `Program` (top) node
  352. // of an existing parse tree.
  353. program: null,
  354. // When `locations` is on, you can pass this to record the source
  355. // file in every node's `loc` object.
  356. sourceFile: null,
  357. // This value, if given, is stored in every node, whether
  358. // `locations` is on or off.
  359. directSourceFile: null,
  360. // When enabled, parenthesized expressions are represented by
  361. // (non-standard) ParenthesizedExpression nodes
  362. preserveParens: false
  363. };
  364. // Interpret and default an options object
  365. var warnedAboutEcmaVersion = false;
  366. function getOptions(opts) {
  367. var options = {};
  368. for (var opt in defaultOptions)
  369. { options[opt] = opts && hasOwn(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  370. if (options.ecmaVersion === "latest") {
  371. options.ecmaVersion = 1e8;
  372. } else if (options.ecmaVersion == null) {
  373. if (!warnedAboutEcmaVersion && typeof console === "object" && console.warn) {
  374. warnedAboutEcmaVersion = true;
  375. console.warn("Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.");
  376. }
  377. options.ecmaVersion = 11;
  378. } else if (options.ecmaVersion >= 2015) {
  379. options.ecmaVersion -= 2009;
  380. }
  381. if (options.allowReserved == null)
  382. { options.allowReserved = options.ecmaVersion < 5; }
  383. if (!opts || opts.allowHashBang == null)
  384. { options.allowHashBang = options.ecmaVersion >= 14; }
  385. if (isArray(options.onToken)) {
  386. var tokens = options.onToken;
  387. options.onToken = function (token) { return tokens.push(token); };
  388. }
  389. if (isArray(options.onComment))
  390. { options.onComment = pushComment(options, options.onComment); }
  391. return options
  392. }
  393. function pushComment(options, array) {
  394. return function(block, text, start, end, startLoc, endLoc) {
  395. var comment = {
  396. type: block ? "Block" : "Line",
  397. value: text,
  398. start: start,
  399. end: end
  400. };
  401. if (options.locations)
  402. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  403. if (options.ranges)
  404. { comment.range = [start, end]; }
  405. array.push(comment);
  406. }
  407. }
  408. // Each scope gets a bitset that may contain these flags
  409. var
  410. SCOPE_TOP = 1,
  411. SCOPE_FUNCTION = 2,
  412. SCOPE_ASYNC = 4,
  413. SCOPE_GENERATOR = 8,
  414. SCOPE_ARROW = 16,
  415. SCOPE_SIMPLE_CATCH = 32,
  416. SCOPE_SUPER = 64,
  417. SCOPE_DIRECT_SUPER = 128,
  418. SCOPE_CLASS_STATIC_BLOCK = 256,
  419. SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;
  420. function functionFlags(async, generator) {
  421. return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
  422. }
  423. // Used in checkLVal* and declareName to determine the type of a binding
  424. var
  425. BIND_NONE = 0, // Not a binding
  426. BIND_VAR = 1, // Var-style binding
  427. BIND_LEXICAL = 2, // Let- or const-style binding
  428. BIND_FUNCTION = 3, // Function declaration
  429. BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
  430. BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
  431. var Parser = function Parser(options, input, startPos) {
  432. this.options = options = getOptions(options);
  433. this.sourceFile = options.sourceFile;
  434. this.keywords = wordsRegexp(keywords$1[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
  435. var reserved = "";
  436. if (options.allowReserved !== true) {
  437. reserved = reservedWords[options.ecmaVersion >= 6 ? 6 : options.ecmaVersion === 5 ? 5 : 3];
  438. if (options.sourceType === "module") { reserved += " await"; }
  439. }
  440. this.reservedWords = wordsRegexp(reserved);
  441. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  442. this.reservedWordsStrict = wordsRegexp(reservedStrict);
  443. this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
  444. this.input = String(input);
  445. // Used to signal to callers of `readWord1` whether the word
  446. // contained any escape sequences. This is needed because words with
  447. // escape sequences must not be interpreted as keywords.
  448. this.containsEsc = false;
  449. // Set up token state
  450. // The current position of the tokenizer in the input.
  451. if (startPos) {
  452. this.pos = startPos;
  453. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  454. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  455. } else {
  456. this.pos = this.lineStart = 0;
  457. this.curLine = 1;
  458. }
  459. // Properties of the current token:
  460. // Its type
  461. this.type = types$1.eof;
  462. // For tokens that include more information than their type, the value
  463. this.value = null;
  464. // Its start and end offset
  465. this.start = this.end = this.pos;
  466. // And, if locations are used, the {line, column} object
  467. // corresponding to those offsets
  468. this.startLoc = this.endLoc = this.curPosition();
  469. // Position information for the previous token
  470. this.lastTokEndLoc = this.lastTokStartLoc = null;
  471. this.lastTokStart = this.lastTokEnd = this.pos;
  472. // The context stack is used to superficially track syntactic
  473. // context to predict whether a regular expression is allowed in a
  474. // given position.
  475. this.context = this.initialContext();
  476. this.exprAllowed = true;
  477. // Figure out if it's a module code.
  478. this.inModule = options.sourceType === "module";
  479. this.strict = this.inModule || this.strictDirective(this.pos);
  480. // Used to signify the start of a potential arrow function
  481. this.potentialArrowAt = -1;
  482. this.potentialArrowInForAwait = false;
  483. // Positions to delayed-check that yield/await does not exist in default parameters.
  484. this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
  485. // Labels in scope.
  486. this.labels = [];
  487. // Thus-far undefined exports.
  488. this.undefinedExports = Object.create(null);
  489. // If enabled, skip leading hashbang line.
  490. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  491. { this.skipLineComment(2); }
  492. // Scope tracking for duplicate variable names (see scope.js)
  493. this.scopeStack = [];
  494. this.enterScope(SCOPE_TOP);
  495. // For RegExp validation
  496. this.regexpState = null;
  497. // The stack of private names.
  498. // Each element has two properties: 'declared' and 'used'.
  499. // When it exited from the outermost class definition, all used private names must be declared.
  500. this.privateNameStack = [];
  501. };
  502. 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 } };
  503. Parser.prototype.parse = function parse () {
  504. var node = this.options.program || this.startNode();
  505. this.nextToken();
  506. return this.parseTopLevel(node)
  507. };
  508. prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
  509. prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 && !this.currentVarScope().inClassFieldInit };
  510. prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit };
  511. prototypeAccessors.canAwait.get = function () {
  512. for (var i = this.scopeStack.length - 1; i >= 0; i--) {
  513. var scope = this.scopeStack[i];
  514. if (scope.inClassFieldInit || scope.flags & SCOPE_CLASS_STATIC_BLOCK) { return false }
  515. if (scope.flags & SCOPE_FUNCTION) { return (scope.flags & SCOPE_ASYNC) > 0 }
  516. }
  517. return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction
  518. };
  519. prototypeAccessors.allowSuper.get = function () {
  520. var ref = this.currentThisScope();
  521. var flags = ref.flags;
  522. var inClassFieldInit = ref.inClassFieldInit;
  523. return (flags & SCOPE_SUPER) > 0 || inClassFieldInit || this.options.allowSuperOutsideMethod
  524. };
  525. prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
  526. prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
  527. prototypeAccessors.allowNewDotTarget.get = function () {
  528. var ref = this.currentThisScope();
  529. var flags = ref.flags;
  530. var inClassFieldInit = ref.inClassFieldInit;
  531. return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || inClassFieldInit
  532. };
  533. prototypeAccessors.inClassStaticBlock.get = function () {
  534. return (this.currentVarScope().flags & SCOPE_CLASS_STATIC_BLOCK) > 0
  535. };
  536. Parser.extend = function extend () {
  537. var plugins = [], len = arguments.length;
  538. while ( len-- ) plugins[ len ] = arguments[ len ];
  539. var cls = this;
  540. for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
  541. return cls
  542. };
  543. Parser.parse = function parse (input, options) {
  544. return new this(options, input).parse()
  545. };
  546. Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
  547. var parser = new this(options, input, pos);
  548. parser.nextToken();
  549. return parser.parseExpression()
  550. };
  551. Parser.tokenizer = function tokenizer (input, options) {
  552. return new this(options, input)
  553. };
  554. Object.defineProperties( Parser.prototype, prototypeAccessors );
  555. var pp$9 = Parser.prototype;
  556. // ## Parser utilities
  557. var literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/;
  558. pp$9.strictDirective = function(start) {
  559. if (this.options.ecmaVersion < 5) { return false }
  560. for (;;) {
  561. // Try to find string literal.
  562. skipWhiteSpace.lastIndex = start;
  563. start += skipWhiteSpace.exec(this.input)[0].length;
  564. var match = literal.exec(this.input.slice(start));
  565. if (!match) { return false }
  566. if ((match[1] || match[2]) === "use strict") {
  567. skipWhiteSpace.lastIndex = start + match[0].length;
  568. var spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length;
  569. var next = this.input.charAt(end);
  570. return next === ";" || next === "}" ||
  571. (lineBreak.test(spaceAfter[0]) &&
  572. !(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "="))
  573. }
  574. start += match[0].length;
  575. // Skip semicolon, if any.
  576. skipWhiteSpace.lastIndex = start;
  577. start += skipWhiteSpace.exec(this.input)[0].length;
  578. if (this.input[start] === ";")
  579. { start++; }
  580. }
  581. };
  582. // Predicate that tests whether the next token is of the given
  583. // type, and if yes, consumes it as a side effect.
  584. pp$9.eat = function(type) {
  585. if (this.type === type) {
  586. this.next();
  587. return true
  588. } else {
  589. return false
  590. }
  591. };
  592. // Tests whether parsed token is a contextual keyword.
  593. pp$9.isContextual = function(name) {
  594. return this.type === types$1.name && this.value === name && !this.containsEsc
  595. };
  596. // Consumes contextual keyword if possible.
  597. pp$9.eatContextual = function(name) {
  598. if (!this.isContextual(name)) { return false }
  599. this.next();
  600. return true
  601. };
  602. // Asserts that following token is given contextual keyword.
  603. pp$9.expectContextual = function(name) {
  604. if (!this.eatContextual(name)) { this.unexpected(); }
  605. };
  606. // Test whether a semicolon can be inserted at the current position.
  607. pp$9.canInsertSemicolon = function() {
  608. return this.type === types$1.eof ||
  609. this.type === types$1.braceR ||
  610. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  611. };
  612. pp$9.insertSemicolon = function() {
  613. if (this.canInsertSemicolon()) {
  614. if (this.options.onInsertedSemicolon)
  615. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  616. return true
  617. }
  618. };
  619. // Consume a semicolon, or, failing that, see if we are allowed to
  620. // pretend that there is a semicolon at this position.
  621. pp$9.semicolon = function() {
  622. if (!this.eat(types$1.semi) && !this.insertSemicolon()) { this.unexpected(); }
  623. };
  624. pp$9.afterTrailingComma = function(tokType, notNext) {
  625. if (this.type === tokType) {
  626. if (this.options.onTrailingComma)
  627. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  628. if (!notNext)
  629. { this.next(); }
  630. return true
  631. }
  632. };
  633. // Expect a token of a given type. If found, consume it, otherwise,
  634. // raise an unexpected token error.
  635. pp$9.expect = function(type) {
  636. this.eat(type) || this.unexpected();
  637. };
  638. // Raise an unexpected token error.
  639. pp$9.unexpected = function(pos) {
  640. this.raise(pos != null ? pos : this.start, "Unexpected token");
  641. };
  642. var DestructuringErrors = function DestructuringErrors() {
  643. this.shorthandAssign =
  644. this.trailingComma =
  645. this.parenthesizedAssign =
  646. this.parenthesizedBind =
  647. this.doubleProto =
  648. -1;
  649. };
  650. pp$9.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  651. if (!refDestructuringErrors) { return }
  652. if (refDestructuringErrors.trailingComma > -1)
  653. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  654. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  655. if (parens > -1) { this.raiseRecoverable(parens, isAssign ? "Assigning to rvalue" : "Parenthesized pattern"); }
  656. };
  657. pp$9.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  658. if (!refDestructuringErrors) { return false }
  659. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  660. var doubleProto = refDestructuringErrors.doubleProto;
  661. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  662. if (shorthandAssign >= 0)
  663. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  664. if (doubleProto >= 0)
  665. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  666. };
  667. pp$9.checkYieldAwaitInDefaultParams = function() {
  668. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  669. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  670. if (this.awaitPos)
  671. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  672. };
  673. pp$9.isSimpleAssignTarget = function(expr) {
  674. if (expr.type === "ParenthesizedExpression")
  675. { return this.isSimpleAssignTarget(expr.expression) }
  676. return expr.type === "Identifier" || expr.type === "MemberExpression"
  677. };
  678. var pp$8 = Parser.prototype;
  679. // ### Statement parsing
  680. // Parse a program. Initializes the parser, reads any number of
  681. // statements, and wraps them in a Program node. Optionally takes a
  682. // `program` argument. If present, the statements will be appended
  683. // to its body instead of creating a new node.
  684. pp$8.parseTopLevel = function(node) {
  685. var exports = Object.create(null);
  686. if (!node.body) { node.body = []; }
  687. while (this.type !== types$1.eof) {
  688. var stmt = this.parseStatement(null, true, exports);
  689. node.body.push(stmt);
  690. }
  691. if (this.inModule)
  692. { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
  693. {
  694. var name = list[i];
  695. this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
  696. } }
  697. this.adaptDirectivePrologue(node.body);
  698. this.next();
  699. node.sourceType = this.options.sourceType;
  700. return this.finishNode(node, "Program")
  701. };
  702. var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
  703. pp$8.isLet = function(context) {
  704. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  705. skipWhiteSpace.lastIndex = this.pos;
  706. var skip = skipWhiteSpace.exec(this.input);
  707. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  708. // For ambiguous cases, determine if a LexicalDeclaration (or only a
  709. // Statement) is allowed here. If context is not empty then only a Statement
  710. // is allowed. However, `let [` is an explicit negative lookahead for
  711. // ExpressionStatement, so special-case it first.
  712. if (nextCh === 91 || nextCh === 92) { return true } // '[', '/'
  713. if (context) { return false }
  714. if (nextCh === 123 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true } // '{', astral
  715. if (isIdentifierStart(nextCh, true)) {
  716. var pos = next + 1;
  717. while (isIdentifierChar(nextCh = this.input.charCodeAt(pos), true)) { ++pos; }
  718. if (nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true }
  719. var ident = this.input.slice(next, pos);
  720. if (!keywordRelationalOperator.test(ident)) { return true }
  721. }
  722. return false
  723. };
  724. // check 'async [no LineTerminator here] function'
  725. // - 'async /*foo*/ function' is OK.
  726. // - 'async /*\n*/ function' is invalid.
  727. pp$8.isAsyncFunction = function() {
  728. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  729. { return false }
  730. skipWhiteSpace.lastIndex = this.pos;
  731. var skip = skipWhiteSpace.exec(this.input);
  732. var next = this.pos + skip[0].length, after;
  733. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  734. this.input.slice(next, next + 8) === "function" &&
  735. (next + 8 === this.input.length ||
  736. !(isIdentifierChar(after = this.input.charCodeAt(next + 8)) || after > 0xd7ff && after < 0xdc00))
  737. };
  738. // Parse a single statement.
  739. //
  740. // If expecting a statement and finding a slash operator, parse a
  741. // regular expression literal. This is to handle cases like
  742. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  743. // does not help.
  744. pp$8.parseStatement = function(context, topLevel, exports) {
  745. var starttype = this.type, node = this.startNode(), kind;
  746. if (this.isLet(context)) {
  747. starttype = types$1._var;
  748. kind = "let";
  749. }
  750. // Most types of statements are recognized by the keyword they
  751. // start with. Many are trivial to parse, some require a bit of
  752. // complexity.
  753. switch (starttype) {
  754. case types$1._break: case types$1._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  755. case types$1._debugger: return this.parseDebuggerStatement(node)
  756. case types$1._do: return this.parseDoStatement(node)
  757. case types$1._for: return this.parseForStatement(node)
  758. case types$1._function:
  759. // Function as sole body of either an if statement or a labeled statement
  760. // works, but not when it is part of a labeled statement that is the sole
  761. // body of an if statement.
  762. if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
  763. return this.parseFunctionStatement(node, false, !context)
  764. case types$1._class:
  765. if (context) { this.unexpected(); }
  766. return this.parseClass(node, true)
  767. case types$1._if: return this.parseIfStatement(node)
  768. case types$1._return: return this.parseReturnStatement(node)
  769. case types$1._switch: return this.parseSwitchStatement(node)
  770. case types$1._throw: return this.parseThrowStatement(node)
  771. case types$1._try: return this.parseTryStatement(node)
  772. case types$1._const: case types$1._var:
  773. kind = kind || this.value;
  774. if (context && kind !== "var") { this.unexpected(); }
  775. return this.parseVarStatement(node, kind)
  776. case types$1._while: return this.parseWhileStatement(node)
  777. case types$1._with: return this.parseWithStatement(node)
  778. case types$1.braceL: return this.parseBlock(true, node)
  779. case types$1.semi: return this.parseEmptyStatement(node)
  780. case types$1._export:
  781. case types$1._import:
  782. if (this.options.ecmaVersion > 10 && starttype === types$1._import) {
  783. skipWhiteSpace.lastIndex = this.pos;
  784. var skip = skipWhiteSpace.exec(this.input);
  785. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  786. if (nextCh === 40 || nextCh === 46) // '(' or '.'
  787. { return this.parseExpressionStatement(node, this.parseExpression()) }
  788. }
  789. if (!this.options.allowImportExportEverywhere) {
  790. if (!topLevel)
  791. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  792. if (!this.inModule)
  793. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  794. }
  795. return starttype === types$1._import ? this.parseImport(node) : this.parseExport(node, exports)
  796. // If the statement does not start with a statement keyword or a
  797. // brace, it's an ExpressionStatement or LabeledStatement. We
  798. // simply start parsing an expression, and afterwards, if the
  799. // next token is a colon and the expression was a simple
  800. // Identifier node, we switch to interpreting it as a label.
  801. default:
  802. if (this.isAsyncFunction()) {
  803. if (context) { this.unexpected(); }
  804. this.next();
  805. return this.parseFunctionStatement(node, true, !context)
  806. }
  807. var maybeName = this.value, expr = this.parseExpression();
  808. if (starttype === types$1.name && expr.type === "Identifier" && this.eat(types$1.colon))
  809. { return this.parseLabeledStatement(node, maybeName, expr, context) }
  810. else { return this.parseExpressionStatement(node, expr) }
  811. }
  812. };
  813. pp$8.parseBreakContinueStatement = function(node, keyword) {
  814. var isBreak = keyword === "break";
  815. this.next();
  816. if (this.eat(types$1.semi) || this.insertSemicolon()) { node.label = null; }
  817. else if (this.type !== types$1.name) { this.unexpected(); }
  818. else {
  819. node.label = this.parseIdent();
  820. this.semicolon();
  821. }
  822. // Verify that there is an actual destination to break or
  823. // continue to.
  824. var i = 0;
  825. for (; i < this.labels.length; ++i) {
  826. var lab = this.labels[i];
  827. if (node.label == null || lab.name === node.label.name) {
  828. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  829. if (node.label && isBreak) { break }
  830. }
  831. }
  832. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  833. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  834. };
  835. pp$8.parseDebuggerStatement = function(node) {
  836. this.next();
  837. this.semicolon();
  838. return this.finishNode(node, "DebuggerStatement")
  839. };
  840. pp$8.parseDoStatement = function(node) {
  841. this.next();
  842. this.labels.push(loopLabel);
  843. node.body = this.parseStatement("do");
  844. this.labels.pop();
  845. this.expect(types$1._while);
  846. node.test = this.parseParenExpression();
  847. if (this.options.ecmaVersion >= 6)
  848. { this.eat(types$1.semi); }
  849. else
  850. { this.semicolon(); }
  851. return this.finishNode(node, "DoWhileStatement")
  852. };
  853. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  854. // loop is non-trivial. Basically, we have to parse the init `var`
  855. // statement or expression, disallowing the `in` operator (see
  856. // the second parameter to `parseExpression`), and then check
  857. // whether the next token is `in` or `of`. When there is no init
  858. // part (semicolon immediately after the opening parenthesis), it
  859. // is a regular `for` loop.
  860. pp$8.parseForStatement = function(node) {
  861. this.next();
  862. var awaitAt = (this.options.ecmaVersion >= 9 && this.canAwait && this.eatContextual("await")) ? this.lastTokStart : -1;
  863. this.labels.push(loopLabel);
  864. this.enterScope(0);
  865. this.expect(types$1.parenL);
  866. if (this.type === types$1.semi) {
  867. if (awaitAt > -1) { this.unexpected(awaitAt); }
  868. return this.parseFor(node, null)
  869. }
  870. var isLet = this.isLet();
  871. if (this.type === types$1._var || this.type === types$1._const || isLet) {
  872. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  873. this.next();
  874. this.parseVar(init$1, true, kind);
  875. this.finishNode(init$1, "VariableDeclaration");
  876. if ((this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
  877. if (this.options.ecmaVersion >= 9) {
  878. if (this.type === types$1._in) {
  879. if (awaitAt > -1) { this.unexpected(awaitAt); }
  880. } else { node.await = awaitAt > -1; }
  881. }
  882. return this.parseForIn(node, init$1)
  883. }
  884. if (awaitAt > -1) { this.unexpected(awaitAt); }
  885. return this.parseFor(node, init$1)
  886. }
  887. var startsWithLet = this.isContextual("let"), isForOf = false;
  888. var refDestructuringErrors = new DestructuringErrors;
  889. var init = this.parseExpression(awaitAt > -1 ? "await" : true, refDestructuringErrors);
  890. if (this.type === types$1._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  891. if (this.options.ecmaVersion >= 9) {
  892. if (this.type === types$1._in) {
  893. if (awaitAt > -1) { this.unexpected(awaitAt); }
  894. } else { node.await = awaitAt > -1; }
  895. }
  896. if (startsWithLet && isForOf) { this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); }
  897. this.toAssignable(init, false, refDestructuringErrors);
  898. this.checkLValPattern(init);
  899. return this.parseForIn(node, init)
  900. } else {
  901. this.checkExpressionErrors(refDestructuringErrors, true);
  902. }
  903. if (awaitAt > -1) { this.unexpected(awaitAt); }
  904. return this.parseFor(node, init)
  905. };
  906. pp$8.parseFunctionStatement = function(node, isAsync, declarationPosition) {
  907. this.next();
  908. return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
  909. };
  910. pp$8.parseIfStatement = function(node) {
  911. this.next();
  912. node.test = this.parseParenExpression();
  913. // allow function declarations in branches, but only in non-strict mode
  914. node.consequent = this.parseStatement("if");
  915. node.alternate = this.eat(types$1._else) ? this.parseStatement("if") : null;
  916. return this.finishNode(node, "IfStatement")
  917. };
  918. pp$8.parseReturnStatement = function(node) {
  919. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  920. { this.raise(this.start, "'return' outside of function"); }
  921. this.next();
  922. // In `return` (and `break`/`continue`), the keywords with
  923. // optional arguments, we eagerly look for a semicolon or the
  924. // possibility to insert one.
  925. if (this.eat(types$1.semi) || this.insertSemicolon()) { node.argument = null; }
  926. else { node.argument = this.parseExpression(); this.semicolon(); }
  927. return this.finishNode(node, "ReturnStatement")
  928. };
  929. pp$8.parseSwitchStatement = function(node) {
  930. this.next();
  931. node.discriminant = this.parseParenExpression();
  932. node.cases = [];
  933. this.expect(types$1.braceL);
  934. this.labels.push(switchLabel);
  935. this.enterScope(0);
  936. // Statements under must be grouped (by label) in SwitchCase
  937. // nodes. `cur` is used to keep the node that we are currently
  938. // adding statements to.
  939. var cur;
  940. for (var sawDefault = false; this.type !== types$1.braceR;) {
  941. if (this.type === types$1._case || this.type === types$1._default) {
  942. var isCase = this.type === types$1._case;
  943. if (cur) { this.finishNode(cur, "SwitchCase"); }
  944. node.cases.push(cur = this.startNode());
  945. cur.consequent = [];
  946. this.next();
  947. if (isCase) {
  948. cur.test = this.parseExpression();
  949. } else {
  950. if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
  951. sawDefault = true;
  952. cur.test = null;
  953. }
  954. this.expect(types$1.colon);
  955. } else {
  956. if (!cur) { this.unexpected(); }
  957. cur.consequent.push(this.parseStatement(null));
  958. }
  959. }
  960. this.exitScope();
  961. if (cur) { this.finishNode(cur, "SwitchCase"); }
  962. this.next(); // Closing brace
  963. this.labels.pop();
  964. return this.finishNode(node, "SwitchStatement")
  965. };
  966. pp$8.parseThrowStatement = function(node) {
  967. this.next();
  968. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  969. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  970. node.argument = this.parseExpression();
  971. this.semicolon();
  972. return this.finishNode(node, "ThrowStatement")
  973. };
  974. // Reused empty array added for node fields that are always empty.
  975. var empty$1 = [];
  976. pp$8.parseTryStatement = function(node) {
  977. this.next();
  978. node.block = this.parseBlock();
  979. node.handler = null;
  980. if (this.type === types$1._catch) {
  981. var clause = this.startNode();
  982. this.next();
  983. if (this.eat(types$1.parenL)) {
  984. clause.param = this.parseBindingAtom();
  985. var simple = clause.param.type === "Identifier";
  986. this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
  987. this.checkLValPattern(clause.param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
  988. this.expect(types$1.parenR);
  989. } else {
  990. if (this.options.ecmaVersion < 10) { this.unexpected(); }
  991. clause.param = null;
  992. this.enterScope(0);
  993. }
  994. clause.body = this.parseBlock(false);
  995. this.exitScope();
  996. node.handler = this.finishNode(clause, "CatchClause");
  997. }
  998. node.finalizer = this.eat(types$1._finally) ? this.parseBlock() : null;
  999. if (!node.handler && !node.finalizer)
  1000. { this.raise(node.start, "Missing catch or finally clause"); }
  1001. return this.finishNode(node, "TryStatement")
  1002. };
  1003. pp$8.parseVarStatement = function(node, kind) {
  1004. this.next();
  1005. this.parseVar(node, false, kind);
  1006. this.semicolon();
  1007. return this.finishNode(node, "VariableDeclaration")
  1008. };
  1009. pp$8.parseWhileStatement = function(node) {
  1010. this.next();
  1011. node.test = this.parseParenExpression();
  1012. this.labels.push(loopLabel);
  1013. node.body = this.parseStatement("while");
  1014. this.labels.pop();
  1015. return this.finishNode(node, "WhileStatement")
  1016. };
  1017. pp$8.parseWithStatement = function(node) {
  1018. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  1019. this.next();
  1020. node.object = this.parseParenExpression();
  1021. node.body = this.parseStatement("with");
  1022. return this.finishNode(node, "WithStatement")
  1023. };
  1024. pp$8.parseEmptyStatement = function(node) {
  1025. this.next();
  1026. return this.finishNode(node, "EmptyStatement")
  1027. };
  1028. pp$8.parseLabeledStatement = function(node, maybeName, expr, context) {
  1029. for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
  1030. {
  1031. var label = list[i$1];
  1032. if (label.name === maybeName)
  1033. { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
  1034. } }
  1035. var kind = this.type.isLoop ? "loop" : this.type === types$1._switch ? "switch" : null;
  1036. for (var i = this.labels.length - 1; i >= 0; i--) {
  1037. var label$1 = this.labels[i];
  1038. if (label$1.statementStart === node.start) {
  1039. // Update information about previous labels on this node
  1040. label$1.statementStart = this.start;
  1041. label$1.kind = kind;
  1042. } else { break }
  1043. }
  1044. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  1045. node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
  1046. this.labels.pop();
  1047. node.label = expr;
  1048. return this.finishNode(node, "LabeledStatement")
  1049. };
  1050. pp$8.parseExpressionStatement = function(node, expr) {
  1051. node.expression = expr;
  1052. this.semicolon();
  1053. return this.finishNode(node, "ExpressionStatement")
  1054. };
  1055. // Parse a semicolon-enclosed block of statements, handling `"use
  1056. // strict"` declarations when `allowStrict` is true (used for
  1057. // function bodies).
  1058. pp$8.parseBlock = function(createNewLexicalScope, node, exitStrict) {
  1059. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  1060. if ( node === void 0 ) node = this.startNode();
  1061. node.body = [];
  1062. this.expect(types$1.braceL);
  1063. if (createNewLexicalScope) { this.enterScope(0); }
  1064. while (this.type !== types$1.braceR) {
  1065. var stmt = this.parseStatement(null);
  1066. node.body.push(stmt);
  1067. }
  1068. if (exitStrict) { this.strict = false; }
  1069. this.next();
  1070. if (createNewLexicalScope) { this.exitScope(); }
  1071. return this.finishNode(node, "BlockStatement")
  1072. };
  1073. // Parse a regular `for` loop. The disambiguation code in
  1074. // `parseStatement` will already have parsed the init statement or
  1075. // expression.
  1076. pp$8.parseFor = function(node, init) {
  1077. node.init = init;
  1078. this.expect(types$1.semi);
  1079. node.test = this.type === types$1.semi ? null : this.parseExpression();
  1080. this.expect(types$1.semi);
  1081. node.update = this.type === types$1.parenR ? null : this.parseExpression();
  1082. this.expect(types$1.parenR);
  1083. node.body = this.parseStatement("for");
  1084. this.exitScope();
  1085. this.labels.pop();
  1086. return this.finishNode(node, "ForStatement")
  1087. };
  1088. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  1089. // same from parser's perspective.
  1090. pp$8.parseForIn = function(node, init) {
  1091. var isForIn = this.type === types$1._in;
  1092. this.next();
  1093. if (
  1094. init.type === "VariableDeclaration" &&
  1095. init.declarations[0].init != null &&
  1096. (
  1097. !isForIn ||
  1098. this.options.ecmaVersion < 8 ||
  1099. this.strict ||
  1100. init.kind !== "var" ||
  1101. init.declarations[0].id.type !== "Identifier"
  1102. )
  1103. ) {
  1104. this.raise(
  1105. init.start,
  1106. ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
  1107. );
  1108. }
  1109. node.left = init;
  1110. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
  1111. this.expect(types$1.parenR);
  1112. node.body = this.parseStatement("for");
  1113. this.exitScope();
  1114. this.labels.pop();
  1115. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
  1116. };
  1117. // Parse a list of variable declarations.
  1118. pp$8.parseVar = function(node, isFor, kind) {
  1119. node.declarations = [];
  1120. node.kind = kind;
  1121. for (;;) {
  1122. var decl = this.startNode();
  1123. this.parseVarId(decl, kind);
  1124. if (this.eat(types$1.eq)) {
  1125. decl.init = this.parseMaybeAssign(isFor);
  1126. } else if (kind === "const" && !(this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
  1127. this.unexpected();
  1128. } else if (decl.id.type !== "Identifier" && !(isFor && (this.type === types$1._in || this.isContextual("of")))) {
  1129. this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
  1130. } else {
  1131. decl.init = null;
  1132. }
  1133. node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
  1134. if (!this.eat(types$1.comma)) { break }
  1135. }
  1136. return node
  1137. };
  1138. pp$8.parseVarId = function(decl, kind) {
  1139. decl.id = this.parseBindingAtom();
  1140. this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
  1141. };
  1142. var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
  1143. // Parse a function declaration or literal (depending on the
  1144. // `statement & FUNC_STATEMENT`).
  1145. // Remove `allowExpressionBody` for 7.0.0, as it is only called with false
  1146. pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, forInit) {
  1147. this.initFunction(node);
  1148. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
  1149. if (this.type === types$1.star && (statement & FUNC_HANGING_STATEMENT))
  1150. { this.unexpected(); }
  1151. node.generator = this.eat(types$1.star);
  1152. }
  1153. if (this.options.ecmaVersion >= 8)
  1154. { node.async = !!isAsync; }
  1155. if (statement & FUNC_STATEMENT) {
  1156. node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types$1.name ? null : this.parseIdent();
  1157. if (node.id && !(statement & FUNC_HANGING_STATEMENT))
  1158. // If it is a regular function declaration in sloppy mode, then it is
  1159. // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
  1160. // mode depends on properties of the current scope (see
  1161. // treatFunctionsAsVar).
  1162. { this.checkLValSimple(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
  1163. }
  1164. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  1165. this.yieldPos = 0;
  1166. this.awaitPos = 0;
  1167. this.awaitIdentPos = 0;
  1168. this.enterScope(functionFlags(node.async, node.generator));
  1169. if (!(statement & FUNC_STATEMENT))
  1170. { node.id = this.type === types$1.name ? this.parseIdent() : null; }
  1171. this.parseFunctionParams(node);
  1172. this.parseFunctionBody(node, allowExpressionBody, false, forInit);
  1173. this.yieldPos = oldYieldPos;
  1174. this.awaitPos = oldAwaitPos;
  1175. this.awaitIdentPos = oldAwaitIdentPos;
  1176. return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
  1177. };
  1178. pp$8.parseFunctionParams = function(node) {
  1179. this.expect(types$1.parenL);
  1180. node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8);
  1181. this.checkYieldAwaitInDefaultParams();
  1182. };
  1183. // Parse a class declaration or literal (depending on the
  1184. // `isStatement` parameter).
  1185. pp$8.parseClass = function(node, isStatement) {
  1186. this.next();
  1187. // ecma-262 14.6 Class Definitions
  1188. // A class definition is always strict mode code.
  1189. var oldStrict = this.strict;
  1190. this.strict = true;
  1191. this.parseClassId(node, isStatement);
  1192. this.parseClassSuper(node);
  1193. var privateNameMap = this.enterClassBody();
  1194. var classBody = this.startNode();
  1195. var hadConstructor = false;
  1196. classBody.body = [];
  1197. this.expect(types$1.braceL);
  1198. while (this.type !== types$1.braceR) {
  1199. var element = this.parseClassElement(node.superClass !== null);
  1200. if (element) {
  1201. classBody.body.push(element);
  1202. if (element.type === "MethodDefinition" && element.kind === "constructor") {
  1203. if (hadConstructor) { this.raise(element.start, "Duplicate constructor in the same class"); }
  1204. hadConstructor = true;
  1205. } else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) {
  1206. this.raiseRecoverable(element.key.start, ("Identifier '#" + (element.key.name) + "' has already been declared"));
  1207. }
  1208. }
  1209. }
  1210. this.strict = oldStrict;
  1211. this.next();
  1212. node.body = this.finishNode(classBody, "ClassBody");
  1213. this.exitClassBody();
  1214. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1215. };
  1216. pp$8.parseClassElement = function(constructorAllowsSuper) {
  1217. if (this.eat(types$1.semi)) { return null }
  1218. var ecmaVersion = this.options.ecmaVersion;
  1219. var node = this.startNode();
  1220. var keyName = "";
  1221. var isGenerator = false;
  1222. var isAsync = false;
  1223. var kind = "method";
  1224. var isStatic = false;
  1225. if (this.eatContextual("static")) {
  1226. // Parse static init block
  1227. if (ecmaVersion >= 13 && this.eat(types$1.braceL)) {
  1228. this.parseClassStaticBlock(node);
  1229. return node
  1230. }
  1231. if (this.isClassElementNameStart() || this.type === types$1.star) {
  1232. isStatic = true;
  1233. } else {
  1234. keyName = "static";
  1235. }
  1236. }
  1237. node.static = isStatic;
  1238. if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) {
  1239. if ((this.isClassElementNameStart() || this.type === types$1.star) && !this.canInsertSemicolon()) {
  1240. isAsync = true;
  1241. } else {
  1242. keyName = "async";
  1243. }
  1244. }
  1245. if (!keyName && (ecmaVersion >= 9 || !isAsync) && this.eat(types$1.star)) {
  1246. isGenerator = true;
  1247. }
  1248. if (!keyName && !isAsync && !isGenerator) {
  1249. var lastValue = this.value;
  1250. if (this.eatContextual("get") || this.eatContextual("set")) {
  1251. if (this.isClassElementNameStart()) {
  1252. kind = lastValue;
  1253. } else {
  1254. keyName = lastValue;
  1255. }
  1256. }
  1257. }
  1258. // Parse element name
  1259. if (keyName) {
  1260. // 'async', 'get', 'set', or 'static' were not a keyword contextually.
  1261. // The last token is any of those. Make it the element name.
  1262. node.computed = false;
  1263. node.key = this.startNodeAt(this.lastTokStart, this.lastTokStartLoc);
  1264. node.key.name = keyName;
  1265. this.finishNode(node.key, "Identifier");
  1266. } else {
  1267. this.parseClassElementName(node);
  1268. }
  1269. // Parse element value
  1270. if (ecmaVersion < 13 || this.type === types$1.parenL || kind !== "method" || isGenerator || isAsync) {
  1271. var isConstructor = !node.static && checkKeyName(node, "constructor");
  1272. var allowsDirectSuper = isConstructor && constructorAllowsSuper;
  1273. // Couldn't move this check into the 'parseClassMethod' method for backward compatibility.
  1274. if (isConstructor && kind !== "method") { this.raise(node.key.start, "Constructor can't have get/set modifier"); }
  1275. node.kind = isConstructor ? "constructor" : kind;
  1276. this.parseClassMethod(node, isGenerator, isAsync, allowsDirectSuper);
  1277. } else {
  1278. this.parseClassField(node);
  1279. }
  1280. return node
  1281. };
  1282. pp$8.isClassElementNameStart = function() {
  1283. return (
  1284. this.type === types$1.name ||
  1285. this.type === types$1.privateId ||
  1286. this.type === types$1.num ||
  1287. this.type === types$1.string ||
  1288. this.type === types$1.bracketL ||
  1289. this.type.keyword
  1290. )
  1291. };
  1292. pp$8.parseClassElementName = function(element) {
  1293. if (this.type === types$1.privateId) {
  1294. if (this.value === "constructor") {
  1295. this.raise(this.start, "Classes can't have an element named '#constructor'");
  1296. }
  1297. element.computed = false;
  1298. element.key = this.parsePrivateIdent();
  1299. } else {
  1300. this.parsePropertyName(element);
  1301. }
  1302. };
  1303. pp$8.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
  1304. // Check key and flags
  1305. var key = method.key;
  1306. if (method.kind === "constructor") {
  1307. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1308. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1309. } else if (method.static && checkKeyName(method, "prototype")) {
  1310. this.raise(key.start, "Classes may not have a static property named prototype");
  1311. }
  1312. // Parse value
  1313. var value = method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
  1314. // Check value
  1315. if (method.kind === "get" && value.params.length !== 0)
  1316. { this.raiseRecoverable(value.start, "getter should have no params"); }
  1317. if (method.kind === "set" && value.params.length !== 1)
  1318. { this.raiseRecoverable(value.start, "setter should have exactly one param"); }
  1319. if (method.kind === "set" && value.params[0].type === "RestElement")
  1320. { this.raiseRecoverable(value.params[0].start, "Setter cannot use rest params"); }
  1321. return this.finishNode(method, "MethodDefinition")
  1322. };
  1323. pp$8.parseClassField = function(field) {
  1324. if (checkKeyName(field, "constructor")) {
  1325. this.raise(field.key.start, "Classes can't have a field named 'constructor'");
  1326. } else if (field.static && checkKeyName(field, "prototype")) {
  1327. this.raise(field.key.start, "Classes can't have a static field named 'prototype'");
  1328. }
  1329. if (this.eat(types$1.eq)) {
  1330. // To raise SyntaxError if 'arguments' exists in the initializer.
  1331. var scope = this.currentThisScope();
  1332. var inClassFieldInit = scope.inClassFieldInit;
  1333. scope.inClassFieldInit = true;
  1334. field.value = this.parseMaybeAssign();
  1335. scope.inClassFieldInit = inClassFieldInit;
  1336. } else {
  1337. field.value = null;
  1338. }
  1339. this.semicolon();
  1340. return this.finishNode(field, "PropertyDefinition")
  1341. };
  1342. pp$8.parseClassStaticBlock = function(node) {
  1343. node.body = [];
  1344. var oldLabels = this.labels;
  1345. this.labels = [];
  1346. this.enterScope(SCOPE_CLASS_STATIC_BLOCK | SCOPE_SUPER);
  1347. while (this.type !== types$1.braceR) {
  1348. var stmt = this.parseStatement(null);
  1349. node.body.push(stmt);
  1350. }
  1351. this.next();
  1352. this.exitScope();
  1353. this.labels = oldLabels;
  1354. return this.finishNode(node, "StaticBlock")
  1355. };
  1356. pp$8.parseClassId = function(node, isStatement) {
  1357. if (this.type === types$1.name) {
  1358. node.id = this.parseIdent();
  1359. if (isStatement)
  1360. { this.checkLValSimple(node.id, BIND_LEXICAL, false); }
  1361. } else {
  1362. if (isStatement === true)
  1363. { this.unexpected(); }
  1364. node.id = null;
  1365. }
  1366. };
  1367. pp$8.parseClassSuper = function(node) {
  1368. node.superClass = this.eat(types$1._extends) ? this.parseExprSubscripts(null, false) : null;
  1369. };
  1370. pp$8.enterClassBody = function() {
  1371. var element = {declared: Object.create(null), used: []};
  1372. this.privateNameStack.push(element);
  1373. return element.declared
  1374. };
  1375. pp$8.exitClassBody = function() {
  1376. var ref = this.privateNameStack.pop();
  1377. var declared = ref.declared;
  1378. var used = ref.used;
  1379. var len = this.privateNameStack.length;
  1380. var parent = len === 0 ? null : this.privateNameStack[len - 1];
  1381. for (var i = 0; i < used.length; ++i) {
  1382. var id = used[i];
  1383. if (!hasOwn(declared, id.name)) {
  1384. if (parent) {
  1385. parent.used.push(id);
  1386. } else {
  1387. this.raiseRecoverable(id.start, ("Private field '#" + (id.name) + "' must be declared in an enclosing class"));
  1388. }
  1389. }
  1390. }
  1391. };
  1392. function isPrivateNameConflicted(privateNameMap, element) {
  1393. var name = element.key.name;
  1394. var curr = privateNameMap[name];
  1395. var next = "true";
  1396. if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) {
  1397. next = (element.static ? "s" : "i") + element.kind;
  1398. }
  1399. // `class { get #a(){}; static set #a(_){} }` is also conflict.
  1400. if (
  1401. curr === "iget" && next === "iset" ||
  1402. curr === "iset" && next === "iget" ||
  1403. curr === "sget" && next === "sset" ||
  1404. curr === "sset" && next === "sget"
  1405. ) {
  1406. privateNameMap[name] = "true";
  1407. return false
  1408. } else if (!curr) {
  1409. privateNameMap[name] = next;
  1410. return false
  1411. } else {
  1412. return true
  1413. }
  1414. }
  1415. function checkKeyName(node, name) {
  1416. var computed = node.computed;
  1417. var key = node.key;
  1418. return !computed && (
  1419. key.type === "Identifier" && key.name === name ||
  1420. key.type === "Literal" && key.value === name
  1421. )
  1422. }
  1423. // Parses module export declaration.
  1424. pp$8.parseExport = function(node, exports) {
  1425. this.next();
  1426. // export * from '...'
  1427. if (this.eat(types$1.star)) {
  1428. if (this.options.ecmaVersion >= 11) {
  1429. if (this.eatContextual("as")) {
  1430. node.exported = this.parseModuleExportName();
  1431. this.checkExport(exports, node.exported, this.lastTokStart);
  1432. } else {
  1433. node.exported = null;
  1434. }
  1435. }
  1436. this.expectContextual("from");
  1437. if (this.type !== types$1.string) { this.unexpected(); }
  1438. node.source = this.parseExprAtom();
  1439. this.semicolon();
  1440. return this.finishNode(node, "ExportAllDeclaration")
  1441. }
  1442. if (this.eat(types$1._default)) { // export default ...
  1443. this.checkExport(exports, "default", this.lastTokStart);
  1444. var isAsync;
  1445. if (this.type === types$1._function || (isAsync = this.isAsyncFunction())) {
  1446. var fNode = this.startNode();
  1447. this.next();
  1448. if (isAsync) { this.next(); }
  1449. node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
  1450. } else if (this.type === types$1._class) {
  1451. var cNode = this.startNode();
  1452. node.declaration = this.parseClass(cNode, "nullableID");
  1453. } else {
  1454. node.declaration = this.parseMaybeAssign();
  1455. this.semicolon();
  1456. }
  1457. return this.finishNode(node, "ExportDefaultDeclaration")
  1458. }
  1459. // export var|const|let|function|class ...
  1460. if (this.shouldParseExportStatement()) {
  1461. node.declaration = this.parseStatement(null);
  1462. if (node.declaration.type === "VariableDeclaration")
  1463. { this.checkVariableExport(exports, node.declaration.declarations); }
  1464. else
  1465. { this.checkExport(exports, node.declaration.id, node.declaration.id.start); }
  1466. node.specifiers = [];
  1467. node.source = null;
  1468. } else { // export { x, y as z } [from '...']
  1469. node.declaration = null;
  1470. node.specifiers = this.parseExportSpecifiers(exports);
  1471. if (this.eatContextual("from")) {
  1472. if (this.type !== types$1.string) { this.unexpected(); }
  1473. node.source = this.parseExprAtom();
  1474. } else {
  1475. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1476. // check for keywords used as local names
  1477. var spec = list[i];
  1478. this.checkUnreserved(spec.local);
  1479. // check if export is defined
  1480. this.checkLocalExport(spec.local);
  1481. if (spec.local.type === "Literal") {
  1482. this.raise(spec.local.start, "A string literal cannot be used as an exported binding without `from`.");
  1483. }
  1484. }
  1485. node.source = null;
  1486. }
  1487. this.semicolon();
  1488. }
  1489. return this.finishNode(node, "ExportNamedDeclaration")
  1490. };
  1491. pp$8.checkExport = function(exports, name, pos) {
  1492. if (!exports) { return }
  1493. if (typeof name !== "string")
  1494. { name = name.type === "Identifier" ? name.name : name.value; }
  1495. if (hasOwn(exports, name))
  1496. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1497. exports[name] = true;
  1498. };
  1499. pp$8.checkPatternExport = function(exports, pat) {
  1500. var type = pat.type;
  1501. if (type === "Identifier")
  1502. { this.checkExport(exports, pat, pat.start); }
  1503. else if (type === "ObjectPattern")
  1504. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1505. {
  1506. var prop = list[i];
  1507. this.checkPatternExport(exports, prop);
  1508. } }
  1509. else if (type === "ArrayPattern")
  1510. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1511. var elt = list$1[i$1];
  1512. if (elt) { this.checkPatternExport(exports, elt); }
  1513. } }
  1514. else if (type === "Property")
  1515. { this.checkPatternExport(exports, pat.value); }
  1516. else if (type === "AssignmentPattern")
  1517. { this.checkPatternExport(exports, pat.left); }
  1518. else if (type === "RestElement")
  1519. { this.checkPatternExport(exports, pat.argument); }
  1520. else if (type === "ParenthesizedExpression")
  1521. { this.checkPatternExport(exports, pat.expression); }
  1522. };
  1523. pp$8.checkVariableExport = function(exports, decls) {
  1524. if (!exports) { return }
  1525. for (var i = 0, list = decls; i < list.length; i += 1)
  1526. {
  1527. var decl = list[i];
  1528. this.checkPatternExport(exports, decl.id);
  1529. }
  1530. };
  1531. pp$8.shouldParseExportStatement = function() {
  1532. return this.type.keyword === "var" ||
  1533. this.type.keyword === "const" ||
  1534. this.type.keyword === "class" ||
  1535. this.type.keyword === "function" ||
  1536. this.isLet() ||
  1537. this.isAsyncFunction()
  1538. };
  1539. // Parses a comma-separated list of module exports.
  1540. pp$8.parseExportSpecifiers = function(exports) {
  1541. var nodes = [], first = true;
  1542. // export { x, y as z } [from '...']
  1543. this.expect(types$1.braceL);
  1544. while (!this.eat(types$1.braceR)) {
  1545. if (!first) {
  1546. this.expect(types$1.comma);
  1547. if (this.afterTrailingComma(types$1.braceR)) { break }
  1548. } else { first = false; }
  1549. var node = this.startNode();
  1550. node.local = this.parseModuleExportName();
  1551. node.exported = this.eatContextual("as") ? this.parseModuleExportName() : node.local;
  1552. this.checkExport(
  1553. exports,
  1554. node.exported,
  1555. node.exported.start
  1556. );
  1557. nodes.push(this.finishNode(node, "ExportSpecifier"));
  1558. }
  1559. return nodes
  1560. };
  1561. // Parses import declaration.
  1562. pp$8.parseImport = function(node) {
  1563. this.next();
  1564. // import '...'
  1565. if (this.type === types$1.string) {
  1566. node.specifiers = empty$1;
  1567. node.source = this.parseExprAtom();
  1568. } else {
  1569. node.specifiers = this.parseImportSpecifiers();
  1570. this.expectContextual("from");
  1571. node.source = this.type === types$1.string ? this.parseExprAtom() : this.unexpected();
  1572. }
  1573. this.semicolon();
  1574. return this.finishNode(node, "ImportDeclaration")
  1575. };
  1576. // Parses a comma-separated list of module imports.
  1577. pp$8.parseImportSpecifiers = function() {
  1578. var nodes = [], first = true;
  1579. if (this.type === types$1.name) {
  1580. // import defaultObj, { x, y as z } from '...'
  1581. var node = this.startNode();
  1582. node.local = this.parseIdent();
  1583. this.checkLValSimple(node.local, BIND_LEXICAL);
  1584. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1585. if (!this.eat(types$1.comma)) { return nodes }
  1586. }
  1587. if (this.type === types$1.star) {
  1588. var node$1 = this.startNode();
  1589. this.next();
  1590. this.expectContextual("as");
  1591. node$1.local = this.parseIdent();
  1592. this.checkLValSimple(node$1.local, BIND_LEXICAL);
  1593. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1594. return nodes
  1595. }
  1596. this.expect(types$1.braceL);
  1597. while (!this.eat(types$1.braceR)) {
  1598. if (!first) {
  1599. this.expect(types$1.comma);
  1600. if (this.afterTrailingComma(types$1.braceR)) { break }
  1601. } else { first = false; }
  1602. var node$2 = this.startNode();
  1603. node$2.imported = this.parseModuleExportName();
  1604. if (this.eatContextual("as")) {
  1605. node$2.local = this.parseIdent();
  1606. } else {
  1607. this.checkUnreserved(node$2.imported);
  1608. node$2.local = node$2.imported;
  1609. }
  1610. this.checkLValSimple(node$2.local, BIND_LEXICAL);
  1611. nodes.push(this.finishNode(node$2, "ImportSpecifier"));
  1612. }
  1613. return nodes
  1614. };
  1615. pp$8.parseModuleExportName = function() {
  1616. if (this.options.ecmaVersion >= 13 && this.type === types$1.string) {
  1617. var stringLiteral = this.parseLiteral(this.value);
  1618. if (loneSurrogate.test(stringLiteral.value)) {
  1619. this.raise(stringLiteral.start, "An export name cannot include a lone surrogate.");
  1620. }
  1621. return stringLiteral
  1622. }
  1623. return this.parseIdent(true)
  1624. };
  1625. // Set `ExpressionStatement#directive` property for directive prologues.
  1626. pp$8.adaptDirectivePrologue = function(statements) {
  1627. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1628. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1629. }
  1630. };
  1631. pp$8.isDirectiveCandidate = function(statement) {
  1632. return (
  1633. this.options.ecmaVersion >= 5 &&
  1634. statement.type === "ExpressionStatement" &&
  1635. statement.expression.type === "Literal" &&
  1636. typeof statement.expression.value === "string" &&
  1637. // Reject parenthesized strings.
  1638. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1639. )
  1640. };
  1641. var pp$7 = Parser.prototype;
  1642. // Convert existing expression atom to assignable pattern
  1643. // if possible.
  1644. pp$7.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1645. if (this.options.ecmaVersion >= 6 && node) {
  1646. switch (node.type) {
  1647. case "Identifier":
  1648. if (this.inAsync && node.name === "await")
  1649. { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
  1650. break
  1651. case "ObjectPattern":
  1652. case "ArrayPattern":
  1653. case "AssignmentPattern":
  1654. case "RestElement":
  1655. break
  1656. case "ObjectExpression":
  1657. node.type = "ObjectPattern";
  1658. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1659. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1660. var prop = list[i];
  1661. this.toAssignable(prop, isBinding);
  1662. // Early error:
  1663. // AssignmentRestProperty[Yield, Await] :
  1664. // `...` DestructuringAssignmentTarget[Yield, Await]
  1665. //
  1666. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1667. if (
  1668. prop.type === "RestElement" &&
  1669. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1670. ) {
  1671. this.raise(prop.argument.start, "Unexpected token");
  1672. }
  1673. }
  1674. break
  1675. case "Property":
  1676. // AssignmentProperty has type === "Property"
  1677. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1678. this.toAssignable(node.value, isBinding);
  1679. break
  1680. case "ArrayExpression":
  1681. node.type = "ArrayPattern";
  1682. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1683. this.toAssignableList(node.elements, isBinding);
  1684. break
  1685. case "SpreadElement":
  1686. node.type = "RestElement";
  1687. this.toAssignable(node.argument, isBinding);
  1688. if (node.argument.type === "AssignmentPattern")
  1689. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1690. break
  1691. case "AssignmentExpression":
  1692. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1693. node.type = "AssignmentPattern";
  1694. delete node.operator;
  1695. this.toAssignable(node.left, isBinding);
  1696. break
  1697. case "ParenthesizedExpression":
  1698. this.toAssignable(node.expression, isBinding, refDestructuringErrors);
  1699. break
  1700. case "ChainExpression":
  1701. this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side");
  1702. break
  1703. case "MemberExpression":
  1704. if (!isBinding) { break }
  1705. default:
  1706. this.raise(node.start, "Assigning to rvalue");
  1707. }
  1708. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1709. return node
  1710. };
  1711. // Convert list of expression atoms to binding list.
  1712. pp$7.toAssignableList = function(exprList, isBinding) {
  1713. var end = exprList.length;
  1714. for (var i = 0; i < end; i++) {
  1715. var elt = exprList[i];
  1716. if (elt) { this.toAssignable(elt, isBinding); }
  1717. }
  1718. if (end) {
  1719. var last = exprList[end - 1];
  1720. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1721. { this.unexpected(last.argument.start); }
  1722. }
  1723. return exprList
  1724. };
  1725. // Parses spread element.
  1726. pp$7.parseSpread = function(refDestructuringErrors) {
  1727. var node = this.startNode();
  1728. this.next();
  1729. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1730. return this.finishNode(node, "SpreadElement")
  1731. };
  1732. pp$7.parseRestBinding = function() {
  1733. var node = this.startNode();
  1734. this.next();
  1735. // RestElement inside of a function parameter must be an identifier
  1736. if (this.options.ecmaVersion === 6 && this.type !== types$1.name)
  1737. { this.unexpected(); }
  1738. node.argument = this.parseBindingAtom();
  1739. return this.finishNode(node, "RestElement")
  1740. };
  1741. // Parses lvalue (assignable) atom.
  1742. pp$7.parseBindingAtom = function() {
  1743. if (this.options.ecmaVersion >= 6) {
  1744. switch (this.type) {
  1745. case types$1.bracketL:
  1746. var node = this.startNode();
  1747. this.next();
  1748. node.elements = this.parseBindingList(types$1.bracketR, true, true);
  1749. return this.finishNode(node, "ArrayPattern")
  1750. case types$1.braceL:
  1751. return this.parseObj(true)
  1752. }
  1753. }
  1754. return this.parseIdent()
  1755. };
  1756. pp$7.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1757. var elts = [], first = true;
  1758. while (!this.eat(close)) {
  1759. if (first) { first = false; }
  1760. else { this.expect(types$1.comma); }
  1761. if (allowEmpty && this.type === types$1.comma) {
  1762. elts.push(null);
  1763. } else if (allowTrailingComma && this.afterTrailingComma(close)) {
  1764. break
  1765. } else if (this.type === types$1.ellipsis) {
  1766. var rest = this.parseRestBinding();
  1767. this.parseBindingListItem(rest);
  1768. elts.push(rest);
  1769. if (this.type === types$1.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
  1770. this.expect(close);
  1771. break
  1772. } else {
  1773. var elem = this.parseMaybeDefault(this.start, this.startLoc);
  1774. this.parseBindingListItem(elem);
  1775. elts.push(elem);
  1776. }
  1777. }
  1778. return elts
  1779. };
  1780. pp$7.parseBindingListItem = function(param) {
  1781. return param
  1782. };
  1783. // Parses assignment pattern around given atom if possible.
  1784. pp$7.parseMaybeDefault = function(startPos, startLoc, left) {
  1785. left = left || this.parseBindingAtom();
  1786. if (this.options.ecmaVersion < 6 || !this.eat(types$1.eq)) { return left }
  1787. var node = this.startNodeAt(startPos, startLoc);
  1788. node.left = left;
  1789. node.right = this.parseMaybeAssign();
  1790. return this.finishNode(node, "AssignmentPattern")
  1791. };
  1792. // The following three functions all verify that a node is an lvalue —
  1793. // something that can be bound, or assigned to. In order to do so, they perform
  1794. // a variety of checks:
  1795. //
  1796. // - Check that none of the bound/assigned-to identifiers are reserved words.
  1797. // - Record name declarations for bindings in the appropriate scope.
  1798. // - Check duplicate argument names, if checkClashes is set.
  1799. //
  1800. // If a complex binding pattern is encountered (e.g., object and array
  1801. // destructuring), the entire pattern is recursively checked.
  1802. //
  1803. // There are three versions of checkLVal*() appropriate for different
  1804. // circumstances:
  1805. //
  1806. // - checkLValSimple() shall be used if the syntactic construct supports
  1807. // nothing other than identifiers and member expressions. Parenthesized
  1808. // expressions are also correctly handled. This is generally appropriate for
  1809. // constructs for which the spec says
  1810. //
  1811. // > It is a Syntax Error if AssignmentTargetType of [the production] is not
  1812. // > simple.
  1813. //
  1814. // It is also appropriate for checking if an identifier is valid and not
  1815. // defined elsewhere, like import declarations or function/class identifiers.
  1816. //
  1817. // Examples where this is used include:
  1818. // a += …;
  1819. // import a from '…';
  1820. // where a is the node to be checked.
  1821. //
  1822. // - checkLValPattern() shall be used if the syntactic construct supports
  1823. // anything checkLValSimple() supports, as well as object and array
  1824. // destructuring patterns. This is generally appropriate for constructs for
  1825. // which the spec says
  1826. //
  1827. // > It is a Syntax Error if [the production] is neither an ObjectLiteral nor
  1828. // > an ArrayLiteral and AssignmentTargetType of [the production] is not
  1829. // > simple.
  1830. //
  1831. // Examples where this is used include:
  1832. // (a = …);
  1833. // const a = …;
  1834. // try { … } catch (a) { … }
  1835. // where a is the node to be checked.
  1836. //
  1837. // - checkLValInnerPattern() shall be used if the syntactic construct supports
  1838. // anything checkLValPattern() supports, as well as default assignment
  1839. // patterns, rest elements, and other constructs that may appear within an
  1840. // object or array destructuring pattern.
  1841. //
  1842. // As a special case, function parameters also use checkLValInnerPattern(),
  1843. // as they also support defaults and rest constructs.
  1844. //
  1845. // These functions deliberately support both assignment and binding constructs,
  1846. // as the logic for both is exceedingly similar. If the node is the target of
  1847. // an assignment, then bindingType should be set to BIND_NONE. Otherwise, it
  1848. // should be set to the appropriate BIND_* constant, like BIND_VAR or
  1849. // BIND_LEXICAL.
  1850. //
  1851. // If the function is called with a non-BIND_NONE bindingType, then
  1852. // additionally a checkClashes object may be specified to allow checking for
  1853. // duplicate argument names. checkClashes is ignored if the provided construct
  1854. // is an assignment (i.e., bindingType is BIND_NONE).
  1855. pp$7.checkLValSimple = function(expr, bindingType, checkClashes) {
  1856. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1857. var isBind = bindingType !== BIND_NONE;
  1858. switch (expr.type) {
  1859. case "Identifier":
  1860. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1861. { this.raiseRecoverable(expr.start, (isBind ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1862. if (isBind) {
  1863. if (bindingType === BIND_LEXICAL && expr.name === "let")
  1864. { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
  1865. if (checkClashes) {
  1866. if (hasOwn(checkClashes, expr.name))
  1867. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1868. checkClashes[expr.name] = true;
  1869. }
  1870. if (bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
  1871. }
  1872. break
  1873. case "ChainExpression":
  1874. this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side");
  1875. break
  1876. case "MemberExpression":
  1877. if (isBind) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  1878. break
  1879. case "ParenthesizedExpression":
  1880. if (isBind) { this.raiseRecoverable(expr.start, "Binding parenthesized expression"); }
  1881. return this.checkLValSimple(expr.expression, bindingType, checkClashes)
  1882. default:
  1883. this.raise(expr.start, (isBind ? "Binding" : "Assigning to") + " rvalue");
  1884. }
  1885. };
  1886. pp$7.checkLValPattern = function(expr, bindingType, checkClashes) {
  1887. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1888. switch (expr.type) {
  1889. case "ObjectPattern":
  1890. for (var i = 0, list = expr.properties; i < list.length; i += 1) {
  1891. var prop = list[i];
  1892. this.checkLValInnerPattern(prop, bindingType, checkClashes);
  1893. }
  1894. break
  1895. case "ArrayPattern":
  1896. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1897. var elem = list$1[i$1];
  1898. if (elem) { this.checkLValInnerPattern(elem, bindingType, checkClashes); }
  1899. }
  1900. break
  1901. default:
  1902. this.checkLValSimple(expr, bindingType, checkClashes);
  1903. }
  1904. };
  1905. pp$7.checkLValInnerPattern = function(expr, bindingType, checkClashes) {
  1906. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1907. switch (expr.type) {
  1908. case "Property":
  1909. // AssignmentProperty has type === "Property"
  1910. this.checkLValInnerPattern(expr.value, bindingType, checkClashes);
  1911. break
  1912. case "AssignmentPattern":
  1913. this.checkLValPattern(expr.left, bindingType, checkClashes);
  1914. break
  1915. case "RestElement":
  1916. this.checkLValPattern(expr.argument, bindingType, checkClashes);
  1917. break
  1918. default:
  1919. this.checkLValPattern(expr, bindingType, checkClashes);
  1920. }
  1921. };
  1922. // The algorithm used to determine whether a regexp can appear at a
  1923. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  1924. this.token = token;
  1925. this.isExpr = !!isExpr;
  1926. this.preserveSpace = !!preserveSpace;
  1927. this.override = override;
  1928. this.generator = !!generator;
  1929. };
  1930. var types = {
  1931. b_stat: new TokContext("{", false),
  1932. b_expr: new TokContext("{", true),
  1933. b_tmpl: new TokContext("${", false),
  1934. p_stat: new TokContext("(", false),
  1935. p_expr: new TokContext("(", true),
  1936. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  1937. f_stat: new TokContext("function", false),
  1938. f_expr: new TokContext("function", true),
  1939. f_expr_gen: new TokContext("function", true, false, null, true),
  1940. f_gen: new TokContext("function", false, false, null, true)
  1941. };
  1942. var pp$6 = Parser.prototype;
  1943. pp$6.initialContext = function() {
  1944. return [types.b_stat]
  1945. };
  1946. pp$6.curContext = function() {
  1947. return this.context[this.context.length - 1]
  1948. };
  1949. pp$6.braceIsBlock = function(prevType) {
  1950. var parent = this.curContext();
  1951. if (parent === types.f_expr || parent === types.f_stat)
  1952. { return true }
  1953. if (prevType === types$1.colon && (parent === types.b_stat || parent === types.b_expr))
  1954. { return !parent.isExpr }
  1955. // The check for `tt.name && exprAllowed` detects whether we are
  1956. // after a `yield` or `of` construct. See the `updateContext` for
  1957. // `tt.name`.
  1958. if (prevType === types$1._return || prevType === types$1.name && this.exprAllowed)
  1959. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  1960. if (prevType === types$1._else || prevType === types$1.semi || prevType === types$1.eof || prevType === types$1.parenR || prevType === types$1.arrow)
  1961. { return true }
  1962. if (prevType === types$1.braceL)
  1963. { return parent === types.b_stat }
  1964. if (prevType === types$1._var || prevType === types$1._const || prevType === types$1.name)
  1965. { return false }
  1966. return !this.exprAllowed
  1967. };
  1968. pp$6.inGeneratorContext = function() {
  1969. for (var i = this.context.length - 1; i >= 1; i--) {
  1970. var context = this.context[i];
  1971. if (context.token === "function")
  1972. { return context.generator }
  1973. }
  1974. return false
  1975. };
  1976. pp$6.updateContext = function(prevType) {
  1977. var update, type = this.type;
  1978. if (type.keyword && prevType === types$1.dot)
  1979. { this.exprAllowed = false; }
  1980. else if (update = type.updateContext)
  1981. { update.call(this, prevType); }
  1982. else
  1983. { this.exprAllowed = type.beforeExpr; }
  1984. };
  1985. // Used to handle egde cases when token context could not be inferred correctly during tokenization phase
  1986. pp$6.overrideContext = function(tokenCtx) {
  1987. if (this.curContext() !== tokenCtx) {
  1988. this.context[this.context.length - 1] = tokenCtx;
  1989. }
  1990. };
  1991. // Token-specific context update code
  1992. types$1.parenR.updateContext = types$1.braceR.updateContext = function() {
  1993. if (this.context.length === 1) {
  1994. this.exprAllowed = true;
  1995. return
  1996. }
  1997. var out = this.context.pop();
  1998. if (out === types.b_stat && this.curContext().token === "function") {
  1999. out = this.context.pop();
  2000. }
  2001. this.exprAllowed = !out.isExpr;
  2002. };
  2003. types$1.braceL.updateContext = function(prevType) {
  2004. this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
  2005. this.exprAllowed = true;
  2006. };
  2007. types$1.dollarBraceL.updateContext = function() {
  2008. this.context.push(types.b_tmpl);
  2009. this.exprAllowed = true;
  2010. };
  2011. types$1.parenL.updateContext = function(prevType) {
  2012. var statementParens = prevType === types$1._if || prevType === types$1._for || prevType === types$1._with || prevType === types$1._while;
  2013. this.context.push(statementParens ? types.p_stat : types.p_expr);
  2014. this.exprAllowed = true;
  2015. };
  2016. types$1.incDec.updateContext = function() {
  2017. // tokExprAllowed stays unchanged
  2018. };
  2019. types$1._function.updateContext = types$1._class.updateContext = function(prevType) {
  2020. if (prevType.beforeExpr && prevType !== types$1._else &&
  2021. !(prevType === types$1.semi && this.curContext() !== types.p_stat) &&
  2022. !(prevType === types$1._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
  2023. !((prevType === types$1.colon || prevType === types$1.braceL) && this.curContext() === types.b_stat))
  2024. { this.context.push(types.f_expr); }
  2025. else
  2026. { this.context.push(types.f_stat); }
  2027. this.exprAllowed = false;
  2028. };
  2029. types$1.backQuote.updateContext = function() {
  2030. if (this.curContext() === types.q_tmpl)
  2031. { this.context.pop(); }
  2032. else
  2033. { this.context.push(types.q_tmpl); }
  2034. this.exprAllowed = false;
  2035. };
  2036. types$1.star.updateContext = function(prevType) {
  2037. if (prevType === types$1._function) {
  2038. var index = this.context.length - 1;
  2039. if (this.context[index] === types.f_expr)
  2040. { this.context[index] = types.f_expr_gen; }
  2041. else
  2042. { this.context[index] = types.f_gen; }
  2043. }
  2044. this.exprAllowed = true;
  2045. };
  2046. types$1.name.updateContext = function(prevType) {
  2047. var allowed = false;
  2048. if (this.options.ecmaVersion >= 6 && prevType !== types$1.dot) {
  2049. if (this.value === "of" && !this.exprAllowed ||
  2050. this.value === "yield" && this.inGeneratorContext())
  2051. { allowed = true; }
  2052. }
  2053. this.exprAllowed = allowed;
  2054. };
  2055. // A recursive descent parser operates by defining functions for all
  2056. var pp$5 = Parser.prototype;
  2057. // Check if property name clashes with already added.
  2058. // Object/class getters and setters are not allowed to clash —
  2059. // either with each other or with an init property — and in
  2060. // strict mode, init properties are also not allowed to be repeated.
  2061. pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  2062. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  2063. { return }
  2064. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  2065. { return }
  2066. var key = prop.key;
  2067. var name;
  2068. switch (key.type) {
  2069. case "Identifier": name = key.name; break
  2070. case "Literal": name = String(key.value); break
  2071. default: return
  2072. }
  2073. var kind = prop.kind;
  2074. if (this.options.ecmaVersion >= 6) {
  2075. if (name === "__proto__" && kind === "init") {
  2076. if (propHash.proto) {
  2077. if (refDestructuringErrors) {
  2078. if (refDestructuringErrors.doubleProto < 0) {
  2079. refDestructuringErrors.doubleProto = key.start;
  2080. }
  2081. } else {
  2082. this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
  2083. }
  2084. }
  2085. propHash.proto = true;
  2086. }
  2087. return
  2088. }
  2089. name = "$" + name;
  2090. var other = propHash[name];
  2091. if (other) {
  2092. var redefinition;
  2093. if (kind === "init") {
  2094. redefinition = this.strict && other.init || other.get || other.set;
  2095. } else {
  2096. redefinition = other.init || other[kind];
  2097. }
  2098. if (redefinition)
  2099. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  2100. } else {
  2101. other = propHash[name] = {
  2102. init: false,
  2103. get: false,
  2104. set: false
  2105. };
  2106. }
  2107. other[kind] = true;
  2108. };
  2109. // ### Expression parsing
  2110. // These nest, from the most general expression type at the top to
  2111. // 'atomic', nondivisible expression types at the bottom. Most of
  2112. // the functions will simply let the function(s) below them parse,
  2113. // and, *if* the syntactic construct they handle is present, wrap
  2114. // the AST node that the inner parser gave them in another node.
  2115. // Parse a full expression. The optional arguments are used to
  2116. // forbid the `in` operator (in for loops initalization expressions)
  2117. // and provide reference for storing '=' operator inside shorthand
  2118. // property assignment in contexts where both object expression
  2119. // and object pattern might appear (so it's possible to raise
  2120. // delayed syntax error at correct position).
  2121. pp$5.parseExpression = function(forInit, refDestructuringErrors) {
  2122. var startPos = this.start, startLoc = this.startLoc;
  2123. var expr = this.parseMaybeAssign(forInit, refDestructuringErrors);
  2124. if (this.type === types$1.comma) {
  2125. var node = this.startNodeAt(startPos, startLoc);
  2126. node.expressions = [expr];
  2127. while (this.eat(types$1.comma)) { node.expressions.push(this.parseMaybeAssign(forInit, refDestructuringErrors)); }
  2128. return this.finishNode(node, "SequenceExpression")
  2129. }
  2130. return expr
  2131. };
  2132. // Parse an assignment expression. This includes applications of
  2133. // operators like `+=`.
  2134. pp$5.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) {
  2135. if (this.isContextual("yield")) {
  2136. if (this.inGenerator) { return this.parseYield(forInit) }
  2137. // The tokenizer will assume an expression is allowed after
  2138. // `yield`, but this isn't that kind of yield
  2139. else { this.exprAllowed = false; }
  2140. }
  2141. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldDoubleProto = -1;
  2142. if (refDestructuringErrors) {
  2143. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  2144. oldTrailingComma = refDestructuringErrors.trailingComma;
  2145. oldDoubleProto = refDestructuringErrors.doubleProto;
  2146. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  2147. } else {
  2148. refDestructuringErrors = new DestructuringErrors;
  2149. ownDestructuringErrors = true;
  2150. }
  2151. var startPos = this.start, startLoc = this.startLoc;
  2152. if (this.type === types$1.parenL || this.type === types$1.name) {
  2153. this.potentialArrowAt = this.start;
  2154. this.potentialArrowInForAwait = forInit === "await";
  2155. }
  2156. var left = this.parseMaybeConditional(forInit, refDestructuringErrors);
  2157. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  2158. if (this.type.isAssign) {
  2159. var node = this.startNodeAt(startPos, startLoc);
  2160. node.operator = this.value;
  2161. if (this.type === types$1.eq)
  2162. { left = this.toAssignable(left, false, refDestructuringErrors); }
  2163. if (!ownDestructuringErrors) {
  2164. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1;
  2165. }
  2166. if (refDestructuringErrors.shorthandAssign >= left.start)
  2167. { refDestructuringErrors.shorthandAssign = -1; } // reset because shorthand default was used correctly
  2168. if (this.type === types$1.eq)
  2169. { this.checkLValPattern(left); }
  2170. else
  2171. { this.checkLValSimple(left); }
  2172. node.left = left;
  2173. this.next();
  2174. node.right = this.parseMaybeAssign(forInit);
  2175. if (oldDoubleProto > -1) { refDestructuringErrors.doubleProto = oldDoubleProto; }
  2176. return this.finishNode(node, "AssignmentExpression")
  2177. } else {
  2178. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  2179. }
  2180. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  2181. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  2182. return left
  2183. };
  2184. // Parse a ternary conditional (`?:`) operator.
  2185. pp$5.parseMaybeConditional = function(forInit, refDestructuringErrors) {
  2186. var startPos = this.start, startLoc = this.startLoc;
  2187. var expr = this.parseExprOps(forInit, refDestructuringErrors);
  2188. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2189. if (this.eat(types$1.question)) {
  2190. var node = this.startNodeAt(startPos, startLoc);
  2191. node.test = expr;
  2192. node.consequent = this.parseMaybeAssign();
  2193. this.expect(types$1.colon);
  2194. node.alternate = this.parseMaybeAssign(forInit);
  2195. return this.finishNode(node, "ConditionalExpression")
  2196. }
  2197. return expr
  2198. };
  2199. // Start the precedence parser.
  2200. pp$5.parseExprOps = function(forInit, refDestructuringErrors) {
  2201. var startPos = this.start, startLoc = this.startLoc;
  2202. var expr = this.parseMaybeUnary(refDestructuringErrors, false, false, forInit);
  2203. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2204. return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, forInit)
  2205. };
  2206. // Parse binary operators with the operator precedence parsing
  2207. // algorithm. `left` is the left-hand side of the operator.
  2208. // `minPrec` provides context that allows the function to stop and
  2209. // defer further parser to one of its callers when it encounters an
  2210. // operator that has a lower precedence than the set it is parsing.
  2211. pp$5.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) {
  2212. var prec = this.type.binop;
  2213. if (prec != null && (!forInit || this.type !== types$1._in)) {
  2214. if (prec > minPrec) {
  2215. var logical = this.type === types$1.logicalOR || this.type === types$1.logicalAND;
  2216. var coalesce = this.type === types$1.coalesce;
  2217. if (coalesce) {
  2218. // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions.
  2219. // In other words, `node.right` shouldn't contain logical expressions in order to check the mixed error.
  2220. prec = types$1.logicalAND.binop;
  2221. }
  2222. var op = this.value;
  2223. this.next();
  2224. var startPos = this.start, startLoc = this.startLoc;
  2225. var right = this.parseExprOp(this.parseMaybeUnary(null, false, false, forInit), startPos, startLoc, prec, forInit);
  2226. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce);
  2227. if ((logical && this.type === types$1.coalesce) || (coalesce && (this.type === types$1.logicalOR || this.type === types$1.logicalAND))) {
  2228. this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses");
  2229. }
  2230. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, forInit)
  2231. }
  2232. }
  2233. return left
  2234. };
  2235. pp$5.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  2236. if (right.type === "PrivateIdentifier") { this.raise(right.start, "Private identifier can only be left side of binary expression"); }
  2237. var node = this.startNodeAt(startPos, startLoc);
  2238. node.left = left;
  2239. node.operator = op;
  2240. node.right = right;
  2241. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  2242. };
  2243. // Parse unary operators, both prefix and postfix.
  2244. pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit) {
  2245. var startPos = this.start, startLoc = this.startLoc, expr;
  2246. if (this.isContextual("await") && this.canAwait) {
  2247. expr = this.parseAwait(forInit);
  2248. sawUnary = true;
  2249. } else if (this.type.prefix) {
  2250. var node = this.startNode(), update = this.type === types$1.incDec;
  2251. node.operator = this.value;
  2252. node.prefix = true;
  2253. this.next();
  2254. node.argument = this.parseMaybeUnary(null, true, update, forInit);
  2255. this.checkExpressionErrors(refDestructuringErrors, true);
  2256. if (update) { this.checkLValSimple(node.argument); }
  2257. else if (this.strict && node.operator === "delete" &&
  2258. node.argument.type === "Identifier")
  2259. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  2260. else if (node.operator === "delete" && isPrivateFieldAccess(node.argument))
  2261. { this.raiseRecoverable(node.start, "Private fields can not be deleted"); }
  2262. else { sawUnary = true; }
  2263. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  2264. } else if (!sawUnary && this.type === types$1.privateId) {
  2265. if (forInit || this.privateNameStack.length === 0) { this.unexpected(); }
  2266. expr = this.parsePrivateIdent();
  2267. // only could be private fields in 'in', such as #x in obj
  2268. if (this.type !== types$1._in) { this.unexpected(); }
  2269. } else {
  2270. expr = this.parseExprSubscripts(refDestructuringErrors, forInit);
  2271. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2272. while (this.type.postfix && !this.canInsertSemicolon()) {
  2273. var node$1 = this.startNodeAt(startPos, startLoc);
  2274. node$1.operator = this.value;
  2275. node$1.prefix = false;
  2276. node$1.argument = expr;
  2277. this.checkLValSimple(expr);
  2278. this.next();
  2279. expr = this.finishNode(node$1, "UpdateExpression");
  2280. }
  2281. }
  2282. if (!incDec && this.eat(types$1.starstar)) {
  2283. if (sawUnary)
  2284. { this.unexpected(this.lastTokStart); }
  2285. else
  2286. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false) }
  2287. } else {
  2288. return expr
  2289. }
  2290. };
  2291. function isPrivateFieldAccess(node) {
  2292. return (
  2293. node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" ||
  2294. node.type === "ChainExpression" && isPrivateFieldAccess(node.expression)
  2295. )
  2296. }
  2297. // Parse call, dot, and `[]`-subscript expressions.
  2298. pp$5.parseExprSubscripts = function(refDestructuringErrors, forInit) {
  2299. var startPos = this.start, startLoc = this.startLoc;
  2300. var expr = this.parseExprAtom(refDestructuringErrors, forInit);
  2301. if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
  2302. { return expr }
  2303. var result = this.parseSubscripts(expr, startPos, startLoc, false, forInit);
  2304. if (refDestructuringErrors && result.type === "MemberExpression") {
  2305. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  2306. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  2307. if (refDestructuringErrors.trailingComma >= result.start) { refDestructuringErrors.trailingComma = -1; }
  2308. }
  2309. return result
  2310. };
  2311. pp$5.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit) {
  2312. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  2313. this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 &&
  2314. this.potentialArrowAt === base.start;
  2315. var optionalChained = false;
  2316. while (true) {
  2317. var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
  2318. if (element.optional) { optionalChained = true; }
  2319. if (element === base || element.type === "ArrowFunctionExpression") {
  2320. if (optionalChained) {
  2321. var chainNode = this.startNodeAt(startPos, startLoc);
  2322. chainNode.expression = element;
  2323. element = this.finishNode(chainNode, "ChainExpression");
  2324. }
  2325. return element
  2326. }
  2327. base = element;
  2328. }
  2329. };
  2330. pp$5.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) {
  2331. var optionalSupported = this.options.ecmaVersion >= 11;
  2332. var optional = optionalSupported && this.eat(types$1.questionDot);
  2333. if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); }
  2334. var computed = this.eat(types$1.bracketL);
  2335. if (computed || (optional && this.type !== types$1.parenL && this.type !== types$1.backQuote) || this.eat(types$1.dot)) {
  2336. var node = this.startNodeAt(startPos, startLoc);
  2337. node.object = base;
  2338. if (computed) {
  2339. node.property = this.parseExpression();
  2340. this.expect(types$1.bracketR);
  2341. } else if (this.type === types$1.privateId && base.type !== "Super") {
  2342. node.property = this.parsePrivateIdent();
  2343. } else {
  2344. node.property = this.parseIdent(this.options.allowReserved !== "never");
  2345. }
  2346. node.computed = !!computed;
  2347. if (optionalSupported) {
  2348. node.optional = optional;
  2349. }
  2350. base = this.finishNode(node, "MemberExpression");
  2351. } else if (!noCalls && this.eat(types$1.parenL)) {
  2352. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2353. this.yieldPos = 0;
  2354. this.awaitPos = 0;
  2355. this.awaitIdentPos = 0;
  2356. var exprList = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors);
  2357. if (maybeAsyncArrow && !optional && !this.canInsertSemicolon() && this.eat(types$1.arrow)) {
  2358. this.checkPatternErrors(refDestructuringErrors, false);
  2359. this.checkYieldAwaitInDefaultParams();
  2360. if (this.awaitIdentPos > 0)
  2361. { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
  2362. this.yieldPos = oldYieldPos;
  2363. this.awaitPos = oldAwaitPos;
  2364. this.awaitIdentPos = oldAwaitIdentPos;
  2365. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true, forInit)
  2366. }
  2367. this.checkExpressionErrors(refDestructuringErrors, true);
  2368. this.yieldPos = oldYieldPos || this.yieldPos;
  2369. this.awaitPos = oldAwaitPos || this.awaitPos;
  2370. this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
  2371. var node$1 = this.startNodeAt(startPos, startLoc);
  2372. node$1.callee = base;
  2373. node$1.arguments = exprList;
  2374. if (optionalSupported) {
  2375. node$1.optional = optional;
  2376. }
  2377. base = this.finishNode(node$1, "CallExpression");
  2378. } else if (this.type === types$1.backQuote) {
  2379. if (optional || optionalChained) {
  2380. this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions");
  2381. }
  2382. var node$2 = this.startNodeAt(startPos, startLoc);
  2383. node$2.tag = base;
  2384. node$2.quasi = this.parseTemplate({isTagged: true});
  2385. base = this.finishNode(node$2, "TaggedTemplateExpression");
  2386. }
  2387. return base
  2388. };
  2389. // Parse an atomic expression — either a single token that is an
  2390. // expression, an expression started by a keyword like `function` or
  2391. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  2392. // or `{}`.
  2393. pp$5.parseExprAtom = function(refDestructuringErrors, forInit) {
  2394. // If a division operator appears in an expression position, the
  2395. // tokenizer got confused, and we force it to read a regexp instead.
  2396. if (this.type === types$1.slash) { this.readRegexp(); }
  2397. var node, canBeArrow = this.potentialArrowAt === this.start;
  2398. switch (this.type) {
  2399. case types$1._super:
  2400. if (!this.allowSuper)
  2401. { this.raise(this.start, "'super' keyword outside a method"); }
  2402. node = this.startNode();
  2403. this.next();
  2404. if (this.type === types$1.parenL && !this.allowDirectSuper)
  2405. { this.raise(node.start, "super() call outside constructor of a subclass"); }
  2406. // The `super` keyword can appear at below:
  2407. // SuperProperty:
  2408. // super [ Expression ]
  2409. // super . IdentifierName
  2410. // SuperCall:
  2411. // super ( Arguments )
  2412. if (this.type !== types$1.dot && this.type !== types$1.bracketL && this.type !== types$1.parenL)
  2413. { this.unexpected(); }
  2414. return this.finishNode(node, "Super")
  2415. case types$1._this:
  2416. node = this.startNode();
  2417. this.next();
  2418. return this.finishNode(node, "ThisExpression")
  2419. case types$1.name:
  2420. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  2421. var id = this.parseIdent(false);
  2422. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types$1._function)) {
  2423. this.overrideContext(types.f_expr);
  2424. return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true, forInit)
  2425. }
  2426. if (canBeArrow && !this.canInsertSemicolon()) {
  2427. if (this.eat(types$1.arrow))
  2428. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false, forInit) }
  2429. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types$1.name && !containsEsc &&
  2430. (!this.potentialArrowInForAwait || this.value !== "of" || this.containsEsc)) {
  2431. id = this.parseIdent(false);
  2432. if (this.canInsertSemicolon() || !this.eat(types$1.arrow))
  2433. { this.unexpected(); }
  2434. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true, forInit)
  2435. }
  2436. }
  2437. return id
  2438. case types$1.regexp:
  2439. var value = this.value;
  2440. node = this.parseLiteral(value.value);
  2441. node.regex = {pattern: value.pattern, flags: value.flags};
  2442. return node
  2443. case types$1.num: case types$1.string:
  2444. return this.parseLiteral(this.value)
  2445. case types$1._null: case types$1._true: case types$1._false:
  2446. node = this.startNode();
  2447. node.value = this.type === types$1._null ? null : this.type === types$1._true;
  2448. node.raw = this.type.keyword;
  2449. this.next();
  2450. return this.finishNode(node, "Literal")
  2451. case types$1.parenL:
  2452. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit);
  2453. if (refDestructuringErrors) {
  2454. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  2455. { refDestructuringErrors.parenthesizedAssign = start; }
  2456. if (refDestructuringErrors.parenthesizedBind < 0)
  2457. { refDestructuringErrors.parenthesizedBind = start; }
  2458. }
  2459. return expr
  2460. case types$1.bracketL:
  2461. node = this.startNode();
  2462. this.next();
  2463. node.elements = this.parseExprList(types$1.bracketR, true, true, refDestructuringErrors);
  2464. return this.finishNode(node, "ArrayExpression")
  2465. case types$1.braceL:
  2466. this.overrideContext(types.b_expr);
  2467. return this.parseObj(false, refDestructuringErrors)
  2468. case types$1._function:
  2469. node = this.startNode();
  2470. this.next();
  2471. return this.parseFunction(node, 0)
  2472. case types$1._class:
  2473. return this.parseClass(this.startNode(), false)
  2474. case types$1._new:
  2475. return this.parseNew()
  2476. case types$1.backQuote:
  2477. return this.parseTemplate()
  2478. case types$1._import:
  2479. if (this.options.ecmaVersion >= 11) {
  2480. return this.parseExprImport()
  2481. } else {
  2482. return this.unexpected()
  2483. }
  2484. default:
  2485. this.unexpected();
  2486. }
  2487. };
  2488. pp$5.parseExprImport = function() {
  2489. var node = this.startNode();
  2490. // Consume `import` as an identifier for `import.meta`.
  2491. // Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`.
  2492. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword import"); }
  2493. var meta = this.parseIdent(true);
  2494. switch (this.type) {
  2495. case types$1.parenL:
  2496. return this.parseDynamicImport(node)
  2497. case types$1.dot:
  2498. node.meta = meta;
  2499. return this.parseImportMeta(node)
  2500. default:
  2501. this.unexpected();
  2502. }
  2503. };
  2504. pp$5.parseDynamicImport = function(node) {
  2505. this.next(); // skip `(`
  2506. // Parse node.source.
  2507. node.source = this.parseMaybeAssign();
  2508. // Verify ending.
  2509. if (!this.eat(types$1.parenR)) {
  2510. var errorPos = this.start;
  2511. if (this.eat(types$1.comma) && this.eat(types$1.parenR)) {
  2512. this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
  2513. } else {
  2514. this.unexpected(errorPos);
  2515. }
  2516. }
  2517. return this.finishNode(node, "ImportExpression")
  2518. };
  2519. pp$5.parseImportMeta = function(node) {
  2520. this.next(); // skip `.`
  2521. var containsEsc = this.containsEsc;
  2522. node.property = this.parseIdent(true);
  2523. if (node.property.name !== "meta")
  2524. { this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); }
  2525. if (containsEsc)
  2526. { this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); }
  2527. if (this.options.sourceType !== "module" && !this.options.allowImportExportEverywhere)
  2528. { this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); }
  2529. return this.finishNode(node, "MetaProperty")
  2530. };
  2531. pp$5.parseLiteral = function(value) {
  2532. var node = this.startNode();
  2533. node.value = value;
  2534. node.raw = this.input.slice(this.start, this.end);
  2535. if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1).replace(/_/g, ""); }
  2536. this.next();
  2537. return this.finishNode(node, "Literal")
  2538. };
  2539. pp$5.parseParenExpression = function() {
  2540. this.expect(types$1.parenL);
  2541. var val = this.parseExpression();
  2542. this.expect(types$1.parenR);
  2543. return val
  2544. };
  2545. pp$5.parseParenAndDistinguishExpression = function(canBeArrow, forInit) {
  2546. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  2547. if (this.options.ecmaVersion >= 6) {
  2548. this.next();
  2549. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  2550. var exprList = [], first = true, lastIsComma = false;
  2551. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  2552. this.yieldPos = 0;
  2553. this.awaitPos = 0;
  2554. // Do not save awaitIdentPos to allow checking awaits nested in parameters
  2555. while (this.type !== types$1.parenR) {
  2556. first ? first = false : this.expect(types$1.comma);
  2557. if (allowTrailingComma && this.afterTrailingComma(types$1.parenR, true)) {
  2558. lastIsComma = true;
  2559. break
  2560. } else if (this.type === types$1.ellipsis) {
  2561. spreadStart = this.start;
  2562. exprList.push(this.parseParenItem(this.parseRestBinding()));
  2563. if (this.type === types$1.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
  2564. break
  2565. } else {
  2566. exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
  2567. }
  2568. }
  2569. var innerEndPos = this.lastTokEnd, innerEndLoc = this.lastTokEndLoc;
  2570. this.expect(types$1.parenR);
  2571. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types$1.arrow)) {
  2572. this.checkPatternErrors(refDestructuringErrors, false);
  2573. this.checkYieldAwaitInDefaultParams();
  2574. this.yieldPos = oldYieldPos;
  2575. this.awaitPos = oldAwaitPos;
  2576. return this.parseParenArrowList(startPos, startLoc, exprList, forInit)
  2577. }
  2578. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  2579. if (spreadStart) { this.unexpected(spreadStart); }
  2580. this.checkExpressionErrors(refDestructuringErrors, true);
  2581. this.yieldPos = oldYieldPos || this.yieldPos;
  2582. this.awaitPos = oldAwaitPos || this.awaitPos;
  2583. if (exprList.length > 1) {
  2584. val = this.startNodeAt(innerStartPos, innerStartLoc);
  2585. val.expressions = exprList;
  2586. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  2587. } else {
  2588. val = exprList[0];
  2589. }
  2590. } else {
  2591. val = this.parseParenExpression();
  2592. }
  2593. if (this.options.preserveParens) {
  2594. var par = this.startNodeAt(startPos, startLoc);
  2595. par.expression = val;
  2596. return this.finishNode(par, "ParenthesizedExpression")
  2597. } else {
  2598. return val
  2599. }
  2600. };
  2601. pp$5.parseParenItem = function(item) {
  2602. return item
  2603. };
  2604. pp$5.parseParenArrowList = function(startPos, startLoc, exprList, forInit) {
  2605. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, false, forInit)
  2606. };
  2607. // New's precedence is slightly tricky. It must allow its argument to
  2608. // be a `[]` or dot subscript expression, but not a call — at least,
  2609. // not without wrapping it in parentheses. Thus, it uses the noCalls
  2610. // argument to parseSubscripts to prevent it from consuming the
  2611. // argument list.
  2612. var empty = [];
  2613. pp$5.parseNew = function() {
  2614. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); }
  2615. var node = this.startNode();
  2616. var meta = this.parseIdent(true);
  2617. if (this.options.ecmaVersion >= 6 && this.eat(types$1.dot)) {
  2618. node.meta = meta;
  2619. var containsEsc = this.containsEsc;
  2620. node.property = this.parseIdent(true);
  2621. if (node.property.name !== "target")
  2622. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); }
  2623. if (containsEsc)
  2624. { this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); }
  2625. if (!this.allowNewDotTarget)
  2626. { this.raiseRecoverable(node.start, "'new.target' can only be used in functions and class static block"); }
  2627. return this.finishNode(node, "MetaProperty")
  2628. }
  2629. var startPos = this.start, startLoc = this.startLoc, isImport = this.type === types$1._import;
  2630. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true, false);
  2631. if (isImport && node.callee.type === "ImportExpression") {
  2632. this.raise(startPos, "Cannot use new with import()");
  2633. }
  2634. if (this.eat(types$1.parenL)) { node.arguments = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false); }
  2635. else { node.arguments = empty; }
  2636. return this.finishNode(node, "NewExpression")
  2637. };
  2638. // Parse template expression.
  2639. pp$5.parseTemplateElement = function(ref) {
  2640. var isTagged = ref.isTagged;
  2641. var elem = this.startNode();
  2642. if (this.type === types$1.invalidTemplate) {
  2643. if (!isTagged) {
  2644. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2645. }
  2646. elem.value = {
  2647. raw: this.value,
  2648. cooked: null
  2649. };
  2650. } else {
  2651. elem.value = {
  2652. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2653. cooked: this.value
  2654. };
  2655. }
  2656. this.next();
  2657. elem.tail = this.type === types$1.backQuote;
  2658. return this.finishNode(elem, "TemplateElement")
  2659. };
  2660. pp$5.parseTemplate = function(ref) {
  2661. if ( ref === void 0 ) ref = {};
  2662. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2663. var node = this.startNode();
  2664. this.next();
  2665. node.expressions = [];
  2666. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2667. node.quasis = [curElt];
  2668. while (!curElt.tail) {
  2669. if (this.type === types$1.eof) { this.raise(this.pos, "Unterminated template literal"); }
  2670. this.expect(types$1.dollarBraceL);
  2671. node.expressions.push(this.parseExpression());
  2672. this.expect(types$1.braceR);
  2673. node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
  2674. }
  2675. this.next();
  2676. return this.finishNode(node, "TemplateLiteral")
  2677. };
  2678. pp$5.isAsyncProp = function(prop) {
  2679. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2680. (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)) &&
  2681. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2682. };
  2683. // Parse an object literal or binding pattern.
  2684. pp$5.parseObj = function(isPattern, refDestructuringErrors) {
  2685. var node = this.startNode(), first = true, propHash = {};
  2686. node.properties = [];
  2687. this.next();
  2688. while (!this.eat(types$1.braceR)) {
  2689. if (!first) {
  2690. this.expect(types$1.comma);
  2691. if (this.options.ecmaVersion >= 5 && this.afterTrailingComma(types$1.braceR)) { break }
  2692. } else { first = false; }
  2693. var prop = this.parseProperty(isPattern, refDestructuringErrors);
  2694. if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
  2695. node.properties.push(prop);
  2696. }
  2697. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2698. };
  2699. pp$5.parseProperty = function(isPattern, refDestructuringErrors) {
  2700. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2701. if (this.options.ecmaVersion >= 9 && this.eat(types$1.ellipsis)) {
  2702. if (isPattern) {
  2703. prop.argument = this.parseIdent(false);
  2704. if (this.type === types$1.comma) {
  2705. this.raise(this.start, "Comma is not permitted after the rest element");
  2706. }
  2707. return this.finishNode(prop, "RestElement")
  2708. }
  2709. // Parse argument.
  2710. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2711. // To disallow trailing comma via `this.toAssignable()`.
  2712. if (this.type === types$1.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2713. refDestructuringErrors.trailingComma = this.start;
  2714. }
  2715. // Finish
  2716. return this.finishNode(prop, "SpreadElement")
  2717. }
  2718. if (this.options.ecmaVersion >= 6) {
  2719. prop.method = false;
  2720. prop.shorthand = false;
  2721. if (isPattern || refDestructuringErrors) {
  2722. startPos = this.start;
  2723. startLoc = this.startLoc;
  2724. }
  2725. if (!isPattern)
  2726. { isGenerator = this.eat(types$1.star); }
  2727. }
  2728. var containsEsc = this.containsEsc;
  2729. this.parsePropertyName(prop);
  2730. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2731. isAsync = true;
  2732. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types$1.star);
  2733. this.parsePropertyName(prop);
  2734. } else {
  2735. isAsync = false;
  2736. }
  2737. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2738. return this.finishNode(prop, "Property")
  2739. };
  2740. pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  2741. if ((isGenerator || isAsync) && this.type === types$1.colon)
  2742. { this.unexpected(); }
  2743. if (this.eat(types$1.colon)) {
  2744. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  2745. prop.kind = "init";
  2746. } else if (this.options.ecmaVersion >= 6 && this.type === types$1.parenL) {
  2747. if (isPattern) { this.unexpected(); }
  2748. prop.kind = "init";
  2749. prop.method = true;
  2750. prop.value = this.parseMethod(isGenerator, isAsync);
  2751. } else if (!isPattern && !containsEsc &&
  2752. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2753. (prop.key.name === "get" || prop.key.name === "set") &&
  2754. (this.type !== types$1.comma && this.type !== types$1.braceR && this.type !== types$1.eq)) {
  2755. if (isGenerator || isAsync) { this.unexpected(); }
  2756. prop.kind = prop.key.name;
  2757. this.parsePropertyName(prop);
  2758. prop.value = this.parseMethod(false);
  2759. var paramCount = prop.kind === "get" ? 0 : 1;
  2760. if (prop.value.params.length !== paramCount) {
  2761. var start = prop.value.start;
  2762. if (prop.kind === "get")
  2763. { this.raiseRecoverable(start, "getter should have no params"); }
  2764. else
  2765. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2766. } else {
  2767. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2768. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2769. }
  2770. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2771. if (isGenerator || isAsync) { this.unexpected(); }
  2772. this.checkUnreserved(prop.key);
  2773. if (prop.key.name === "await" && !this.awaitIdentPos)
  2774. { this.awaitIdentPos = startPos; }
  2775. prop.kind = "init";
  2776. if (isPattern) {
  2777. prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
  2778. } else if (this.type === types$1.eq && refDestructuringErrors) {
  2779. if (refDestructuringErrors.shorthandAssign < 0)
  2780. { refDestructuringErrors.shorthandAssign = this.start; }
  2781. prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
  2782. } else {
  2783. prop.value = this.copyNode(prop.key);
  2784. }
  2785. prop.shorthand = true;
  2786. } else { this.unexpected(); }
  2787. };
  2788. pp$5.parsePropertyName = function(prop) {
  2789. if (this.options.ecmaVersion >= 6) {
  2790. if (this.eat(types$1.bracketL)) {
  2791. prop.computed = true;
  2792. prop.key = this.parseMaybeAssign();
  2793. this.expect(types$1.bracketR);
  2794. return prop.key
  2795. } else {
  2796. prop.computed = false;
  2797. }
  2798. }
  2799. return prop.key = this.type === types$1.num || this.type === types$1.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
  2800. };
  2801. // Initialize empty function node.
  2802. pp$5.initFunction = function(node) {
  2803. node.id = null;
  2804. if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
  2805. if (this.options.ecmaVersion >= 8) { node.async = false; }
  2806. };
  2807. // Parse object or class method.
  2808. pp$5.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
  2809. var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2810. this.initFunction(node);
  2811. if (this.options.ecmaVersion >= 6)
  2812. { node.generator = isGenerator; }
  2813. if (this.options.ecmaVersion >= 8)
  2814. { node.async = !!isAsync; }
  2815. this.yieldPos = 0;
  2816. this.awaitPos = 0;
  2817. this.awaitIdentPos = 0;
  2818. this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  2819. this.expect(types$1.parenL);
  2820. node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8);
  2821. this.checkYieldAwaitInDefaultParams();
  2822. this.parseFunctionBody(node, false, true, false);
  2823. this.yieldPos = oldYieldPos;
  2824. this.awaitPos = oldAwaitPos;
  2825. this.awaitIdentPos = oldAwaitIdentPos;
  2826. return this.finishNode(node, "FunctionExpression")
  2827. };
  2828. // Parse arrow function expression with given parameters.
  2829. pp$5.parseArrowExpression = function(node, params, isAsync, forInit) {
  2830. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2831. this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
  2832. this.initFunction(node);
  2833. if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
  2834. this.yieldPos = 0;
  2835. this.awaitPos = 0;
  2836. this.awaitIdentPos = 0;
  2837. node.params = this.toAssignableList(params, true);
  2838. this.parseFunctionBody(node, true, false, forInit);
  2839. this.yieldPos = oldYieldPos;
  2840. this.awaitPos = oldAwaitPos;
  2841. this.awaitIdentPos = oldAwaitIdentPos;
  2842. return this.finishNode(node, "ArrowFunctionExpression")
  2843. };
  2844. // Parse function body and check parameters.
  2845. pp$5.parseFunctionBody = function(node, isArrowFunction, isMethod, forInit) {
  2846. var isExpression = isArrowFunction && this.type !== types$1.braceL;
  2847. var oldStrict = this.strict, useStrict = false;
  2848. if (isExpression) {
  2849. node.body = this.parseMaybeAssign(forInit);
  2850. node.expression = true;
  2851. this.checkParams(node, false);
  2852. } else {
  2853. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2854. if (!oldStrict || nonSimple) {
  2855. useStrict = this.strictDirective(this.end);
  2856. // If this is a strict mode function, verify that argument names
  2857. // are not repeated, and it does not try to bind the words `eval`
  2858. // or `arguments`.
  2859. if (useStrict && nonSimple)
  2860. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2861. }
  2862. // Start a new scope with regard to labels and the `inFunction`
  2863. // flag (restore them to their old value afterwards).
  2864. var oldLabels = this.labels;
  2865. this.labels = [];
  2866. if (useStrict) { this.strict = true; }
  2867. // Add the params to varDeclaredNames to ensure that an error is thrown
  2868. // if a let/const declaration in the function clashes with one of the params.
  2869. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
  2870. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2871. if (this.strict && node.id) { this.checkLValSimple(node.id, BIND_OUTSIDE); }
  2872. node.body = this.parseBlock(false, undefined, useStrict && !oldStrict);
  2873. node.expression = false;
  2874. this.adaptDirectivePrologue(node.body.body);
  2875. this.labels = oldLabels;
  2876. }
  2877. this.exitScope();
  2878. };
  2879. pp$5.isSimpleParamList = function(params) {
  2880. for (var i = 0, list = params; i < list.length; i += 1)
  2881. {
  2882. var param = list[i];
  2883. if (param.type !== "Identifier") { return false
  2884. } }
  2885. return true
  2886. };
  2887. // Checks function params for various disallowed patterns such as using "eval"
  2888. // or "arguments" and duplicate parameters.
  2889. pp$5.checkParams = function(node, allowDuplicates) {
  2890. var nameHash = Object.create(null);
  2891. for (var i = 0, list = node.params; i < list.length; i += 1)
  2892. {
  2893. var param = list[i];
  2894. this.checkLValInnerPattern(param, BIND_VAR, allowDuplicates ? null : nameHash);
  2895. }
  2896. };
  2897. // Parses a comma-separated list of expressions, and returns them as
  2898. // an array. `close` is the token type that ends the list, and
  2899. // `allowEmpty` can be turned on to allow subsequent commas with
  2900. // nothing in between them to be parsed as `null` (which is needed
  2901. // for array literals).
  2902. pp$5.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2903. var elts = [], first = true;
  2904. while (!this.eat(close)) {
  2905. if (!first) {
  2906. this.expect(types$1.comma);
  2907. if (allowTrailingComma && this.afterTrailingComma(close)) { break }
  2908. } else { first = false; }
  2909. var elt = (void 0);
  2910. if (allowEmpty && this.type === types$1.comma)
  2911. { elt = null; }
  2912. else if (this.type === types$1.ellipsis) {
  2913. elt = this.parseSpread(refDestructuringErrors);
  2914. if (refDestructuringErrors && this.type === types$1.comma && refDestructuringErrors.trailingComma < 0)
  2915. { refDestructuringErrors.trailingComma = this.start; }
  2916. } else {
  2917. elt = this.parseMaybeAssign(false, refDestructuringErrors);
  2918. }
  2919. elts.push(elt);
  2920. }
  2921. return elts
  2922. };
  2923. pp$5.checkUnreserved = function(ref) {
  2924. var start = ref.start;
  2925. var end = ref.end;
  2926. var name = ref.name;
  2927. if (this.inGenerator && name === "yield")
  2928. { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
  2929. if (this.inAsync && name === "await")
  2930. { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
  2931. if (this.currentThisScope().inClassFieldInit && name === "arguments")
  2932. { this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer"); }
  2933. if (this.inClassStaticBlock && (name === "arguments" || name === "await"))
  2934. { this.raise(start, ("Cannot use " + name + " in class static initialization block")); }
  2935. if (this.keywords.test(name))
  2936. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2937. if (this.options.ecmaVersion < 6 &&
  2938. this.input.slice(start, end).indexOf("\\") !== -1) { return }
  2939. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2940. if (re.test(name)) {
  2941. if (!this.inAsync && name === "await")
  2942. { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
  2943. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  2944. }
  2945. };
  2946. // Parse the next token as an identifier. If `liberal` is true (used
  2947. // when parsing properties), it will also convert keywords into
  2948. // identifiers.
  2949. pp$5.parseIdent = function(liberal) {
  2950. var node = this.startNode();
  2951. if (this.type === types$1.name) {
  2952. node.name = this.value;
  2953. } else if (this.type.keyword) {
  2954. node.name = this.type.keyword;
  2955. // To fix https://github.com/acornjs/acorn/issues/575
  2956. // `class` and `function` keywords push new context into this.context.
  2957. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  2958. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  2959. if ((node.name === "class" || node.name === "function") &&
  2960. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  2961. this.context.pop();
  2962. }
  2963. } else {
  2964. this.unexpected();
  2965. }
  2966. this.next(!!liberal);
  2967. this.finishNode(node, "Identifier");
  2968. if (!liberal) {
  2969. this.checkUnreserved(node);
  2970. if (node.name === "await" && !this.awaitIdentPos)
  2971. { this.awaitIdentPos = node.start; }
  2972. }
  2973. return node
  2974. };
  2975. pp$5.parsePrivateIdent = function() {
  2976. var node = this.startNode();
  2977. if (this.type === types$1.privateId) {
  2978. node.name = this.value;
  2979. } else {
  2980. this.unexpected();
  2981. }
  2982. this.next();
  2983. this.finishNode(node, "PrivateIdentifier");
  2984. // For validating existence
  2985. if (this.privateNameStack.length === 0) {
  2986. this.raise(node.start, ("Private field '#" + (node.name) + "' must be declared in an enclosing class"));
  2987. } else {
  2988. this.privateNameStack[this.privateNameStack.length - 1].used.push(node);
  2989. }
  2990. return node
  2991. };
  2992. // Parses yield expression inside generator.
  2993. pp$5.parseYield = function(forInit) {
  2994. if (!this.yieldPos) { this.yieldPos = this.start; }
  2995. var node = this.startNode();
  2996. this.next();
  2997. if (this.type === types$1.semi || this.canInsertSemicolon() || (this.type !== types$1.star && !this.type.startsExpr)) {
  2998. node.delegate = false;
  2999. node.argument = null;
  3000. } else {
  3001. node.delegate = this.eat(types$1.star);
  3002. node.argument = this.parseMaybeAssign(forInit);
  3003. }
  3004. return this.finishNode(node, "YieldExpression")
  3005. };
  3006. pp$5.parseAwait = function(forInit) {
  3007. if (!this.awaitPos) { this.awaitPos = this.start; }
  3008. var node = this.startNode();
  3009. this.next();
  3010. node.argument = this.parseMaybeUnary(null, true, false, forInit);
  3011. return this.finishNode(node, "AwaitExpression")
  3012. };
  3013. var pp$4 = Parser.prototype;
  3014. // This function is used to raise exceptions on parse errors. It
  3015. // takes an offset integer (into the current `input`) to indicate
  3016. // the location of the error, attaches the position to the end
  3017. // of the error message, and then raises a `SyntaxError` with that
  3018. // message.
  3019. pp$4.raise = function(pos, message) {
  3020. var loc = getLineInfo(this.input, pos);
  3021. message += " (" + loc.line + ":" + loc.column + ")";
  3022. var err = new SyntaxError(message);
  3023. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  3024. throw err
  3025. };
  3026. pp$4.raiseRecoverable = pp$4.raise;
  3027. pp$4.curPosition = function() {
  3028. if (this.options.locations) {
  3029. return new Position(this.curLine, this.pos - this.lineStart)
  3030. }
  3031. };
  3032. var pp$3 = Parser.prototype;
  3033. var Scope = function Scope(flags) {
  3034. this.flags = flags;
  3035. // A list of var-declared names in the current lexical scope
  3036. this.var = [];
  3037. // A list of lexically-declared names in the current lexical scope
  3038. this.lexical = [];
  3039. // A list of lexically-declared FunctionDeclaration names in the current lexical scope
  3040. this.functions = [];
  3041. // A switch to disallow the identifier reference 'arguments'
  3042. this.inClassFieldInit = false;
  3043. };
  3044. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  3045. pp$3.enterScope = function(flags) {
  3046. this.scopeStack.push(new Scope(flags));
  3047. };
  3048. pp$3.exitScope = function() {
  3049. this.scopeStack.pop();
  3050. };
  3051. // The spec says:
  3052. // > At the top level of a function, or script, function declarations are
  3053. // > treated like var declarations rather than like lexical declarations.
  3054. pp$3.treatFunctionsAsVarInScope = function(scope) {
  3055. return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
  3056. };
  3057. pp$3.declareName = function(name, bindingType, pos) {
  3058. var redeclared = false;
  3059. if (bindingType === BIND_LEXICAL) {
  3060. var scope = this.currentScope();
  3061. redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
  3062. scope.lexical.push(name);
  3063. if (this.inModule && (scope.flags & SCOPE_TOP))
  3064. { delete this.undefinedExports[name]; }
  3065. } else if (bindingType === BIND_SIMPLE_CATCH) {
  3066. var scope$1 = this.currentScope();
  3067. scope$1.lexical.push(name);
  3068. } else if (bindingType === BIND_FUNCTION) {
  3069. var scope$2 = this.currentScope();
  3070. if (this.treatFunctionsAsVar)
  3071. { redeclared = scope$2.lexical.indexOf(name) > -1; }
  3072. else
  3073. { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
  3074. scope$2.functions.push(name);
  3075. } else {
  3076. for (var i = this.scopeStack.length - 1; i >= 0; --i) {
  3077. var scope$3 = this.scopeStack[i];
  3078. if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
  3079. !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
  3080. redeclared = true;
  3081. break
  3082. }
  3083. scope$3.var.push(name);
  3084. if (this.inModule && (scope$3.flags & SCOPE_TOP))
  3085. { delete this.undefinedExports[name]; }
  3086. if (scope$3.flags & SCOPE_VAR) { break }
  3087. }
  3088. }
  3089. if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
  3090. };
  3091. pp$3.checkLocalExport = function(id) {
  3092. // scope.functions must be empty as Module code is always strict.
  3093. if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
  3094. this.scopeStack[0].var.indexOf(id.name) === -1) {
  3095. this.undefinedExports[id.name] = id;
  3096. }
  3097. };
  3098. pp$3.currentScope = function() {
  3099. return this.scopeStack[this.scopeStack.length - 1]
  3100. };
  3101. pp$3.currentVarScope = function() {
  3102. for (var i = this.scopeStack.length - 1;; i--) {
  3103. var scope = this.scopeStack[i];
  3104. if (scope.flags & SCOPE_VAR) { return scope }
  3105. }
  3106. };
  3107. // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
  3108. pp$3.currentThisScope = function() {
  3109. for (var i = this.scopeStack.length - 1;; i--) {
  3110. var scope = this.scopeStack[i];
  3111. if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
  3112. }
  3113. };
  3114. var Node = function Node(parser, pos, loc) {
  3115. this.type = "";
  3116. this.start = pos;
  3117. this.end = 0;
  3118. if (parser.options.locations)
  3119. { this.loc = new SourceLocation(parser, loc); }
  3120. if (parser.options.directSourceFile)
  3121. { this.sourceFile = parser.options.directSourceFile; }
  3122. if (parser.options.ranges)
  3123. { this.range = [pos, 0]; }
  3124. };
  3125. // Start an AST node, attaching a start offset.
  3126. var pp$2 = Parser.prototype;
  3127. pp$2.startNode = function() {
  3128. return new Node(this, this.start, this.startLoc)
  3129. };
  3130. pp$2.startNodeAt = function(pos, loc) {
  3131. return new Node(this, pos, loc)
  3132. };
  3133. // Finish an AST node, adding `type` and `end` properties.
  3134. function finishNodeAt(node, type, pos, loc) {
  3135. node.type = type;
  3136. node.end = pos;
  3137. if (this.options.locations)
  3138. { node.loc.end = loc; }
  3139. if (this.options.ranges)
  3140. { node.range[1] = pos; }
  3141. return node
  3142. }
  3143. pp$2.finishNode = function(node, type) {
  3144. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  3145. };
  3146. // Finish node at given position
  3147. pp$2.finishNodeAt = function(node, type, pos, loc) {
  3148. return finishNodeAt.call(this, node, type, pos, loc)
  3149. };
  3150. pp$2.copyNode = function(node) {
  3151. var newNode = new Node(this, node.start, this.startLoc);
  3152. for (var prop in node) { newNode[prop] = node[prop]; }
  3153. return newNode
  3154. };
  3155. // This file contains Unicode properties extracted from the ECMAScript specification.
  3156. // The lists are extracted like so:
  3157. // $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
  3158. // #table-binary-unicode-properties
  3159. 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";
  3160. var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
  3161. var ecma11BinaryProperties = ecma10BinaryProperties;
  3162. var ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict";
  3163. var ecma13BinaryProperties = ecma12BinaryProperties;
  3164. var ecma14BinaryProperties = ecma13BinaryProperties;
  3165. var unicodeBinaryProperties = {
  3166. 9: ecma9BinaryProperties,
  3167. 10: ecma10BinaryProperties,
  3168. 11: ecma11BinaryProperties,
  3169. 12: ecma12BinaryProperties,
  3170. 13: ecma13BinaryProperties,
  3171. 14: ecma14BinaryProperties
  3172. };
  3173. // #table-unicode-general-category-values
  3174. 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";
  3175. // #table-unicode-script-values
  3176. 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";
  3177. var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
  3178. var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
  3179. var ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi";
  3180. var ecma13ScriptValues = ecma12ScriptValues + " Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith";
  3181. var ecma14ScriptValues = ecma13ScriptValues + " Kawi Nag_Mundari Nagm";
  3182. var unicodeScriptValues = {
  3183. 9: ecma9ScriptValues,
  3184. 10: ecma10ScriptValues,
  3185. 11: ecma11ScriptValues,
  3186. 12: ecma12ScriptValues,
  3187. 13: ecma13ScriptValues,
  3188. 14: ecma14ScriptValues
  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, 14]; 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 >= 14 ? 14 : 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. }
  4790. default:
  4791. if (ch >= 48 && ch <= 55) {
  4792. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  4793. var octal = parseInt(octalStr, 8);
  4794. if (octal > 255) {
  4795. octalStr = octalStr.slice(0, -1);
  4796. octal = parseInt(octalStr, 8);
  4797. }
  4798. this.pos += octalStr.length - 1;
  4799. ch = this.input.charCodeAt(this.pos);
  4800. if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
  4801. this.invalidStringToken(
  4802. this.pos - 1 - octalStr.length,
  4803. inTemplate
  4804. ? "Octal literal in template string"
  4805. : "Octal literal in strict mode"
  4806. );
  4807. }
  4808. return String.fromCharCode(octal)
  4809. }
  4810. if (isNewLine(ch)) {
  4811. // Unicode new line characters after \ get removed from output in both
  4812. // template literals and strings
  4813. return ""
  4814. }
  4815. return String.fromCharCode(ch)
  4816. }
  4817. };
  4818. // Used to read character escape sequences ('\x', '\u', '\U').
  4819. pp.readHexChar = function(len) {
  4820. var codePos = this.pos;
  4821. var n = this.readInt(16, len);
  4822. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  4823. return n
  4824. };
  4825. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  4826. // to whether the word contained a '\u' escape.
  4827. //
  4828. // Incrementally adds only escaped chars, adding other chunks as-is
  4829. // as a micro-optimization.
  4830. pp.readWord1 = function() {
  4831. this.containsEsc = false;
  4832. var word = "", first = true, chunkStart = this.pos;
  4833. var astral = this.options.ecmaVersion >= 6;
  4834. while (this.pos < this.input.length) {
  4835. var ch = this.fullCharCodeAtPos();
  4836. if (isIdentifierChar(ch, astral)) {
  4837. this.pos += ch <= 0xffff ? 1 : 2;
  4838. } else if (ch === 92) { // "\"
  4839. this.containsEsc = true;
  4840. word += this.input.slice(chunkStart, this.pos);
  4841. var escStart = this.pos;
  4842. if (this.input.charCodeAt(++this.pos) !== 117) // "u"
  4843. { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  4844. ++this.pos;
  4845. var esc = this.readCodePoint();
  4846. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  4847. { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
  4848. word += codePointToString(esc);
  4849. chunkStart = this.pos;
  4850. } else {
  4851. break
  4852. }
  4853. first = false;
  4854. }
  4855. return word + this.input.slice(chunkStart, this.pos)
  4856. };
  4857. // Read an identifier or keyword token. Will check for reserved
  4858. // words when necessary.
  4859. pp.readWord = function() {
  4860. var word = this.readWord1();
  4861. var type = types$1.name;
  4862. if (this.keywords.test(word)) {
  4863. type = keywords[word];
  4864. }
  4865. return this.finishToken(type, word)
  4866. };
  4867. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  4868. var version = "8.8.2";
  4869. Parser.acorn = {
  4870. Parser: Parser,
  4871. version: version,
  4872. defaultOptions: defaultOptions,
  4873. Position: Position,
  4874. SourceLocation: SourceLocation,
  4875. getLineInfo: getLineInfo,
  4876. Node: Node,
  4877. TokenType: TokenType,
  4878. tokTypes: types$1,
  4879. keywordTypes: keywords,
  4880. TokContext: TokContext,
  4881. tokContexts: types,
  4882. isIdentifierChar: isIdentifierChar,
  4883. isIdentifierStart: isIdentifierStart,
  4884. Token: Token,
  4885. isNewLine: isNewLine,
  4886. lineBreak: lineBreak,
  4887. lineBreakG: lineBreakG,
  4888. nonASCIIwhitespace: nonASCIIwhitespace
  4889. };
  4890. // The main exported interface (under `self.acorn` when in the
  4891. // browser) is a `parse` function that takes a code string and
  4892. // returns an abstract syntax tree as specified by [Mozilla parser
  4893. // API][api].
  4894. //
  4895. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4896. function parse(input, options) {
  4897. return Parser.parse(input, options)
  4898. }
  4899. // This function tries to parse a single expression at a given
  4900. // offset in a string. Useful for parsing mixed-language formats
  4901. // that embed JavaScript expressions.
  4902. function parseExpressionAt(input, pos, options) {
  4903. return Parser.parseExpressionAt(input, pos, options)
  4904. }
  4905. // Acorn is organized as a tokenizer and a recursive-descent parser.
  4906. // The `tokenizer` export provides an interface to the tokenizer.
  4907. function tokenizer(input, options) {
  4908. return Parser.tokenizer(input, options)
  4909. }
  4910. exports.Node = Node;
  4911. exports.Parser = Parser;
  4912. exports.Position = Position;
  4913. exports.SourceLocation = SourceLocation;
  4914. exports.TokContext = TokContext;
  4915. exports.Token = Token;
  4916. exports.TokenType = TokenType;
  4917. exports.defaultOptions = defaultOptions;
  4918. exports.getLineInfo = getLineInfo;
  4919. exports.isIdentifierChar = isIdentifierChar;
  4920. exports.isIdentifierStart = isIdentifierStart;
  4921. exports.isNewLine = isNewLine;
  4922. exports.keywordTypes = keywords;
  4923. exports.lineBreak = lineBreak;
  4924. exports.lineBreakG = lineBreakG;
  4925. exports.nonASCIIwhitespace = nonASCIIwhitespace;
  4926. exports.parse = parse;
  4927. exports.parseExpressionAt = parseExpressionAt;
  4928. exports.tokContexts = types;
  4929. exports.tokTypes = types$1;
  4930. exports.tokenizer = tokenizer;
  4931. exports.version = version;
  4932. }));