acorn.es.js 174 KB

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