acorn.js 175 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.acorn = {})));
  5. }(this, (function (exports) { 'use strict';
  6. // Reserved word lists for various dialects of the language
  7. var reservedWords = {
  8. 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",
  9. 5: "class enum extends super const export import",
  10. 6: "enum",
  11. strict: "implements interface let package private protected public static yield",
  12. strictBind: "eval arguments"
  13. };
  14. // And the keywords
  15. 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";
  16. var keywords = {
  17. 5: ecma5AndLessKeywords,
  18. 6: ecma5AndLessKeywords + " const class extends export import super"
  19. };
  20. var keywordRelationalOperator = /^in(stanceof)?$/;
  21. // ## Character categories
  22. // Big ugly regular expressions that match characters in the
  23. // whitespace, identifier, and identifier-start categories. These
  24. // are only applied when a character is found to actually have a
  25. // code point above 128.
  26. // Generated by `bin/generate-identifier-regex.js`.
  27. 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\u08a0-\u08b4\u08b6-\u08bd\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\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\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\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\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-\u170c\u170e-\u1711\u1720-\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-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\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-\u2c2e\u2c30-\u2c5e\u2c60-\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-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7b9\ua7f7-\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-\uab65\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";
  28. 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\u08d3-\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\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\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\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\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-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\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\u1cf2-\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\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\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";
  29. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  30. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  31. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  32. // These are a run-length and offset encoded representation of the
  33. // >0xffff code points that are a valid part of identifiers. The
  34. // offset starts at 0x10000, and each pair of numbers represents an
  35. // offset to the next range, and then a size of the range. They were
  36. // generated by bin/generate-identifier-regex.js
  37. // eslint-disable-next-line comma-spacing
  38. 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,157,310,10,21,11,7,153,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,477,28,11,0,9,21,190,52,76,44,33,24,27,35,30,0,12,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,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,26,230,43,117,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,20,0,35,56,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,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,68,12,0,67,12,65,1,31,6129,15,754,9486,286,82,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,4149,196,60,67,1213,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,42710,42,4148,12,221,3,5761,15,7472,3104,541];
  39. // eslint-disable-next-line comma-spacing
  40. 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,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,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,280,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,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,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,2214,6,110,6,6,9,792487,239];
  41. // This has a complexity linear to the value of the code. The
  42. // assumption is that looking up astral identifier characters is
  43. // rare.
  44. function isInAstralSet(code, set) {
  45. var pos = 0x10000;
  46. for (var i = 0; i < set.length; i += 2) {
  47. pos += set[i];
  48. if (pos > code) { return false }
  49. pos += set[i + 1];
  50. if (pos >= code) { return true }
  51. }
  52. }
  53. // Test whether a given character code starts an identifier.
  54. function isIdentifierStart(code, astral) {
  55. if (code < 65) { return code === 36 }
  56. if (code < 91) { return true }
  57. if (code < 97) { return code === 95 }
  58. if (code < 123) { return true }
  59. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  60. if (astral === false) { return false }
  61. return isInAstralSet(code, astralIdentifierStartCodes)
  62. }
  63. // Test whether a given character is part of an identifier.
  64. function isIdentifierChar(code, astral) {
  65. if (code < 48) { return code === 36 }
  66. if (code < 58) { return true }
  67. if (code < 65) { return false }
  68. if (code < 91) { return true }
  69. if (code < 97) { return code === 95 }
  70. if (code < 123) { return true }
  71. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  72. if (astral === false) { return false }
  73. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  74. }
  75. // ## Token types
  76. // The assignment of fine-grained, information-carrying type objects
  77. // allows the tokenizer to store the information it has about a
  78. // token in a way that is very cheap for the parser to look up.
  79. // All token type variables start with an underscore, to make them
  80. // easy to recognize.
  81. // The `beforeExpr` property is used to disambiguate between regular
  82. // expressions and divisions. It is set on all token types that can
  83. // be followed by an expression (thus, a slash after them would be a
  84. // regular expression).
  85. //
  86. // The `startsExpr` property is used to check if the token ends a
  87. // `yield` expression. It is set on all token types that either can
  88. // directly start an expression (like a quotation mark) or can
  89. // continue an expression (like the body of a string).
  90. //
  91. // `isLoop` marks a keyword as starting a loop, which is important
  92. // to know when parsing a label, in order to allow or disallow
  93. // continue jumps to that label.
  94. var TokenType = function TokenType(label, conf) {
  95. if ( conf === void 0 ) conf = {};
  96. this.label = label;
  97. this.keyword = conf.keyword;
  98. this.beforeExpr = !!conf.beforeExpr;
  99. this.startsExpr = !!conf.startsExpr;
  100. this.isLoop = !!conf.isLoop;
  101. this.isAssign = !!conf.isAssign;
  102. this.prefix = !!conf.prefix;
  103. this.postfix = !!conf.postfix;
  104. this.binop = conf.binop || null;
  105. this.updateContext = null;
  106. };
  107. function binop(name, prec) {
  108. return new TokenType(name, {beforeExpr: true, binop: prec})
  109. }
  110. var beforeExpr = {beforeExpr: true};
  111. var startsExpr = {startsExpr: true};
  112. // Map keyword names to token types.
  113. var keywords$1 = {};
  114. // Succinct definitions of keyword token types
  115. function kw(name, options) {
  116. if ( options === void 0 ) options = {};
  117. options.keyword = name;
  118. return keywords$1[name] = new TokenType(name, options)
  119. }
  120. var types = {
  121. num: new TokenType("num", startsExpr),
  122. regexp: new TokenType("regexp", startsExpr),
  123. string: new TokenType("string", startsExpr),
  124. name: new TokenType("name", startsExpr),
  125. eof: new TokenType("eof"),
  126. // Punctuation token types.
  127. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  128. bracketR: new TokenType("]"),
  129. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  130. braceR: new TokenType("}"),
  131. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  132. parenR: new TokenType(")"),
  133. comma: new TokenType(",", beforeExpr),
  134. semi: new TokenType(";", beforeExpr),
  135. colon: new TokenType(":", beforeExpr),
  136. dot: new TokenType("."),
  137. question: new TokenType("?", beforeExpr),
  138. arrow: new TokenType("=>", beforeExpr),
  139. template: new TokenType("template"),
  140. invalidTemplate: new TokenType("invalidTemplate"),
  141. ellipsis: new TokenType("...", beforeExpr),
  142. backQuote: new TokenType("`", startsExpr),
  143. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  144. // Operators. These carry several kinds of properties to help the
  145. // parser use them properly (the presence of these properties is
  146. // what categorizes them as operators).
  147. //
  148. // `binop`, when present, specifies that this operator is a binary
  149. // operator, and will refer to its precedence.
  150. //
  151. // `prefix` and `postfix` mark the operator as a prefix or postfix
  152. // unary operator.
  153. //
  154. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  155. // binary operators with a very low precedence, that should result
  156. // in AssignmentExpression nodes.
  157. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  158. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  159. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  160. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  161. logicalOR: binop("||", 1),
  162. logicalAND: binop("&&", 2),
  163. bitwiseOR: binop("|", 3),
  164. bitwiseXOR: binop("^", 4),
  165. bitwiseAND: binop("&", 5),
  166. equality: binop("==/!=/===/!==", 6),
  167. relational: binop("</>/<=/>=", 7),
  168. bitShift: binop("<</>>/>>>", 8),
  169. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  170. modulo: binop("%", 10),
  171. star: binop("*", 10),
  172. slash: binop("/", 10),
  173. starstar: new TokenType("**", {beforeExpr: true}),
  174. // Keyword token types.
  175. _break: kw("break"),
  176. _case: kw("case", beforeExpr),
  177. _catch: kw("catch"),
  178. _continue: kw("continue"),
  179. _debugger: kw("debugger"),
  180. _default: kw("default", beforeExpr),
  181. _do: kw("do", {isLoop: true, beforeExpr: true}),
  182. _else: kw("else", beforeExpr),
  183. _finally: kw("finally"),
  184. _for: kw("for", {isLoop: true}),
  185. _function: kw("function", startsExpr),
  186. _if: kw("if"),
  187. _return: kw("return", beforeExpr),
  188. _switch: kw("switch"),
  189. _throw: kw("throw", beforeExpr),
  190. _try: kw("try"),
  191. _var: kw("var"),
  192. _const: kw("const"),
  193. _while: kw("while", {isLoop: true}),
  194. _with: kw("with"),
  195. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  196. _this: kw("this", startsExpr),
  197. _super: kw("super", startsExpr),
  198. _class: kw("class", startsExpr),
  199. _extends: kw("extends", beforeExpr),
  200. _export: kw("export"),
  201. _import: kw("import"),
  202. _null: kw("null", startsExpr),
  203. _true: kw("true", startsExpr),
  204. _false: kw("false", startsExpr),
  205. _in: kw("in", {beforeExpr: true, binop: 7}),
  206. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  207. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  208. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  209. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  210. };
  211. // Matches a whole line break (where CRLF is considered a single
  212. // line break). Used to count lines.
  213. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  214. var lineBreakG = new RegExp(lineBreak.source, "g");
  215. function isNewLine(code, ecma2019String) {
  216. return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
  217. }
  218. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  219. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  220. var ref = Object.prototype;
  221. var hasOwnProperty = ref.hasOwnProperty;
  222. var toString = ref.toString;
  223. // Checks if an object has a property.
  224. function has(obj, propName) {
  225. return hasOwnProperty.call(obj, propName)
  226. }
  227. var isArray = Array.isArray || (function (obj) { return (
  228. toString.call(obj) === "[object Array]"
  229. ); });
  230. // These are used when `options.locations` is on, for the
  231. // `startLoc` and `endLoc` properties.
  232. var Position = function Position(line, col) {
  233. this.line = line;
  234. this.column = col;
  235. };
  236. Position.prototype.offset = function offset (n) {
  237. return new Position(this.line, this.column + n)
  238. };
  239. var SourceLocation = function SourceLocation(p, start, end) {
  240. this.start = start;
  241. this.end = end;
  242. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  243. };
  244. // The `getLineInfo` function is mostly useful when the
  245. // `locations` option is off (for performance reasons) and you
  246. // want to find the line/column position for a given character
  247. // offset. `input` should be the code string that the offset refers
  248. // into.
  249. function getLineInfo(input, offset) {
  250. for (var line = 1, cur = 0;;) {
  251. lineBreakG.lastIndex = cur;
  252. var match = lineBreakG.exec(input);
  253. if (match && match.index < offset) {
  254. ++line;
  255. cur = match.index + match[0].length;
  256. } else {
  257. return new Position(line, offset - cur)
  258. }
  259. }
  260. }
  261. // A second optional argument can be given to further configure
  262. // the parser process. These options are recognized:
  263. var defaultOptions = {
  264. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  265. // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
  266. // for strict mode, the set of reserved words, and support for
  267. // new syntax features. The default is 7.
  268. ecmaVersion: 7,
  269. // `sourceType` indicates the mode the code should be parsed in.
  270. // Can be either `"script"` or `"module"`. This influences global
  271. // strict mode and parsing of `import` and `export` declarations.
  272. sourceType: "script",
  273. // `onInsertedSemicolon` can be a callback that will be called
  274. // when a semicolon is automatically inserted. It will be passed
  275. // th position of the comma as an offset, and if `locations` is
  276. // enabled, it is given the location as a `{line, column}` object
  277. // as second argument.
  278. onInsertedSemicolon: null,
  279. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  280. // trailing commas.
  281. onTrailingComma: null,
  282. // By default, reserved words are only enforced if ecmaVersion >= 5.
  283. // Set `allowReserved` to a boolean value to explicitly turn this on
  284. // an off. When this option has the value "never", reserved words
  285. // and keywords can also not be used as property names.
  286. allowReserved: null,
  287. // When enabled, a return at the top level is not considered an
  288. // error.
  289. allowReturnOutsideFunction: false,
  290. // When enabled, import/export statements are not constrained to
  291. // appearing at the top of the program.
  292. allowImportExportEverywhere: false,
  293. // When enabled, await identifiers are allowed to appear at the top-level scope,
  294. // but they are still not allowed in non-async functions.
  295. allowAwaitOutsideFunction: false,
  296. // When enabled, hashbang directive in the beginning of file
  297. // is allowed and treated as a line comment.
  298. allowHashBang: false,
  299. // When `locations` is on, `loc` properties holding objects with
  300. // `start` and `end` properties in `{line, column}` form (with
  301. // line being 1-based and column 0-based) will be attached to the
  302. // nodes.
  303. locations: false,
  304. // A function can be passed as `onToken` option, which will
  305. // cause Acorn to call that function with object in the same
  306. // format as tokens returned from `tokenizer().getToken()`. Note
  307. // that you are not allowed to call the parser from the
  308. // callback—that will corrupt its internal state.
  309. onToken: null,
  310. // A function can be passed as `onComment` option, which will
  311. // cause Acorn to call that function with `(block, text, start,
  312. // end)` parameters whenever a comment is skipped. `block` is a
  313. // boolean indicating whether this is a block (`/* */`) comment,
  314. // `text` is the content of the comment, and `start` and `end` are
  315. // character offsets that denote the start and end of the comment.
  316. // When the `locations` option is on, two more parameters are
  317. // passed, the full `{line, column}` locations of the start and
  318. // end of the comments. Note that you are not allowed to call the
  319. // parser from the callback—that will corrupt its internal state.
  320. onComment: null,
  321. // Nodes have their start and end characters offsets recorded in
  322. // `start` and `end` properties (directly on the node, rather than
  323. // the `loc` object, which holds line/column data. To also add a
  324. // [semi-standardized][range] `range` property holding a `[start,
  325. // end]` array with the same numbers, set the `ranges` option to
  326. // `true`.
  327. //
  328. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  329. ranges: false,
  330. // It is possible to parse multiple files into a single AST by
  331. // passing the tree produced by parsing the first file as
  332. // `program` option in subsequent parses. This will add the
  333. // toplevel forms of the parsed file to the `Program` (top) node
  334. // of an existing parse tree.
  335. program: null,
  336. // When `locations` is on, you can pass this to record the source
  337. // file in every node's `loc` object.
  338. sourceFile: null,
  339. // This value, if given, is stored in every node, whether
  340. // `locations` is on or off.
  341. directSourceFile: null,
  342. // When enabled, parenthesized expressions are represented by
  343. // (non-standard) ParenthesizedExpression nodes
  344. preserveParens: false,
  345. plugins: {}
  346. };
  347. // Interpret and default an options object
  348. function getOptions(opts) {
  349. var options = {};
  350. for (var opt in defaultOptions)
  351. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  352. if (options.ecmaVersion >= 2015)
  353. { options.ecmaVersion -= 2009; }
  354. if (options.allowReserved == null)
  355. { options.allowReserved = options.ecmaVersion < 5; }
  356. if (isArray(options.onToken)) {
  357. var tokens = options.onToken;
  358. options.onToken = function (token) { return tokens.push(token); };
  359. }
  360. if (isArray(options.onComment))
  361. { options.onComment = pushComment(options, options.onComment); }
  362. return options
  363. }
  364. function pushComment(options, array) {
  365. return function(block, text, start, end, startLoc, endLoc) {
  366. var comment = {
  367. type: block ? "Block" : "Line",
  368. value: text,
  369. start: start,
  370. end: end
  371. };
  372. if (options.locations)
  373. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  374. if (options.ranges)
  375. { comment.range = [start, end]; }
  376. array.push(comment);
  377. }
  378. }
  379. // Registered plugins
  380. var plugins = {};
  381. function keywordRegexp(words) {
  382. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  383. }
  384. var Parser = function Parser(options, input, startPos) {
  385. this.options = options = getOptions(options);
  386. this.sourceFile = options.sourceFile;
  387. this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  388. var reserved = "";
  389. if (!options.allowReserved) {
  390. for (var v = options.ecmaVersion;; v--)
  391. { if (reserved = reservedWords[v]) { break } }
  392. if (options.sourceType === "module") { reserved += " await"; }
  393. }
  394. this.reservedWords = keywordRegexp(reserved);
  395. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  396. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  397. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
  398. this.input = String(input);
  399. // Used to signal to callers of `readWord1` whether the word
  400. // contained any escape sequences. This is needed because words with
  401. // escape sequences must not be interpreted as keywords.
  402. this.containsEsc = false;
  403. // Load plugins
  404. this.loadPlugins(options.plugins);
  405. // Set up token state
  406. // The current position of the tokenizer in the input.
  407. if (startPos) {
  408. this.pos = startPos;
  409. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  410. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  411. } else {
  412. this.pos = this.lineStart = 0;
  413. this.curLine = 1;
  414. }
  415. // Properties of the current token:
  416. // Its type
  417. this.type = types.eof;
  418. // For tokens that include more information than their type, the value
  419. this.value = null;
  420. // Its start and end offset
  421. this.start = this.end = this.pos;
  422. // And, if locations are used, the {line, column} object
  423. // corresponding to those offsets
  424. this.startLoc = this.endLoc = this.curPosition();
  425. // Position information for the previous token
  426. this.lastTokEndLoc = this.lastTokStartLoc = null;
  427. this.lastTokStart = this.lastTokEnd = this.pos;
  428. // The context stack is used to superficially track syntactic
  429. // context to predict whether a regular expression is allowed in a
  430. // given position.
  431. this.context = this.initialContext();
  432. this.exprAllowed = true;
  433. // Figure out if it's a module code.
  434. this.inModule = options.sourceType === "module";
  435. this.strict = this.inModule || this.strictDirective(this.pos);
  436. // Used to signify the start of a potential arrow function
  437. this.potentialArrowAt = -1;
  438. // Flags to track whether we are in a function, a generator, an async function.
  439. this.inFunction = this.inGenerator = this.inAsync = false;
  440. // Positions to delayed-check that yield/await does not exist in default parameters.
  441. this.yieldPos = this.awaitPos = 0;
  442. // Labels in scope.
  443. this.labels = [];
  444. // If enabled, skip leading hashbang line.
  445. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  446. { this.skipLineComment(2); }
  447. // Scope tracking for duplicate variable names (see scope.js)
  448. this.scopeStack = [];
  449. this.enterFunctionScope();
  450. // For RegExp validation
  451. this.regexpState = null;
  452. };
  453. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  454. Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
  455. Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
  456. Parser.prototype.extend = function extend (name, f) {
  457. this[name] = f(this[name]);
  458. };
  459. Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
  460. var this$1 = this;
  461. for (var name in pluginConfigs) {
  462. var plugin = plugins[name];
  463. if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
  464. plugin(this$1, pluginConfigs[name]);
  465. }
  466. };
  467. Parser.prototype.parse = function parse () {
  468. var node = this.options.program || this.startNode();
  469. this.nextToken();
  470. return this.parseTopLevel(node)
  471. };
  472. var pp = Parser.prototype;
  473. // ## Parser utilities
  474. var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
  475. pp.strictDirective = function(start) {
  476. var this$1 = this;
  477. for (;;) {
  478. skipWhiteSpace.lastIndex = start;
  479. start += skipWhiteSpace.exec(this$1.input)[0].length;
  480. var match = literal.exec(this$1.input.slice(start));
  481. if (!match) { return false }
  482. if ((match[1] || match[2]) === "use strict") { return true }
  483. start += match[0].length;
  484. }
  485. };
  486. // Predicate that tests whether the next token is of the given
  487. // type, and if yes, consumes it as a side effect.
  488. pp.eat = function(type) {
  489. if (this.type === type) {
  490. this.next();
  491. return true
  492. } else {
  493. return false
  494. }
  495. };
  496. // Tests whether parsed token is a contextual keyword.
  497. pp.isContextual = function(name) {
  498. return this.type === types.name && this.value === name && !this.containsEsc
  499. };
  500. // Consumes contextual keyword if possible.
  501. pp.eatContextual = function(name) {
  502. if (!this.isContextual(name)) { return false }
  503. this.next();
  504. return true
  505. };
  506. // Asserts that following token is given contextual keyword.
  507. pp.expectContextual = function(name) {
  508. if (!this.eatContextual(name)) { this.unexpected(); }
  509. };
  510. // Test whether a semicolon can be inserted at the current position.
  511. pp.canInsertSemicolon = function() {
  512. return this.type === types.eof ||
  513. this.type === types.braceR ||
  514. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  515. };
  516. pp.insertSemicolon = function() {
  517. if (this.canInsertSemicolon()) {
  518. if (this.options.onInsertedSemicolon)
  519. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  520. return true
  521. }
  522. };
  523. // Consume a semicolon, or, failing that, see if we are allowed to
  524. // pretend that there is a semicolon at this position.
  525. pp.semicolon = function() {
  526. if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
  527. };
  528. pp.afterTrailingComma = function(tokType, notNext) {
  529. if (this.type === tokType) {
  530. if (this.options.onTrailingComma)
  531. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  532. if (!notNext)
  533. { this.next(); }
  534. return true
  535. }
  536. };
  537. // Expect a token of a given type. If found, consume it, otherwise,
  538. // raise an unexpected token error.
  539. pp.expect = function(type) {
  540. this.eat(type) || this.unexpected();
  541. };
  542. // Raise an unexpected token error.
  543. pp.unexpected = function(pos) {
  544. this.raise(pos != null ? pos : this.start, "Unexpected token");
  545. };
  546. function DestructuringErrors() {
  547. this.shorthandAssign =
  548. this.trailingComma =
  549. this.parenthesizedAssign =
  550. this.parenthesizedBind =
  551. this.doubleProto =
  552. -1;
  553. }
  554. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  555. if (!refDestructuringErrors) { return }
  556. if (refDestructuringErrors.trailingComma > -1)
  557. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  558. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  559. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  560. };
  561. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  562. if (!refDestructuringErrors) { return false }
  563. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  564. var doubleProto = refDestructuringErrors.doubleProto;
  565. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  566. if (shorthandAssign >= 0)
  567. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  568. if (doubleProto >= 0)
  569. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  570. };
  571. pp.checkYieldAwaitInDefaultParams = function() {
  572. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  573. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  574. if (this.awaitPos)
  575. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  576. };
  577. pp.isSimpleAssignTarget = function(expr) {
  578. if (expr.type === "ParenthesizedExpression")
  579. { return this.isSimpleAssignTarget(expr.expression) }
  580. return expr.type === "Identifier" || expr.type === "MemberExpression"
  581. };
  582. var pp$1 = Parser.prototype;
  583. // ### Statement parsing
  584. // Parse a program. Initializes the parser, reads any number of
  585. // statements, and wraps them in a Program node. Optionally takes a
  586. // `program` argument. If present, the statements will be appended
  587. // to its body instead of creating a new node.
  588. pp$1.parseTopLevel = function(node) {
  589. var this$1 = this;
  590. var exports = {};
  591. if (!node.body) { node.body = []; }
  592. while (this.type !== types.eof) {
  593. var stmt = this$1.parseStatement(true, true, exports);
  594. node.body.push(stmt);
  595. }
  596. this.adaptDirectivePrologue(node.body);
  597. this.next();
  598. if (this.options.ecmaVersion >= 6) {
  599. node.sourceType = this.options.sourceType;
  600. }
  601. return this.finishNode(node, "Program")
  602. };
  603. var loopLabel = {kind: "loop"};
  604. var switchLabel = {kind: "switch"};
  605. pp$1.isLet = function() {
  606. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  607. skipWhiteSpace.lastIndex = this.pos;
  608. var skip = skipWhiteSpace.exec(this.input);
  609. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  610. if (nextCh === 91 || nextCh === 123) { return true } // '{' and '['
  611. if (isIdentifierStart(nextCh, true)) {
  612. var pos = next + 1;
  613. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  614. var ident = this.input.slice(next, pos);
  615. if (!keywordRelationalOperator.test(ident)) { return true }
  616. }
  617. return false
  618. };
  619. // check 'async [no LineTerminator here] function'
  620. // - 'async /*foo*/ function' is OK.
  621. // - 'async /*\n*/ function' is invalid.
  622. pp$1.isAsyncFunction = function() {
  623. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  624. { return false }
  625. skipWhiteSpace.lastIndex = this.pos;
  626. var skip = skipWhiteSpace.exec(this.input);
  627. var next = this.pos + skip[0].length;
  628. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  629. this.input.slice(next, next + 8) === "function" &&
  630. (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  631. };
  632. // Parse a single statement.
  633. //
  634. // If expecting a statement and finding a slash operator, parse a
  635. // regular expression literal. This is to handle cases like
  636. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  637. // does not help.
  638. pp$1.parseStatement = function(declaration, topLevel, exports) {
  639. var starttype = this.type, node = this.startNode(), kind;
  640. if (this.isLet()) {
  641. starttype = types._var;
  642. kind = "let";
  643. }
  644. // Most types of statements are recognized by the keyword they
  645. // start with. Many are trivial to parse, some require a bit of
  646. // complexity.
  647. switch (starttype) {
  648. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  649. case types._debugger: return this.parseDebuggerStatement(node)
  650. case types._do: return this.parseDoStatement(node)
  651. case types._for: return this.parseForStatement(node)
  652. case types._function:
  653. if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
  654. return this.parseFunctionStatement(node, false)
  655. case types._class:
  656. if (!declaration) { this.unexpected(); }
  657. return this.parseClass(node, true)
  658. case types._if: return this.parseIfStatement(node)
  659. case types._return: return this.parseReturnStatement(node)
  660. case types._switch: return this.parseSwitchStatement(node)
  661. case types._throw: return this.parseThrowStatement(node)
  662. case types._try: return this.parseTryStatement(node)
  663. case types._const: case types._var:
  664. kind = kind || this.value;
  665. if (!declaration && kind !== "var") { this.unexpected(); }
  666. return this.parseVarStatement(node, kind)
  667. case types._while: return this.parseWhileStatement(node)
  668. case types._with: return this.parseWithStatement(node)
  669. case types.braceL: return this.parseBlock()
  670. case types.semi: return this.parseEmptyStatement(node)
  671. case types._export:
  672. case types._import:
  673. if (!this.options.allowImportExportEverywhere) {
  674. if (!topLevel)
  675. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  676. if (!this.inModule)
  677. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  678. }
  679. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  680. // If the statement does not start with a statement keyword or a
  681. // brace, it's an ExpressionStatement or LabeledStatement. We
  682. // simply start parsing an expression, and afterwards, if the
  683. // next token is a colon and the expression was a simple
  684. // Identifier node, we switch to interpreting it as a label.
  685. default:
  686. if (this.isAsyncFunction()) {
  687. if (!declaration) { this.unexpected(); }
  688. this.next();
  689. return this.parseFunctionStatement(node, true)
  690. }
  691. var maybeName = this.value, expr = this.parseExpression();
  692. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  693. { return this.parseLabeledStatement(node, maybeName, expr) }
  694. else { return this.parseExpressionStatement(node, expr) }
  695. }
  696. };
  697. pp$1.parseBreakContinueStatement = function(node, keyword) {
  698. var this$1 = this;
  699. var isBreak = keyword === "break";
  700. this.next();
  701. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  702. else if (this.type !== types.name) { this.unexpected(); }
  703. else {
  704. node.label = this.parseIdent();
  705. this.semicolon();
  706. }
  707. // Verify that there is an actual destination to break or
  708. // continue to.
  709. var i = 0;
  710. for (; i < this.labels.length; ++i) {
  711. var lab = this$1.labels[i];
  712. if (node.label == null || lab.name === node.label.name) {
  713. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  714. if (node.label && isBreak) { break }
  715. }
  716. }
  717. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  718. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  719. };
  720. pp$1.parseDebuggerStatement = function(node) {
  721. this.next();
  722. this.semicolon();
  723. return this.finishNode(node, "DebuggerStatement")
  724. };
  725. pp$1.parseDoStatement = function(node) {
  726. this.next();
  727. this.labels.push(loopLabel);
  728. node.body = this.parseStatement(false);
  729. this.labels.pop();
  730. this.expect(types._while);
  731. node.test = this.parseParenExpression();
  732. if (this.options.ecmaVersion >= 6)
  733. { this.eat(types.semi); }
  734. else
  735. { this.semicolon(); }
  736. return this.finishNode(node, "DoWhileStatement")
  737. };
  738. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  739. // loop is non-trivial. Basically, we have to parse the init `var`
  740. // statement or expression, disallowing the `in` operator (see
  741. // the second parameter to `parseExpression`), and then check
  742. // whether the next token is `in` or `of`. When there is no init
  743. // part (semicolon immediately after the opening parenthesis), it
  744. // is a regular `for` loop.
  745. pp$1.parseForStatement = function(node) {
  746. this.next();
  747. var awaitAt = (this.options.ecmaVersion >= 9 && this.inAsync && this.eatContextual("await")) ? this.lastTokStart : -1;
  748. this.labels.push(loopLabel);
  749. this.enterLexicalScope();
  750. this.expect(types.parenL);
  751. if (this.type === types.semi) {
  752. if (awaitAt > -1) { this.unexpected(awaitAt); }
  753. return this.parseFor(node, null)
  754. }
  755. var isLet = this.isLet();
  756. if (this.type === types._var || this.type === types._const || isLet) {
  757. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  758. this.next();
  759. this.parseVar(init$1, true, kind);
  760. this.finishNode(init$1, "VariableDeclaration");
  761. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
  762. !(kind !== "var" && init$1.declarations[0].init)) {
  763. if (this.options.ecmaVersion >= 9) {
  764. if (this.type === types._in) {
  765. if (awaitAt > -1) { this.unexpected(awaitAt); }
  766. } else { node.await = awaitAt > -1; }
  767. }
  768. return this.parseForIn(node, init$1)
  769. }
  770. if (awaitAt > -1) { this.unexpected(awaitAt); }
  771. return this.parseFor(node, init$1)
  772. }
  773. var refDestructuringErrors = new DestructuringErrors;
  774. var init = this.parseExpression(true, refDestructuringErrors);
  775. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  776. if (this.options.ecmaVersion >= 9) {
  777. if (this.type === types._in) {
  778. if (awaitAt > -1) { this.unexpected(awaitAt); }
  779. } else { node.await = awaitAt > -1; }
  780. }
  781. this.toAssignable(init, false, refDestructuringErrors);
  782. this.checkLVal(init);
  783. return this.parseForIn(node, init)
  784. } else {
  785. this.checkExpressionErrors(refDestructuringErrors, true);
  786. }
  787. if (awaitAt > -1) { this.unexpected(awaitAt); }
  788. return this.parseFor(node, init)
  789. };
  790. pp$1.parseFunctionStatement = function(node, isAsync) {
  791. this.next();
  792. return this.parseFunction(node, true, false, isAsync)
  793. };
  794. pp$1.parseIfStatement = function(node) {
  795. this.next();
  796. node.test = this.parseParenExpression();
  797. // allow function declarations in branches, but only in non-strict mode
  798. node.consequent = this.parseStatement(!this.strict && this.type === types._function);
  799. node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.type === types._function) : null;
  800. return this.finishNode(node, "IfStatement")
  801. };
  802. pp$1.parseReturnStatement = function(node) {
  803. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  804. { this.raise(this.start, "'return' outside of function"); }
  805. this.next();
  806. // In `return` (and `break`/`continue`), the keywords with
  807. // optional arguments, we eagerly look for a semicolon or the
  808. // possibility to insert one.
  809. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  810. else { node.argument = this.parseExpression(); this.semicolon(); }
  811. return this.finishNode(node, "ReturnStatement")
  812. };
  813. pp$1.parseSwitchStatement = function(node) {
  814. var this$1 = this;
  815. this.next();
  816. node.discriminant = this.parseParenExpression();
  817. node.cases = [];
  818. this.expect(types.braceL);
  819. this.labels.push(switchLabel);
  820. this.enterLexicalScope();
  821. // Statements under must be grouped (by label) in SwitchCase
  822. // nodes. `cur` is used to keep the node that we are currently
  823. // adding statements to.
  824. var cur;
  825. for (var sawDefault = false; this.type !== types.braceR;) {
  826. if (this$1.type === types._case || this$1.type === types._default) {
  827. var isCase = this$1.type === types._case;
  828. if (cur) { this$1.finishNode(cur, "SwitchCase"); }
  829. node.cases.push(cur = this$1.startNode());
  830. cur.consequent = [];
  831. this$1.next();
  832. if (isCase) {
  833. cur.test = this$1.parseExpression();
  834. } else {
  835. if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
  836. sawDefault = true;
  837. cur.test = null;
  838. }
  839. this$1.expect(types.colon);
  840. } else {
  841. if (!cur) { this$1.unexpected(); }
  842. cur.consequent.push(this$1.parseStatement(true));
  843. }
  844. }
  845. this.exitLexicalScope();
  846. if (cur) { this.finishNode(cur, "SwitchCase"); }
  847. this.next(); // Closing brace
  848. this.labels.pop();
  849. return this.finishNode(node, "SwitchStatement")
  850. };
  851. pp$1.parseThrowStatement = function(node) {
  852. this.next();
  853. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  854. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  855. node.argument = this.parseExpression();
  856. this.semicolon();
  857. return this.finishNode(node, "ThrowStatement")
  858. };
  859. // Reused empty array added for node fields that are always empty.
  860. var empty = [];
  861. pp$1.parseTryStatement = function(node) {
  862. this.next();
  863. node.block = this.parseBlock();
  864. node.handler = null;
  865. if (this.type === types._catch) {
  866. var clause = this.startNode();
  867. this.next();
  868. if (this.eat(types.parenL)) {
  869. clause.param = this.parseBindingAtom();
  870. this.enterLexicalScope();
  871. this.checkLVal(clause.param, "let");
  872. this.expect(types.parenR);
  873. } else {
  874. if (this.options.ecmaVersion < 10) { this.unexpected(); }
  875. clause.param = null;
  876. this.enterLexicalScope();
  877. }
  878. clause.body = this.parseBlock(false);
  879. this.exitLexicalScope();
  880. node.handler = this.finishNode(clause, "CatchClause");
  881. }
  882. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  883. if (!node.handler && !node.finalizer)
  884. { this.raise(node.start, "Missing catch or finally clause"); }
  885. return this.finishNode(node, "TryStatement")
  886. };
  887. pp$1.parseVarStatement = function(node, kind) {
  888. this.next();
  889. this.parseVar(node, false, kind);
  890. this.semicolon();
  891. return this.finishNode(node, "VariableDeclaration")
  892. };
  893. pp$1.parseWhileStatement = function(node) {
  894. this.next();
  895. node.test = this.parseParenExpression();
  896. this.labels.push(loopLabel);
  897. node.body = this.parseStatement(false);
  898. this.labels.pop();
  899. return this.finishNode(node, "WhileStatement")
  900. };
  901. pp$1.parseWithStatement = function(node) {
  902. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  903. this.next();
  904. node.object = this.parseParenExpression();
  905. node.body = this.parseStatement(false);
  906. return this.finishNode(node, "WithStatement")
  907. };
  908. pp$1.parseEmptyStatement = function(node) {
  909. this.next();
  910. return this.finishNode(node, "EmptyStatement")
  911. };
  912. pp$1.parseLabeledStatement = function(node, maybeName, expr) {
  913. var this$1 = this;
  914. for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
  915. {
  916. var label = list[i$1];
  917. if (label.name === maybeName)
  918. { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
  919. } }
  920. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  921. for (var i = this.labels.length - 1; i >= 0; i--) {
  922. var label$1 = this$1.labels[i];
  923. if (label$1.statementStart === node.start) {
  924. // Update information about previous labels on this node
  925. label$1.statementStart = this$1.start;
  926. label$1.kind = kind;
  927. } else { break }
  928. }
  929. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  930. node.body = this.parseStatement(true);
  931. if (node.body.type === "ClassDeclaration" ||
  932. node.body.type === "VariableDeclaration" && node.body.kind !== "var" ||
  933. node.body.type === "FunctionDeclaration" && (this.strict || node.body.generator))
  934. { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
  935. this.labels.pop();
  936. node.label = expr;
  937. return this.finishNode(node, "LabeledStatement")
  938. };
  939. pp$1.parseExpressionStatement = function(node, expr) {
  940. node.expression = expr;
  941. this.semicolon();
  942. return this.finishNode(node, "ExpressionStatement")
  943. };
  944. // Parse a semicolon-enclosed block of statements, handling `"use
  945. // strict"` declarations when `allowStrict` is true (used for
  946. // function bodies).
  947. pp$1.parseBlock = function(createNewLexicalScope) {
  948. var this$1 = this;
  949. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  950. var node = this.startNode();
  951. node.body = [];
  952. this.expect(types.braceL);
  953. if (createNewLexicalScope) {
  954. this.enterLexicalScope();
  955. }
  956. while (!this.eat(types.braceR)) {
  957. var stmt = this$1.parseStatement(true);
  958. node.body.push(stmt);
  959. }
  960. if (createNewLexicalScope) {
  961. this.exitLexicalScope();
  962. }
  963. return this.finishNode(node, "BlockStatement")
  964. };
  965. // Parse a regular `for` loop. The disambiguation code in
  966. // `parseStatement` will already have parsed the init statement or
  967. // expression.
  968. pp$1.parseFor = function(node, init) {
  969. node.init = init;
  970. this.expect(types.semi);
  971. node.test = this.type === types.semi ? null : this.parseExpression();
  972. this.expect(types.semi);
  973. node.update = this.type === types.parenR ? null : this.parseExpression();
  974. this.expect(types.parenR);
  975. this.exitLexicalScope();
  976. node.body = this.parseStatement(false);
  977. this.labels.pop();
  978. return this.finishNode(node, "ForStatement")
  979. };
  980. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  981. // same from parser's perspective.
  982. pp$1.parseForIn = function(node, init) {
  983. var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
  984. this.next();
  985. if (type === "ForInStatement") {
  986. if (init.type === "AssignmentPattern" ||
  987. (init.type === "VariableDeclaration" && init.declarations[0].init != null &&
  988. (this.strict || init.declarations[0].id.type !== "Identifier")))
  989. { this.raise(init.start, "Invalid assignment in for-in loop head"); }
  990. }
  991. node.left = init;
  992. node.right = type === "ForInStatement" ? this.parseExpression() : this.parseMaybeAssign();
  993. this.expect(types.parenR);
  994. this.exitLexicalScope();
  995. node.body = this.parseStatement(false);
  996. this.labels.pop();
  997. return this.finishNode(node, type)
  998. };
  999. // Parse a list of variable declarations.
  1000. pp$1.parseVar = function(node, isFor, kind) {
  1001. var this$1 = this;
  1002. node.declarations = [];
  1003. node.kind = kind;
  1004. for (;;) {
  1005. var decl = this$1.startNode();
  1006. this$1.parseVarId(decl, kind);
  1007. if (this$1.eat(types.eq)) {
  1008. decl.init = this$1.parseMaybeAssign(isFor);
  1009. } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
  1010. this$1.unexpected();
  1011. } else if (decl.id.type !== "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
  1012. this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
  1013. } else {
  1014. decl.init = null;
  1015. }
  1016. node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
  1017. if (!this$1.eat(types.comma)) { break }
  1018. }
  1019. return node
  1020. };
  1021. pp$1.parseVarId = function(decl, kind) {
  1022. decl.id = this.parseBindingAtom(kind);
  1023. this.checkLVal(decl.id, kind, false);
  1024. };
  1025. // Parse a function declaration or literal (depending on the
  1026. // `isStatement` parameter).
  1027. pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
  1028. this.initFunction(node);
  1029. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync)
  1030. { node.generator = this.eat(types.star); }
  1031. if (this.options.ecmaVersion >= 8)
  1032. { node.async = !!isAsync; }
  1033. if (isStatement) {
  1034. node.id = isStatement === "nullableID" && this.type !== types.name ? null : this.parseIdent();
  1035. if (node.id) {
  1036. this.checkLVal(node.id, "var");
  1037. }
  1038. }
  1039. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  1040. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  1041. this.inGenerator = node.generator;
  1042. this.inAsync = node.async;
  1043. this.yieldPos = 0;
  1044. this.awaitPos = 0;
  1045. this.inFunction = true;
  1046. this.enterFunctionScope();
  1047. if (!isStatement)
  1048. { node.id = this.type === types.name ? this.parseIdent() : null; }
  1049. this.parseFunctionParams(node);
  1050. this.parseFunctionBody(node, allowExpressionBody);
  1051. this.inGenerator = oldInGen;
  1052. this.inAsync = oldInAsync;
  1053. this.yieldPos = oldYieldPos;
  1054. this.awaitPos = oldAwaitPos;
  1055. this.inFunction = oldInFunc;
  1056. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
  1057. };
  1058. pp$1.parseFunctionParams = function(node) {
  1059. this.expect(types.parenL);
  1060. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  1061. this.checkYieldAwaitInDefaultParams();
  1062. };
  1063. // Parse a class declaration or literal (depending on the
  1064. // `isStatement` parameter).
  1065. pp$1.parseClass = function(node, isStatement) {
  1066. var this$1 = this;
  1067. this.next();
  1068. this.parseClassId(node, isStatement);
  1069. this.parseClassSuper(node);
  1070. var classBody = this.startNode();
  1071. var hadConstructor = false;
  1072. classBody.body = [];
  1073. this.expect(types.braceL);
  1074. while (!this.eat(types.braceR)) {
  1075. var member = this$1.parseClassMember(classBody);
  1076. if (member && member.type === "MethodDefinition" && member.kind === "constructor") {
  1077. if (hadConstructor) { this$1.raise(member.start, "Duplicate constructor in the same class"); }
  1078. hadConstructor = true;
  1079. }
  1080. }
  1081. node.body = this.finishNode(classBody, "ClassBody");
  1082. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1083. };
  1084. pp$1.parseClassMember = function(classBody) {
  1085. var this$1 = this;
  1086. if (this.eat(types.semi)) { return null }
  1087. var method = this.startNode();
  1088. var tryContextual = function (k, noLineBreak) {
  1089. if ( noLineBreak === void 0 ) noLineBreak = false;
  1090. var start = this$1.start, startLoc = this$1.startLoc;
  1091. if (!this$1.eatContextual(k)) { return false }
  1092. if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
  1093. if (method.key) { this$1.unexpected(); }
  1094. method.computed = false;
  1095. method.key = this$1.startNodeAt(start, startLoc);
  1096. method.key.name = k;
  1097. this$1.finishNode(method.key, "Identifier");
  1098. return false
  1099. };
  1100. method.kind = "method";
  1101. method.static = tryContextual("static");
  1102. var isGenerator = this.eat(types.star);
  1103. var isAsync = false;
  1104. if (!isGenerator) {
  1105. if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
  1106. isAsync = true;
  1107. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  1108. } else if (tryContextual("get")) {
  1109. method.kind = "get";
  1110. } else if (tryContextual("set")) {
  1111. method.kind = "set";
  1112. }
  1113. }
  1114. if (!method.key) { this.parsePropertyName(method); }
  1115. var key = method.key;
  1116. if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
  1117. key.type === "Literal" && key.value === "constructor")) {
  1118. if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
  1119. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1120. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1121. method.kind = "constructor";
  1122. } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
  1123. this.raise(key.start, "Classes may not have a static property named prototype");
  1124. }
  1125. this.parseClassMethod(classBody, method, isGenerator, isAsync);
  1126. if (method.kind === "get" && method.value.params.length !== 0)
  1127. { this.raiseRecoverable(method.value.start, "getter should have no params"); }
  1128. if (method.kind === "set" && method.value.params.length !== 1)
  1129. { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
  1130. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  1131. { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  1132. return method
  1133. };
  1134. pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
  1135. method.value = this.parseMethod(isGenerator, isAsync);
  1136. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  1137. };
  1138. pp$1.parseClassId = function(node, isStatement) {
  1139. node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
  1140. };
  1141. pp$1.parseClassSuper = function(node) {
  1142. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  1143. };
  1144. // Parses module export declaration.
  1145. pp$1.parseExport = function(node, exports) {
  1146. var this$1 = this;
  1147. this.next();
  1148. // export * from '...'
  1149. if (this.eat(types.star)) {
  1150. this.expectContextual("from");
  1151. if (this.type !== types.string) { this.unexpected(); }
  1152. node.source = this.parseExprAtom();
  1153. this.semicolon();
  1154. return this.finishNode(node, "ExportAllDeclaration")
  1155. }
  1156. if (this.eat(types._default)) { // export default ...
  1157. this.checkExport(exports, "default", this.lastTokStart);
  1158. var isAsync;
  1159. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  1160. var fNode = this.startNode();
  1161. this.next();
  1162. if (isAsync) { this.next(); }
  1163. node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
  1164. } else if (this.type === types._class) {
  1165. var cNode = this.startNode();
  1166. node.declaration = this.parseClass(cNode, "nullableID");
  1167. } else {
  1168. node.declaration = this.parseMaybeAssign();
  1169. this.semicolon();
  1170. }
  1171. return this.finishNode(node, "ExportDefaultDeclaration")
  1172. }
  1173. // export var|const|let|function|class ...
  1174. if (this.shouldParseExportStatement()) {
  1175. node.declaration = this.parseStatement(true);
  1176. if (node.declaration.type === "VariableDeclaration")
  1177. { this.checkVariableExport(exports, node.declaration.declarations); }
  1178. else
  1179. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1180. node.specifiers = [];
  1181. node.source = null;
  1182. } else { // export { x, y as z } [from '...']
  1183. node.declaration = null;
  1184. node.specifiers = this.parseExportSpecifiers(exports);
  1185. if (this.eatContextual("from")) {
  1186. if (this.type !== types.string) { this.unexpected(); }
  1187. node.source = this.parseExprAtom();
  1188. } else {
  1189. // check for keywords used as local names
  1190. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1191. var spec = list[i];
  1192. this$1.checkUnreserved(spec.local);
  1193. }
  1194. node.source = null;
  1195. }
  1196. this.semicolon();
  1197. }
  1198. return this.finishNode(node, "ExportNamedDeclaration")
  1199. };
  1200. pp$1.checkExport = function(exports, name, pos) {
  1201. if (!exports) { return }
  1202. if (has(exports, name))
  1203. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1204. exports[name] = true;
  1205. };
  1206. pp$1.checkPatternExport = function(exports, pat) {
  1207. var this$1 = this;
  1208. var type = pat.type;
  1209. if (type === "Identifier")
  1210. { this.checkExport(exports, pat.name, pat.start); }
  1211. else if (type === "ObjectPattern")
  1212. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1213. {
  1214. var prop = list[i];
  1215. this$1.checkPatternExport(exports, prop);
  1216. } }
  1217. else if (type === "ArrayPattern")
  1218. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1219. var elt = list$1[i$1];
  1220. if (elt) { this$1.checkPatternExport(exports, elt); }
  1221. } }
  1222. else if (type === "Property")
  1223. { this.checkPatternExport(exports, pat.value); }
  1224. else if (type === "AssignmentPattern")
  1225. { this.checkPatternExport(exports, pat.left); }
  1226. else if (type === "RestElement")
  1227. { this.checkPatternExport(exports, pat.argument); }
  1228. else if (type === "ParenthesizedExpression")
  1229. { this.checkPatternExport(exports, pat.expression); }
  1230. };
  1231. pp$1.checkVariableExport = function(exports, decls) {
  1232. var this$1 = this;
  1233. if (!exports) { return }
  1234. for (var i = 0, list = decls; i < list.length; i += 1)
  1235. {
  1236. var decl = list[i];
  1237. this$1.checkPatternExport(exports, decl.id);
  1238. }
  1239. };
  1240. pp$1.shouldParseExportStatement = function() {
  1241. return this.type.keyword === "var" ||
  1242. this.type.keyword === "const" ||
  1243. this.type.keyword === "class" ||
  1244. this.type.keyword === "function" ||
  1245. this.isLet() ||
  1246. this.isAsyncFunction()
  1247. };
  1248. // Parses a comma-separated list of module exports.
  1249. pp$1.parseExportSpecifiers = function(exports) {
  1250. var this$1 = this;
  1251. var nodes = [], first = true;
  1252. // export { x, y as z } [from '...']
  1253. this.expect(types.braceL);
  1254. while (!this.eat(types.braceR)) {
  1255. if (!first) {
  1256. this$1.expect(types.comma);
  1257. if (this$1.afterTrailingComma(types.braceR)) { break }
  1258. } else { first = false; }
  1259. var node = this$1.startNode();
  1260. node.local = this$1.parseIdent(true);
  1261. node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
  1262. this$1.checkExport(exports, node.exported.name, node.exported.start);
  1263. nodes.push(this$1.finishNode(node, "ExportSpecifier"));
  1264. }
  1265. return nodes
  1266. };
  1267. // Parses import declaration.
  1268. pp$1.parseImport = function(node) {
  1269. this.next();
  1270. // import '...'
  1271. if (this.type === types.string) {
  1272. node.specifiers = empty;
  1273. node.source = this.parseExprAtom();
  1274. } else {
  1275. node.specifiers = this.parseImportSpecifiers();
  1276. this.expectContextual("from");
  1277. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1278. }
  1279. this.semicolon();
  1280. return this.finishNode(node, "ImportDeclaration")
  1281. };
  1282. // Parses a comma-separated list of module imports.
  1283. pp$1.parseImportSpecifiers = function() {
  1284. var this$1 = this;
  1285. var nodes = [], first = true;
  1286. if (this.type === types.name) {
  1287. // import defaultObj, { x, y as z } from '...'
  1288. var node = this.startNode();
  1289. node.local = this.parseIdent();
  1290. this.checkLVal(node.local, "let");
  1291. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1292. if (!this.eat(types.comma)) { return nodes }
  1293. }
  1294. if (this.type === types.star) {
  1295. var node$1 = this.startNode();
  1296. this.next();
  1297. this.expectContextual("as");
  1298. node$1.local = this.parseIdent();
  1299. this.checkLVal(node$1.local, "let");
  1300. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1301. return nodes
  1302. }
  1303. this.expect(types.braceL);
  1304. while (!this.eat(types.braceR)) {
  1305. if (!first) {
  1306. this$1.expect(types.comma);
  1307. if (this$1.afterTrailingComma(types.braceR)) { break }
  1308. } else { first = false; }
  1309. var node$2 = this$1.startNode();
  1310. node$2.imported = this$1.parseIdent(true);
  1311. if (this$1.eatContextual("as")) {
  1312. node$2.local = this$1.parseIdent();
  1313. } else {
  1314. this$1.checkUnreserved(node$2.imported);
  1315. node$2.local = node$2.imported;
  1316. }
  1317. this$1.checkLVal(node$2.local, "let");
  1318. nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
  1319. }
  1320. return nodes
  1321. };
  1322. // Set `ExpressionStatement#directive` property for directive prologues.
  1323. pp$1.adaptDirectivePrologue = function(statements) {
  1324. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1325. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1326. }
  1327. };
  1328. pp$1.isDirectiveCandidate = function(statement) {
  1329. return (
  1330. statement.type === "ExpressionStatement" &&
  1331. statement.expression.type === "Literal" &&
  1332. typeof statement.expression.value === "string" &&
  1333. // Reject parenthesized strings.
  1334. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1335. )
  1336. };
  1337. var pp$2 = Parser.prototype;
  1338. // Convert existing expression atom to assignable pattern
  1339. // if possible.
  1340. pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1341. var this$1 = this;
  1342. if (this.options.ecmaVersion >= 6 && node) {
  1343. switch (node.type) {
  1344. case "Identifier":
  1345. if (this.inAsync && node.name === "await")
  1346. { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
  1347. break
  1348. case "ObjectPattern":
  1349. case "ArrayPattern":
  1350. case "RestElement":
  1351. break
  1352. case "ObjectExpression":
  1353. node.type = "ObjectPattern";
  1354. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1355. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1356. var prop = list[i];
  1357. this$1.toAssignable(prop, isBinding);
  1358. // Early error:
  1359. // AssignmentRestProperty[Yield, Await] :
  1360. // `...` DestructuringAssignmentTarget[Yield, Await]
  1361. //
  1362. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1363. if (
  1364. prop.type === "RestElement" &&
  1365. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1366. ) {
  1367. this$1.raise(prop.argument.start, "Unexpected token");
  1368. }
  1369. }
  1370. break
  1371. case "Property":
  1372. // AssignmentProperty has type === "Property"
  1373. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1374. this.toAssignable(node.value, isBinding);
  1375. break
  1376. case "ArrayExpression":
  1377. node.type = "ArrayPattern";
  1378. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1379. this.toAssignableList(node.elements, isBinding);
  1380. break
  1381. case "SpreadElement":
  1382. node.type = "RestElement";
  1383. this.toAssignable(node.argument, isBinding);
  1384. if (node.argument.type === "AssignmentPattern")
  1385. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1386. break
  1387. case "AssignmentExpression":
  1388. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1389. node.type = "AssignmentPattern";
  1390. delete node.operator;
  1391. this.toAssignable(node.left, isBinding);
  1392. // falls through to AssignmentPattern
  1393. case "AssignmentPattern":
  1394. break
  1395. case "ParenthesizedExpression":
  1396. this.toAssignable(node.expression, isBinding);
  1397. break
  1398. case "MemberExpression":
  1399. if (!isBinding) { break }
  1400. default:
  1401. this.raise(node.start, "Assigning to rvalue");
  1402. }
  1403. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1404. return node
  1405. };
  1406. // Convert list of expression atoms to binding list.
  1407. pp$2.toAssignableList = function(exprList, isBinding) {
  1408. var this$1 = this;
  1409. var end = exprList.length;
  1410. for (var i = 0; i < end; i++) {
  1411. var elt = exprList[i];
  1412. if (elt) { this$1.toAssignable(elt, isBinding); }
  1413. }
  1414. if (end) {
  1415. var last = exprList[end - 1];
  1416. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1417. { this.unexpected(last.argument.start); }
  1418. }
  1419. return exprList
  1420. };
  1421. // Parses spread element.
  1422. pp$2.parseSpread = function(refDestructuringErrors) {
  1423. var node = this.startNode();
  1424. this.next();
  1425. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1426. return this.finishNode(node, "SpreadElement")
  1427. };
  1428. pp$2.parseRestBinding = function() {
  1429. var node = this.startNode();
  1430. this.next();
  1431. // RestElement inside of a function parameter must be an identifier
  1432. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  1433. { this.unexpected(); }
  1434. node.argument = this.parseBindingAtom();
  1435. return this.finishNode(node, "RestElement")
  1436. };
  1437. // Parses lvalue (assignable) atom.
  1438. pp$2.parseBindingAtom = function() {
  1439. if (this.options.ecmaVersion >= 6) {
  1440. switch (this.type) {
  1441. case types.bracketL:
  1442. var node = this.startNode();
  1443. this.next();
  1444. node.elements = this.parseBindingList(types.bracketR, true, true);
  1445. return this.finishNode(node, "ArrayPattern")
  1446. case types.braceL:
  1447. return this.parseObj(true)
  1448. }
  1449. }
  1450. return this.parseIdent()
  1451. };
  1452. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1453. var this$1 = this;
  1454. var elts = [], first = true;
  1455. while (!this.eat(close)) {
  1456. if (first) { first = false; }
  1457. else { this$1.expect(types.comma); }
  1458. if (allowEmpty && this$1.type === types.comma) {
  1459. elts.push(null);
  1460. } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
  1461. break
  1462. } else if (this$1.type === types.ellipsis) {
  1463. var rest = this$1.parseRestBinding();
  1464. this$1.parseBindingListItem(rest);
  1465. elts.push(rest);
  1466. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1467. this$1.expect(close);
  1468. break
  1469. } else {
  1470. var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
  1471. this$1.parseBindingListItem(elem);
  1472. elts.push(elem);
  1473. }
  1474. }
  1475. return elts
  1476. };
  1477. pp$2.parseBindingListItem = function(param) {
  1478. return param
  1479. };
  1480. // Parses assignment pattern around given atom if possible.
  1481. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1482. left = left || this.parseBindingAtom();
  1483. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  1484. var node = this.startNodeAt(startPos, startLoc);
  1485. node.left = left;
  1486. node.right = this.parseMaybeAssign();
  1487. return this.finishNode(node, "AssignmentPattern")
  1488. };
  1489. // Verify that a node is an lval — something that can be assigned
  1490. // to.
  1491. // bindingType can be either:
  1492. // 'var' indicating that the lval creates a 'var' binding
  1493. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  1494. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  1495. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  1496. var this$1 = this;
  1497. switch (expr.type) {
  1498. case "Identifier":
  1499. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1500. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1501. if (checkClashes) {
  1502. if (has(checkClashes, expr.name))
  1503. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1504. checkClashes[expr.name] = true;
  1505. }
  1506. if (bindingType && bindingType !== "none") {
  1507. if (
  1508. bindingType === "var" && !this.canDeclareVarName(expr.name) ||
  1509. bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
  1510. ) {
  1511. this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
  1512. }
  1513. if (bindingType === "var") {
  1514. this.declareVarName(expr.name);
  1515. } else {
  1516. this.declareLexicalName(expr.name);
  1517. }
  1518. }
  1519. break
  1520. case "MemberExpression":
  1521. if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  1522. break
  1523. case "ObjectPattern":
  1524. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  1525. {
  1526. var prop = list[i];
  1527. this$1.checkLVal(prop, bindingType, checkClashes);
  1528. }
  1529. break
  1530. case "Property":
  1531. // AssignmentProperty has type === "Property"
  1532. this.checkLVal(expr.value, bindingType, checkClashes);
  1533. break
  1534. case "ArrayPattern":
  1535. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1536. var elem = list$1[i$1];
  1537. if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
  1538. }
  1539. break
  1540. case "AssignmentPattern":
  1541. this.checkLVal(expr.left, bindingType, checkClashes);
  1542. break
  1543. case "RestElement":
  1544. this.checkLVal(expr.argument, bindingType, checkClashes);
  1545. break
  1546. case "ParenthesizedExpression":
  1547. this.checkLVal(expr.expression, bindingType, checkClashes);
  1548. break
  1549. default:
  1550. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  1551. }
  1552. };
  1553. // A recursive descent parser operates by defining functions for all
  1554. // syntactic elements, and recursively calling those, each function
  1555. // advancing the input stream and returning an AST node. Precedence
  1556. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  1557. // instead of `(!x)[1]` is handled by the fact that the parser
  1558. // function that parses unary prefix operators is called first, and
  1559. // in turn calls the function that parses `[]` subscripts — that
  1560. // way, it'll receive the node for `x[1]` already parsed, and wraps
  1561. // *that* in the unary operator node.
  1562. //
  1563. // Acorn uses an [operator precedence parser][opp] to handle binary
  1564. // operator precedence, because it is much more compact than using
  1565. // the technique outlined above, which uses different, nesting
  1566. // functions to specify precedence, for all of the ten binary
  1567. // precedence levels that JavaScript defines.
  1568. //
  1569. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  1570. var pp$3 = Parser.prototype;
  1571. // Check if property name clashes with already added.
  1572. // Object/class getters and setters are not allowed to clash —
  1573. // either with each other or with an init property — and in
  1574. // strict mode, init properties are also not allowed to be repeated.
  1575. pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  1576. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  1577. { return }
  1578. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1579. { return }
  1580. var key = prop.key;
  1581. var name;
  1582. switch (key.type) {
  1583. case "Identifier": name = key.name; break
  1584. case "Literal": name = String(key.value); break
  1585. default: return
  1586. }
  1587. var kind = prop.kind;
  1588. if (this.options.ecmaVersion >= 6) {
  1589. if (name === "__proto__" && kind === "init") {
  1590. if (propHash.proto) {
  1591. if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; }
  1592. // Backwards-compat kludge. Can be removed in version 6.0
  1593. else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  1594. }
  1595. propHash.proto = true;
  1596. }
  1597. return
  1598. }
  1599. name = "$" + name;
  1600. var other = propHash[name];
  1601. if (other) {
  1602. var redefinition;
  1603. if (kind === "init") {
  1604. redefinition = this.strict && other.init || other.get || other.set;
  1605. } else {
  1606. redefinition = other.init || other[kind];
  1607. }
  1608. if (redefinition)
  1609. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  1610. } else {
  1611. other = propHash[name] = {
  1612. init: false,
  1613. get: false,
  1614. set: false
  1615. };
  1616. }
  1617. other[kind] = true;
  1618. };
  1619. // ### Expression parsing
  1620. // These nest, from the most general expression type at the top to
  1621. // 'atomic', nondivisible expression types at the bottom. Most of
  1622. // the functions will simply let the function(s) below them parse,
  1623. // and, *if* the syntactic construct they handle is present, wrap
  1624. // the AST node that the inner parser gave them in another node.
  1625. // Parse a full expression. The optional arguments are used to
  1626. // forbid the `in` operator (in for loops initalization expressions)
  1627. // and provide reference for storing '=' operator inside shorthand
  1628. // property assignment in contexts where both object expression
  1629. // and object pattern might appear (so it's possible to raise
  1630. // delayed syntax error at correct position).
  1631. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1632. var this$1 = this;
  1633. var startPos = this.start, startLoc = this.startLoc;
  1634. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1635. if (this.type === types.comma) {
  1636. var node = this.startNodeAt(startPos, startLoc);
  1637. node.expressions = [expr];
  1638. while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
  1639. return this.finishNode(node, "SequenceExpression")
  1640. }
  1641. return expr
  1642. };
  1643. // Parse an assignment expression. This includes applications of
  1644. // operators like `+=`.
  1645. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1646. if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
  1647. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
  1648. if (refDestructuringErrors) {
  1649. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  1650. oldTrailingComma = refDestructuringErrors.trailingComma;
  1651. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  1652. } else {
  1653. refDestructuringErrors = new DestructuringErrors;
  1654. ownDestructuringErrors = true;
  1655. }
  1656. var startPos = this.start, startLoc = this.startLoc;
  1657. if (this.type === types.parenL || this.type === types.name)
  1658. { this.potentialArrowAt = this.start; }
  1659. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1660. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  1661. if (this.type.isAssign) {
  1662. var node = this.startNodeAt(startPos, startLoc);
  1663. node.operator = this.value;
  1664. node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
  1665. if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
  1666. refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
  1667. this.checkLVal(left);
  1668. this.next();
  1669. node.right = this.parseMaybeAssign(noIn);
  1670. return this.finishNode(node, "AssignmentExpression")
  1671. } else {
  1672. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  1673. }
  1674. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  1675. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  1676. return left
  1677. };
  1678. // Parse a ternary conditional (`?:`) operator.
  1679. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1680. var startPos = this.start, startLoc = this.startLoc;
  1681. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1682. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1683. if (this.eat(types.question)) {
  1684. var node = this.startNodeAt(startPos, startLoc);
  1685. node.test = expr;
  1686. node.consequent = this.parseMaybeAssign();
  1687. this.expect(types.colon);
  1688. node.alternate = this.parseMaybeAssign(noIn);
  1689. return this.finishNode(node, "ConditionalExpression")
  1690. }
  1691. return expr
  1692. };
  1693. // Start the precedence parser.
  1694. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1695. var startPos = this.start, startLoc = this.startLoc;
  1696. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1697. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1698. return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1699. };
  1700. // Parse binary operators with the operator precedence parsing
  1701. // algorithm. `left` is the left-hand side of the operator.
  1702. // `minPrec` provides context that allows the function to stop and
  1703. // defer further parser to one of its callers when it encounters an
  1704. // operator that has a lower precedence than the set it is parsing.
  1705. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1706. var prec = this.type.binop;
  1707. if (prec != null && (!noIn || this.type !== types._in)) {
  1708. if (prec > minPrec) {
  1709. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  1710. var op = this.value;
  1711. this.next();
  1712. var startPos = this.start, startLoc = this.startLoc;
  1713. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1714. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  1715. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1716. }
  1717. }
  1718. return left
  1719. };
  1720. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1721. var node = this.startNodeAt(startPos, startLoc);
  1722. node.left = left;
  1723. node.operator = op;
  1724. node.right = right;
  1725. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1726. };
  1727. // Parse unary operators, both prefix and postfix.
  1728. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1729. var this$1 = this;
  1730. var startPos = this.start, startLoc = this.startLoc, expr;
  1731. if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
  1732. expr = this.parseAwait();
  1733. sawUnary = true;
  1734. } else if (this.type.prefix) {
  1735. var node = this.startNode(), update = this.type === types.incDec;
  1736. node.operator = this.value;
  1737. node.prefix = true;
  1738. this.next();
  1739. node.argument = this.parseMaybeUnary(null, true);
  1740. this.checkExpressionErrors(refDestructuringErrors, true);
  1741. if (update) { this.checkLVal(node.argument); }
  1742. else if (this.strict && node.operator === "delete" &&
  1743. node.argument.type === "Identifier")
  1744. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  1745. else { sawUnary = true; }
  1746. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1747. } else {
  1748. expr = this.parseExprSubscripts(refDestructuringErrors);
  1749. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1750. while (this.type.postfix && !this.canInsertSemicolon()) {
  1751. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1752. node$1.operator = this$1.value;
  1753. node$1.prefix = false;
  1754. node$1.argument = expr;
  1755. this$1.checkLVal(expr);
  1756. this$1.next();
  1757. expr = this$1.finishNode(node$1, "UpdateExpression");
  1758. }
  1759. }
  1760. if (!sawUnary && this.eat(types.starstar))
  1761. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  1762. else
  1763. { return expr }
  1764. };
  1765. // Parse call, dot, and `[]`-subscript expressions.
  1766. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1767. var startPos = this.start, startLoc = this.startLoc;
  1768. var expr = this.parseExprAtom(refDestructuringErrors);
  1769. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  1770. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
  1771. var result = this.parseSubscripts(expr, startPos, startLoc);
  1772. if (refDestructuringErrors && result.type === "MemberExpression") {
  1773. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  1774. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  1775. }
  1776. return result
  1777. };
  1778. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1779. var this$1 = this;
  1780. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  1781. this.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async";
  1782. for (var computed = (void 0);;) {
  1783. if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
  1784. var node = this$1.startNodeAt(startPos, startLoc);
  1785. node.object = base;
  1786. node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
  1787. node.computed = !!computed;
  1788. if (computed) { this$1.expect(types.bracketR); }
  1789. base = this$1.finishNode(node, "MemberExpression");
  1790. } else if (!noCalls && this$1.eat(types.parenL)) {
  1791. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
  1792. this$1.yieldPos = 0;
  1793. this$1.awaitPos = 0;
  1794. var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
  1795. if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
  1796. this$1.checkPatternErrors(refDestructuringErrors, false);
  1797. this$1.checkYieldAwaitInDefaultParams();
  1798. this$1.yieldPos = oldYieldPos;
  1799. this$1.awaitPos = oldAwaitPos;
  1800. return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
  1801. }
  1802. this$1.checkExpressionErrors(refDestructuringErrors, true);
  1803. this$1.yieldPos = oldYieldPos || this$1.yieldPos;
  1804. this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
  1805. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1806. node$1.callee = base;
  1807. node$1.arguments = exprList;
  1808. base = this$1.finishNode(node$1, "CallExpression");
  1809. } else if (this$1.type === types.backQuote) {
  1810. var node$2 = this$1.startNodeAt(startPos, startLoc);
  1811. node$2.tag = base;
  1812. node$2.quasi = this$1.parseTemplate({isTagged: true});
  1813. base = this$1.finishNode(node$2, "TaggedTemplateExpression");
  1814. } else {
  1815. return base
  1816. }
  1817. }
  1818. };
  1819. // Parse an atomic expression — either a single token that is an
  1820. // expression, an expression started by a keyword like `function` or
  1821. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1822. // or `{}`.
  1823. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1824. var node, canBeArrow = this.potentialArrowAt === this.start;
  1825. switch (this.type) {
  1826. case types._super:
  1827. if (!this.inFunction)
  1828. { this.raise(this.start, "'super' outside of function or class"); }
  1829. node = this.startNode();
  1830. this.next();
  1831. // The `super` keyword can appear at below:
  1832. // SuperProperty:
  1833. // super [ Expression ]
  1834. // super . IdentifierName
  1835. // SuperCall:
  1836. // super Arguments
  1837. if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
  1838. { this.unexpected(); }
  1839. return this.finishNode(node, "Super")
  1840. case types._this:
  1841. node = this.startNode();
  1842. this.next();
  1843. return this.finishNode(node, "ThisExpression")
  1844. case types.name:
  1845. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  1846. var id = this.parseIdent(this.type !== types.name);
  1847. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  1848. { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
  1849. if (canBeArrow && !this.canInsertSemicolon()) {
  1850. if (this.eat(types.arrow))
  1851. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  1852. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
  1853. id = this.parseIdent();
  1854. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  1855. { this.unexpected(); }
  1856. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  1857. }
  1858. }
  1859. return id
  1860. case types.regexp:
  1861. var value = this.value;
  1862. node = this.parseLiteral(value.value);
  1863. node.regex = {pattern: value.pattern, flags: value.flags};
  1864. return node
  1865. case types.num: case types.string:
  1866. return this.parseLiteral(this.value)
  1867. case types._null: case types._true: case types._false:
  1868. node = this.startNode();
  1869. node.value = this.type === types._null ? null : this.type === types._true;
  1870. node.raw = this.type.keyword;
  1871. this.next();
  1872. return this.finishNode(node, "Literal")
  1873. case types.parenL:
  1874. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  1875. if (refDestructuringErrors) {
  1876. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  1877. { refDestructuringErrors.parenthesizedAssign = start; }
  1878. if (refDestructuringErrors.parenthesizedBind < 0)
  1879. { refDestructuringErrors.parenthesizedBind = start; }
  1880. }
  1881. return expr
  1882. case types.bracketL:
  1883. node = this.startNode();
  1884. this.next();
  1885. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  1886. return this.finishNode(node, "ArrayExpression")
  1887. case types.braceL:
  1888. return this.parseObj(false, refDestructuringErrors)
  1889. case types._function:
  1890. node = this.startNode();
  1891. this.next();
  1892. return this.parseFunction(node, false)
  1893. case types._class:
  1894. return this.parseClass(this.startNode(), false)
  1895. case types._new:
  1896. return this.parseNew()
  1897. case types.backQuote:
  1898. return this.parseTemplate()
  1899. default:
  1900. this.unexpected();
  1901. }
  1902. };
  1903. pp$3.parseLiteral = function(value) {
  1904. var node = this.startNode();
  1905. node.value = value;
  1906. node.raw = this.input.slice(this.start, this.end);
  1907. this.next();
  1908. return this.finishNode(node, "Literal")
  1909. };
  1910. pp$3.parseParenExpression = function() {
  1911. this.expect(types.parenL);
  1912. var val = this.parseExpression();
  1913. this.expect(types.parenR);
  1914. return val
  1915. };
  1916. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  1917. var this$1 = this;
  1918. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  1919. if (this.options.ecmaVersion >= 6) {
  1920. this.next();
  1921. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  1922. var exprList = [], first = true, lastIsComma = false;
  1923. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  1924. this.yieldPos = 0;
  1925. this.awaitPos = 0;
  1926. while (this.type !== types.parenR) {
  1927. first ? first = false : this$1.expect(types.comma);
  1928. if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
  1929. lastIsComma = true;
  1930. break
  1931. } else if (this$1.type === types.ellipsis) {
  1932. spreadStart = this$1.start;
  1933. exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
  1934. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1935. break
  1936. } else {
  1937. exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
  1938. }
  1939. }
  1940. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  1941. this.expect(types.parenR);
  1942. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  1943. this.checkPatternErrors(refDestructuringErrors, false);
  1944. this.checkYieldAwaitInDefaultParams();
  1945. this.yieldPos = oldYieldPos;
  1946. this.awaitPos = oldAwaitPos;
  1947. return this.parseParenArrowList(startPos, startLoc, exprList)
  1948. }
  1949. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  1950. if (spreadStart) { this.unexpected(spreadStart); }
  1951. this.checkExpressionErrors(refDestructuringErrors, true);
  1952. this.yieldPos = oldYieldPos || this.yieldPos;
  1953. this.awaitPos = oldAwaitPos || this.awaitPos;
  1954. if (exprList.length > 1) {
  1955. val = this.startNodeAt(innerStartPos, innerStartLoc);
  1956. val.expressions = exprList;
  1957. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  1958. } else {
  1959. val = exprList[0];
  1960. }
  1961. } else {
  1962. val = this.parseParenExpression();
  1963. }
  1964. if (this.options.preserveParens) {
  1965. var par = this.startNodeAt(startPos, startLoc);
  1966. par.expression = val;
  1967. return this.finishNode(par, "ParenthesizedExpression")
  1968. } else {
  1969. return val
  1970. }
  1971. };
  1972. pp$3.parseParenItem = function(item) {
  1973. return item
  1974. };
  1975. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  1976. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  1977. };
  1978. // New's precedence is slightly tricky. It must allow its argument to
  1979. // be a `[]` or dot subscript expression, but not a call — at least,
  1980. // not without wrapping it in parentheses. Thus, it uses the noCalls
  1981. // argument to parseSubscripts to prevent it from consuming the
  1982. // argument list.
  1983. var empty$1 = [];
  1984. pp$3.parseNew = function() {
  1985. var node = this.startNode();
  1986. var meta = this.parseIdent(true);
  1987. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  1988. node.meta = meta;
  1989. var containsEsc = this.containsEsc;
  1990. node.property = this.parseIdent(true);
  1991. if (node.property.name !== "target" || containsEsc)
  1992. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
  1993. if (!this.inFunction)
  1994. { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
  1995. return this.finishNode(node, "MetaProperty")
  1996. }
  1997. var startPos = this.start, startLoc = this.startLoc;
  1998. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  1999. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
  2000. else { node.arguments = empty$1; }
  2001. return this.finishNode(node, "NewExpression")
  2002. };
  2003. // Parse template expression.
  2004. pp$3.parseTemplateElement = function(ref) {
  2005. var isTagged = ref.isTagged;
  2006. var elem = this.startNode();
  2007. if (this.type === types.invalidTemplate) {
  2008. if (!isTagged) {
  2009. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2010. }
  2011. elem.value = {
  2012. raw: this.value,
  2013. cooked: null
  2014. };
  2015. } else {
  2016. elem.value = {
  2017. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2018. cooked: this.value
  2019. };
  2020. }
  2021. this.next();
  2022. elem.tail = this.type === types.backQuote;
  2023. return this.finishNode(elem, "TemplateElement")
  2024. };
  2025. pp$3.parseTemplate = function(ref) {
  2026. var this$1 = this;
  2027. if ( ref === void 0 ) ref = {};
  2028. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2029. var node = this.startNode();
  2030. this.next();
  2031. node.expressions = [];
  2032. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2033. node.quasis = [curElt];
  2034. while (!curElt.tail) {
  2035. this$1.expect(types.dollarBraceL);
  2036. node.expressions.push(this$1.parseExpression());
  2037. this$1.expect(types.braceR);
  2038. node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
  2039. }
  2040. this.next();
  2041. return this.finishNode(node, "TemplateLiteral")
  2042. };
  2043. pp$3.isAsyncProp = function(prop) {
  2044. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2045. (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) &&
  2046. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2047. };
  2048. // Parse an object literal or binding pattern.
  2049. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  2050. var this$1 = this;
  2051. var node = this.startNode(), first = true, propHash = {};
  2052. node.properties = [];
  2053. this.next();
  2054. while (!this.eat(types.braceR)) {
  2055. if (!first) {
  2056. this$1.expect(types.comma);
  2057. if (this$1.afterTrailingComma(types.braceR)) { break }
  2058. } else { first = false; }
  2059. var prop = this$1.parseProperty(isPattern, refDestructuringErrors);
  2060. if (!isPattern) { this$1.checkPropClash(prop, propHash, refDestructuringErrors); }
  2061. node.properties.push(prop);
  2062. }
  2063. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2064. };
  2065. pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
  2066. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2067. if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
  2068. if (isPattern) {
  2069. prop.argument = this.parseIdent(false);
  2070. if (this.type === types.comma) {
  2071. this.raise(this.start, "Comma is not permitted after the rest element");
  2072. }
  2073. return this.finishNode(prop, "RestElement")
  2074. }
  2075. // To disallow parenthesized identifier via `this.toAssignable()`.
  2076. if (this.type === types.parenL && refDestructuringErrors) {
  2077. if (refDestructuringErrors.parenthesizedAssign < 0) {
  2078. refDestructuringErrors.parenthesizedAssign = this.start;
  2079. }
  2080. if (refDestructuringErrors.parenthesizedBind < 0) {
  2081. refDestructuringErrors.parenthesizedBind = this.start;
  2082. }
  2083. }
  2084. // Parse argument.
  2085. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2086. // To disallow trailing comma via `this.toAssignable()`.
  2087. if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2088. refDestructuringErrors.trailingComma = this.start;
  2089. }
  2090. // Finish
  2091. return this.finishNode(prop, "SpreadElement")
  2092. }
  2093. if (this.options.ecmaVersion >= 6) {
  2094. prop.method = false;
  2095. prop.shorthand = false;
  2096. if (isPattern || refDestructuringErrors) {
  2097. startPos = this.start;
  2098. startLoc = this.startLoc;
  2099. }
  2100. if (!isPattern)
  2101. { isGenerator = this.eat(types.star); }
  2102. }
  2103. var containsEsc = this.containsEsc;
  2104. this.parsePropertyName(prop);
  2105. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2106. isAsync = true;
  2107. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
  2108. this.parsePropertyName(prop, refDestructuringErrors);
  2109. } else {
  2110. isAsync = false;
  2111. }
  2112. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2113. return this.finishNode(prop, "Property")
  2114. };
  2115. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  2116. if ((isGenerator || isAsync) && this.type === types.colon)
  2117. { this.unexpected(); }
  2118. if (this.eat(types.colon)) {
  2119. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  2120. prop.kind = "init";
  2121. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  2122. if (isPattern) { this.unexpected(); }
  2123. prop.kind = "init";
  2124. prop.method = true;
  2125. prop.value = this.parseMethod(isGenerator, isAsync);
  2126. } else if (!isPattern && !containsEsc &&
  2127. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2128. (prop.key.name === "get" || prop.key.name === "set") &&
  2129. (this.type !== types.comma && this.type !== types.braceR)) {
  2130. if (isGenerator || isAsync) { this.unexpected(); }
  2131. prop.kind = prop.key.name;
  2132. this.parsePropertyName(prop);
  2133. prop.value = this.parseMethod(false);
  2134. var paramCount = prop.kind === "get" ? 0 : 1;
  2135. if (prop.value.params.length !== paramCount) {
  2136. var start = prop.value.start;
  2137. if (prop.kind === "get")
  2138. { this.raiseRecoverable(start, "getter should have no params"); }
  2139. else
  2140. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2141. } else {
  2142. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2143. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2144. }
  2145. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2146. this.checkUnreserved(prop.key);
  2147. prop.kind = "init";
  2148. if (isPattern) {
  2149. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2150. } else if (this.type === types.eq && refDestructuringErrors) {
  2151. if (refDestructuringErrors.shorthandAssign < 0)
  2152. { refDestructuringErrors.shorthandAssign = this.start; }
  2153. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2154. } else {
  2155. prop.value = prop.key;
  2156. }
  2157. prop.shorthand = true;
  2158. } else { this.unexpected(); }
  2159. };
  2160. pp$3.parsePropertyName = function(prop) {
  2161. if (this.options.ecmaVersion >= 6) {
  2162. if (this.eat(types.bracketL)) {
  2163. prop.computed = true;
  2164. prop.key = this.parseMaybeAssign();
  2165. this.expect(types.bracketR);
  2166. return prop.key
  2167. } else {
  2168. prop.computed = false;
  2169. }
  2170. }
  2171. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
  2172. };
  2173. // Initialize empty function node.
  2174. pp$3.initFunction = function(node) {
  2175. node.id = null;
  2176. if (this.options.ecmaVersion >= 6) {
  2177. node.generator = false;
  2178. node.expression = false;
  2179. }
  2180. if (this.options.ecmaVersion >= 8)
  2181. { node.async = false; }
  2182. };
  2183. // Parse object or class method.
  2184. pp$3.parseMethod = function(isGenerator, isAsync) {
  2185. var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2186. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2187. this.initFunction(node);
  2188. if (this.options.ecmaVersion >= 6)
  2189. { node.generator = isGenerator; }
  2190. if (this.options.ecmaVersion >= 8)
  2191. { node.async = !!isAsync; }
  2192. this.inGenerator = node.generator;
  2193. this.inAsync = node.async;
  2194. this.yieldPos = 0;
  2195. this.awaitPos = 0;
  2196. this.inFunction = true;
  2197. this.enterFunctionScope();
  2198. this.expect(types.parenL);
  2199. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2200. this.checkYieldAwaitInDefaultParams();
  2201. this.parseFunctionBody(node, false);
  2202. this.inGenerator = oldInGen;
  2203. this.inAsync = oldInAsync;
  2204. this.yieldPos = oldYieldPos;
  2205. this.awaitPos = oldAwaitPos;
  2206. this.inFunction = oldInFunc;
  2207. return this.finishNode(node, "FunctionExpression")
  2208. };
  2209. // Parse arrow function expression with given parameters.
  2210. pp$3.parseArrowExpression = function(node, params, isAsync) {
  2211. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2212. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2213. this.enterFunctionScope();
  2214. this.initFunction(node);
  2215. if (this.options.ecmaVersion >= 8)
  2216. { node.async = !!isAsync; }
  2217. this.inGenerator = false;
  2218. this.inAsync = node.async;
  2219. this.yieldPos = 0;
  2220. this.awaitPos = 0;
  2221. this.inFunction = true;
  2222. node.params = this.toAssignableList(params, true);
  2223. this.parseFunctionBody(node, true);
  2224. this.inGenerator = oldInGen;
  2225. this.inAsync = oldInAsync;
  2226. this.yieldPos = oldYieldPos;
  2227. this.awaitPos = oldAwaitPos;
  2228. this.inFunction = oldInFunc;
  2229. return this.finishNode(node, "ArrowFunctionExpression")
  2230. };
  2231. // Parse function body and check parameters.
  2232. pp$3.parseFunctionBody = function(node, isArrowFunction) {
  2233. var isExpression = isArrowFunction && this.type !== types.braceL;
  2234. var oldStrict = this.strict, useStrict = false;
  2235. if (isExpression) {
  2236. node.body = this.parseMaybeAssign();
  2237. node.expression = true;
  2238. this.checkParams(node, false);
  2239. } else {
  2240. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2241. if (!oldStrict || nonSimple) {
  2242. useStrict = this.strictDirective(this.end);
  2243. // If this is a strict mode function, verify that argument names
  2244. // are not repeated, and it does not try to bind the words `eval`
  2245. // or `arguments`.
  2246. if (useStrict && nonSimple)
  2247. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2248. }
  2249. // Start a new scope with regard to labels and the `inFunction`
  2250. // flag (restore them to their old value afterwards).
  2251. var oldLabels = this.labels;
  2252. this.labels = [];
  2253. if (useStrict) { this.strict = true; }
  2254. // Add the params to varDeclaredNames to ensure that an error is thrown
  2255. // if a let/const declaration in the function clashes with one of the params.
  2256. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
  2257. node.body = this.parseBlock(false);
  2258. node.expression = false;
  2259. this.adaptDirectivePrologue(node.body.body);
  2260. this.labels = oldLabels;
  2261. }
  2262. this.exitFunctionScope();
  2263. if (this.strict && node.id) {
  2264. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2265. this.checkLVal(node.id, "none");
  2266. }
  2267. this.strict = oldStrict;
  2268. };
  2269. pp$3.isSimpleParamList = function(params) {
  2270. for (var i = 0, list = params; i < list.length; i += 1)
  2271. {
  2272. var param = list[i];
  2273. if (param.type !== "Identifier") { return false
  2274. } }
  2275. return true
  2276. };
  2277. // Checks function params for various disallowed patterns such as using "eval"
  2278. // or "arguments" and duplicate parameters.
  2279. pp$3.checkParams = function(node, allowDuplicates) {
  2280. var this$1 = this;
  2281. var nameHash = {};
  2282. for (var i = 0, list = node.params; i < list.length; i += 1)
  2283. {
  2284. var param = list[i];
  2285. this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
  2286. }
  2287. };
  2288. // Parses a comma-separated list of expressions, and returns them as
  2289. // an array. `close` is the token type that ends the list, and
  2290. // `allowEmpty` can be turned on to allow subsequent commas with
  2291. // nothing in between them to be parsed as `null` (which is needed
  2292. // for array literals).
  2293. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2294. var this$1 = this;
  2295. var elts = [], first = true;
  2296. while (!this.eat(close)) {
  2297. if (!first) {
  2298. this$1.expect(types.comma);
  2299. if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
  2300. } else { first = false; }
  2301. var elt = (void 0);
  2302. if (allowEmpty && this$1.type === types.comma)
  2303. { elt = null; }
  2304. else if (this$1.type === types.ellipsis) {
  2305. elt = this$1.parseSpread(refDestructuringErrors);
  2306. if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
  2307. { refDestructuringErrors.trailingComma = this$1.start; }
  2308. } else {
  2309. elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
  2310. }
  2311. elts.push(elt);
  2312. }
  2313. return elts
  2314. };
  2315. pp$3.checkUnreserved = function(ref) {
  2316. var start = ref.start;
  2317. var end = ref.end;
  2318. var name = ref.name;
  2319. if (this.inGenerator && name === "yield")
  2320. { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
  2321. if (this.inAsync && name === "await")
  2322. { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
  2323. if (this.isKeyword(name))
  2324. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2325. if (this.options.ecmaVersion < 6 &&
  2326. this.input.slice(start, end).indexOf("\\") !== -1) { return }
  2327. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2328. if (re.test(name)) {
  2329. if (!this.inAsync && name === "await")
  2330. { this.raiseRecoverable(start, "Can not use keyword 'await' outside an async function"); }
  2331. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  2332. }
  2333. };
  2334. // Parse the next token as an identifier. If `liberal` is true (used
  2335. // when parsing properties), it will also convert keywords into
  2336. // identifiers.
  2337. pp$3.parseIdent = function(liberal, isBinding) {
  2338. var node = this.startNode();
  2339. if (liberal && this.options.allowReserved === "never") { liberal = false; }
  2340. if (this.type === types.name) {
  2341. node.name = this.value;
  2342. } else if (this.type.keyword) {
  2343. node.name = this.type.keyword;
  2344. // To fix https://github.com/acornjs/acorn/issues/575
  2345. // `class` and `function` keywords push new context into this.context.
  2346. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  2347. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  2348. if ((node.name === "class" || node.name === "function") &&
  2349. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  2350. this.context.pop();
  2351. }
  2352. } else {
  2353. this.unexpected();
  2354. }
  2355. this.next();
  2356. this.finishNode(node, "Identifier");
  2357. if (!liberal) { this.checkUnreserved(node); }
  2358. return node
  2359. };
  2360. // Parses yield expression inside generator.
  2361. pp$3.parseYield = function() {
  2362. if (!this.yieldPos) { this.yieldPos = this.start; }
  2363. var node = this.startNode();
  2364. this.next();
  2365. if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
  2366. node.delegate = false;
  2367. node.argument = null;
  2368. } else {
  2369. node.delegate = this.eat(types.star);
  2370. node.argument = this.parseMaybeAssign();
  2371. }
  2372. return this.finishNode(node, "YieldExpression")
  2373. };
  2374. pp$3.parseAwait = function() {
  2375. if (!this.awaitPos) { this.awaitPos = this.start; }
  2376. var node = this.startNode();
  2377. this.next();
  2378. node.argument = this.parseMaybeUnary(null, true);
  2379. return this.finishNode(node, "AwaitExpression")
  2380. };
  2381. var pp$4 = Parser.prototype;
  2382. // This function is used to raise exceptions on parse errors. It
  2383. // takes an offset integer (into the current `input`) to indicate
  2384. // the location of the error, attaches the position to the end
  2385. // of the error message, and then raises a `SyntaxError` with that
  2386. // message.
  2387. pp$4.raise = function(pos, message) {
  2388. var loc = getLineInfo(this.input, pos);
  2389. message += " (" + loc.line + ":" + loc.column + ")";
  2390. var err = new SyntaxError(message);
  2391. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  2392. throw err
  2393. };
  2394. pp$4.raiseRecoverable = pp$4.raise;
  2395. pp$4.curPosition = function() {
  2396. if (this.options.locations) {
  2397. return new Position(this.curLine, this.pos - this.lineStart)
  2398. }
  2399. };
  2400. var pp$5 = Parser.prototype;
  2401. // Object.assign polyfill
  2402. var assign = Object.assign || function(target) {
  2403. var sources = [], len = arguments.length - 1;
  2404. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  2405. for (var i = 0, list = sources; i < list.length; i += 1) {
  2406. var source = list[i];
  2407. for (var key in source) {
  2408. if (has(source, key)) {
  2409. target[key] = source[key];
  2410. }
  2411. }
  2412. }
  2413. return target
  2414. };
  2415. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  2416. pp$5.enterFunctionScope = function() {
  2417. // var: a hash of var-declared names in the current lexical scope
  2418. // lexical: a hash of lexically-declared names in the current lexical scope
  2419. // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
  2420. // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
  2421. this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
  2422. };
  2423. pp$5.exitFunctionScope = function() {
  2424. this.scopeStack.pop();
  2425. };
  2426. pp$5.enterLexicalScope = function() {
  2427. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2428. var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
  2429. this.scopeStack.push(childScope);
  2430. assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
  2431. };
  2432. pp$5.exitLexicalScope = function() {
  2433. var childScope = this.scopeStack.pop();
  2434. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2435. assign(parentScope.childVar, childScope.var, childScope.childVar);
  2436. };
  2437. /**
  2438. * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
  2439. * in the current lexical scope or any of the parent lexical scopes in this function.
  2440. */
  2441. pp$5.canDeclareVarName = function(name) {
  2442. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2443. return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
  2444. };
  2445. /**
  2446. * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
  2447. * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
  2448. * any child lexical scopes in this function.
  2449. */
  2450. pp$5.canDeclareLexicalName = function(name) {
  2451. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2452. return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
  2453. };
  2454. pp$5.declareVarName = function(name) {
  2455. this.scopeStack[this.scopeStack.length - 1].var[name] = true;
  2456. };
  2457. pp$5.declareLexicalName = function(name) {
  2458. this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
  2459. };
  2460. var Node = function Node(parser, pos, loc) {
  2461. this.type = "";
  2462. this.start = pos;
  2463. this.end = 0;
  2464. if (parser.options.locations)
  2465. { this.loc = new SourceLocation(parser, loc); }
  2466. if (parser.options.directSourceFile)
  2467. { this.sourceFile = parser.options.directSourceFile; }
  2468. if (parser.options.ranges)
  2469. { this.range = [pos, 0]; }
  2470. };
  2471. // Start an AST node, attaching a start offset.
  2472. var pp$6 = Parser.prototype;
  2473. pp$6.startNode = function() {
  2474. return new Node(this, this.start, this.startLoc)
  2475. };
  2476. pp$6.startNodeAt = function(pos, loc) {
  2477. return new Node(this, pos, loc)
  2478. };
  2479. // Finish an AST node, adding `type` and `end` properties.
  2480. function finishNodeAt(node, type, pos, loc) {
  2481. node.type = type;
  2482. node.end = pos;
  2483. if (this.options.locations)
  2484. { node.loc.end = loc; }
  2485. if (this.options.ranges)
  2486. { node.range[1] = pos; }
  2487. return node
  2488. }
  2489. pp$6.finishNode = function(node, type) {
  2490. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  2491. };
  2492. // Finish node at given position
  2493. pp$6.finishNodeAt = function(node, type, pos, loc) {
  2494. return finishNodeAt.call(this, node, type, pos, loc)
  2495. };
  2496. // The algorithm used to determine whether a regexp can appear at a
  2497. // given point in the program is loosely based on sweet.js' approach.
  2498. // See https://github.com/mozilla/sweet.js/wiki/design
  2499. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2500. this.token = token;
  2501. this.isExpr = !!isExpr;
  2502. this.preserveSpace = !!preserveSpace;
  2503. this.override = override;
  2504. this.generator = !!generator;
  2505. };
  2506. var types$1 = {
  2507. b_stat: new TokContext("{", false),
  2508. b_expr: new TokContext("{", true),
  2509. b_tmpl: new TokContext("${", false),
  2510. p_stat: new TokContext("(", false),
  2511. p_expr: new TokContext("(", true),
  2512. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2513. f_stat: new TokContext("function", false),
  2514. f_expr: new TokContext("function", true),
  2515. f_expr_gen: new TokContext("function", true, false, null, true),
  2516. f_gen: new TokContext("function", false, false, null, true)
  2517. };
  2518. var pp$7 = Parser.prototype;
  2519. pp$7.initialContext = function() {
  2520. return [types$1.b_stat]
  2521. };
  2522. pp$7.braceIsBlock = function(prevType) {
  2523. var parent = this.curContext();
  2524. if (parent === types$1.f_expr || parent === types$1.f_stat)
  2525. { return true }
  2526. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  2527. { return !parent.isExpr }
  2528. // The check for `tt.name && exprAllowed` detects whether we are
  2529. // after a `yield` or `of` construct. See the `updateContext` for
  2530. // `tt.name`.
  2531. if (prevType === types._return || prevType === types.name && this.exprAllowed)
  2532. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2533. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
  2534. { return true }
  2535. if (prevType === types.braceL)
  2536. { return parent === types$1.b_stat }
  2537. if (prevType === types._var || prevType === types.name)
  2538. { return false }
  2539. return !this.exprAllowed
  2540. };
  2541. pp$7.inGeneratorContext = function() {
  2542. var this$1 = this;
  2543. for (var i = this.context.length - 1; i >= 1; i--) {
  2544. var context = this$1.context[i];
  2545. if (context.token === "function")
  2546. { return context.generator }
  2547. }
  2548. return false
  2549. };
  2550. pp$7.updateContext = function(prevType) {
  2551. var update, type = this.type;
  2552. if (type.keyword && prevType === types.dot)
  2553. { this.exprAllowed = false; }
  2554. else if (update = type.updateContext)
  2555. { update.call(this, prevType); }
  2556. else
  2557. { this.exprAllowed = type.beforeExpr; }
  2558. };
  2559. // Token-specific context update code
  2560. types.parenR.updateContext = types.braceR.updateContext = function() {
  2561. if (this.context.length === 1) {
  2562. this.exprAllowed = true;
  2563. return
  2564. }
  2565. var out = this.context.pop();
  2566. if (out === types$1.b_stat && this.curContext().token === "function") {
  2567. out = this.context.pop();
  2568. }
  2569. this.exprAllowed = !out.isExpr;
  2570. };
  2571. types.braceL.updateContext = function(prevType) {
  2572. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  2573. this.exprAllowed = true;
  2574. };
  2575. types.dollarBraceL.updateContext = function() {
  2576. this.context.push(types$1.b_tmpl);
  2577. this.exprAllowed = true;
  2578. };
  2579. types.parenL.updateContext = function(prevType) {
  2580. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  2581. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  2582. this.exprAllowed = true;
  2583. };
  2584. types.incDec.updateContext = function() {
  2585. // tokExprAllowed stays unchanged
  2586. };
  2587. types._function.updateContext = types._class.updateContext = function(prevType) {
  2588. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  2589. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  2590. { this.context.push(types$1.f_expr); }
  2591. else
  2592. { this.context.push(types$1.f_stat); }
  2593. this.exprAllowed = false;
  2594. };
  2595. types.backQuote.updateContext = function() {
  2596. if (this.curContext() === types$1.q_tmpl)
  2597. { this.context.pop(); }
  2598. else
  2599. { this.context.push(types$1.q_tmpl); }
  2600. this.exprAllowed = false;
  2601. };
  2602. types.star.updateContext = function(prevType) {
  2603. if (prevType === types._function) {
  2604. var index = this.context.length - 1;
  2605. if (this.context[index] === types$1.f_expr)
  2606. { this.context[index] = types$1.f_expr_gen; }
  2607. else
  2608. { this.context[index] = types$1.f_gen; }
  2609. }
  2610. this.exprAllowed = true;
  2611. };
  2612. types.name.updateContext = function(prevType) {
  2613. var allowed = false;
  2614. if (this.options.ecmaVersion >= 6) {
  2615. if (this.value === "of" && !this.exprAllowed ||
  2616. this.value === "yield" && this.inGeneratorContext())
  2617. { allowed = true; }
  2618. }
  2619. this.exprAllowed = allowed;
  2620. };
  2621. var data = {
  2622. "$LONE": [
  2623. "ASCII",
  2624. "ASCII_Hex_Digit",
  2625. "AHex",
  2626. "Alphabetic",
  2627. "Alpha",
  2628. "Any",
  2629. "Assigned",
  2630. "Bidi_Control",
  2631. "Bidi_C",
  2632. "Bidi_Mirrored",
  2633. "Bidi_M",
  2634. "Case_Ignorable",
  2635. "CI",
  2636. "Cased",
  2637. "Changes_When_Casefolded",
  2638. "CWCF",
  2639. "Changes_When_Casemapped",
  2640. "CWCM",
  2641. "Changes_When_Lowercased",
  2642. "CWL",
  2643. "Changes_When_NFKC_Casefolded",
  2644. "CWKCF",
  2645. "Changes_When_Titlecased",
  2646. "CWT",
  2647. "Changes_When_Uppercased",
  2648. "CWU",
  2649. "Dash",
  2650. "Default_Ignorable_Code_Point",
  2651. "DI",
  2652. "Deprecated",
  2653. "Dep",
  2654. "Diacritic",
  2655. "Dia",
  2656. "Emoji",
  2657. "Emoji_Component",
  2658. "Emoji_Modifier",
  2659. "Emoji_Modifier_Base",
  2660. "Emoji_Presentation",
  2661. "Extender",
  2662. "Ext",
  2663. "Grapheme_Base",
  2664. "Gr_Base",
  2665. "Grapheme_Extend",
  2666. "Gr_Ext",
  2667. "Hex_Digit",
  2668. "Hex",
  2669. "IDS_Binary_Operator",
  2670. "IDSB",
  2671. "IDS_Trinary_Operator",
  2672. "IDST",
  2673. "ID_Continue",
  2674. "IDC",
  2675. "ID_Start",
  2676. "IDS",
  2677. "Ideographic",
  2678. "Ideo",
  2679. "Join_Control",
  2680. "Join_C",
  2681. "Logical_Order_Exception",
  2682. "LOE",
  2683. "Lowercase",
  2684. "Lower",
  2685. "Math",
  2686. "Noncharacter_Code_Point",
  2687. "NChar",
  2688. "Pattern_Syntax",
  2689. "Pat_Syn",
  2690. "Pattern_White_Space",
  2691. "Pat_WS",
  2692. "Quotation_Mark",
  2693. "QMark",
  2694. "Radical",
  2695. "Regional_Indicator",
  2696. "RI",
  2697. "Sentence_Terminal",
  2698. "STerm",
  2699. "Soft_Dotted",
  2700. "SD",
  2701. "Terminal_Punctuation",
  2702. "Term",
  2703. "Unified_Ideograph",
  2704. "UIdeo",
  2705. "Uppercase",
  2706. "Upper",
  2707. "Variation_Selector",
  2708. "VS",
  2709. "White_Space",
  2710. "space",
  2711. "XID_Continue",
  2712. "XIDC",
  2713. "XID_Start",
  2714. "XIDS"
  2715. ],
  2716. "General_Category": [
  2717. "Cased_Letter",
  2718. "LC",
  2719. "Close_Punctuation",
  2720. "Pe",
  2721. "Connector_Punctuation",
  2722. "Pc",
  2723. "Control",
  2724. "Cc",
  2725. "cntrl",
  2726. "Currency_Symbol",
  2727. "Sc",
  2728. "Dash_Punctuation",
  2729. "Pd",
  2730. "Decimal_Number",
  2731. "Nd",
  2732. "digit",
  2733. "Enclosing_Mark",
  2734. "Me",
  2735. "Final_Punctuation",
  2736. "Pf",
  2737. "Format",
  2738. "Cf",
  2739. "Initial_Punctuation",
  2740. "Pi",
  2741. "Letter",
  2742. "L",
  2743. "Letter_Number",
  2744. "Nl",
  2745. "Line_Separator",
  2746. "Zl",
  2747. "Lowercase_Letter",
  2748. "Ll",
  2749. "Mark",
  2750. "M",
  2751. "Combining_Mark",
  2752. "Math_Symbol",
  2753. "Sm",
  2754. "Modifier_Letter",
  2755. "Lm",
  2756. "Modifier_Symbol",
  2757. "Sk",
  2758. "Nonspacing_Mark",
  2759. "Mn",
  2760. "Number",
  2761. "N",
  2762. "Open_Punctuation",
  2763. "Ps",
  2764. "Other",
  2765. "C",
  2766. "Other_Letter",
  2767. "Lo",
  2768. "Other_Number",
  2769. "No",
  2770. "Other_Punctuation",
  2771. "Po",
  2772. "Other_Symbol",
  2773. "So",
  2774. "Paragraph_Separator",
  2775. "Zp",
  2776. "Private_Use",
  2777. "Co",
  2778. "Punctuation",
  2779. "P",
  2780. "punct",
  2781. "Separator",
  2782. "Z",
  2783. "Space_Separator",
  2784. "Zs",
  2785. "Spacing_Mark",
  2786. "Mc",
  2787. "Surrogate",
  2788. "Cs",
  2789. "Symbol",
  2790. "S",
  2791. "Titlecase_Letter",
  2792. "Lt",
  2793. "Unassigned",
  2794. "Cn",
  2795. "Uppercase_Letter",
  2796. "Lu"
  2797. ],
  2798. "Script": [
  2799. "Adlam",
  2800. "Adlm",
  2801. "Ahom",
  2802. "Anatolian_Hieroglyphs",
  2803. "Hluw",
  2804. "Arabic",
  2805. "Arab",
  2806. "Armenian",
  2807. "Armn",
  2808. "Avestan",
  2809. "Avst",
  2810. "Balinese",
  2811. "Bali",
  2812. "Bamum",
  2813. "Bamu",
  2814. "Bassa_Vah",
  2815. "Bass",
  2816. "Batak",
  2817. "Batk",
  2818. "Bengali",
  2819. "Beng",
  2820. "Bhaiksuki",
  2821. "Bhks",
  2822. "Bopomofo",
  2823. "Bopo",
  2824. "Brahmi",
  2825. "Brah",
  2826. "Braille",
  2827. "Brai",
  2828. "Buginese",
  2829. "Bugi",
  2830. "Buhid",
  2831. "Buhd",
  2832. "Canadian_Aboriginal",
  2833. "Cans",
  2834. "Carian",
  2835. "Cari",
  2836. "Caucasian_Albanian",
  2837. "Aghb",
  2838. "Chakma",
  2839. "Cakm",
  2840. "Cham",
  2841. "Cherokee",
  2842. "Cher",
  2843. "Common",
  2844. "Zyyy",
  2845. "Coptic",
  2846. "Copt",
  2847. "Qaac",
  2848. "Cuneiform",
  2849. "Xsux",
  2850. "Cypriot",
  2851. "Cprt",
  2852. "Cyrillic",
  2853. "Cyrl",
  2854. "Deseret",
  2855. "Dsrt",
  2856. "Devanagari",
  2857. "Deva",
  2858. "Duployan",
  2859. "Dupl",
  2860. "Egyptian_Hieroglyphs",
  2861. "Egyp",
  2862. "Elbasan",
  2863. "Elba",
  2864. "Ethiopic",
  2865. "Ethi",
  2866. "Georgian",
  2867. "Geor",
  2868. "Glagolitic",
  2869. "Glag",
  2870. "Gothic",
  2871. "Goth",
  2872. "Grantha",
  2873. "Gran",
  2874. "Greek",
  2875. "Grek",
  2876. "Gujarati",
  2877. "Gujr",
  2878. "Gurmukhi",
  2879. "Guru",
  2880. "Han",
  2881. "Hani",
  2882. "Hangul",
  2883. "Hang",
  2884. "Hanunoo",
  2885. "Hano",
  2886. "Hatran",
  2887. "Hatr",
  2888. "Hebrew",
  2889. "Hebr",
  2890. "Hiragana",
  2891. "Hira",
  2892. "Imperial_Aramaic",
  2893. "Armi",
  2894. "Inherited",
  2895. "Zinh",
  2896. "Qaai",
  2897. "Inscriptional_Pahlavi",
  2898. "Phli",
  2899. "Inscriptional_Parthian",
  2900. "Prti",
  2901. "Javanese",
  2902. "Java",
  2903. "Kaithi",
  2904. "Kthi",
  2905. "Kannada",
  2906. "Knda",
  2907. "Katakana",
  2908. "Kana",
  2909. "Kayah_Li",
  2910. "Kali",
  2911. "Kharoshthi",
  2912. "Khar",
  2913. "Khmer",
  2914. "Khmr",
  2915. "Khojki",
  2916. "Khoj",
  2917. "Khudawadi",
  2918. "Sind",
  2919. "Lao",
  2920. "Laoo",
  2921. "Latin",
  2922. "Latn",
  2923. "Lepcha",
  2924. "Lepc",
  2925. "Limbu",
  2926. "Limb",
  2927. "Linear_A",
  2928. "Lina",
  2929. "Linear_B",
  2930. "Linb",
  2931. "Lisu",
  2932. "Lycian",
  2933. "Lyci",
  2934. "Lydian",
  2935. "Lydi",
  2936. "Mahajani",
  2937. "Mahj",
  2938. "Malayalam",
  2939. "Mlym",
  2940. "Mandaic",
  2941. "Mand",
  2942. "Manichaean",
  2943. "Mani",
  2944. "Marchen",
  2945. "Marc",
  2946. "Masaram_Gondi",
  2947. "Gonm",
  2948. "Meetei_Mayek",
  2949. "Mtei",
  2950. "Mende_Kikakui",
  2951. "Mend",
  2952. "Meroitic_Cursive",
  2953. "Merc",
  2954. "Meroitic_Hieroglyphs",
  2955. "Mero",
  2956. "Miao",
  2957. "Plrd",
  2958. "Modi",
  2959. "Mongolian",
  2960. "Mong",
  2961. "Mro",
  2962. "Mroo",
  2963. "Multani",
  2964. "Mult",
  2965. "Myanmar",
  2966. "Mymr",
  2967. "Nabataean",
  2968. "Nbat",
  2969. "New_Tai_Lue",
  2970. "Talu",
  2971. "Newa",
  2972. "Nko",
  2973. "Nkoo",
  2974. "Nushu",
  2975. "Nshu",
  2976. "Ogham",
  2977. "Ogam",
  2978. "Ol_Chiki",
  2979. "Olck",
  2980. "Old_Hungarian",
  2981. "Hung",
  2982. "Old_Italic",
  2983. "Ital",
  2984. "Old_North_Arabian",
  2985. "Narb",
  2986. "Old_Permic",
  2987. "Perm",
  2988. "Old_Persian",
  2989. "Xpeo",
  2990. "Old_South_Arabian",
  2991. "Sarb",
  2992. "Old_Turkic",
  2993. "Orkh",
  2994. "Oriya",
  2995. "Orya",
  2996. "Osage",
  2997. "Osge",
  2998. "Osmanya",
  2999. "Osma",
  3000. "Pahawh_Hmong",
  3001. "Hmng",
  3002. "Palmyrene",
  3003. "Palm",
  3004. "Pau_Cin_Hau",
  3005. "Pauc",
  3006. "Phags_Pa",
  3007. "Phag",
  3008. "Phoenician",
  3009. "Phnx",
  3010. "Psalter_Pahlavi",
  3011. "Phlp",
  3012. "Rejang",
  3013. "Rjng",
  3014. "Runic",
  3015. "Runr",
  3016. "Samaritan",
  3017. "Samr",
  3018. "Saurashtra",
  3019. "Saur",
  3020. "Sharada",
  3021. "Shrd",
  3022. "Shavian",
  3023. "Shaw",
  3024. "Siddham",
  3025. "Sidd",
  3026. "SignWriting",
  3027. "Sgnw",
  3028. "Sinhala",
  3029. "Sinh",
  3030. "Sora_Sompeng",
  3031. "Sora",
  3032. "Soyombo",
  3033. "Soyo",
  3034. "Sundanese",
  3035. "Sund",
  3036. "Syloti_Nagri",
  3037. "Sylo",
  3038. "Syriac",
  3039. "Syrc",
  3040. "Tagalog",
  3041. "Tglg",
  3042. "Tagbanwa",
  3043. "Tagb",
  3044. "Tai_Le",
  3045. "Tale",
  3046. "Tai_Tham",
  3047. "Lana",
  3048. "Tai_Viet",
  3049. "Tavt",
  3050. "Takri",
  3051. "Takr",
  3052. "Tamil",
  3053. "Taml",
  3054. "Tangut",
  3055. "Tang",
  3056. "Telugu",
  3057. "Telu",
  3058. "Thaana",
  3059. "Thaa",
  3060. "Thai",
  3061. "Tibetan",
  3062. "Tibt",
  3063. "Tifinagh",
  3064. "Tfng",
  3065. "Tirhuta",
  3066. "Tirh",
  3067. "Ugaritic",
  3068. "Ugar",
  3069. "Vai",
  3070. "Vaii",
  3071. "Warang_Citi",
  3072. "Wara",
  3073. "Yi",
  3074. "Yiii",
  3075. "Zanabazar_Square",
  3076. "Zanb"
  3077. ]
  3078. };
  3079. Array.prototype.push.apply(data.$LONE, data.General_Category);
  3080. data.gc = data.General_Category;
  3081. data.sc = data.Script_Extensions = data.scx = data.Script;
  3082. var pp$9 = Parser.prototype;
  3083. var RegExpValidationState = function RegExpValidationState(parser) {
  3084. this.parser = parser;
  3085. this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
  3086. this.source = "";
  3087. this.flags = "";
  3088. this.start = 0;
  3089. this.switchU = false;
  3090. this.switchN = false;
  3091. this.pos = 0;
  3092. this.lastIntValue = 0;
  3093. this.lastStringValue = "";
  3094. this.lastAssertionIsQuantifiable = false;
  3095. this.numCapturingParens = 0;
  3096. this.maxBackReference = 0;
  3097. this.groupNames = [];
  3098. this.backReferenceNames = [];
  3099. };
  3100. RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
  3101. var unicode = flags.indexOf("u") !== -1;
  3102. this.start = start | 0;
  3103. this.source = pattern + "";
  3104. this.flags = flags;
  3105. this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
  3106. this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
  3107. };
  3108. RegExpValidationState.prototype.raise = function raise (message) {
  3109. this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
  3110. };
  3111. // If u flag is given, this returns the code point at the index (it combines a surrogate pair).
  3112. // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
  3113. RegExpValidationState.prototype.at = function at (i) {
  3114. var s = this.source;
  3115. var l = s.length;
  3116. if (i >= l) {
  3117. return -1
  3118. }
  3119. var c = s.charCodeAt(i);
  3120. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3121. return c
  3122. }
  3123. return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00
  3124. };
  3125. RegExpValidationState.prototype.nextIndex = function nextIndex (i) {
  3126. var s = this.source;
  3127. var l = s.length;
  3128. if (i >= l) {
  3129. return l
  3130. }
  3131. var c = s.charCodeAt(i);
  3132. if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3133. return i + 1
  3134. }
  3135. return i + 2
  3136. };
  3137. RegExpValidationState.prototype.current = function current () {
  3138. return this.at(this.pos)
  3139. };
  3140. RegExpValidationState.prototype.lookahead = function lookahead () {
  3141. return this.at(this.nextIndex(this.pos))
  3142. };
  3143. RegExpValidationState.prototype.advance = function advance () {
  3144. this.pos = this.nextIndex(this.pos);
  3145. };
  3146. RegExpValidationState.prototype.eat = function eat (ch) {
  3147. if (this.current() === ch) {
  3148. this.advance();
  3149. return true
  3150. }
  3151. return false
  3152. };
  3153. function codePointToString$1(ch) {
  3154. if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
  3155. ch -= 0x10000;
  3156. return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
  3157. }
  3158. /**
  3159. * Validate the flags part of a given RegExpLiteral.
  3160. *
  3161. * @param {RegExpValidationState} state The state to validate RegExp.
  3162. * @returns {void}
  3163. */
  3164. pp$9.validateRegExpFlags = function(state) {
  3165. var this$1 = this;
  3166. var validFlags = state.validFlags;
  3167. var flags = state.flags;
  3168. for (var i = 0; i < flags.length; i++) {
  3169. var flag = flags.charAt(i);
  3170. if (validFlags.indexOf(flag) === -1) {
  3171. this$1.raise(state.start, "Invalid regular expression flag");
  3172. }
  3173. if (flags.indexOf(flag, i + 1) > -1) {
  3174. this$1.raise(state.start, "Duplicate regular expression flag");
  3175. }
  3176. }
  3177. };
  3178. /**
  3179. * Validate the pattern part of a given RegExpLiteral.
  3180. *
  3181. * @param {RegExpValidationState} state The state to validate RegExp.
  3182. * @returns {void}
  3183. */
  3184. pp$9.validateRegExpPattern = function(state) {
  3185. this.regexp_pattern(state);
  3186. // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
  3187. // parsing contains a |GroupName|, reparse with the goal symbol
  3188. // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
  3189. // exception if _P_ did not conform to the grammar, if any elements of _P_
  3190. // were not matched by the parse, or if any Early Error conditions exist.
  3191. if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
  3192. state.switchN = true;
  3193. this.regexp_pattern(state);
  3194. }
  3195. };
  3196. // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
  3197. pp$9.regexp_pattern = function(state) {
  3198. state.pos = 0;
  3199. state.lastIntValue = 0;
  3200. state.lastStringValue = "";
  3201. state.lastAssertionIsQuantifiable = false;
  3202. state.numCapturingParens = 0;
  3203. state.maxBackReference = 0;
  3204. state.groupNames.length = 0;
  3205. state.backReferenceNames.length = 0;
  3206. this.regexp_disjunction(state);
  3207. if (state.pos !== state.source.length) {
  3208. // Make the same messages as V8.
  3209. if (state.eat(0x29 /* ) */)) {
  3210. state.raise("Unmatched ')'");
  3211. }
  3212. if (state.eat(0x5D /* [ */) || state.eat(0x7D /* } */)) {
  3213. state.raise("Lone quantifier brackets");
  3214. }
  3215. }
  3216. if (state.maxBackReference > state.numCapturingParens) {
  3217. state.raise("Invalid escape");
  3218. }
  3219. for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
  3220. var name = list[i];
  3221. if (state.groupNames.indexOf(name) === -1) {
  3222. state.raise("Invalid named capture referenced");
  3223. }
  3224. }
  3225. };
  3226. // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
  3227. pp$9.regexp_disjunction = function(state) {
  3228. var this$1 = this;
  3229. this.regexp_alternative(state);
  3230. while (state.eat(0x7C /* | */)) {
  3231. this$1.regexp_alternative(state);
  3232. }
  3233. // Make the same message as V8.
  3234. if (this.regexp_eatQuantifier(state, true)) {
  3235. state.raise("Nothing to repeat");
  3236. }
  3237. if (state.eat(0x7B /* { */)) {
  3238. state.raise("Lone quantifier brackets");
  3239. }
  3240. };
  3241. // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
  3242. pp$9.regexp_alternative = function(state) {
  3243. while (state.pos < state.source.length && this.regexp_eatTerm(state))
  3244. { }
  3245. };
  3246. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
  3247. pp$9.regexp_eatTerm = function(state) {
  3248. if (this.regexp_eatAssertion(state)) {
  3249. // Handle `QuantifiableAssertion Quantifier` alternative.
  3250. // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
  3251. // is a QuantifiableAssertion.
  3252. if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
  3253. // Make the same message as V8.
  3254. if (state.switchU) {
  3255. state.raise("Invalid quantifier");
  3256. }
  3257. }
  3258. return true
  3259. }
  3260. if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
  3261. this.regexp_eatQuantifier(state);
  3262. return true
  3263. }
  3264. return false
  3265. };
  3266. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
  3267. pp$9.regexp_eatAssertion = function(state) {
  3268. var start = state.pos;
  3269. state.lastAssertionIsQuantifiable = false;
  3270. // ^, $
  3271. if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
  3272. return true
  3273. }
  3274. // \b \B
  3275. if (state.eat(0x5C /* \ */)) {
  3276. if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
  3277. return true
  3278. }
  3279. state.pos = start;
  3280. }
  3281. // Lookahead / Lookbehind
  3282. if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
  3283. var lookbehind = false;
  3284. if (this.options.ecmaVersion >= 9) {
  3285. lookbehind = state.eat(0x3C /* < */);
  3286. }
  3287. if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
  3288. this.regexp_disjunction(state);
  3289. if (!state.eat(0x29 /* ) */)) {
  3290. state.raise("Unterminated group");
  3291. }
  3292. state.lastAssertionIsQuantifiable = !lookbehind;
  3293. return true
  3294. }
  3295. }
  3296. state.pos = start;
  3297. return false
  3298. };
  3299. // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
  3300. pp$9.regexp_eatQuantifier = function(state, noError) {
  3301. if ( noError === void 0 ) noError = false;
  3302. if (this.regexp_eatQuantifierPrefix(state, noError)) {
  3303. state.eat(0x3F /* ? */);
  3304. return true
  3305. }
  3306. return false
  3307. };
  3308. // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
  3309. pp$9.regexp_eatQuantifierPrefix = function(state, noError) {
  3310. return (
  3311. state.eat(0x2A /* * */) ||
  3312. state.eat(0x2B /* + */) ||
  3313. state.eat(0x3F /* ? */) ||
  3314. this.regexp_eatBracedQuantifier(state, noError)
  3315. )
  3316. };
  3317. pp$9.regexp_eatBracedQuantifier = function(state, noError) {
  3318. var start = state.pos;
  3319. if (state.eat(0x7B /* { */)) {
  3320. var min = 0, max = -1;
  3321. if (this.regexp_eatDecimalDigits(state)) {
  3322. min = state.lastIntValue;
  3323. if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
  3324. max = state.lastIntValue;
  3325. }
  3326. if (state.eat(0x7D /* } */)) {
  3327. // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
  3328. if (max !== -1 && max < min && !noError) {
  3329. state.raise("numbers out of order in {} quantifier");
  3330. }
  3331. return true
  3332. }
  3333. }
  3334. if (state.switchU && !noError) {
  3335. state.raise("Incomplete quantifier");
  3336. }
  3337. state.pos = start;
  3338. }
  3339. return false
  3340. };
  3341. // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
  3342. pp$9.regexp_eatAtom = function(state) {
  3343. return (
  3344. this.regexp_eatPatternCharacters(state) ||
  3345. state.eat(0x2E /* . */) ||
  3346. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3347. this.regexp_eatCharacterClass(state) ||
  3348. this.regexp_eatUncapturingGroup(state) ||
  3349. this.regexp_eatCapturingGroup(state)
  3350. )
  3351. };
  3352. pp$9.regexp_eatReverseSolidusAtomEscape = function(state) {
  3353. var start = state.pos;
  3354. if (state.eat(0x5C /* \ */)) {
  3355. if (this.regexp_eatAtomEscape(state)) {
  3356. return true
  3357. }
  3358. state.pos = start;
  3359. }
  3360. return false
  3361. };
  3362. pp$9.regexp_eatUncapturingGroup = function(state) {
  3363. var start = state.pos;
  3364. if (state.eat(0x28 /* ( */)) {
  3365. if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
  3366. this.regexp_disjunction(state);
  3367. if (state.eat(0x29 /* ) */)) {
  3368. return true
  3369. }
  3370. state.raise("Unterminated group");
  3371. }
  3372. state.pos = start;
  3373. }
  3374. return false
  3375. };
  3376. pp$9.regexp_eatCapturingGroup = function(state) {
  3377. if (state.eat(0x28 /* ( */)) {
  3378. if (this.options.ecmaVersion >= 9) {
  3379. this.regexp_groupSpecifier(state);
  3380. } else if (state.current() === 0x3F /* ? */) {
  3381. state.raise("Invalid group");
  3382. }
  3383. this.regexp_disjunction(state);
  3384. if (state.eat(0x29 /* ) */)) {
  3385. state.numCapturingParens += 1;
  3386. return true
  3387. }
  3388. state.raise("Unterminated group");
  3389. }
  3390. return false
  3391. };
  3392. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
  3393. pp$9.regexp_eatExtendedAtom = function(state) {
  3394. return (
  3395. state.eat(0x2E /* . */) ||
  3396. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3397. this.regexp_eatCharacterClass(state) ||
  3398. this.regexp_eatUncapturingGroup(state) ||
  3399. this.regexp_eatCapturingGroup(state) ||
  3400. this.regexp_eatInvalidBracedQuantifier(state) ||
  3401. this.regexp_eatExtendedPatternCharacter(state)
  3402. )
  3403. };
  3404. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
  3405. pp$9.regexp_eatInvalidBracedQuantifier = function(state) {
  3406. if (this.regexp_eatBracedQuantifier(state, true)) {
  3407. state.raise("Nothing to repeat");
  3408. }
  3409. return false
  3410. };
  3411. // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
  3412. pp$9.regexp_eatSyntaxCharacter = function(state) {
  3413. var ch = state.current();
  3414. if (isSyntaxCharacter(ch)) {
  3415. state.lastIntValue = ch;
  3416. state.advance();
  3417. return true
  3418. }
  3419. return false
  3420. };
  3421. function isSyntaxCharacter(ch) {
  3422. return (
  3423. ch === 0x24 /* $ */ ||
  3424. ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
  3425. ch === 0x2E /* . */ ||
  3426. ch === 0x3F /* ? */ ||
  3427. ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
  3428. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  3429. )
  3430. }
  3431. // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
  3432. // But eat eager.
  3433. pp$9.regexp_eatPatternCharacters = function(state) {
  3434. var start = state.pos;
  3435. var ch = 0;
  3436. while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
  3437. state.advance();
  3438. }
  3439. return state.pos !== start
  3440. };
  3441. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
  3442. pp$9.regexp_eatExtendedPatternCharacter = function(state) {
  3443. var ch = state.current();
  3444. if (
  3445. ch !== -1 &&
  3446. ch !== 0x24 /* $ */ &&
  3447. !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
  3448. ch !== 0x2E /* . */ &&
  3449. ch !== 0x3F /* ? */ &&
  3450. ch !== 0x5B /* [ */ &&
  3451. ch !== 0x5E /* ^ */ &&
  3452. ch !== 0x7C /* | */
  3453. ) {
  3454. state.advance();
  3455. return true
  3456. }
  3457. return false
  3458. };
  3459. // GroupSpecifier[U] ::
  3460. // [empty]
  3461. // `?` GroupName[?U]
  3462. pp$9.regexp_groupSpecifier = function(state) {
  3463. if (state.eat(0x3F /* ? */)) {
  3464. if (this.regexp_eatGroupName(state)) {
  3465. if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
  3466. state.raise("Duplicate capture group name");
  3467. }
  3468. state.groupNames.push(state.lastStringValue);
  3469. return
  3470. }
  3471. state.raise("Invalid group");
  3472. }
  3473. };
  3474. // GroupName[U] ::
  3475. // `<` RegExpIdentifierName[?U] `>`
  3476. // Note: this updates `state.lastStringValue` property with the eaten name.
  3477. pp$9.regexp_eatGroupName = function(state) {
  3478. state.lastStringValue = "";
  3479. if (state.eat(0x3C /* < */)) {
  3480. if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
  3481. return true
  3482. }
  3483. state.raise("Invalid capture group name");
  3484. }
  3485. return false
  3486. };
  3487. // RegExpIdentifierName[U] ::
  3488. // RegExpIdentifierStart[?U]
  3489. // RegExpIdentifierName[?U] RegExpIdentifierPart[?U]
  3490. // Note: this updates `state.lastStringValue` property with the eaten name.
  3491. pp$9.regexp_eatRegExpIdentifierName = function(state) {
  3492. state.lastStringValue = "";
  3493. if (this.regexp_eatRegExpIdentifierStart(state)) {
  3494. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3495. while (this.regexp_eatRegExpIdentifierPart(state)) {
  3496. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3497. }
  3498. return true
  3499. }
  3500. return false
  3501. };
  3502. // RegExpIdentifierStart[U] ::
  3503. // UnicodeIDStart
  3504. // `$`
  3505. // `_`
  3506. // `\` RegExpUnicodeEscapeSequence[?U]
  3507. pp$9.regexp_eatRegExpIdentifierStart = function(state) {
  3508. var start = state.pos;
  3509. var ch = state.current();
  3510. state.advance();
  3511. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3512. ch = state.lastIntValue;
  3513. }
  3514. if (isRegExpIdentifierStart(ch)) {
  3515. state.lastIntValue = ch;
  3516. return true
  3517. }
  3518. state.pos = start;
  3519. return false
  3520. };
  3521. function isRegExpIdentifierStart(ch) {
  3522. return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
  3523. }
  3524. // RegExpIdentifierPart[U] ::
  3525. // UnicodeIDContinue
  3526. // `$`
  3527. // `_`
  3528. // `\` RegExpUnicodeEscapeSequence[?U]
  3529. // <ZWNJ>
  3530. // <ZWJ>
  3531. pp$9.regexp_eatRegExpIdentifierPart = function(state) {
  3532. var start = state.pos;
  3533. var ch = state.current();
  3534. state.advance();
  3535. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) {
  3536. ch = state.lastIntValue;
  3537. }
  3538. if (isRegExpIdentifierPart(ch)) {
  3539. state.lastIntValue = ch;
  3540. return true
  3541. }
  3542. state.pos = start;
  3543. return false
  3544. };
  3545. function isRegExpIdentifierPart(ch) {
  3546. return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
  3547. }
  3548. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
  3549. pp$9.regexp_eatAtomEscape = function(state) {
  3550. if (
  3551. this.regexp_eatBackReference(state) ||
  3552. this.regexp_eatCharacterClassEscape(state) ||
  3553. this.regexp_eatCharacterEscape(state) ||
  3554. (state.switchN && this.regexp_eatKGroupName(state))
  3555. ) {
  3556. return true
  3557. }
  3558. if (state.switchU) {
  3559. // Make the same message as V8.
  3560. if (state.current() === 0x63 /* c */) {
  3561. state.raise("Invalid unicode escape");
  3562. }
  3563. state.raise("Invalid escape");
  3564. }
  3565. return false
  3566. };
  3567. pp$9.regexp_eatBackReference = function(state) {
  3568. var start = state.pos;
  3569. if (this.regexp_eatDecimalEscape(state)) {
  3570. var n = state.lastIntValue;
  3571. if (state.switchU) {
  3572. // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
  3573. if (n > state.maxBackReference) {
  3574. state.maxBackReference = n;
  3575. }
  3576. return true
  3577. }
  3578. if (n <= state.numCapturingParens) {
  3579. return true
  3580. }
  3581. state.pos = start;
  3582. }
  3583. return false
  3584. };
  3585. pp$9.regexp_eatKGroupName = function(state) {
  3586. if (state.eat(0x6B /* k */)) {
  3587. if (this.regexp_eatGroupName(state)) {
  3588. state.backReferenceNames.push(state.lastStringValue);
  3589. return true
  3590. }
  3591. state.raise("Invalid named reference");
  3592. }
  3593. return false
  3594. };
  3595. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
  3596. pp$9.regexp_eatCharacterEscape = function(state) {
  3597. return (
  3598. this.regexp_eatControlEscape(state) ||
  3599. this.regexp_eatCControlLetter(state) ||
  3600. this.regexp_eatZero(state) ||
  3601. this.regexp_eatHexEscapeSequence(state) ||
  3602. this.regexp_eatRegExpUnicodeEscapeSequence(state) ||
  3603. (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
  3604. this.regexp_eatIdentityEscape(state)
  3605. )
  3606. };
  3607. pp$9.regexp_eatCControlLetter = function(state) {
  3608. var start = state.pos;
  3609. if (state.eat(0x63 /* c */)) {
  3610. if (this.regexp_eatControlLetter(state)) {
  3611. return true
  3612. }
  3613. state.pos = start;
  3614. }
  3615. return false
  3616. };
  3617. pp$9.regexp_eatZero = function(state) {
  3618. if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
  3619. state.lastIntValue = 0;
  3620. state.advance();
  3621. return true
  3622. }
  3623. return false
  3624. };
  3625. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
  3626. pp$9.regexp_eatControlEscape = function(state) {
  3627. var ch = state.current();
  3628. if (ch === 0x74 /* t */) {
  3629. state.lastIntValue = 0x09; /* \t */
  3630. state.advance();
  3631. return true
  3632. }
  3633. if (ch === 0x6E /* n */) {
  3634. state.lastIntValue = 0x0A; /* \n */
  3635. state.advance();
  3636. return true
  3637. }
  3638. if (ch === 0x76 /* v */) {
  3639. state.lastIntValue = 0x0B; /* \v */
  3640. state.advance();
  3641. return true
  3642. }
  3643. if (ch === 0x66 /* f */) {
  3644. state.lastIntValue = 0x0C; /* \f */
  3645. state.advance();
  3646. return true
  3647. }
  3648. if (ch === 0x72 /* r */) {
  3649. state.lastIntValue = 0x0D; /* \r */
  3650. state.advance();
  3651. return true
  3652. }
  3653. return false
  3654. };
  3655. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
  3656. pp$9.regexp_eatControlLetter = function(state) {
  3657. var ch = state.current();
  3658. if (isControlLetter(ch)) {
  3659. state.lastIntValue = ch % 0x20;
  3660. state.advance();
  3661. return true
  3662. }
  3663. return false
  3664. };
  3665. function isControlLetter(ch) {
  3666. return (
  3667. (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
  3668. (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
  3669. )
  3670. }
  3671. // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
  3672. pp$9.regexp_eatRegExpUnicodeEscapeSequence = function(state) {
  3673. var start = state.pos;
  3674. if (state.eat(0x75 /* u */)) {
  3675. if (this.regexp_eatFixedHexDigits(state, 4)) {
  3676. var lead = state.lastIntValue;
  3677. if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) {
  3678. var leadSurrogateEnd = state.pos;
  3679. if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
  3680. var trail = state.lastIntValue;
  3681. if (trail >= 0xDC00 && trail <= 0xDFFF) {
  3682. state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3683. return true
  3684. }
  3685. }
  3686. state.pos = leadSurrogateEnd;
  3687. state.lastIntValue = lead;
  3688. }
  3689. return true
  3690. }
  3691. if (
  3692. state.switchU &&
  3693. state.eat(0x7B /* { */) &&
  3694. this.regexp_eatHexDigits(state) &&
  3695. state.eat(0x7D /* } */) &&
  3696. isValidUnicode(state.lastIntValue)
  3697. ) {
  3698. return true
  3699. }
  3700. if (state.switchU) {
  3701. state.raise("Invalid unicode escape");
  3702. }
  3703. state.pos = start;
  3704. }
  3705. return false
  3706. };
  3707. function isValidUnicode(ch) {
  3708. return ch >= 0 && ch <= 0x10FFFF
  3709. }
  3710. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
  3711. pp$9.regexp_eatIdentityEscape = function(state) {
  3712. if (state.switchU) {
  3713. if (this.regexp_eatSyntaxCharacter(state)) {
  3714. return true
  3715. }
  3716. if (state.eat(0x2F /* / */)) {
  3717. state.lastIntValue = 0x2F; /* / */
  3718. return true
  3719. }
  3720. return false
  3721. }
  3722. var ch = state.current();
  3723. if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
  3724. state.lastIntValue = ch;
  3725. state.advance();
  3726. return true
  3727. }
  3728. return false
  3729. };
  3730. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
  3731. pp$9.regexp_eatDecimalEscape = function(state) {
  3732. state.lastIntValue = 0;
  3733. var ch = state.current();
  3734. if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
  3735. do {
  3736. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3737. state.advance();
  3738. } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
  3739. return true
  3740. }
  3741. return false
  3742. };
  3743. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
  3744. pp$9.regexp_eatCharacterClassEscape = function(state) {
  3745. var ch = state.current();
  3746. if (isCharacterClassEscape(ch)) {
  3747. state.lastIntValue = -1;
  3748. state.advance();
  3749. return true
  3750. }
  3751. if (
  3752. state.switchU &&
  3753. this.options.ecmaVersion >= 9 &&
  3754. (ch === 0x50 /* P */ || ch === 0x70 /* p */)
  3755. ) {
  3756. state.lastIntValue = -1;
  3757. state.advance();
  3758. if (
  3759. state.eat(0x7B /* { */) &&
  3760. this.regexp_eatUnicodePropertyValueExpression(state) &&
  3761. state.eat(0x7D /* } */)
  3762. ) {
  3763. return true
  3764. }
  3765. state.raise("Invalid property name");
  3766. }
  3767. return false
  3768. };
  3769. function isCharacterClassEscape(ch) {
  3770. return (
  3771. ch === 0x64 /* d */ ||
  3772. ch === 0x44 /* D */ ||
  3773. ch === 0x73 /* s */ ||
  3774. ch === 0x53 /* S */ ||
  3775. ch === 0x77 /* w */ ||
  3776. ch === 0x57 /* W */
  3777. )
  3778. }
  3779. // UnicodePropertyValueExpression ::
  3780. // UnicodePropertyName `=` UnicodePropertyValue
  3781. // LoneUnicodePropertyNameOrValue
  3782. pp$9.regexp_eatUnicodePropertyValueExpression = function(state) {
  3783. var start = state.pos;
  3784. // UnicodePropertyName `=` UnicodePropertyValue
  3785. if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
  3786. var name = state.lastStringValue;
  3787. if (this.regexp_eatUnicodePropertyValue(state)) {
  3788. var value = state.lastStringValue;
  3789. this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
  3790. return true
  3791. }
  3792. }
  3793. state.pos = start;
  3794. // LoneUnicodePropertyNameOrValue
  3795. if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
  3796. var nameOrValue = state.lastStringValue;
  3797. this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
  3798. return true
  3799. }
  3800. return false
  3801. };
  3802. pp$9.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
  3803. if (!data.hasOwnProperty(name) || data[name].indexOf(value) === -1) {
  3804. state.raise("Invalid property name");
  3805. }
  3806. };
  3807. pp$9.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
  3808. if (data.$LONE.indexOf(nameOrValue) === -1) {
  3809. state.raise("Invalid property name");
  3810. }
  3811. };
  3812. // UnicodePropertyName ::
  3813. // UnicodePropertyNameCharacters
  3814. pp$9.regexp_eatUnicodePropertyName = function(state) {
  3815. var ch = 0;
  3816. state.lastStringValue = "";
  3817. while (isUnicodePropertyNameCharacter(ch = state.current())) {
  3818. state.lastStringValue += codePointToString$1(ch);
  3819. state.advance();
  3820. }
  3821. return state.lastStringValue !== ""
  3822. };
  3823. function isUnicodePropertyNameCharacter(ch) {
  3824. return isControlLetter(ch) || ch === 0x5F /* _ */
  3825. }
  3826. // UnicodePropertyValue ::
  3827. // UnicodePropertyValueCharacters
  3828. pp$9.regexp_eatUnicodePropertyValue = function(state) {
  3829. var ch = 0;
  3830. state.lastStringValue = "";
  3831. while (isUnicodePropertyValueCharacter(ch = state.current())) {
  3832. state.lastStringValue += codePointToString$1(ch);
  3833. state.advance();
  3834. }
  3835. return state.lastStringValue !== ""
  3836. };
  3837. function isUnicodePropertyValueCharacter(ch) {
  3838. return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
  3839. }
  3840. // LoneUnicodePropertyNameOrValue ::
  3841. // UnicodePropertyValueCharacters
  3842. pp$9.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
  3843. return this.regexp_eatUnicodePropertyValue(state)
  3844. };
  3845. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
  3846. pp$9.regexp_eatCharacterClass = function(state) {
  3847. if (state.eat(0x5B /* [ */)) {
  3848. state.eat(0x5E /* ^ */);
  3849. this.regexp_classRanges(state);
  3850. if (state.eat(0x5D /* [ */)) {
  3851. return true
  3852. }
  3853. // Unreachable since it threw "unterminated regular expression" error before.
  3854. state.raise("Unterminated character class");
  3855. }
  3856. return false
  3857. };
  3858. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
  3859. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
  3860. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
  3861. pp$9.regexp_classRanges = function(state) {
  3862. var this$1 = this;
  3863. while (this.regexp_eatClassAtom(state)) {
  3864. var left = state.lastIntValue;
  3865. if (state.eat(0x2D /* - */) && this$1.regexp_eatClassAtom(state)) {
  3866. var right = state.lastIntValue;
  3867. if (state.switchU && (left === -1 || right === -1)) {
  3868. state.raise("Invalid character class");
  3869. }
  3870. if (left !== -1 && right !== -1 && left > right) {
  3871. state.raise("Range out of order in character class");
  3872. }
  3873. }
  3874. }
  3875. };
  3876. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
  3877. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
  3878. pp$9.regexp_eatClassAtom = function(state) {
  3879. var start = state.pos;
  3880. if (state.eat(0x5C /* \ */)) {
  3881. if (this.regexp_eatClassEscape(state)) {
  3882. return true
  3883. }
  3884. if (state.switchU) {
  3885. // Make the same message as V8.
  3886. var ch$1 = state.current();
  3887. if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
  3888. state.raise("Invalid class escape");
  3889. }
  3890. state.raise("Invalid escape");
  3891. }
  3892. state.pos = start;
  3893. }
  3894. var ch = state.current();
  3895. if (ch !== 0x5D /* [ */) {
  3896. state.lastIntValue = ch;
  3897. state.advance();
  3898. return true
  3899. }
  3900. return false
  3901. };
  3902. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
  3903. pp$9.regexp_eatClassEscape = function(state) {
  3904. var start = state.pos;
  3905. if (state.eat(0x62 /* b */)) {
  3906. state.lastIntValue = 0x08; /* <BS> */
  3907. return true
  3908. }
  3909. if (state.switchU && state.eat(0x2D /* - */)) {
  3910. state.lastIntValue = 0x2D; /* - */
  3911. return true
  3912. }
  3913. if (!state.switchU && state.eat(0x63 /* c */)) {
  3914. if (this.regexp_eatClassControlLetter(state)) {
  3915. return true
  3916. }
  3917. state.pos = start;
  3918. }
  3919. return (
  3920. this.regexp_eatCharacterClassEscape(state) ||
  3921. this.regexp_eatCharacterEscape(state)
  3922. )
  3923. };
  3924. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
  3925. pp$9.regexp_eatClassControlLetter = function(state) {
  3926. var ch = state.current();
  3927. if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
  3928. state.lastIntValue = ch % 0x20;
  3929. state.advance();
  3930. return true
  3931. }
  3932. return false
  3933. };
  3934. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  3935. pp$9.regexp_eatHexEscapeSequence = function(state) {
  3936. var start = state.pos;
  3937. if (state.eat(0x78 /* x */)) {
  3938. if (this.regexp_eatFixedHexDigits(state, 2)) {
  3939. return true
  3940. }
  3941. if (state.switchU) {
  3942. state.raise("Invalid escape");
  3943. }
  3944. state.pos = start;
  3945. }
  3946. return false
  3947. };
  3948. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
  3949. pp$9.regexp_eatDecimalDigits = function(state) {
  3950. var start = state.pos;
  3951. var ch = 0;
  3952. state.lastIntValue = 0;
  3953. while (isDecimalDigit(ch = state.current())) {
  3954. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3955. state.advance();
  3956. }
  3957. return state.pos !== start
  3958. };
  3959. function isDecimalDigit(ch) {
  3960. return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
  3961. }
  3962. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
  3963. pp$9.regexp_eatHexDigits = function(state) {
  3964. var start = state.pos;
  3965. var ch = 0;
  3966. state.lastIntValue = 0;
  3967. while (isHexDigit(ch = state.current())) {
  3968. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  3969. state.advance();
  3970. }
  3971. return state.pos !== start
  3972. };
  3973. function isHexDigit(ch) {
  3974. return (
  3975. (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
  3976. (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
  3977. (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
  3978. )
  3979. }
  3980. function hexToInt(ch) {
  3981. if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
  3982. return 10 + (ch - 0x41 /* A */)
  3983. }
  3984. if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
  3985. return 10 + (ch - 0x61 /* a */)
  3986. }
  3987. return ch - 0x30 /* 0 */
  3988. }
  3989. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
  3990. // Allows only 0-377(octal) i.e. 0-255(decimal).
  3991. pp$9.regexp_eatLegacyOctalEscapeSequence = function(state) {
  3992. if (this.regexp_eatOctalDigit(state)) {
  3993. var n1 = state.lastIntValue;
  3994. if (this.regexp_eatOctalDigit(state)) {
  3995. var n2 = state.lastIntValue;
  3996. if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
  3997. state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
  3998. } else {
  3999. state.lastIntValue = n1 * 8 + n2;
  4000. }
  4001. } else {
  4002. state.lastIntValue = n1;
  4003. }
  4004. return true
  4005. }
  4006. return false
  4007. };
  4008. // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
  4009. pp$9.regexp_eatOctalDigit = function(state) {
  4010. var ch = state.current();
  4011. if (isOctalDigit(ch)) {
  4012. state.lastIntValue = ch - 0x30; /* 0 */
  4013. state.advance();
  4014. return true
  4015. }
  4016. state.lastIntValue = 0;
  4017. return false
  4018. };
  4019. function isOctalDigit(ch) {
  4020. return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
  4021. }
  4022. // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
  4023. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
  4024. // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4025. pp$9.regexp_eatFixedHexDigits = function(state, length) {
  4026. var start = state.pos;
  4027. state.lastIntValue = 0;
  4028. for (var i = 0; i < length; ++i) {
  4029. var ch = state.current();
  4030. if (!isHexDigit(ch)) {
  4031. state.pos = start;
  4032. return false
  4033. }
  4034. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4035. state.advance();
  4036. }
  4037. return true
  4038. };
  4039. // Object type used to represent tokens. Note that normally, tokens
  4040. // simply exist as properties on the parser object. This is only
  4041. // used for the onToken callback and the external tokenizer.
  4042. var Token = function Token(p) {
  4043. this.type = p.type;
  4044. this.value = p.value;
  4045. this.start = p.start;
  4046. this.end = p.end;
  4047. if (p.options.locations)
  4048. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  4049. if (p.options.ranges)
  4050. { this.range = [p.start, p.end]; }
  4051. };
  4052. // ## Tokenizer
  4053. var pp$8 = Parser.prototype;
  4054. // Move to the next token
  4055. pp$8.next = function() {
  4056. if (this.options.onToken)
  4057. { this.options.onToken(new Token(this)); }
  4058. this.lastTokEnd = this.end;
  4059. this.lastTokStart = this.start;
  4060. this.lastTokEndLoc = this.endLoc;
  4061. this.lastTokStartLoc = this.startLoc;
  4062. this.nextToken();
  4063. };
  4064. pp$8.getToken = function() {
  4065. this.next();
  4066. return new Token(this)
  4067. };
  4068. // If we're in an ES6 environment, make parsers iterable
  4069. if (typeof Symbol !== "undefined")
  4070. { pp$8[Symbol.iterator] = function() {
  4071. var this$1 = this;
  4072. return {
  4073. next: function () {
  4074. var token = this$1.getToken();
  4075. return {
  4076. done: token.type === types.eof,
  4077. value: token
  4078. }
  4079. }
  4080. }
  4081. }; }
  4082. // Toggle strict mode. Re-reads the next number or string to please
  4083. // pedantic tests (`"use strict"; 010;` should fail).
  4084. pp$8.curContext = function() {
  4085. return this.context[this.context.length - 1]
  4086. };
  4087. // Read a single token, updating the parser object's token-related
  4088. // properties.
  4089. pp$8.nextToken = function() {
  4090. var curContext = this.curContext();
  4091. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  4092. this.start = this.pos;
  4093. if (this.options.locations) { this.startLoc = this.curPosition(); }
  4094. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  4095. if (curContext.override) { return curContext.override(this) }
  4096. else { this.readToken(this.fullCharCodeAtPos()); }
  4097. };
  4098. pp$8.readToken = function(code) {
  4099. // Identifier or keyword. '\uXXXX' sequences are allowed in
  4100. // identifiers, so '\' also dispatches to that.
  4101. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  4102. { return this.readWord() }
  4103. return this.getTokenFromCode(code)
  4104. };
  4105. pp$8.fullCharCodeAtPos = function() {
  4106. var code = this.input.charCodeAt(this.pos);
  4107. if (code <= 0xd7ff || code >= 0xe000) { return code }
  4108. var next = this.input.charCodeAt(this.pos + 1);
  4109. return (code << 10) + next - 0x35fdc00
  4110. };
  4111. pp$8.skipBlockComment = function() {
  4112. var this$1 = this;
  4113. var startLoc = this.options.onComment && this.curPosition();
  4114. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  4115. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  4116. this.pos = end + 2;
  4117. if (this.options.locations) {
  4118. lineBreakG.lastIndex = start;
  4119. var match;
  4120. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  4121. ++this$1.curLine;
  4122. this$1.lineStart = match.index + match[0].length;
  4123. }
  4124. }
  4125. if (this.options.onComment)
  4126. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  4127. startLoc, this.curPosition()); }
  4128. };
  4129. pp$8.skipLineComment = function(startSkip) {
  4130. var this$1 = this;
  4131. var start = this.pos;
  4132. var startLoc = this.options.onComment && this.curPosition();
  4133. var ch = this.input.charCodeAt(this.pos += startSkip);
  4134. while (this.pos < this.input.length && !isNewLine(ch)) {
  4135. ch = this$1.input.charCodeAt(++this$1.pos);
  4136. }
  4137. if (this.options.onComment)
  4138. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  4139. startLoc, this.curPosition()); }
  4140. };
  4141. // Called at the start of the parse and after every token. Skips
  4142. // whitespace and comments, and.
  4143. pp$8.skipSpace = function() {
  4144. var this$1 = this;
  4145. loop: while (this.pos < this.input.length) {
  4146. var ch = this$1.input.charCodeAt(this$1.pos);
  4147. switch (ch) {
  4148. case 32: case 160: // ' '
  4149. ++this$1.pos;
  4150. break
  4151. case 13:
  4152. if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
  4153. ++this$1.pos;
  4154. }
  4155. case 10: case 8232: case 8233:
  4156. ++this$1.pos;
  4157. if (this$1.options.locations) {
  4158. ++this$1.curLine;
  4159. this$1.lineStart = this$1.pos;
  4160. }
  4161. break
  4162. case 47: // '/'
  4163. switch (this$1.input.charCodeAt(this$1.pos + 1)) {
  4164. case 42: // '*'
  4165. this$1.skipBlockComment();
  4166. break
  4167. case 47:
  4168. this$1.skipLineComment(2);
  4169. break
  4170. default:
  4171. break loop
  4172. }
  4173. break
  4174. default:
  4175. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  4176. ++this$1.pos;
  4177. } else {
  4178. break loop
  4179. }
  4180. }
  4181. }
  4182. };
  4183. // Called at the end of every token. Sets `end`, `val`, and
  4184. // maintains `context` and `exprAllowed`, and skips the space after
  4185. // the token, so that the next one's `start` will point at the
  4186. // right position.
  4187. pp$8.finishToken = function(type, val) {
  4188. this.end = this.pos;
  4189. if (this.options.locations) { this.endLoc = this.curPosition(); }
  4190. var prevType = this.type;
  4191. this.type = type;
  4192. this.value = val;
  4193. this.updateContext(prevType);
  4194. };
  4195. // ### Token reading
  4196. // This is the function that is called to fetch the next token. It
  4197. // is somewhat obscure, because it works in character codes rather
  4198. // than characters, and because operator parsing has been inlined
  4199. // into it.
  4200. //
  4201. // All in the name of speed.
  4202. //
  4203. pp$8.readToken_dot = function() {
  4204. var next = this.input.charCodeAt(this.pos + 1);
  4205. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  4206. var next2 = this.input.charCodeAt(this.pos + 2);
  4207. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  4208. this.pos += 3;
  4209. return this.finishToken(types.ellipsis)
  4210. } else {
  4211. ++this.pos;
  4212. return this.finishToken(types.dot)
  4213. }
  4214. };
  4215. pp$8.readToken_slash = function() { // '/'
  4216. var next = this.input.charCodeAt(this.pos + 1);
  4217. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  4218. if (next === 61) { return this.finishOp(types.assign, 2) }
  4219. return this.finishOp(types.slash, 1)
  4220. };
  4221. pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
  4222. var next = this.input.charCodeAt(this.pos + 1);
  4223. var size = 1;
  4224. var tokentype = code === 42 ? types.star : types.modulo;
  4225. // exponentiation operator ** and **=
  4226. if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
  4227. ++size;
  4228. tokentype = types.starstar;
  4229. next = this.input.charCodeAt(this.pos + 2);
  4230. }
  4231. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  4232. return this.finishOp(tokentype, size)
  4233. };
  4234. pp$8.readToken_pipe_amp = function(code) { // '|&'
  4235. var next = this.input.charCodeAt(this.pos + 1);
  4236. if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
  4237. if (next === 61) { return this.finishOp(types.assign, 2) }
  4238. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  4239. };
  4240. pp$8.readToken_caret = function() { // '^'
  4241. var next = this.input.charCodeAt(this.pos + 1);
  4242. if (next === 61) { return this.finishOp(types.assign, 2) }
  4243. return this.finishOp(types.bitwiseXOR, 1)
  4244. };
  4245. pp$8.readToken_plus_min = function(code) { // '+-'
  4246. var next = this.input.charCodeAt(this.pos + 1);
  4247. if (next === code) {
  4248. if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
  4249. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  4250. // A `-->` line comment
  4251. this.skipLineComment(3);
  4252. this.skipSpace();
  4253. return this.nextToken()
  4254. }
  4255. return this.finishOp(types.incDec, 2)
  4256. }
  4257. if (next === 61) { return this.finishOp(types.assign, 2) }
  4258. return this.finishOp(types.plusMin, 1)
  4259. };
  4260. pp$8.readToken_lt_gt = function(code) { // '<>'
  4261. var next = this.input.charCodeAt(this.pos + 1);
  4262. var size = 1;
  4263. if (next === code) {
  4264. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  4265. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  4266. return this.finishOp(types.bitShift, size)
  4267. }
  4268. if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
  4269. this.input.charCodeAt(this.pos + 3) === 45) {
  4270. // `<!--`, an XML-style comment that should be interpreted as a line comment
  4271. this.skipLineComment(4);
  4272. this.skipSpace();
  4273. return this.nextToken()
  4274. }
  4275. if (next === 61) { size = 2; }
  4276. return this.finishOp(types.relational, size)
  4277. };
  4278. pp$8.readToken_eq_excl = function(code) { // '=!'
  4279. var next = this.input.charCodeAt(this.pos + 1);
  4280. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  4281. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  4282. this.pos += 2;
  4283. return this.finishToken(types.arrow)
  4284. }
  4285. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  4286. };
  4287. pp$8.getTokenFromCode = function(code) {
  4288. switch (code) {
  4289. // The interpretation of a dot depends on whether it is followed
  4290. // by a digit or another two dots.
  4291. case 46: // '.'
  4292. return this.readToken_dot()
  4293. // Punctuation tokens.
  4294. case 40: ++this.pos; return this.finishToken(types.parenL)
  4295. case 41: ++this.pos; return this.finishToken(types.parenR)
  4296. case 59: ++this.pos; return this.finishToken(types.semi)
  4297. case 44: ++this.pos; return this.finishToken(types.comma)
  4298. case 91: ++this.pos; return this.finishToken(types.bracketL)
  4299. case 93: ++this.pos; return this.finishToken(types.bracketR)
  4300. case 123: ++this.pos; return this.finishToken(types.braceL)
  4301. case 125: ++this.pos; return this.finishToken(types.braceR)
  4302. case 58: ++this.pos; return this.finishToken(types.colon)
  4303. case 63: ++this.pos; return this.finishToken(types.question)
  4304. case 96: // '`'
  4305. if (this.options.ecmaVersion < 6) { break }
  4306. ++this.pos;
  4307. return this.finishToken(types.backQuote)
  4308. case 48: // '0'
  4309. var next = this.input.charCodeAt(this.pos + 1);
  4310. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  4311. if (this.options.ecmaVersion >= 6) {
  4312. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  4313. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  4314. }
  4315. // Anything else beginning with a digit is an integer, octal
  4316. // number, or float.
  4317. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  4318. return this.readNumber(false)
  4319. // Quotes produce strings.
  4320. case 34: case 39: // '"', "'"
  4321. return this.readString(code)
  4322. // Operators are parsed inline in tiny state machines. '=' (61) is
  4323. // often referred to. `finishOp` simply skips the amount of
  4324. // characters it is given as second argument, and returns a token
  4325. // of the type given by its first argument.
  4326. case 47: // '/'
  4327. return this.readToken_slash()
  4328. case 37: case 42: // '%*'
  4329. return this.readToken_mult_modulo_exp(code)
  4330. case 124: case 38: // '|&'
  4331. return this.readToken_pipe_amp(code)
  4332. case 94: // '^'
  4333. return this.readToken_caret()
  4334. case 43: case 45: // '+-'
  4335. return this.readToken_plus_min(code)
  4336. case 60: case 62: // '<>'
  4337. return this.readToken_lt_gt(code)
  4338. case 61: case 33: // '=!'
  4339. return this.readToken_eq_excl(code)
  4340. case 126: // '~'
  4341. return this.finishOp(types.prefix, 1)
  4342. }
  4343. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  4344. };
  4345. pp$8.finishOp = function(type, size) {
  4346. var str = this.input.slice(this.pos, this.pos + size);
  4347. this.pos += size;
  4348. return this.finishToken(type, str)
  4349. };
  4350. pp$8.readRegexp = function() {
  4351. var this$1 = this;
  4352. var escaped, inClass, start = this.pos;
  4353. for (;;) {
  4354. if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
  4355. var ch = this$1.input.charAt(this$1.pos);
  4356. if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
  4357. if (!escaped) {
  4358. if (ch === "[") { inClass = true; }
  4359. else if (ch === "]" && inClass) { inClass = false; }
  4360. else if (ch === "/" && !inClass) { break }
  4361. escaped = ch === "\\";
  4362. } else { escaped = false; }
  4363. ++this$1.pos;
  4364. }
  4365. var pattern = this.input.slice(start, this.pos);
  4366. ++this.pos;
  4367. var flagsStart = this.pos;
  4368. var flags = this.readWord1();
  4369. if (this.containsEsc) { this.unexpected(flagsStart); }
  4370. // Validate pattern
  4371. var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
  4372. state.reset(start, pattern, flags);
  4373. this.validateRegExpFlags(state);
  4374. this.validateRegExpPattern(state);
  4375. // Create Literal#value property value.
  4376. var value = null;
  4377. try {
  4378. value = new RegExp(pattern, flags);
  4379. } catch (e) {
  4380. // ESTree requires null if it failed to instantiate RegExp object.
  4381. // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
  4382. }
  4383. return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
  4384. };
  4385. // Read an integer in the given radix. Return null if zero digits
  4386. // were read, the integer value otherwise. When `len` is given, this
  4387. // will return `null` unless the integer has exactly `len` digits.
  4388. pp$8.readInt = function(radix, len) {
  4389. var this$1 = this;
  4390. var start = this.pos, total = 0;
  4391. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  4392. var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
  4393. if (code >= 97) { val = code - 97 + 10; } // a
  4394. else if (code >= 65) { val = code - 65 + 10; } // A
  4395. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  4396. else { val = Infinity; }
  4397. if (val >= radix) { break }
  4398. ++this$1.pos;
  4399. total = total * radix + val;
  4400. }
  4401. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  4402. return total
  4403. };
  4404. pp$8.readRadixNumber = function(radix) {
  4405. this.pos += 2; // 0x
  4406. var val = this.readInt(radix);
  4407. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  4408. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4409. return this.finishToken(types.num, val)
  4410. };
  4411. // Read an integer, octal integer, or floating-point number.
  4412. pp$8.readNumber = function(startsWithDot) {
  4413. var start = this.pos;
  4414. if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4415. var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  4416. if (octal && this.strict) { this.raise(start, "Invalid number"); }
  4417. if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
  4418. var next = this.input.charCodeAt(this.pos);
  4419. if (next === 46 && !octal) { // '.'
  4420. ++this.pos;
  4421. this.readInt(10);
  4422. next = this.input.charCodeAt(this.pos);
  4423. }
  4424. if ((next === 69 || next === 101) && !octal) { // 'eE'
  4425. next = this.input.charCodeAt(++this.pos);
  4426. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  4427. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4428. }
  4429. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4430. var str = this.input.slice(start, this.pos);
  4431. var val = octal ? parseInt(str, 8) : parseFloat(str);
  4432. return this.finishToken(types.num, val)
  4433. };
  4434. // Read a string value, interpreting backslash-escapes.
  4435. pp$8.readCodePoint = function() {
  4436. var ch = this.input.charCodeAt(this.pos), code;
  4437. if (ch === 123) { // '{'
  4438. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  4439. var codePos = ++this.pos;
  4440. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  4441. ++this.pos;
  4442. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  4443. } else {
  4444. code = this.readHexChar(4);
  4445. }
  4446. return code
  4447. };
  4448. function codePointToString(code) {
  4449. // UTF-16 Decoding
  4450. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  4451. code -= 0x10000;
  4452. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  4453. }
  4454. pp$8.readString = function(quote) {
  4455. var this$1 = this;
  4456. var out = "", chunkStart = ++this.pos;
  4457. for (;;) {
  4458. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4459. var ch = this$1.input.charCodeAt(this$1.pos);
  4460. if (ch === quote) { break }
  4461. if (ch === 92) { // '\'
  4462. out += this$1.input.slice(chunkStart, this$1.pos);
  4463. out += this$1.readEscapedChar(false);
  4464. chunkStart = this$1.pos;
  4465. } else {
  4466. if (isNewLine(ch, this$1.options.ecmaVersion >= 10)) { this$1.raise(this$1.start, "Unterminated string constant"); }
  4467. ++this$1.pos;
  4468. }
  4469. }
  4470. out += this.input.slice(chunkStart, this.pos++);
  4471. return this.finishToken(types.string, out)
  4472. };
  4473. // Reads template string tokens.
  4474. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  4475. pp$8.tryReadTemplateToken = function() {
  4476. this.inTemplateElement = true;
  4477. try {
  4478. this.readTmplToken();
  4479. } catch (err) {
  4480. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  4481. this.readInvalidTemplateToken();
  4482. } else {
  4483. throw err
  4484. }
  4485. }
  4486. this.inTemplateElement = false;
  4487. };
  4488. pp$8.invalidStringToken = function(position, message) {
  4489. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  4490. throw INVALID_TEMPLATE_ESCAPE_ERROR
  4491. } else {
  4492. this.raise(position, message);
  4493. }
  4494. };
  4495. pp$8.readTmplToken = function() {
  4496. var this$1 = this;
  4497. var out = "", chunkStart = this.pos;
  4498. for (;;) {
  4499. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
  4500. var ch = this$1.input.charCodeAt(this$1.pos);
  4501. if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
  4502. if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
  4503. if (ch === 36) {
  4504. this$1.pos += 2;
  4505. return this$1.finishToken(types.dollarBraceL)
  4506. } else {
  4507. ++this$1.pos;
  4508. return this$1.finishToken(types.backQuote)
  4509. }
  4510. }
  4511. out += this$1.input.slice(chunkStart, this$1.pos);
  4512. return this$1.finishToken(types.template, out)
  4513. }
  4514. if (ch === 92) { // '\'
  4515. out += this$1.input.slice(chunkStart, this$1.pos);
  4516. out += this$1.readEscapedChar(true);
  4517. chunkStart = this$1.pos;
  4518. } else if (isNewLine(ch)) {
  4519. out += this$1.input.slice(chunkStart, this$1.pos);
  4520. ++this$1.pos;
  4521. switch (ch) {
  4522. case 13:
  4523. if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
  4524. case 10:
  4525. out += "\n";
  4526. break
  4527. default:
  4528. out += String.fromCharCode(ch);
  4529. break
  4530. }
  4531. if (this$1.options.locations) {
  4532. ++this$1.curLine;
  4533. this$1.lineStart = this$1.pos;
  4534. }
  4535. chunkStart = this$1.pos;
  4536. } else {
  4537. ++this$1.pos;
  4538. }
  4539. }
  4540. };
  4541. // Reads a template token to search for the end, without validating any escape sequences
  4542. pp$8.readInvalidTemplateToken = function() {
  4543. var this$1 = this;
  4544. for (; this.pos < this.input.length; this.pos++) {
  4545. switch (this$1.input[this$1.pos]) {
  4546. case "\\":
  4547. ++this$1.pos;
  4548. break
  4549. case "$":
  4550. if (this$1.input[this$1.pos + 1] !== "{") {
  4551. break
  4552. }
  4553. // falls through
  4554. case "`":
  4555. return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
  4556. // no default
  4557. }
  4558. }
  4559. this.raise(this.start, "Unterminated template");
  4560. };
  4561. // Used to read escaped characters
  4562. pp$8.readEscapedChar = function(inTemplate) {
  4563. var ch = this.input.charCodeAt(++this.pos);
  4564. ++this.pos;
  4565. switch (ch) {
  4566. case 110: return "\n" // 'n' -> '\n'
  4567. case 114: return "\r" // 'r' -> '\r'
  4568. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  4569. case 117: return codePointToString(this.readCodePoint()) // 'u'
  4570. case 116: return "\t" // 't' -> '\t'
  4571. case 98: return "\b" // 'b' -> '\b'
  4572. case 118: return "\u000b" // 'v' -> '\u000b'
  4573. case 102: return "\f" // 'f' -> '\f'
  4574. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  4575. case 10: // ' \n'
  4576. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  4577. return ""
  4578. default:
  4579. if (ch >= 48 && ch <= 55) {
  4580. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  4581. var octal = parseInt(octalStr, 8);
  4582. if (octal > 255) {
  4583. octalStr = octalStr.slice(0, -1);
  4584. octal = parseInt(octalStr, 8);
  4585. }
  4586. this.pos += octalStr.length - 1;
  4587. ch = this.input.charCodeAt(this.pos);
  4588. if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
  4589. this.invalidStringToken(
  4590. this.pos - 1 - octalStr.length,
  4591. inTemplate
  4592. ? "Octal literal in template string"
  4593. : "Octal literal in strict mode"
  4594. );
  4595. }
  4596. return String.fromCharCode(octal)
  4597. }
  4598. return String.fromCharCode(ch)
  4599. }
  4600. };
  4601. // Used to read character escape sequences ('\x', '\u', '\U').
  4602. pp$8.readHexChar = function(len) {
  4603. var codePos = this.pos;
  4604. var n = this.readInt(16, len);
  4605. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  4606. return n
  4607. };
  4608. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  4609. // to whether the word contained a '\u' escape.
  4610. //
  4611. // Incrementally adds only escaped chars, adding other chunks as-is
  4612. // as a micro-optimization.
  4613. pp$8.readWord1 = function() {
  4614. var this$1 = this;
  4615. this.containsEsc = false;
  4616. var word = "", first = true, chunkStart = this.pos;
  4617. var astral = this.options.ecmaVersion >= 6;
  4618. while (this.pos < this.input.length) {
  4619. var ch = this$1.fullCharCodeAtPos();
  4620. if (isIdentifierChar(ch, astral)) {
  4621. this$1.pos += ch <= 0xffff ? 1 : 2;
  4622. } else if (ch === 92) { // "\"
  4623. this$1.containsEsc = true;
  4624. word += this$1.input.slice(chunkStart, this$1.pos);
  4625. var escStart = this$1.pos;
  4626. if (this$1.input.charCodeAt(++this$1.pos) !== 117) // "u"
  4627. { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  4628. ++this$1.pos;
  4629. var esc = this$1.readCodePoint();
  4630. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  4631. { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
  4632. word += codePointToString(esc);
  4633. chunkStart = this$1.pos;
  4634. } else {
  4635. break
  4636. }
  4637. first = false;
  4638. }
  4639. return word + this.input.slice(chunkStart, this.pos)
  4640. };
  4641. // Read an identifier or keyword token. Will check for reserved
  4642. // words when necessary.
  4643. pp$8.readWord = function() {
  4644. var word = this.readWord1();
  4645. var type = types.name;
  4646. if (this.keywords.test(word)) {
  4647. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
  4648. type = keywords$1[word];
  4649. }
  4650. return this.finishToken(type, word)
  4651. };
  4652. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  4653. //
  4654. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  4655. // various contributors and released under an MIT license.
  4656. //
  4657. // Git repositories for Acorn are available at
  4658. //
  4659. // http://marijnhaverbeke.nl/git/acorn
  4660. // https://github.com/acornjs/acorn.git
  4661. //
  4662. // Please use the [github bug tracker][ghbt] to report issues.
  4663. //
  4664. // [ghbt]: https://github.com/acornjs/acorn/issues
  4665. //
  4666. // This file defines the main parser interface. The library also comes
  4667. // with a [error-tolerant parser][dammit] and an
  4668. // [abstract syntax tree walker][walk], defined in other files.
  4669. //
  4670. // [dammit]: acorn_loose.js
  4671. // [walk]: util/walk.js
  4672. var version = "5.7.1";
  4673. // The main exported interface (under `self.acorn` when in the
  4674. // browser) is a `parse` function that takes a code string and
  4675. // returns an abstract syntax tree as specified by [Mozilla parser
  4676. // API][api].
  4677. //
  4678. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4679. function parse(input, options) {
  4680. return new Parser(options, input).parse()
  4681. }
  4682. // This function tries to parse a single expression at a given
  4683. // offset in a string. Useful for parsing mixed-language formats
  4684. // that embed JavaScript expressions.
  4685. function parseExpressionAt(input, pos, options) {
  4686. var p = new Parser(options, input, pos);
  4687. p.nextToken();
  4688. return p.parseExpression()
  4689. }
  4690. // Acorn is organized as a tokenizer and a recursive-descent parser.
  4691. // The `tokenizer` export provides an interface to the tokenizer.
  4692. function tokenizer(input, options) {
  4693. return new Parser(options, input)
  4694. }
  4695. // This is a terrible kludge to support the existing, pre-ES6
  4696. // interface where the loose parser module retroactively adds exports
  4697. // to this module.
  4698. // eslint-disable-line camelcase
  4699. function addLooseExports(parse, Parser$$1, plugins$$1) {
  4700. exports.parse_dammit = parse; // eslint-disable-line camelcase
  4701. exports.LooseParser = Parser$$1;
  4702. exports.pluginsLoose = plugins$$1;
  4703. }
  4704. exports.version = version;
  4705. exports.parse = parse;
  4706. exports.parseExpressionAt = parseExpressionAt;
  4707. exports.tokenizer = tokenizer;
  4708. exports.addLooseExports = addLooseExports;
  4709. exports.Parser = Parser;
  4710. exports.plugins = plugins;
  4711. exports.defaultOptions = defaultOptions;
  4712. exports.Position = Position;
  4713. exports.SourceLocation = SourceLocation;
  4714. exports.getLineInfo = getLineInfo;
  4715. exports.Node = Node;
  4716. exports.TokenType = TokenType;
  4717. exports.tokTypes = types;
  4718. exports.keywordTypes = keywords$1;
  4719. exports.TokContext = TokContext;
  4720. exports.tokContexts = types$1;
  4721. exports.isIdentifierChar = isIdentifierChar;
  4722. exports.isIdentifierStart = isIdentifierStart;
  4723. exports.Token = Token;
  4724. exports.isNewLine = isNewLine;
  4725. exports.lineBreak = lineBreak;
  4726. exports.lineBreakG = lineBreakG;
  4727. exports.nonASCIIwhitespace = nonASCIIwhitespace;
  4728. Object.defineProperty(exports, '__esModule', { value: true });
  4729. })));