acorn.js 213 KB

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