acorn.es.js 175 KB

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