acorn.js 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.acorn = global.acorn || {})));
  5. }(this, (function (exports) { 'use strict';
  6. // Reserved word lists for various dialects of the language
  7. var reservedWords = {
  8. 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
  9. 5: "class enum extends super const export import",
  10. 6: "enum",
  11. strict: "implements interface let package private protected public static yield",
  12. strictBind: "eval arguments"
  13. };
  14. // And the keywords
  15. var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
  16. var keywords = {
  17. 5: ecma5AndLessKeywords,
  18. 6: ecma5AndLessKeywords + " const class extends export import super"
  19. };
  20. // ## Character categories
  21. // Big ugly regular expressions that match characters in the
  22. // whitespace, identifier, and identifier-start categories. These
  23. // are only applied when a character is found to actually have a
  24. // code point above 128.
  25. // Generated by `bin/generate-identifier-regex.js`.
  26. 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\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\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-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fd5\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";
  27. 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\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\u0d01-\u0d03\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\u1cf8\u1cf9\u1dc0-\u1df5\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";
  28. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  29. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  30. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  31. // These are a run-length and offset encoded representation of the
  32. // >0xffff code points that are a valid part of identifiers. The
  33. // offset starts at 0x10000, and each pair of numbers represents an
  34. // offset to the next range, and then a size of the range. They were
  35. // generated by bin/generate-identifier-regex.js
  36. // eslint-disable-next-line comma-spacing
  37. var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,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,449,56,264,8,2,36,18,0,50,29,881,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,0,32,6124,20,754,9486,1,3071,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,10591,541];
  38. // eslint-disable-next-line comma-spacing
  39. 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,838,7,2,7,17,9,57,21,2,13,19882,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];
  40. // This has a complexity linear to the value of the code. The
  41. // assumption is that looking up astral identifier characters is
  42. // rare.
  43. function isInAstralSet(code, set) {
  44. var pos = 0x10000;
  45. for (var i = 0; i < set.length; i += 2) {
  46. pos += set[i];
  47. if (pos > code) { return false }
  48. pos += set[i + 1];
  49. if (pos >= code) { return true }
  50. }
  51. }
  52. // Test whether a given character code starts an identifier.
  53. function isIdentifierStart(code, astral) {
  54. if (code < 65) { return code === 36 }
  55. if (code < 91) { return true }
  56. if (code < 97) { return code === 95 }
  57. if (code < 123) { return true }
  58. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  59. if (astral === false) { return false }
  60. return isInAstralSet(code, astralIdentifierStartCodes)
  61. }
  62. // Test whether a given character is part of an identifier.
  63. function isIdentifierChar(code, astral) {
  64. if (code < 48) { return code === 36 }
  65. if (code < 58) { return true }
  66. if (code < 65) { return false }
  67. if (code < 91) { return true }
  68. if (code < 97) { return code === 95 }
  69. if (code < 123) { return true }
  70. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  71. if (astral === false) { return false }
  72. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  73. }
  74. // ## Token types
  75. // The assignment of fine-grained, information-carrying type objects
  76. // allows the tokenizer to store the information it has about a
  77. // token in a way that is very cheap for the parser to look up.
  78. // All token type variables start with an underscore, to make them
  79. // easy to recognize.
  80. // The `beforeExpr` property is used to disambiguate between regular
  81. // expressions and divisions. It is set on all token types that can
  82. // be followed by an expression (thus, a slash after them would be a
  83. // regular expression).
  84. //
  85. // The `startsExpr` property is used to check if the token ends a
  86. // `yield` expression. It is set on all token types that either can
  87. // directly start an expression (like a quotation mark) or can
  88. // continue an expression (like the body of a string).
  89. //
  90. // `isLoop` marks a keyword as starting a loop, which is important
  91. // to know when parsing a label, in order to allow or disallow
  92. // continue jumps to that label.
  93. var TokenType = function TokenType(label, conf) {
  94. if ( conf === void 0 ) conf = {};
  95. this.label = label;
  96. this.keyword = conf.keyword;
  97. this.beforeExpr = !!conf.beforeExpr;
  98. this.startsExpr = !!conf.startsExpr;
  99. this.isLoop = !!conf.isLoop;
  100. this.isAssign = !!conf.isAssign;
  101. this.prefix = !!conf.prefix;
  102. this.postfix = !!conf.postfix;
  103. this.binop = conf.binop || null;
  104. this.updateContext = null;
  105. };
  106. function binop(name, prec) {
  107. return new TokenType(name, {beforeExpr: true, binop: prec})
  108. }
  109. var beforeExpr = {beforeExpr: true};
  110. var startsExpr = {startsExpr: true};
  111. // Map keyword names to token types.
  112. var keywords$1 = {};
  113. // Succinct definitions of keyword token types
  114. function kw(name, options) {
  115. if ( options === void 0 ) options = {};
  116. options.keyword = name;
  117. return keywords$1[name] = new TokenType(name, options)
  118. }
  119. var types = {
  120. num: new TokenType("num", startsExpr),
  121. regexp: new TokenType("regexp", startsExpr),
  122. string: new TokenType("string", startsExpr),
  123. name: new TokenType("name", startsExpr),
  124. eof: new TokenType("eof"),
  125. // Punctuation token types.
  126. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  127. bracketR: new TokenType("]"),
  128. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  129. braceR: new TokenType("}"),
  130. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  131. parenR: new TokenType(")"),
  132. comma: new TokenType(",", beforeExpr),
  133. semi: new TokenType(";", beforeExpr),
  134. colon: new TokenType(":", beforeExpr),
  135. dot: new TokenType("."),
  136. question: new TokenType("?", beforeExpr),
  137. arrow: new TokenType("=>", beforeExpr),
  138. template: new TokenType("template"),
  139. invalidTemplate: new TokenType("invalidTemplate"),
  140. ellipsis: new TokenType("...", beforeExpr),
  141. backQuote: new TokenType("`", startsExpr),
  142. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  143. // Operators. These carry several kinds of properties to help the
  144. // parser use them properly (the presence of these properties is
  145. // what categorizes them as operators).
  146. //
  147. // `binop`, when present, specifies that this operator is a binary
  148. // operator, and will refer to its precedence.
  149. //
  150. // `prefix` and `postfix` mark the operator as a prefix or postfix
  151. // unary operator.
  152. //
  153. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  154. // binary operators with a very low precedence, that should result
  155. // in AssignmentExpression nodes.
  156. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  157. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  158. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  159. prefix: new TokenType("prefix", {beforeExpr: true, prefix: true, startsExpr: true}),
  160. logicalOR: binop("||", 1),
  161. logicalAND: binop("&&", 2),
  162. bitwiseOR: binop("|", 3),
  163. bitwiseXOR: binop("^", 4),
  164. bitwiseAND: binop("&", 5),
  165. equality: binop("==/!=", 6),
  166. relational: binop("</>", 7),
  167. bitShift: binop("<</>>", 8),
  168. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  169. modulo: binop("%", 10),
  170. star: binop("*", 10),
  171. slash: binop("/", 10),
  172. starstar: new TokenType("**", {beforeExpr: true}),
  173. // Keyword token types.
  174. _break: kw("break"),
  175. _case: kw("case", beforeExpr),
  176. _catch: kw("catch"),
  177. _continue: kw("continue"),
  178. _debugger: kw("debugger"),
  179. _default: kw("default", beforeExpr),
  180. _do: kw("do", {isLoop: true, beforeExpr: true}),
  181. _else: kw("else", beforeExpr),
  182. _finally: kw("finally"),
  183. _for: kw("for", {isLoop: true}),
  184. _function: kw("function", startsExpr),
  185. _if: kw("if"),
  186. _return: kw("return", beforeExpr),
  187. _switch: kw("switch"),
  188. _throw: kw("throw", beforeExpr),
  189. _try: kw("try"),
  190. _var: kw("var"),
  191. _const: kw("const"),
  192. _while: kw("while", {isLoop: true}),
  193. _with: kw("with"),
  194. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  195. _this: kw("this", startsExpr),
  196. _super: kw("super", startsExpr),
  197. _class: kw("class", startsExpr),
  198. _extends: kw("extends", beforeExpr),
  199. _export: kw("export"),
  200. _import: kw("import"),
  201. _null: kw("null", startsExpr),
  202. _true: kw("true", startsExpr),
  203. _false: kw("false", startsExpr),
  204. _in: kw("in", {beforeExpr: true, binop: 7}),
  205. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  206. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  207. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  208. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  209. };
  210. // Matches a whole line break (where CRLF is considered a single
  211. // line break). Used to count lines.
  212. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  213. var lineBreakG = new RegExp(lineBreak.source, "g");
  214. function isNewLine(code) {
  215. return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
  216. }
  217. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  218. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  219. var ref = Object.prototype;
  220. var hasOwnProperty = ref.hasOwnProperty;
  221. var toString = ref.toString;
  222. // Checks if an object has a property.
  223. function has(obj, propName) {
  224. return hasOwnProperty.call(obj, propName)
  225. }
  226. var isArray = Array.isArray || (function (obj) { return (
  227. toString.call(obj) === "[object Array]"
  228. ); });
  229. // These are used when `options.locations` is on, for the
  230. // `startLoc` and `endLoc` properties.
  231. var Position = function Position(line, col) {
  232. this.line = line;
  233. this.column = col;
  234. };
  235. Position.prototype.offset = function offset (n) {
  236. return new Position(this.line, this.column + n)
  237. };
  238. var SourceLocation = function SourceLocation(p, start, end) {
  239. this.start = start;
  240. this.end = end;
  241. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  242. };
  243. // The `getLineInfo` function is mostly useful when the
  244. // `locations` option is off (for performance reasons) and you
  245. // want to find the line/column position for a given character
  246. // offset. `input` should be the code string that the offset refers
  247. // into.
  248. function getLineInfo(input, offset) {
  249. for (var line = 1, cur = 0;;) {
  250. lineBreakG.lastIndex = cur;
  251. var match = lineBreakG.exec(input);
  252. if (match && match.index < offset) {
  253. ++line;
  254. cur = match.index + match[0].length;
  255. } else {
  256. return new Position(line, offset - cur)
  257. }
  258. }
  259. }
  260. // A second optional argument can be given to further configure
  261. // the parser process. These options are recognized:
  262. var defaultOptions = {
  263. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  264. // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
  265. // for strict mode, the set of reserved words, and support for
  266. // new syntax features. The default is 7.
  267. ecmaVersion: 7,
  268. // `sourceType` indicates the mode the code should be parsed in.
  269. // Can be either `"script"` or `"module"`. This influences global
  270. // strict mode and parsing of `import` and `export` declarations.
  271. sourceType: "script",
  272. // `onInsertedSemicolon` can be a callback that will be called
  273. // when a semicolon is automatically inserted. It will be passed
  274. // th position of the comma as an offset, and if `locations` is
  275. // enabled, it is given the location as a `{line, column}` object
  276. // as second argument.
  277. onInsertedSemicolon: null,
  278. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  279. // trailing commas.
  280. onTrailingComma: null,
  281. // By default, reserved words are only enforced if ecmaVersion >= 5.
  282. // Set `allowReserved` to a boolean value to explicitly turn this on
  283. // an off. When this option has the value "never", reserved words
  284. // and keywords can also not be used as property names.
  285. allowReserved: null,
  286. // When enabled, a return at the top level is not considered an
  287. // error.
  288. allowReturnOutsideFunction: false,
  289. // When enabled, import/export statements are not constrained to
  290. // appearing at the top of the program.
  291. allowImportExportEverywhere: false,
  292. // When enabled, hashbang directive in the beginning of file
  293. // is allowed and treated as a line comment.
  294. allowHashBang: false,
  295. // When `locations` is on, `loc` properties holding objects with
  296. // `start` and `end` properties in `{line, column}` form (with
  297. // line being 1-based and column 0-based) will be attached to the
  298. // nodes.
  299. locations: false,
  300. // A function can be passed as `onToken` option, which will
  301. // cause Acorn to call that function with object in the same
  302. // format as tokens returned from `tokenizer().getToken()`. Note
  303. // that you are not allowed to call the parser from the
  304. // callback—that will corrupt its internal state.
  305. onToken: null,
  306. // A function can be passed as `onComment` option, which will
  307. // cause Acorn to call that function with `(block, text, start,
  308. // end)` parameters whenever a comment is skipped. `block` is a
  309. // boolean indicating whether this is a block (`/* */`) comment,
  310. // `text` is the content of the comment, and `start` and `end` are
  311. // character offsets that denote the start and end of the comment.
  312. // When the `locations` option is on, two more parameters are
  313. // passed, the full `{line, column}` locations of the start and
  314. // end of the comments. Note that you are not allowed to call the
  315. // parser from the callback—that will corrupt its internal state.
  316. onComment: null,
  317. // Nodes have their start and end characters offsets recorded in
  318. // `start` and `end` properties (directly on the node, rather than
  319. // the `loc` object, which holds line/column data. To also add a
  320. // [semi-standardized][range] `range` property holding a `[start,
  321. // end]` array with the same numbers, set the `ranges` option to
  322. // `true`.
  323. //
  324. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  325. ranges: false,
  326. // It is possible to parse multiple files into a single AST by
  327. // passing the tree produced by parsing the first file as
  328. // `program` option in subsequent parses. This will add the
  329. // toplevel forms of the parsed file to the `Program` (top) node
  330. // of an existing parse tree.
  331. program: null,
  332. // When `locations` is on, you can pass this to record the source
  333. // file in every node's `loc` object.
  334. sourceFile: null,
  335. // This value, if given, is stored in every node, whether
  336. // `locations` is on or off.
  337. directSourceFile: null,
  338. // When enabled, parenthesized expressions are represented by
  339. // (non-standard) ParenthesizedExpression nodes
  340. preserveParens: false,
  341. plugins: {}
  342. };
  343. // Interpret and default an options object
  344. function getOptions(opts) {
  345. var options = {};
  346. for (var opt in defaultOptions)
  347. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  348. if (options.ecmaVersion >= 2015)
  349. { options.ecmaVersion -= 2009; }
  350. if (options.allowReserved == null)
  351. { options.allowReserved = options.ecmaVersion < 5; }
  352. if (isArray(options.onToken)) {
  353. var tokens = options.onToken;
  354. options.onToken = function (token) { return tokens.push(token); };
  355. }
  356. if (isArray(options.onComment))
  357. { options.onComment = pushComment(options, options.onComment); }
  358. return options
  359. }
  360. function pushComment(options, array) {
  361. return function(block, text, start, end, startLoc, endLoc) {
  362. var comment = {
  363. type: block ? "Block" : "Line",
  364. value: text,
  365. start: start,
  366. end: end
  367. };
  368. if (options.locations)
  369. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  370. if (options.ranges)
  371. { comment.range = [start, end]; }
  372. array.push(comment);
  373. }
  374. }
  375. // Registered plugins
  376. var plugins = {};
  377. function keywordRegexp(words) {
  378. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  379. }
  380. var Parser = function Parser(options, input, startPos) {
  381. this.options = options = getOptions(options);
  382. this.sourceFile = options.sourceFile;
  383. this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  384. var reserved = "";
  385. if (!options.allowReserved) {
  386. for (var v = options.ecmaVersion;; v--)
  387. { if (reserved = reservedWords[v]) { break } }
  388. if (options.sourceType == "module") { reserved += " await"; }
  389. }
  390. this.reservedWords = keywordRegexp(reserved);
  391. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  392. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  393. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
  394. this.input = String(input);
  395. // Used to signal to callers of `readWord1` whether the word
  396. // contained any escape sequences. This is needed because words with
  397. // escape sequences must not be interpreted as keywords.
  398. this.containsEsc = false;
  399. // Load plugins
  400. this.loadPlugins(options.plugins);
  401. // Set up token state
  402. // The current position of the tokenizer in the input.
  403. if (startPos) {
  404. this.pos = startPos;
  405. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  406. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  407. } else {
  408. this.pos = this.lineStart = 0;
  409. this.curLine = 1;
  410. }
  411. // Properties of the current token:
  412. // Its type
  413. this.type = types.eof;
  414. // For tokens that include more information than their type, the value
  415. this.value = null;
  416. // Its start and end offset
  417. this.start = this.end = this.pos;
  418. // And, if locations are used, the {line, column} object
  419. // corresponding to those offsets
  420. this.startLoc = this.endLoc = this.curPosition();
  421. // Position information for the previous token
  422. this.lastTokEndLoc = this.lastTokStartLoc = null;
  423. this.lastTokStart = this.lastTokEnd = this.pos;
  424. // The context stack is used to superficially track syntactic
  425. // context to predict whether a regular expression is allowed in a
  426. // given position.
  427. this.context = this.initialContext();
  428. this.exprAllowed = true;
  429. // Figure out if it's a module code.
  430. this.inModule = options.sourceType === "module";
  431. this.strict = this.inModule || this.strictDirective(this.pos);
  432. // Used to signify the start of a potential arrow function
  433. this.potentialArrowAt = -1;
  434. // Flags to track whether we are in a function, a generator, an async function.
  435. this.inFunction = this.inGenerator = this.inAsync = false;
  436. // Positions to delayed-check that yield/await does not exist in default parameters.
  437. this.yieldPos = this.awaitPos = 0;
  438. // Labels in scope.
  439. this.labels = [];
  440. // If enabled, skip leading hashbang line.
  441. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  442. { this.skipLineComment(2); }
  443. // Scope tracking for duplicate variable names (see scope.js)
  444. this.scopeStack = [];
  445. this.enterFunctionScope();
  446. };
  447. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  448. Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
  449. Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
  450. Parser.prototype.extend = function extend (name, f) {
  451. this[name] = f(this[name]);
  452. };
  453. Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
  454. var this$1 = this;
  455. for (var name in pluginConfigs) {
  456. var plugin = plugins[name];
  457. if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
  458. plugin(this$1, pluginConfigs[name]);
  459. }
  460. };
  461. Parser.prototype.parse = function parse () {
  462. var node = this.options.program || this.startNode();
  463. this.nextToken();
  464. return this.parseTopLevel(node)
  465. };
  466. var pp = Parser.prototype;
  467. // ## Parser utilities
  468. var literal = /^(?:'((?:[^']|\.)*)'|"((?:[^"]|\.)*)"|;)/;
  469. pp.strictDirective = function(start) {
  470. var this$1 = this;
  471. for (;;) {
  472. skipWhiteSpace.lastIndex = start;
  473. start += skipWhiteSpace.exec(this$1.input)[0].length;
  474. var match = literal.exec(this$1.input.slice(start));
  475. if (!match) { return false }
  476. if ((match[1] || match[2]) == "use strict") { return true }
  477. start += match[0].length;
  478. }
  479. };
  480. // Predicate that tests whether the next token is of the given
  481. // type, and if yes, consumes it as a side effect.
  482. pp.eat = function(type) {
  483. if (this.type === type) {
  484. this.next();
  485. return true
  486. } else {
  487. return false
  488. }
  489. };
  490. // Tests whether parsed token is a contextual keyword.
  491. pp.isContextual = function(name) {
  492. return this.type === types.name && this.value === name
  493. };
  494. // Consumes contextual keyword if possible.
  495. pp.eatContextual = function(name) {
  496. return this.value === name && this.eat(types.name)
  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. -1;
  544. }
  545. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  546. if (!refDestructuringErrors) { return }
  547. if (refDestructuringErrors.trailingComma > -1)
  548. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  549. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  550. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  551. };
  552. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  553. var pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1;
  554. if (!andThrow) { return pos >= 0 }
  555. if (pos > -1) { this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns"); }
  556. };
  557. pp.checkYieldAwaitInDefaultParams = function() {
  558. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  559. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  560. if (this.awaitPos)
  561. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  562. };
  563. pp.isSimpleAssignTarget = function(expr) {
  564. if (expr.type === "ParenthesizedExpression")
  565. { return this.isSimpleAssignTarget(expr.expression) }
  566. return expr.type === "Identifier" || expr.type === "MemberExpression"
  567. };
  568. var pp$1 = Parser.prototype;
  569. // ### Statement parsing
  570. // Parse a program. Initializes the parser, reads any number of
  571. // statements, and wraps them in a Program node. Optionally takes a
  572. // `program` argument. If present, the statements will be appended
  573. // to its body instead of creating a new node.
  574. pp$1.parseTopLevel = function(node) {
  575. var this$1 = this;
  576. var exports = {};
  577. if (!node.body) { node.body = []; }
  578. while (this.type !== types.eof) {
  579. var stmt = this$1.parseStatement(true, true, exports);
  580. node.body.push(stmt);
  581. }
  582. this.next();
  583. if (this.options.ecmaVersion >= 6) {
  584. node.sourceType = this.options.sourceType;
  585. }
  586. return this.finishNode(node, "Program")
  587. };
  588. var loopLabel = {kind: "loop"};
  589. var switchLabel = {kind: "switch"};
  590. pp$1.isLet = function() {
  591. if (this.type !== types.name || this.options.ecmaVersion < 6 || this.value != "let") { return false }
  592. skipWhiteSpace.lastIndex = this.pos;
  593. var skip = skipWhiteSpace.exec(this.input);
  594. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  595. if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
  596. if (isIdentifierStart(nextCh, true)) {
  597. var pos = next + 1;
  598. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  599. var ident = this.input.slice(next, pos);
  600. if (!this.isKeyword(ident)) { return true }
  601. }
  602. return false
  603. };
  604. // check 'async [no LineTerminator here] function'
  605. // - 'async /*foo*/ function' is OK.
  606. // - 'async /*\n*/ function' is invalid.
  607. pp$1.isAsyncFunction = function() {
  608. if (this.type !== types.name || this.options.ecmaVersion < 8 || this.value != "async")
  609. { return false }
  610. skipWhiteSpace.lastIndex = this.pos;
  611. var skip = skipWhiteSpace.exec(this.input);
  612. var next = this.pos + skip[0].length;
  613. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  614. this.input.slice(next, next + 8) === "function" &&
  615. (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  616. };
  617. // Parse a single statement.
  618. //
  619. // If expecting a statement and finding a slash operator, parse a
  620. // regular expression literal. This is to handle cases like
  621. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  622. // does not help.
  623. pp$1.parseStatement = function(declaration, topLevel, exports) {
  624. var starttype = this.type, node = this.startNode(), kind;
  625. if (this.isLet()) {
  626. starttype = types._var;
  627. kind = "let";
  628. }
  629. // Most types of statements are recognized by the keyword they
  630. // start with. Many are trivial to parse, some require a bit of
  631. // complexity.
  632. switch (starttype) {
  633. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  634. case types._debugger: return this.parseDebuggerStatement(node)
  635. case types._do: return this.parseDoStatement(node)
  636. case types._for: return this.parseForStatement(node)
  637. case types._function:
  638. if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
  639. return this.parseFunctionStatement(node, false)
  640. case types._class:
  641. if (!declaration) { this.unexpected(); }
  642. return this.parseClass(node, true)
  643. case types._if: return this.parseIfStatement(node)
  644. case types._return: return this.parseReturnStatement(node)
  645. case types._switch: return this.parseSwitchStatement(node)
  646. case types._throw: return this.parseThrowStatement(node)
  647. case types._try: return this.parseTryStatement(node)
  648. case types._const: case types._var:
  649. kind = kind || this.value;
  650. if (!declaration && kind != "var") { this.unexpected(); }
  651. return this.parseVarStatement(node, kind)
  652. case types._while: return this.parseWhileStatement(node)
  653. case types._with: return this.parseWithStatement(node)
  654. case types.braceL: return this.parseBlock()
  655. case types.semi: return this.parseEmptyStatement(node)
  656. case types._export:
  657. case types._import:
  658. if (!this.options.allowImportExportEverywhere) {
  659. if (!topLevel)
  660. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  661. if (!this.inModule)
  662. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  663. }
  664. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  665. // If the statement does not start with a statement keyword or a
  666. // brace, it's an ExpressionStatement or LabeledStatement. We
  667. // simply start parsing an expression, and afterwards, if the
  668. // next token is a colon and the expression was a simple
  669. // Identifier node, we switch to interpreting it as a label.
  670. default:
  671. if (this.isAsyncFunction() && declaration) {
  672. this.next();
  673. return this.parseFunctionStatement(node, true)
  674. }
  675. var maybeName = this.value, expr = this.parseExpression();
  676. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  677. { return this.parseLabeledStatement(node, maybeName, expr) }
  678. else { return this.parseExpressionStatement(node, expr) }
  679. }
  680. };
  681. pp$1.parseBreakContinueStatement = function(node, keyword) {
  682. var this$1 = this;
  683. var isBreak = keyword == "break";
  684. this.next();
  685. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  686. else if (this.type !== types.name) { this.unexpected(); }
  687. else {
  688. node.label = this.parseIdent();
  689. this.semicolon();
  690. }
  691. // Verify that there is an actual destination to break or
  692. // continue to.
  693. var i = 0;
  694. for (; i < this.labels.length; ++i) {
  695. var lab = this$1.labels[i];
  696. if (node.label == null || lab.name === node.label.name) {
  697. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  698. if (node.label && isBreak) { break }
  699. }
  700. }
  701. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  702. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  703. };
  704. pp$1.parseDebuggerStatement = function(node) {
  705. this.next();
  706. this.semicolon();
  707. return this.finishNode(node, "DebuggerStatement")
  708. };
  709. pp$1.parseDoStatement = function(node) {
  710. this.next();
  711. this.labels.push(loopLabel);
  712. node.body = this.parseStatement(false);
  713. this.labels.pop();
  714. this.expect(types._while);
  715. node.test = this.parseParenExpression();
  716. if (this.options.ecmaVersion >= 6)
  717. { this.eat(types.semi); }
  718. else
  719. { this.semicolon(); }
  720. return this.finishNode(node, "DoWhileStatement")
  721. };
  722. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  723. // loop is non-trivial. Basically, we have to parse the init `var`
  724. // statement or expression, disallowing the `in` operator (see
  725. // the second parameter to `parseExpression`), and then check
  726. // whether the next token is `in` or `of`. When there is no init
  727. // part (semicolon immediately after the opening parenthesis), it
  728. // is a regular `for` loop.
  729. pp$1.parseForStatement = function(node) {
  730. this.next();
  731. this.labels.push(loopLabel);
  732. this.enterLexicalScope();
  733. this.expect(types.parenL);
  734. if (this.type === types.semi) { return this.parseFor(node, null) }
  735. var isLet = this.isLet();
  736. if (this.type === types._var || this.type === types._const || isLet) {
  737. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  738. this.next();
  739. this.parseVar(init$1, true, kind);
  740. this.finishNode(init$1, "VariableDeclaration");
  741. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
  742. !(kind !== "var" && init$1.declarations[0].init))
  743. { return this.parseForIn(node, init$1) }
  744. return this.parseFor(node, init$1)
  745. }
  746. var refDestructuringErrors = new DestructuringErrors;
  747. var init = this.parseExpression(true, refDestructuringErrors);
  748. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  749. this.toAssignable(init);
  750. this.checkLVal(init);
  751. this.checkPatternErrors(refDestructuringErrors, true);
  752. return this.parseForIn(node, init)
  753. } else {
  754. this.checkExpressionErrors(refDestructuringErrors, true);
  755. }
  756. return this.parseFor(node, init)
  757. };
  758. pp$1.parseFunctionStatement = function(node, isAsync) {
  759. this.next();
  760. return this.parseFunction(node, true, false, isAsync)
  761. };
  762. pp$1.isFunction = function() {
  763. return this.type === types._function || this.isAsyncFunction()
  764. };
  765. pp$1.parseIfStatement = function(node) {
  766. this.next();
  767. node.test = this.parseParenExpression();
  768. // allow function declarations in branches, but only in non-strict mode
  769. node.consequent = this.parseStatement(!this.strict && this.isFunction());
  770. node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.isFunction()) : null;
  771. return this.finishNode(node, "IfStatement")
  772. };
  773. pp$1.parseReturnStatement = function(node) {
  774. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  775. { this.raise(this.start, "'return' outside of function"); }
  776. this.next();
  777. // In `return` (and `break`/`continue`), the keywords with
  778. // optional arguments, we eagerly look for a semicolon or the
  779. // possibility to insert one.
  780. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  781. else { node.argument = this.parseExpression(); this.semicolon(); }
  782. return this.finishNode(node, "ReturnStatement")
  783. };
  784. pp$1.parseSwitchStatement = function(node) {
  785. var this$1 = this;
  786. this.next();
  787. node.discriminant = this.parseParenExpression();
  788. node.cases = [];
  789. this.expect(types.braceL);
  790. this.labels.push(switchLabel);
  791. this.enterLexicalScope();
  792. // Statements under must be grouped (by label) in SwitchCase
  793. // nodes. `cur` is used to keep the node that we are currently
  794. // adding statements to.
  795. var cur;
  796. for (var sawDefault = false; this.type != types.braceR;) {
  797. if (this$1.type === types._case || this$1.type === types._default) {
  798. var isCase = this$1.type === types._case;
  799. if (cur) { this$1.finishNode(cur, "SwitchCase"); }
  800. node.cases.push(cur = this$1.startNode());
  801. cur.consequent = [];
  802. this$1.next();
  803. if (isCase) {
  804. cur.test = this$1.parseExpression();
  805. } else {
  806. if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
  807. sawDefault = true;
  808. cur.test = null;
  809. }
  810. this$1.expect(types.colon);
  811. } else {
  812. if (!cur) { this$1.unexpected(); }
  813. cur.consequent.push(this$1.parseStatement(true));
  814. }
  815. }
  816. this.exitLexicalScope();
  817. if (cur) { this.finishNode(cur, "SwitchCase"); }
  818. this.next(); // Closing brace
  819. this.labels.pop();
  820. return this.finishNode(node, "SwitchStatement")
  821. };
  822. pp$1.parseThrowStatement = function(node) {
  823. this.next();
  824. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  825. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  826. node.argument = this.parseExpression();
  827. this.semicolon();
  828. return this.finishNode(node, "ThrowStatement")
  829. };
  830. // Reused empty array added for node fields that are always empty.
  831. var empty = [];
  832. pp$1.parseTryStatement = function(node) {
  833. this.next();
  834. node.block = this.parseBlock();
  835. node.handler = null;
  836. if (this.type === types._catch) {
  837. var clause = this.startNode();
  838. this.next();
  839. this.expect(types.parenL);
  840. clause.param = this.parseBindingAtom();
  841. this.enterLexicalScope();
  842. this.checkLVal(clause.param, "let");
  843. this.expect(types.parenR);
  844. clause.body = this.parseBlock(false);
  845. this.exitLexicalScope();
  846. node.handler = this.finishNode(clause, "CatchClause");
  847. }
  848. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  849. if (!node.handler && !node.finalizer)
  850. { this.raise(node.start, "Missing catch or finally clause"); }
  851. return this.finishNode(node, "TryStatement")
  852. };
  853. pp$1.parseVarStatement = function(node, kind) {
  854. this.next();
  855. this.parseVar(node, false, kind);
  856. this.semicolon();
  857. return this.finishNode(node, "VariableDeclaration")
  858. };
  859. pp$1.parseWhileStatement = function(node) {
  860. this.next();
  861. node.test = this.parseParenExpression();
  862. this.labels.push(loopLabel);
  863. node.body = this.parseStatement(false);
  864. this.labels.pop();
  865. return this.finishNode(node, "WhileStatement")
  866. };
  867. pp$1.parseWithStatement = function(node) {
  868. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  869. this.next();
  870. node.object = this.parseParenExpression();
  871. node.body = this.parseStatement(false);
  872. return this.finishNode(node, "WithStatement")
  873. };
  874. pp$1.parseEmptyStatement = function(node) {
  875. this.next();
  876. return this.finishNode(node, "EmptyStatement")
  877. };
  878. pp$1.parseLabeledStatement = function(node, maybeName, expr) {
  879. var this$1 = this;
  880. for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
  881. {
  882. var label = list[i$1];
  883. if (label.name === maybeName)
  884. { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
  885. } }
  886. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  887. for (var i = this.labels.length - 1; i >= 0; i--) {
  888. var label$1 = this$1.labels[i];
  889. if (label$1.statementStart == node.start) {
  890. label$1.statementStart = this$1.start;
  891. label$1.kind = kind;
  892. } else { break }
  893. }
  894. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  895. node.body = this.parseStatement(true);
  896. if (node.body.type == "ClassDeclaration" ||
  897. node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
  898. node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
  899. { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
  900. this.labels.pop();
  901. node.label = expr;
  902. return this.finishNode(node, "LabeledStatement")
  903. };
  904. pp$1.parseExpressionStatement = function(node, expr) {
  905. node.expression = expr;
  906. this.semicolon();
  907. return this.finishNode(node, "ExpressionStatement")
  908. };
  909. // Parse a semicolon-enclosed block of statements, handling `"use
  910. // strict"` declarations when `allowStrict` is true (used for
  911. // function bodies).
  912. pp$1.parseBlock = function(createNewLexicalScope) {
  913. var this$1 = this;
  914. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  915. var node = this.startNode();
  916. node.body = [];
  917. this.expect(types.braceL);
  918. if (createNewLexicalScope) {
  919. this.enterLexicalScope();
  920. }
  921. while (!this.eat(types.braceR)) {
  922. var stmt = this$1.parseStatement(true);
  923. node.body.push(stmt);
  924. }
  925. if (createNewLexicalScope) {
  926. this.exitLexicalScope();
  927. }
  928. return this.finishNode(node, "BlockStatement")
  929. };
  930. // Parse a regular `for` loop. The disambiguation code in
  931. // `parseStatement` will already have parsed the init statement or
  932. // expression.
  933. pp$1.parseFor = function(node, init) {
  934. node.init = init;
  935. this.expect(types.semi);
  936. node.test = this.type === types.semi ? null : this.parseExpression();
  937. this.expect(types.semi);
  938. node.update = this.type === types.parenR ? null : this.parseExpression();
  939. this.expect(types.parenR);
  940. this.exitLexicalScope();
  941. node.body = this.parseStatement(false);
  942. this.labels.pop();
  943. return this.finishNode(node, "ForStatement")
  944. };
  945. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  946. // same from parser's perspective.
  947. pp$1.parseForIn = function(node, init) {
  948. var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
  949. this.next();
  950. node.left = init;
  951. node.right = this.parseExpression();
  952. this.expect(types.parenR);
  953. this.exitLexicalScope();
  954. node.body = this.parseStatement(false);
  955. this.labels.pop();
  956. return this.finishNode(node, type)
  957. };
  958. // Parse a list of variable declarations.
  959. pp$1.parseVar = function(node, isFor, kind) {
  960. var this$1 = this;
  961. node.declarations = [];
  962. node.kind = kind;
  963. for (;;) {
  964. var decl = this$1.startNode();
  965. this$1.parseVarId(decl, kind);
  966. if (this$1.eat(types.eq)) {
  967. decl.init = this$1.parseMaybeAssign(isFor);
  968. } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
  969. this$1.unexpected();
  970. } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
  971. this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
  972. } else {
  973. decl.init = null;
  974. }
  975. node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
  976. if (!this$1.eat(types.comma)) { break }
  977. }
  978. return node
  979. };
  980. pp$1.parseVarId = function(decl, kind) {
  981. decl.id = this.parseBindingAtom(kind);
  982. this.checkLVal(decl.id, kind, false);
  983. };
  984. // Parse a function declaration or literal (depending on the
  985. // `isStatement` parameter).
  986. pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
  987. this.initFunction(node);
  988. if (this.options.ecmaVersion >= 6 && !isAsync)
  989. { node.generator = this.eat(types.star); }
  990. if (this.options.ecmaVersion >= 8)
  991. { node.async = !!isAsync; }
  992. if (isStatement) {
  993. node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
  994. if (node.id) {
  995. this.checkLVal(node.id, "var");
  996. }
  997. }
  998. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  999. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  1000. this.inGenerator = node.generator;
  1001. this.inAsync = node.async;
  1002. this.yieldPos = 0;
  1003. this.awaitPos = 0;
  1004. this.inFunction = true;
  1005. this.enterFunctionScope();
  1006. if (!isStatement)
  1007. { node.id = this.type == types.name ? this.parseIdent() : null; }
  1008. this.parseFunctionParams(node);
  1009. this.parseFunctionBody(node, allowExpressionBody);
  1010. this.inGenerator = oldInGen;
  1011. this.inAsync = oldInAsync;
  1012. this.yieldPos = oldYieldPos;
  1013. this.awaitPos = oldAwaitPos;
  1014. this.inFunction = oldInFunc;
  1015. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
  1016. };
  1017. pp$1.parseFunctionParams = function(node) {
  1018. this.expect(types.parenL);
  1019. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  1020. this.checkYieldAwaitInDefaultParams();
  1021. };
  1022. // Parse a class declaration or literal (depending on the
  1023. // `isStatement` parameter).
  1024. pp$1.parseClass = function(node, isStatement) {
  1025. var this$1 = this;
  1026. this.next();
  1027. this.parseClassId(node, isStatement);
  1028. this.parseClassSuper(node);
  1029. var classBody = this.startNode();
  1030. var hadConstructor = false;
  1031. classBody.body = [];
  1032. this.expect(types.braceL);
  1033. while (!this.eat(types.braceR)) {
  1034. if (this$1.eat(types.semi)) { continue }
  1035. var method = this$1.startNode();
  1036. var isGenerator = this$1.eat(types.star);
  1037. var isAsync = false;
  1038. var isMaybeStatic = this$1.type === types.name && this$1.value === "static";
  1039. this$1.parsePropertyName(method);
  1040. method.static = isMaybeStatic && this$1.type !== types.parenL;
  1041. if (method.static) {
  1042. if (isGenerator) { this$1.unexpected(); }
  1043. isGenerator = this$1.eat(types.star);
  1044. this$1.parsePropertyName(method);
  1045. }
  1046. if (this$1.options.ecmaVersion >= 8 && !isGenerator && !method.computed &&
  1047. method.key.type === "Identifier" && method.key.name === "async" && this$1.type !== types.parenL &&
  1048. !this$1.canInsertSemicolon()) {
  1049. isAsync = true;
  1050. this$1.parsePropertyName(method);
  1051. }
  1052. method.kind = "method";
  1053. var isGetSet = false;
  1054. if (!method.computed) {
  1055. var key = method.key;
  1056. if (!isGenerator && !isAsync && key.type === "Identifier" && this$1.type !== types.parenL && (key.name === "get" || key.name === "set")) {
  1057. isGetSet = true;
  1058. method.kind = key.name;
  1059. key = this$1.parsePropertyName(method);
  1060. }
  1061. if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
  1062. key.type === "Literal" && key.value === "constructor")) {
  1063. if (hadConstructor) { this$1.raise(key.start, "Duplicate constructor in the same class"); }
  1064. if (isGetSet) { this$1.raise(key.start, "Constructor can't have get/set modifier"); }
  1065. if (isGenerator) { this$1.raise(key.start, "Constructor can't be a generator"); }
  1066. if (isAsync) { this$1.raise(key.start, "Constructor can't be an async method"); }
  1067. method.kind = "constructor";
  1068. hadConstructor = true;
  1069. }
  1070. }
  1071. this$1.parseClassMethod(classBody, method, isGenerator, isAsync);
  1072. if (isGetSet) {
  1073. var paramCount = method.kind === "get" ? 0 : 1;
  1074. if (method.value.params.length !== paramCount) {
  1075. var start = method.value.start;
  1076. if (method.kind === "get")
  1077. { this$1.raiseRecoverable(start, "getter should have no params"); }
  1078. else
  1079. { this$1.raiseRecoverable(start, "setter should have exactly one param"); }
  1080. } else {
  1081. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  1082. { this$1.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  1083. }
  1084. }
  1085. }
  1086. node.body = this.finishNode(classBody, "ClassBody");
  1087. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1088. };
  1089. pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
  1090. method.value = this.parseMethod(isGenerator, isAsync);
  1091. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  1092. };
  1093. pp$1.parseClassId = function(node, isStatement) {
  1094. node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
  1095. };
  1096. pp$1.parseClassSuper = function(node) {
  1097. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  1098. };
  1099. // Parses module export declaration.
  1100. pp$1.parseExport = function(node, exports) {
  1101. var this$1 = this;
  1102. this.next();
  1103. // export * from '...'
  1104. if (this.eat(types.star)) {
  1105. this.expectContextual("from");
  1106. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1107. this.semicolon();
  1108. return this.finishNode(node, "ExportAllDeclaration")
  1109. }
  1110. if (this.eat(types._default)) { // export default ...
  1111. this.checkExport(exports, "default", this.lastTokStart);
  1112. var isAsync;
  1113. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  1114. var fNode = this.startNode();
  1115. this.next();
  1116. if (isAsync) { this.next(); }
  1117. node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
  1118. } else if (this.type === types._class) {
  1119. var cNode = this.startNode();
  1120. node.declaration = this.parseClass(cNode, "nullableID");
  1121. } else {
  1122. node.declaration = this.parseMaybeAssign();
  1123. this.semicolon();
  1124. }
  1125. return this.finishNode(node, "ExportDefaultDeclaration")
  1126. }
  1127. // export var|const|let|function|class ...
  1128. if (this.shouldParseExportStatement()) {
  1129. node.declaration = this.parseStatement(true);
  1130. if (node.declaration.type === "VariableDeclaration")
  1131. { this.checkVariableExport(exports, node.declaration.declarations); }
  1132. else
  1133. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1134. node.specifiers = [];
  1135. node.source = null;
  1136. } else { // export { x, y as z } [from '...']
  1137. node.declaration = null;
  1138. node.specifiers = this.parseExportSpecifiers(exports);
  1139. if (this.eatContextual("from")) {
  1140. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1141. } else {
  1142. // check for keywords used as local names
  1143. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1144. var spec = list[i];
  1145. this$1.checkUnreserved(spec.local);
  1146. }
  1147. node.source = null;
  1148. }
  1149. this.semicolon();
  1150. }
  1151. return this.finishNode(node, "ExportNamedDeclaration")
  1152. };
  1153. pp$1.checkExport = function(exports, name, pos) {
  1154. if (!exports) { return }
  1155. if (has(exports, name))
  1156. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1157. exports[name] = true;
  1158. };
  1159. pp$1.checkPatternExport = function(exports, pat) {
  1160. var this$1 = this;
  1161. var type = pat.type;
  1162. if (type == "Identifier")
  1163. { this.checkExport(exports, pat.name, pat.start); }
  1164. else if (type == "ObjectPattern")
  1165. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1166. {
  1167. var prop = list[i];
  1168. this$1.checkPatternExport(exports, prop.value);
  1169. } }
  1170. else if (type == "ArrayPattern")
  1171. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1172. var elt = list$1[i$1];
  1173. if (elt) { this$1.checkPatternExport(exports, elt); }
  1174. } }
  1175. else if (type == "AssignmentPattern")
  1176. { this.checkPatternExport(exports, pat.left); }
  1177. else if (type == "ParenthesizedExpression")
  1178. { this.checkPatternExport(exports, pat.expression); }
  1179. };
  1180. pp$1.checkVariableExport = function(exports, decls) {
  1181. var this$1 = this;
  1182. if (!exports) { return }
  1183. for (var i = 0, list = decls; i < list.length; i += 1)
  1184. {
  1185. var decl = list[i];
  1186. this$1.checkPatternExport(exports, decl.id);
  1187. }
  1188. };
  1189. pp$1.shouldParseExportStatement = function() {
  1190. return this.type.keyword === "var" ||
  1191. this.type.keyword === "const" ||
  1192. this.type.keyword === "class" ||
  1193. this.type.keyword === "function" ||
  1194. this.isLet() ||
  1195. this.isAsyncFunction()
  1196. };
  1197. // Parses a comma-separated list of module exports.
  1198. pp$1.parseExportSpecifiers = function(exports) {
  1199. var this$1 = this;
  1200. var nodes = [], first = true;
  1201. // export { x, y as z } [from '...']
  1202. this.expect(types.braceL);
  1203. while (!this.eat(types.braceR)) {
  1204. if (!first) {
  1205. this$1.expect(types.comma);
  1206. if (this$1.afterTrailingComma(types.braceR)) { break }
  1207. } else { first = false; }
  1208. var node = this$1.startNode();
  1209. node.local = this$1.parseIdent(true);
  1210. node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
  1211. this$1.checkExport(exports, node.exported.name, node.exported.start);
  1212. nodes.push(this$1.finishNode(node, "ExportSpecifier"));
  1213. }
  1214. return nodes
  1215. };
  1216. // Parses import declaration.
  1217. pp$1.parseImport = function(node) {
  1218. this.next();
  1219. // import '...'
  1220. if (this.type === types.string) {
  1221. node.specifiers = empty;
  1222. node.source = this.parseExprAtom();
  1223. } else {
  1224. node.specifiers = this.parseImportSpecifiers();
  1225. this.expectContextual("from");
  1226. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1227. }
  1228. this.semicolon();
  1229. return this.finishNode(node, "ImportDeclaration")
  1230. };
  1231. // Parses a comma-separated list of module imports.
  1232. pp$1.parseImportSpecifiers = function() {
  1233. var this$1 = this;
  1234. var nodes = [], first = true;
  1235. if (this.type === types.name) {
  1236. // import defaultObj, { x, y as z } from '...'
  1237. var node = this.startNode();
  1238. node.local = this.parseIdent();
  1239. this.checkLVal(node.local, "let");
  1240. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1241. if (!this.eat(types.comma)) { return nodes }
  1242. }
  1243. if (this.type === types.star) {
  1244. var node$1 = this.startNode();
  1245. this.next();
  1246. this.expectContextual("as");
  1247. node$1.local = this.parseIdent();
  1248. this.checkLVal(node$1.local, "let");
  1249. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1250. return nodes
  1251. }
  1252. this.expect(types.braceL);
  1253. while (!this.eat(types.braceR)) {
  1254. if (!first) {
  1255. this$1.expect(types.comma);
  1256. if (this$1.afterTrailingComma(types.braceR)) { break }
  1257. } else { first = false; }
  1258. var node$2 = this$1.startNode();
  1259. node$2.imported = this$1.parseIdent(true);
  1260. if (this$1.eatContextual("as")) {
  1261. node$2.local = this$1.parseIdent();
  1262. } else {
  1263. this$1.checkUnreserved(node$2.imported);
  1264. node$2.local = node$2.imported;
  1265. }
  1266. this$1.checkLVal(node$2.local, "let");
  1267. nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
  1268. }
  1269. return nodes
  1270. };
  1271. var pp$2 = Parser.prototype;
  1272. // Convert existing expression atom to assignable pattern
  1273. // if possible.
  1274. pp$2.toAssignable = function(node, isBinding) {
  1275. var this$1 = this;
  1276. if (this.options.ecmaVersion >= 6 && node) {
  1277. switch (node.type) {
  1278. case "Identifier":
  1279. if (this.inAsync && node.name === "await")
  1280. { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
  1281. break
  1282. case "ObjectPattern":
  1283. case "ArrayPattern":
  1284. break
  1285. case "ObjectExpression":
  1286. node.type = "ObjectPattern";
  1287. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1288. var prop = list[i];
  1289. if (prop.kind !== "init") { this$1.raise(prop.key.start, "Object pattern can't contain getter or setter"); }
  1290. this$1.toAssignable(prop.value, isBinding);
  1291. }
  1292. break
  1293. case "ArrayExpression":
  1294. node.type = "ArrayPattern";
  1295. this.toAssignableList(node.elements, isBinding);
  1296. break
  1297. case "AssignmentExpression":
  1298. if (node.operator === "=") {
  1299. node.type = "AssignmentPattern";
  1300. delete node.operator;
  1301. this.toAssignable(node.left, isBinding);
  1302. // falls through to AssignmentPattern
  1303. } else {
  1304. this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
  1305. break
  1306. }
  1307. case "AssignmentPattern":
  1308. break
  1309. case "ParenthesizedExpression":
  1310. this.toAssignable(node.expression, isBinding);
  1311. break
  1312. case "MemberExpression":
  1313. if (!isBinding) { break }
  1314. default:
  1315. this.raise(node.start, "Assigning to rvalue");
  1316. }
  1317. }
  1318. return node
  1319. };
  1320. // Convert list of expression atoms to binding list.
  1321. pp$2.toAssignableList = function(exprList, isBinding) {
  1322. var this$1 = this;
  1323. var end = exprList.length;
  1324. if (end) {
  1325. var last = exprList[end - 1];
  1326. if (last && last.type == "RestElement") {
  1327. --end;
  1328. } else if (last && last.type == "SpreadElement") {
  1329. last.type = "RestElement";
  1330. var arg = last.argument;
  1331. this.toAssignable(arg, isBinding);
  1332. --end;
  1333. }
  1334. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1335. { this.unexpected(last.argument.start); }
  1336. }
  1337. for (var i = 0; i < end; i++) {
  1338. var elt = exprList[i];
  1339. if (elt) { this$1.toAssignable(elt, isBinding); }
  1340. }
  1341. return exprList
  1342. };
  1343. // Parses spread element.
  1344. pp$2.parseSpread = function(refDestructuringErrors) {
  1345. var node = this.startNode();
  1346. this.next();
  1347. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1348. return this.finishNode(node, "SpreadElement")
  1349. };
  1350. pp$2.parseRestBinding = function() {
  1351. var node = this.startNode();
  1352. this.next();
  1353. // RestElement inside of a function parameter must be an identifier
  1354. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  1355. { this.unexpected(); }
  1356. node.argument = this.parseBindingAtom();
  1357. return this.finishNode(node, "RestElement")
  1358. };
  1359. // Parses lvalue (assignable) atom.
  1360. pp$2.parseBindingAtom = function() {
  1361. if (this.options.ecmaVersion < 6) { return this.parseIdent() }
  1362. switch (this.type) {
  1363. case types.name:
  1364. return this.parseIdent()
  1365. case types.bracketL:
  1366. var node = this.startNode();
  1367. this.next();
  1368. node.elements = this.parseBindingList(types.bracketR, true, true);
  1369. return this.finishNode(node, "ArrayPattern")
  1370. case types.braceL:
  1371. return this.parseObj(true)
  1372. default:
  1373. this.unexpected();
  1374. }
  1375. };
  1376. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1377. var this$1 = this;
  1378. var elts = [], first = true;
  1379. while (!this.eat(close)) {
  1380. if (first) { first = false; }
  1381. else { this$1.expect(types.comma); }
  1382. if (allowEmpty && this$1.type === types.comma) {
  1383. elts.push(null);
  1384. } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
  1385. break
  1386. } else if (this$1.type === types.ellipsis) {
  1387. var rest = this$1.parseRestBinding();
  1388. this$1.parseBindingListItem(rest);
  1389. elts.push(rest);
  1390. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1391. this$1.expect(close);
  1392. break
  1393. } else {
  1394. var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
  1395. this$1.parseBindingListItem(elem);
  1396. elts.push(elem);
  1397. }
  1398. }
  1399. return elts
  1400. };
  1401. pp$2.parseBindingListItem = function(param) {
  1402. return param
  1403. };
  1404. // Parses assignment pattern around given atom if possible.
  1405. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1406. left = left || this.parseBindingAtom();
  1407. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  1408. var node = this.startNodeAt(startPos, startLoc);
  1409. node.left = left;
  1410. node.right = this.parseMaybeAssign();
  1411. return this.finishNode(node, "AssignmentPattern")
  1412. };
  1413. // Verify that a node is an lval — something that can be assigned
  1414. // to.
  1415. // bindingType can be either:
  1416. // 'var' indicating that the lval creates a 'var' binding
  1417. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  1418. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  1419. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  1420. var this$1 = this;
  1421. switch (expr.type) {
  1422. case "Identifier":
  1423. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1424. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1425. if (checkClashes) {
  1426. if (has(checkClashes, expr.name))
  1427. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1428. checkClashes[expr.name] = true;
  1429. }
  1430. if (bindingType && bindingType !== "none") {
  1431. if (
  1432. bindingType === "var" && !this.canDeclareVarName(expr.name) ||
  1433. bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
  1434. ) {
  1435. this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
  1436. }
  1437. if (bindingType === "var") {
  1438. this.declareVarName(expr.name);
  1439. } else {
  1440. this.declareLexicalName(expr.name);
  1441. }
  1442. }
  1443. break
  1444. case "MemberExpression":
  1445. if (bindingType) { this.raiseRecoverable(expr.start, (bindingType ? "Binding" : "Assigning to") + " member expression"); }
  1446. break
  1447. case "ObjectPattern":
  1448. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  1449. {
  1450. var prop = list[i];
  1451. this$1.checkLVal(prop.value, bindingType, checkClashes);
  1452. }
  1453. break
  1454. case "ArrayPattern":
  1455. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1456. var elem = list$1[i$1];
  1457. if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
  1458. }
  1459. break
  1460. case "AssignmentPattern":
  1461. this.checkLVal(expr.left, bindingType, checkClashes);
  1462. break
  1463. case "RestElement":
  1464. this.checkLVal(expr.argument, bindingType, checkClashes);
  1465. break
  1466. case "ParenthesizedExpression":
  1467. this.checkLVal(expr.expression, bindingType, checkClashes);
  1468. break
  1469. default:
  1470. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  1471. }
  1472. };
  1473. // A recursive descent parser operates by defining functions for all
  1474. // syntactic elements, and recursively calling those, each function
  1475. // advancing the input stream and returning an AST node. Precedence
  1476. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  1477. // instead of `(!x)[1]` is handled by the fact that the parser
  1478. // function that parses unary prefix operators is called first, and
  1479. // in turn calls the function that parses `[]` subscripts — that
  1480. // way, it'll receive the node for `x[1]` already parsed, and wraps
  1481. // *that* in the unary operator node.
  1482. //
  1483. // Acorn uses an [operator precedence parser][opp] to handle binary
  1484. // operator precedence, because it is much more compact than using
  1485. // the technique outlined above, which uses different, nesting
  1486. // functions to specify precedence, for all of the ten binary
  1487. // precedence levels that JavaScript defines.
  1488. //
  1489. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  1490. var pp$3 = Parser.prototype;
  1491. // Check if property name clashes with already added.
  1492. // Object/class getters and setters are not allowed to clash —
  1493. // either with each other or with an init property — and in
  1494. // strict mode, init properties are also not allowed to be repeated.
  1495. pp$3.checkPropClash = function(prop, propHash) {
  1496. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1497. { return }
  1498. var key = prop.key;
  1499. var name;
  1500. switch (key.type) {
  1501. case "Identifier": name = key.name; break
  1502. case "Literal": name = String(key.value); break
  1503. default: return
  1504. }
  1505. var kind = prop.kind;
  1506. if (this.options.ecmaVersion >= 6) {
  1507. if (name === "__proto__" && kind === "init") {
  1508. if (propHash.proto) { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  1509. propHash.proto = true;
  1510. }
  1511. return
  1512. }
  1513. name = "$" + name;
  1514. var other = propHash[name];
  1515. if (other) {
  1516. var redefinition;
  1517. if (kind === "init") {
  1518. redefinition = this.strict && other.init || other.get || other.set;
  1519. } else {
  1520. redefinition = other.init || other[kind];
  1521. }
  1522. if (redefinition)
  1523. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  1524. } else {
  1525. other = propHash[name] = {
  1526. init: false,
  1527. get: false,
  1528. set: false
  1529. };
  1530. }
  1531. other[kind] = true;
  1532. };
  1533. // ### Expression parsing
  1534. // These nest, from the most general expression type at the top to
  1535. // 'atomic', nondivisible expression types at the bottom. Most of
  1536. // the functions will simply let the function(s) below them parse,
  1537. // and, *if* the syntactic construct they handle is present, wrap
  1538. // the AST node that the inner parser gave them in another node.
  1539. // Parse a full expression. The optional arguments are used to
  1540. // forbid the `in` operator (in for loops initalization expressions)
  1541. // and provide reference for storing '=' operator inside shorthand
  1542. // property assignment in contexts where both object expression
  1543. // and object pattern might appear (so it's possible to raise
  1544. // delayed syntax error at correct position).
  1545. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1546. var this$1 = this;
  1547. var startPos = this.start, startLoc = this.startLoc;
  1548. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1549. if (this.type === types.comma) {
  1550. var node = this.startNodeAt(startPos, startLoc);
  1551. node.expressions = [expr];
  1552. while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
  1553. return this.finishNode(node, "SequenceExpression")
  1554. }
  1555. return expr
  1556. };
  1557. // Parse an assignment expression. This includes applications of
  1558. // operators like `+=`.
  1559. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1560. if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
  1561. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
  1562. if (refDestructuringErrors) {
  1563. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  1564. oldTrailingComma = refDestructuringErrors.trailingComma;
  1565. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  1566. } else {
  1567. refDestructuringErrors = new DestructuringErrors;
  1568. ownDestructuringErrors = true;
  1569. }
  1570. var startPos = this.start, startLoc = this.startLoc;
  1571. if (this.type == types.parenL || this.type == types.name)
  1572. { this.potentialArrowAt = this.start; }
  1573. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1574. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  1575. if (this.type.isAssign) {
  1576. this.checkPatternErrors(refDestructuringErrors, true);
  1577. if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
  1578. var node = this.startNodeAt(startPos, startLoc);
  1579. node.operator = this.value;
  1580. node.left = this.type === types.eq ? this.toAssignable(left) : left;
  1581. refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
  1582. this.checkLVal(left);
  1583. this.next();
  1584. node.right = this.parseMaybeAssign(noIn);
  1585. return this.finishNode(node, "AssignmentExpression")
  1586. } else {
  1587. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  1588. }
  1589. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  1590. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  1591. return left
  1592. };
  1593. // Parse a ternary conditional (`?:`) operator.
  1594. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1595. var startPos = this.start, startLoc = this.startLoc;
  1596. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1597. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1598. if (this.eat(types.question)) {
  1599. var node = this.startNodeAt(startPos, startLoc);
  1600. node.test = expr;
  1601. node.consequent = this.parseMaybeAssign();
  1602. this.expect(types.colon);
  1603. node.alternate = this.parseMaybeAssign(noIn);
  1604. return this.finishNode(node, "ConditionalExpression")
  1605. }
  1606. return expr
  1607. };
  1608. // Start the precedence parser.
  1609. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1610. var startPos = this.start, startLoc = this.startLoc;
  1611. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1612. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1613. return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1614. };
  1615. // Parse binary operators with the operator precedence parsing
  1616. // algorithm. `left` is the left-hand side of the operator.
  1617. // `minPrec` provides context that allows the function to stop and
  1618. // defer further parser to one of its callers when it encounters an
  1619. // operator that has a lower precedence than the set it is parsing.
  1620. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1621. var prec = this.type.binop;
  1622. if (prec != null && (!noIn || this.type !== types._in)) {
  1623. if (prec > minPrec) {
  1624. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  1625. var op = this.value;
  1626. this.next();
  1627. var startPos = this.start, startLoc = this.startLoc;
  1628. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1629. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  1630. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1631. }
  1632. }
  1633. return left
  1634. };
  1635. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1636. var node = this.startNodeAt(startPos, startLoc);
  1637. node.left = left;
  1638. node.operator = op;
  1639. node.right = right;
  1640. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1641. };
  1642. // Parse unary operators, both prefix and postfix.
  1643. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1644. var this$1 = this;
  1645. var startPos = this.start, startLoc = this.startLoc, expr;
  1646. if (this.inAsync && this.isContextual("await")) {
  1647. expr = this.parseAwait(refDestructuringErrors);
  1648. sawUnary = true;
  1649. } else if (this.type.prefix) {
  1650. var node = this.startNode(), update = this.type === types.incDec;
  1651. node.operator = this.value;
  1652. node.prefix = true;
  1653. this.next();
  1654. node.argument = this.parseMaybeUnary(null, true);
  1655. this.checkExpressionErrors(refDestructuringErrors, true);
  1656. if (update) { this.checkLVal(node.argument); }
  1657. else if (this.strict && node.operator === "delete" &&
  1658. node.argument.type === "Identifier")
  1659. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  1660. else { sawUnary = true; }
  1661. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1662. } else {
  1663. expr = this.parseExprSubscripts(refDestructuringErrors);
  1664. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1665. while (this.type.postfix && !this.canInsertSemicolon()) {
  1666. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1667. node$1.operator = this$1.value;
  1668. node$1.prefix = false;
  1669. node$1.argument = expr;
  1670. this$1.checkLVal(expr);
  1671. this$1.next();
  1672. expr = this$1.finishNode(node$1, "UpdateExpression");
  1673. }
  1674. }
  1675. if (!sawUnary && this.eat(types.starstar))
  1676. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  1677. else
  1678. { return expr }
  1679. };
  1680. // Parse call, dot, and `[]`-subscript expressions.
  1681. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1682. var startPos = this.start, startLoc = this.startLoc;
  1683. var expr = this.parseExprAtom(refDestructuringErrors);
  1684. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  1685. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
  1686. var result = this.parseSubscripts(expr, startPos, startLoc);
  1687. if (refDestructuringErrors && result.type === "MemberExpression") {
  1688. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  1689. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  1690. }
  1691. return result
  1692. };
  1693. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1694. var this$1 = this;
  1695. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  1696. this.lastTokEnd == base.end && !this.canInsertSemicolon();
  1697. for (var computed = (void 0);;) {
  1698. if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
  1699. var node = this$1.startNodeAt(startPos, startLoc);
  1700. node.object = base;
  1701. node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
  1702. node.computed = !!computed;
  1703. if (computed) { this$1.expect(types.bracketR); }
  1704. base = this$1.finishNode(node, "MemberExpression");
  1705. } else if (!noCalls && this$1.eat(types.parenL)) {
  1706. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
  1707. this$1.yieldPos = 0;
  1708. this$1.awaitPos = 0;
  1709. var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
  1710. if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
  1711. this$1.checkPatternErrors(refDestructuringErrors, false);
  1712. this$1.checkYieldAwaitInDefaultParams();
  1713. this$1.yieldPos = oldYieldPos;
  1714. this$1.awaitPos = oldAwaitPos;
  1715. return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
  1716. }
  1717. this$1.checkExpressionErrors(refDestructuringErrors, true);
  1718. this$1.yieldPos = oldYieldPos || this$1.yieldPos;
  1719. this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
  1720. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1721. node$1.callee = base;
  1722. node$1.arguments = exprList;
  1723. base = this$1.finishNode(node$1, "CallExpression");
  1724. } else if (this$1.type === types.backQuote) {
  1725. var node$2 = this$1.startNodeAt(startPos, startLoc);
  1726. node$2.tag = base;
  1727. node$2.quasi = this$1.parseTemplate({isTagged: true});
  1728. base = this$1.finishNode(node$2, "TaggedTemplateExpression");
  1729. } else {
  1730. return base
  1731. }
  1732. }
  1733. };
  1734. // Parse an atomic expression — either a single token that is an
  1735. // expression, an expression started by a keyword like `function` or
  1736. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1737. // or `{}`.
  1738. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1739. var node, canBeArrow = this.potentialArrowAt == this.start;
  1740. switch (this.type) {
  1741. case types._super:
  1742. if (!this.inFunction)
  1743. { this.raise(this.start, "'super' outside of function or class"); }
  1744. case types._this:
  1745. var type = this.type === types._this ? "ThisExpression" : "Super";
  1746. node = this.startNode();
  1747. this.next();
  1748. return this.finishNode(node, type)
  1749. case types.name:
  1750. var startPos = this.start, startLoc = this.startLoc;
  1751. var id = this.parseIdent(this.type !== types.name);
  1752. if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  1753. { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
  1754. if (canBeArrow && !this.canInsertSemicolon()) {
  1755. if (this.eat(types.arrow))
  1756. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  1757. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name) {
  1758. id = this.parseIdent();
  1759. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  1760. { this.unexpected(); }
  1761. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  1762. }
  1763. }
  1764. return id
  1765. case types.regexp:
  1766. var value = this.value;
  1767. node = this.parseLiteral(value.value);
  1768. node.regex = {pattern: value.pattern, flags: value.flags};
  1769. return node
  1770. case types.num: case types.string:
  1771. return this.parseLiteral(this.value)
  1772. case types._null: case types._true: case types._false:
  1773. node = this.startNode();
  1774. node.value = this.type === types._null ? null : this.type === types._true;
  1775. node.raw = this.type.keyword;
  1776. this.next();
  1777. return this.finishNode(node, "Literal")
  1778. case types.parenL:
  1779. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  1780. if (refDestructuringErrors) {
  1781. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  1782. { refDestructuringErrors.parenthesizedAssign = start; }
  1783. if (refDestructuringErrors.parenthesizedBind < 0)
  1784. { refDestructuringErrors.parenthesizedBind = start; }
  1785. }
  1786. return expr
  1787. case types.bracketL:
  1788. node = this.startNode();
  1789. this.next();
  1790. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  1791. return this.finishNode(node, "ArrayExpression")
  1792. case types.braceL:
  1793. return this.parseObj(false, refDestructuringErrors)
  1794. case types._function:
  1795. node = this.startNode();
  1796. this.next();
  1797. return this.parseFunction(node, false)
  1798. case types._class:
  1799. return this.parseClass(this.startNode(), false)
  1800. case types._new:
  1801. return this.parseNew()
  1802. case types.backQuote:
  1803. return this.parseTemplate()
  1804. default:
  1805. this.unexpected();
  1806. }
  1807. };
  1808. pp$3.parseLiteral = function(value) {
  1809. var node = this.startNode();
  1810. node.value = value;
  1811. node.raw = this.input.slice(this.start, this.end);
  1812. this.next();
  1813. return this.finishNode(node, "Literal")
  1814. };
  1815. pp$3.parseParenExpression = function() {
  1816. this.expect(types.parenL);
  1817. var val = this.parseExpression();
  1818. this.expect(types.parenR);
  1819. return val
  1820. };
  1821. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  1822. var this$1 = this;
  1823. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  1824. if (this.options.ecmaVersion >= 6) {
  1825. this.next();
  1826. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  1827. var exprList = [], first = true, lastIsComma = false;
  1828. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart, innerParenStart;
  1829. this.yieldPos = 0;
  1830. this.awaitPos = 0;
  1831. while (this.type !== types.parenR) {
  1832. first ? first = false : this$1.expect(types.comma);
  1833. if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
  1834. lastIsComma = true;
  1835. break
  1836. } else if (this$1.type === types.ellipsis) {
  1837. spreadStart = this$1.start;
  1838. exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
  1839. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1840. break
  1841. } else {
  1842. if (this$1.type === types.parenL && !innerParenStart) {
  1843. innerParenStart = this$1.start;
  1844. }
  1845. exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
  1846. }
  1847. }
  1848. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  1849. this.expect(types.parenR);
  1850. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  1851. this.checkPatternErrors(refDestructuringErrors, false);
  1852. this.checkYieldAwaitInDefaultParams();
  1853. if (innerParenStart) { this.unexpected(innerParenStart); }
  1854. this.yieldPos = oldYieldPos;
  1855. this.awaitPos = oldAwaitPos;
  1856. return this.parseParenArrowList(startPos, startLoc, exprList)
  1857. }
  1858. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  1859. if (spreadStart) { this.unexpected(spreadStart); }
  1860. this.checkExpressionErrors(refDestructuringErrors, true);
  1861. this.yieldPos = oldYieldPos || this.yieldPos;
  1862. this.awaitPos = oldAwaitPos || this.awaitPos;
  1863. if (exprList.length > 1) {
  1864. val = this.startNodeAt(innerStartPos, innerStartLoc);
  1865. val.expressions = exprList;
  1866. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  1867. } else {
  1868. val = exprList[0];
  1869. }
  1870. } else {
  1871. val = this.parseParenExpression();
  1872. }
  1873. if (this.options.preserveParens) {
  1874. var par = this.startNodeAt(startPos, startLoc);
  1875. par.expression = val;
  1876. return this.finishNode(par, "ParenthesizedExpression")
  1877. } else {
  1878. return val
  1879. }
  1880. };
  1881. pp$3.parseParenItem = function(item) {
  1882. return item
  1883. };
  1884. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  1885. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  1886. };
  1887. // New's precedence is slightly tricky. It must allow its argument to
  1888. // be a `[]` or dot subscript expression, but not a call — at least,
  1889. // not without wrapping it in parentheses. Thus, it uses the noCalls
  1890. // argument to parseSubscripts to prevent it from consuming the
  1891. // argument list.
  1892. var empty$1 = [];
  1893. pp$3.parseNew = function() {
  1894. var node = this.startNode();
  1895. var meta = this.parseIdent(true);
  1896. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  1897. node.meta = meta;
  1898. node.property = this.parseIdent(true);
  1899. if (node.property.name !== "target")
  1900. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
  1901. if (!this.inFunction)
  1902. { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
  1903. return this.finishNode(node, "MetaProperty")
  1904. }
  1905. var startPos = this.start, startLoc = this.startLoc;
  1906. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  1907. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
  1908. else { node.arguments = empty$1; }
  1909. return this.finishNode(node, "NewExpression")
  1910. };
  1911. // Parse template expression.
  1912. pp$3.parseTemplateElement = function(ref) {
  1913. var isTagged = ref.isTagged;
  1914. var elem = this.startNode();
  1915. if (this.type === types.invalidTemplate) {
  1916. if (!isTagged) {
  1917. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  1918. }
  1919. elem.value = {
  1920. raw: this.value,
  1921. cooked: null
  1922. };
  1923. } else {
  1924. elem.value = {
  1925. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  1926. cooked: this.value
  1927. };
  1928. }
  1929. this.next();
  1930. elem.tail = this.type === types.backQuote;
  1931. return this.finishNode(elem, "TemplateElement")
  1932. };
  1933. pp$3.parseTemplate = function(ref) {
  1934. var this$1 = this;
  1935. if ( ref === void 0 ) ref = {};
  1936. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  1937. var node = this.startNode();
  1938. this.next();
  1939. node.expressions = [];
  1940. var curElt = this.parseTemplateElement({isTagged: isTagged});
  1941. node.quasis = [curElt];
  1942. while (!curElt.tail) {
  1943. this$1.expect(types.dollarBraceL);
  1944. node.expressions.push(this$1.parseExpression());
  1945. this$1.expect(types.braceR);
  1946. node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
  1947. }
  1948. this.next();
  1949. return this.finishNode(node, "TemplateLiteral")
  1950. };
  1951. // Parse an object literal or binding pattern.
  1952. pp$3.isAsyncProp = function(prop) {
  1953. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  1954. (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL) &&
  1955. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  1956. };
  1957. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  1958. var this$1 = this;
  1959. var node = this.startNode(), first = true, propHash = {};
  1960. node.properties = [];
  1961. this.next();
  1962. while (!this.eat(types.braceR)) {
  1963. if (!first) {
  1964. this$1.expect(types.comma);
  1965. if (this$1.afterTrailingComma(types.braceR)) { break }
  1966. } else { first = false; }
  1967. var prop = this$1.startNode(), isGenerator = (void 0), isAsync = (void 0), startPos = (void 0), startLoc = (void 0);
  1968. if (this$1.options.ecmaVersion >= 6) {
  1969. prop.method = false;
  1970. prop.shorthand = false;
  1971. if (isPattern || refDestructuringErrors) {
  1972. startPos = this$1.start;
  1973. startLoc = this$1.startLoc;
  1974. }
  1975. if (!isPattern)
  1976. { isGenerator = this$1.eat(types.star); }
  1977. }
  1978. this$1.parsePropertyName(prop);
  1979. if (!isPattern && this$1.options.ecmaVersion >= 8 && !isGenerator && this$1.isAsyncProp(prop)) {
  1980. isAsync = true;
  1981. this$1.parsePropertyName(prop, refDestructuringErrors);
  1982. } else {
  1983. isAsync = false;
  1984. }
  1985. this$1.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
  1986. this$1.checkPropClash(prop, propHash);
  1987. node.properties.push(this$1.finishNode(prop, "Property"));
  1988. }
  1989. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  1990. };
  1991. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
  1992. if ((isGenerator || isAsync) && this.type === types.colon)
  1993. { this.unexpected(); }
  1994. if (this.eat(types.colon)) {
  1995. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  1996. prop.kind = "init";
  1997. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  1998. if (isPattern) { this.unexpected(); }
  1999. prop.kind = "init";
  2000. prop.method = true;
  2001. prop.value = this.parseMethod(isGenerator, isAsync);
  2002. } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2003. (prop.key.name === "get" || prop.key.name === "set") &&
  2004. (this.type != types.comma && this.type != types.braceR)) {
  2005. if (isGenerator || isAsync || isPattern) { this.unexpected(); }
  2006. prop.kind = prop.key.name;
  2007. this.parsePropertyName(prop);
  2008. prop.value = this.parseMethod(false);
  2009. var paramCount = prop.kind === "get" ? 0 : 1;
  2010. if (prop.value.params.length !== paramCount) {
  2011. var start = prop.value.start;
  2012. if (prop.kind === "get")
  2013. { this.raiseRecoverable(start, "getter should have no params"); }
  2014. else
  2015. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2016. } else {
  2017. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2018. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2019. }
  2020. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2021. this.checkUnreserved(prop.key);
  2022. prop.kind = "init";
  2023. if (isPattern) {
  2024. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2025. } else if (this.type === types.eq && refDestructuringErrors) {
  2026. if (refDestructuringErrors.shorthandAssign < 0)
  2027. { refDestructuringErrors.shorthandAssign = this.start; }
  2028. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2029. } else {
  2030. prop.value = prop.key;
  2031. }
  2032. prop.shorthand = true;
  2033. } else { this.unexpected(); }
  2034. };
  2035. pp$3.parsePropertyName = function(prop) {
  2036. if (this.options.ecmaVersion >= 6) {
  2037. if (this.eat(types.bracketL)) {
  2038. prop.computed = true;
  2039. prop.key = this.parseMaybeAssign();
  2040. this.expect(types.bracketR);
  2041. return prop.key
  2042. } else {
  2043. prop.computed = false;
  2044. }
  2045. }
  2046. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
  2047. };
  2048. // Initialize empty function node.
  2049. pp$3.initFunction = function(node) {
  2050. node.id = null;
  2051. if (this.options.ecmaVersion >= 6) {
  2052. node.generator = false;
  2053. node.expression = false;
  2054. }
  2055. if (this.options.ecmaVersion >= 8)
  2056. { node.async = false; }
  2057. };
  2058. // Parse object or class method.
  2059. pp$3.parseMethod = function(isGenerator, isAsync) {
  2060. var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2061. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2062. this.initFunction(node);
  2063. if (this.options.ecmaVersion >= 6)
  2064. { node.generator = isGenerator; }
  2065. if (this.options.ecmaVersion >= 8)
  2066. { node.async = !!isAsync; }
  2067. this.inGenerator = node.generator;
  2068. this.inAsync = node.async;
  2069. this.yieldPos = 0;
  2070. this.awaitPos = 0;
  2071. this.inFunction = true;
  2072. this.enterFunctionScope();
  2073. this.expect(types.parenL);
  2074. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2075. this.checkYieldAwaitInDefaultParams();
  2076. this.parseFunctionBody(node, false);
  2077. this.inGenerator = oldInGen;
  2078. this.inAsync = oldInAsync;
  2079. this.yieldPos = oldYieldPos;
  2080. this.awaitPos = oldAwaitPos;
  2081. this.inFunction = oldInFunc;
  2082. return this.finishNode(node, "FunctionExpression")
  2083. };
  2084. // Parse arrow function expression with given parameters.
  2085. pp$3.parseArrowExpression = function(node, params, isAsync) {
  2086. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2087. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2088. this.enterFunctionScope();
  2089. this.initFunction(node);
  2090. if (this.options.ecmaVersion >= 8)
  2091. { node.async = !!isAsync; }
  2092. this.inGenerator = false;
  2093. this.inAsync = node.async;
  2094. this.yieldPos = 0;
  2095. this.awaitPos = 0;
  2096. this.inFunction = true;
  2097. node.params = this.toAssignableList(params, true);
  2098. this.parseFunctionBody(node, true);
  2099. this.inGenerator = oldInGen;
  2100. this.inAsync = oldInAsync;
  2101. this.yieldPos = oldYieldPos;
  2102. this.awaitPos = oldAwaitPos;
  2103. this.inFunction = oldInFunc;
  2104. return this.finishNode(node, "ArrowFunctionExpression")
  2105. };
  2106. // Parse function body and check parameters.
  2107. pp$3.parseFunctionBody = function(node, isArrowFunction) {
  2108. var isExpression = isArrowFunction && this.type !== types.braceL;
  2109. var oldStrict = this.strict, useStrict = false;
  2110. if (isExpression) {
  2111. node.body = this.parseMaybeAssign();
  2112. node.expression = true;
  2113. this.checkParams(node, false);
  2114. } else {
  2115. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2116. if (!oldStrict || nonSimple) {
  2117. useStrict = this.strictDirective(this.end);
  2118. // If this is a strict mode function, verify that argument names
  2119. // are not repeated, and it does not try to bind the words `eval`
  2120. // or `arguments`.
  2121. if (useStrict && nonSimple)
  2122. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2123. }
  2124. // Start a new scope with regard to labels and the `inFunction`
  2125. // flag (restore them to their old value afterwards).
  2126. var oldLabels = this.labels;
  2127. this.labels = [];
  2128. if (useStrict) { this.strict = true; }
  2129. // Add the params to varDeclaredNames to ensure that an error is thrown
  2130. // if a let/const declaration in the function clashes with one of the params.
  2131. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
  2132. node.body = this.parseBlock(false);
  2133. node.expression = false;
  2134. this.labels = oldLabels;
  2135. }
  2136. this.exitFunctionScope();
  2137. if (this.strict && node.id) {
  2138. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2139. this.checkLVal(node.id, "none");
  2140. }
  2141. this.strict = oldStrict;
  2142. };
  2143. pp$3.isSimpleParamList = function(params) {
  2144. for (var i = 0, list = params; i < list.length; i += 1)
  2145. {
  2146. var param = list[i];
  2147. if (param.type !== "Identifier") { return false
  2148. } }
  2149. return true
  2150. };
  2151. // Checks function params for various disallowed patterns such as using "eval"
  2152. // or "arguments" and duplicate parameters.
  2153. pp$3.checkParams = function(node, allowDuplicates) {
  2154. var this$1 = this;
  2155. var nameHash = {};
  2156. for (var i = 0, list = node.params; i < list.length; i += 1)
  2157. {
  2158. var param = list[i];
  2159. this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
  2160. }
  2161. };
  2162. // Parses a comma-separated list of expressions, and returns them as
  2163. // an array. `close` is the token type that ends the list, and
  2164. // `allowEmpty` can be turned on to allow subsequent commas with
  2165. // nothing in between them to be parsed as `null` (which is needed
  2166. // for array literals).
  2167. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2168. var this$1 = this;
  2169. var elts = [], first = true;
  2170. while (!this.eat(close)) {
  2171. if (!first) {
  2172. this$1.expect(types.comma);
  2173. if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
  2174. } else { first = false; }
  2175. var elt = (void 0);
  2176. if (allowEmpty && this$1.type === types.comma)
  2177. { elt = null; }
  2178. else if (this$1.type === types.ellipsis) {
  2179. elt = this$1.parseSpread(refDestructuringErrors);
  2180. if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
  2181. { refDestructuringErrors.trailingComma = this$1.start; }
  2182. } else {
  2183. elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
  2184. }
  2185. elts.push(elt);
  2186. }
  2187. return elts
  2188. };
  2189. // Parse the next token as an identifier. If `liberal` is true (used
  2190. // when parsing properties), it will also convert keywords into
  2191. // identifiers.
  2192. pp$3.checkUnreserved = function(ref) {
  2193. var start = ref.start;
  2194. var end = ref.end;
  2195. var name = ref.name;
  2196. if (this.inGenerator && name === "yield")
  2197. { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
  2198. if (this.inAsync && name === "await")
  2199. { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
  2200. if (this.isKeyword(name))
  2201. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2202. if (this.options.ecmaVersion < 6 &&
  2203. this.input.slice(start, end).indexOf("\\") != -1) { return }
  2204. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2205. if (re.test(name))
  2206. { this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved")); }
  2207. };
  2208. pp$3.parseIdent = function(liberal, isBinding) {
  2209. var node = this.startNode();
  2210. if (liberal && this.options.allowReserved == "never") { liberal = false; }
  2211. if (this.type === types.name) {
  2212. node.name = this.value;
  2213. } else if (this.type.keyword) {
  2214. node.name = this.type.keyword;
  2215. } else {
  2216. this.unexpected();
  2217. }
  2218. this.next();
  2219. this.finishNode(node, "Identifier");
  2220. if (!liberal) { this.checkUnreserved(node); }
  2221. return node
  2222. };
  2223. // Parses yield expression inside generator.
  2224. pp$3.parseYield = function() {
  2225. if (!this.yieldPos) { this.yieldPos = this.start; }
  2226. var node = this.startNode();
  2227. this.next();
  2228. if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
  2229. node.delegate = false;
  2230. node.argument = null;
  2231. } else {
  2232. node.delegate = this.eat(types.star);
  2233. node.argument = this.parseMaybeAssign();
  2234. }
  2235. return this.finishNode(node, "YieldExpression")
  2236. };
  2237. pp$3.parseAwait = function() {
  2238. if (!this.awaitPos) { this.awaitPos = this.start; }
  2239. var node = this.startNode();
  2240. this.next();
  2241. node.argument = this.parseMaybeUnary(null, true);
  2242. return this.finishNode(node, "AwaitExpression")
  2243. };
  2244. var pp$4 = Parser.prototype;
  2245. // This function is used to raise exceptions on parse errors. It
  2246. // takes an offset integer (into the current `input`) to indicate
  2247. // the location of the error, attaches the position to the end
  2248. // of the error message, and then raises a `SyntaxError` with that
  2249. // message.
  2250. pp$4.raise = function(pos, message) {
  2251. var loc = getLineInfo(this.input, pos);
  2252. message += " (" + loc.line + ":" + loc.column + ")";
  2253. var err = new SyntaxError(message);
  2254. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  2255. throw err
  2256. };
  2257. pp$4.raiseRecoverable = pp$4.raise;
  2258. pp$4.curPosition = function() {
  2259. if (this.options.locations) {
  2260. return new Position(this.curLine, this.pos - this.lineStart)
  2261. }
  2262. };
  2263. var pp$5 = Parser.prototype;
  2264. // Object.assign polyfill
  2265. var assign = Object.assign || function(target) {
  2266. var sources = [], len = arguments.length - 1;
  2267. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  2268. for (var i = 0, list = sources; i < list.length; i += 1) {
  2269. var source = list[i];
  2270. for (var key in source) {
  2271. if (has(source, key)) {
  2272. target[key] = source[key];
  2273. }
  2274. }
  2275. }
  2276. return target
  2277. };
  2278. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  2279. pp$5.enterFunctionScope = function() {
  2280. // var: a hash of var-declared names in the current lexical scope
  2281. // lexical: a hash of lexically-declared names in the current lexical scope
  2282. // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
  2283. // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
  2284. this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
  2285. };
  2286. pp$5.exitFunctionScope = function() {
  2287. this.scopeStack.pop();
  2288. };
  2289. pp$5.enterLexicalScope = function() {
  2290. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2291. var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
  2292. this.scopeStack.push(childScope);
  2293. assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
  2294. };
  2295. pp$5.exitLexicalScope = function() {
  2296. var childScope = this.scopeStack.pop();
  2297. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2298. assign(parentScope.childVar, childScope.var, childScope.childVar);
  2299. };
  2300. /**
  2301. * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
  2302. * in the current lexical scope or any of the parent lexical scopes in this function.
  2303. */
  2304. pp$5.canDeclareVarName = function(name) {
  2305. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2306. return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
  2307. };
  2308. /**
  2309. * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
  2310. * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
  2311. * any child lexical scopes in this function.
  2312. */
  2313. pp$5.canDeclareLexicalName = function(name) {
  2314. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2315. return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
  2316. };
  2317. pp$5.declareVarName = function(name) {
  2318. this.scopeStack[this.scopeStack.length - 1].var[name] = true;
  2319. };
  2320. pp$5.declareLexicalName = function(name) {
  2321. this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
  2322. };
  2323. var Node = function Node(parser, pos, loc) {
  2324. this.type = "";
  2325. this.start = pos;
  2326. this.end = 0;
  2327. if (parser.options.locations)
  2328. { this.loc = new SourceLocation(parser, loc); }
  2329. if (parser.options.directSourceFile)
  2330. { this.sourceFile = parser.options.directSourceFile; }
  2331. if (parser.options.ranges)
  2332. { this.range = [pos, 0]; }
  2333. };
  2334. // Start an AST node, attaching a start offset.
  2335. var pp$6 = Parser.prototype;
  2336. pp$6.startNode = function() {
  2337. return new Node(this, this.start, this.startLoc)
  2338. };
  2339. pp$6.startNodeAt = function(pos, loc) {
  2340. return new Node(this, pos, loc)
  2341. };
  2342. // Finish an AST node, adding `type` and `end` properties.
  2343. function finishNodeAt(node, type, pos, loc) {
  2344. node.type = type;
  2345. node.end = pos;
  2346. if (this.options.locations)
  2347. { node.loc.end = loc; }
  2348. if (this.options.ranges)
  2349. { node.range[1] = pos; }
  2350. return node
  2351. }
  2352. pp$6.finishNode = function(node, type) {
  2353. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  2354. };
  2355. // Finish node at given position
  2356. pp$6.finishNodeAt = function(node, type, pos, loc) {
  2357. return finishNodeAt.call(this, node, type, pos, loc)
  2358. };
  2359. // The algorithm used to determine whether a regexp can appear at a
  2360. // given point in the program is loosely based on sweet.js' approach.
  2361. // See https://github.com/mozilla/sweet.js/wiki/design
  2362. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2363. this.token = token;
  2364. this.isExpr = !!isExpr;
  2365. this.preserveSpace = !!preserveSpace;
  2366. this.override = override;
  2367. this.generator = !!generator;
  2368. };
  2369. var types$1 = {
  2370. b_stat: new TokContext("{", false),
  2371. b_expr: new TokContext("{", true),
  2372. b_tmpl: new TokContext("${", false),
  2373. p_stat: new TokContext("(", false),
  2374. p_expr: new TokContext("(", true),
  2375. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2376. f_stat: new TokContext("function", false),
  2377. f_expr: new TokContext("function", true),
  2378. f_expr_gen: new TokContext("function", true, false, null, true),
  2379. f_gen: new TokContext("function", false, false, null, true)
  2380. };
  2381. var pp$7 = Parser.prototype;
  2382. pp$7.initialContext = function() {
  2383. return [types$1.b_stat]
  2384. };
  2385. pp$7.braceIsBlock = function(prevType) {
  2386. var parent = this.curContext();
  2387. if (parent === types$1.f_expr || parent === types$1.f_stat)
  2388. { return true }
  2389. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  2390. { return !parent.isExpr }
  2391. // The check for `tt.name && exprAllowed` detects whether we are
  2392. // after a `yield` or `of` construct. See the `updateContext` for
  2393. // `tt.name`.
  2394. if (prevType === types._return || prevType == types.name && this.exprAllowed)
  2395. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2396. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
  2397. { return true }
  2398. if (prevType == types.braceL)
  2399. { return parent === types$1.b_stat }
  2400. if (prevType == types._var || prevType == types.name)
  2401. { return false }
  2402. return !this.exprAllowed
  2403. };
  2404. pp$7.inGeneratorContext = function() {
  2405. var this$1 = this;
  2406. for (var i = this.context.length - 1; i >= 1; i--) {
  2407. var context = this$1.context[i];
  2408. if (context.token === "function")
  2409. { return context.generator }
  2410. }
  2411. return false
  2412. };
  2413. pp$7.updateContext = function(prevType) {
  2414. var update, type = this.type;
  2415. if (type.keyword && prevType == types.dot)
  2416. { this.exprAllowed = false; }
  2417. else if (update = type.updateContext)
  2418. { update.call(this, prevType); }
  2419. else
  2420. { this.exprAllowed = type.beforeExpr; }
  2421. };
  2422. // Token-specific context update code
  2423. types.parenR.updateContext = types.braceR.updateContext = function() {
  2424. if (this.context.length == 1) {
  2425. this.exprAllowed = true;
  2426. return
  2427. }
  2428. var out = this.context.pop();
  2429. if (out === types$1.b_stat && this.curContext().token === "function") {
  2430. out = this.context.pop();
  2431. }
  2432. this.exprAllowed = !out.isExpr;
  2433. };
  2434. types.braceL.updateContext = function(prevType) {
  2435. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  2436. this.exprAllowed = true;
  2437. };
  2438. types.dollarBraceL.updateContext = function() {
  2439. this.context.push(types$1.b_tmpl);
  2440. this.exprAllowed = true;
  2441. };
  2442. types.parenL.updateContext = function(prevType) {
  2443. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  2444. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  2445. this.exprAllowed = true;
  2446. };
  2447. types.incDec.updateContext = function() {
  2448. // tokExprAllowed stays unchanged
  2449. };
  2450. types._function.updateContext = types._class.updateContext = function(prevType) {
  2451. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  2452. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  2453. { this.context.push(types$1.f_expr); }
  2454. else
  2455. { this.context.push(types$1.f_stat); }
  2456. this.exprAllowed = false;
  2457. };
  2458. types.backQuote.updateContext = function() {
  2459. if (this.curContext() === types$1.q_tmpl)
  2460. { this.context.pop(); }
  2461. else
  2462. { this.context.push(types$1.q_tmpl); }
  2463. this.exprAllowed = false;
  2464. };
  2465. types.star.updateContext = function(prevType) {
  2466. if (prevType == types._function) {
  2467. var index = this.context.length - 1;
  2468. if (this.context[index] === types$1.f_expr)
  2469. { this.context[index] = types$1.f_expr_gen; }
  2470. else
  2471. { this.context[index] = types$1.f_gen; }
  2472. }
  2473. this.exprAllowed = true;
  2474. };
  2475. types.name.updateContext = function(prevType) {
  2476. var allowed = false;
  2477. if (this.options.ecmaVersion >= 6) {
  2478. if (this.value == "of" && !this.exprAllowed ||
  2479. this.value == "yield" && this.inGeneratorContext())
  2480. { allowed = true; }
  2481. }
  2482. this.exprAllowed = allowed;
  2483. };
  2484. // Object type used to represent tokens. Note that normally, tokens
  2485. // simply exist as properties on the parser object. This is only
  2486. // used for the onToken callback and the external tokenizer.
  2487. var Token = function Token(p) {
  2488. this.type = p.type;
  2489. this.value = p.value;
  2490. this.start = p.start;
  2491. this.end = p.end;
  2492. if (p.options.locations)
  2493. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  2494. if (p.options.ranges)
  2495. { this.range = [p.start, p.end]; }
  2496. };
  2497. // ## Tokenizer
  2498. var pp$8 = Parser.prototype;
  2499. // Are we running under Rhino?
  2500. var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
  2501. // Move to the next token
  2502. pp$8.next = function() {
  2503. if (this.options.onToken)
  2504. { this.options.onToken(new Token(this)); }
  2505. this.lastTokEnd = this.end;
  2506. this.lastTokStart = this.start;
  2507. this.lastTokEndLoc = this.endLoc;
  2508. this.lastTokStartLoc = this.startLoc;
  2509. this.nextToken();
  2510. };
  2511. pp$8.getToken = function() {
  2512. this.next();
  2513. return new Token(this)
  2514. };
  2515. // If we're in an ES6 environment, make parsers iterable
  2516. if (typeof Symbol !== "undefined")
  2517. { pp$8[Symbol.iterator] = function() {
  2518. var this$1 = this;
  2519. return {
  2520. next: function () {
  2521. var token = this$1.getToken();
  2522. return {
  2523. done: token.type === types.eof,
  2524. value: token
  2525. }
  2526. }
  2527. }
  2528. }; }
  2529. // Toggle strict mode. Re-reads the next number or string to please
  2530. // pedantic tests (`"use strict"; 010;` should fail).
  2531. pp$8.curContext = function() {
  2532. return this.context[this.context.length - 1]
  2533. };
  2534. // Read a single token, updating the parser object's token-related
  2535. // properties.
  2536. pp$8.nextToken = function() {
  2537. var curContext = this.curContext();
  2538. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  2539. this.start = this.pos;
  2540. if (this.options.locations) { this.startLoc = this.curPosition(); }
  2541. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  2542. if (curContext.override) { return curContext.override(this) }
  2543. else { this.readToken(this.fullCharCodeAtPos()); }
  2544. };
  2545. pp$8.readToken = function(code) {
  2546. // Identifier or keyword. '\uXXXX' sequences are allowed in
  2547. // identifiers, so '\' also dispatches to that.
  2548. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  2549. { return this.readWord() }
  2550. return this.getTokenFromCode(code)
  2551. };
  2552. pp$8.fullCharCodeAtPos = function() {
  2553. var code = this.input.charCodeAt(this.pos);
  2554. if (code <= 0xd7ff || code >= 0xe000) { return code }
  2555. var next = this.input.charCodeAt(this.pos + 1);
  2556. return (code << 10) + next - 0x35fdc00
  2557. };
  2558. pp$8.skipBlockComment = function() {
  2559. var this$1 = this;
  2560. var startLoc = this.options.onComment && this.curPosition();
  2561. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  2562. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  2563. this.pos = end + 2;
  2564. if (this.options.locations) {
  2565. lineBreakG.lastIndex = start;
  2566. var match;
  2567. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  2568. ++this$1.curLine;
  2569. this$1.lineStart = match.index + match[0].length;
  2570. }
  2571. }
  2572. if (this.options.onComment)
  2573. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  2574. startLoc, this.curPosition()); }
  2575. };
  2576. pp$8.skipLineComment = function(startSkip) {
  2577. var this$1 = this;
  2578. var start = this.pos;
  2579. var startLoc = this.options.onComment && this.curPosition();
  2580. var ch = this.input.charCodeAt(this.pos += startSkip);
  2581. while (this.pos < this.input.length && !isNewLine(ch)) {
  2582. ch = this$1.input.charCodeAt(++this$1.pos);
  2583. }
  2584. if (this.options.onComment)
  2585. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  2586. startLoc, this.curPosition()); }
  2587. };
  2588. // Called at the start of the parse and after every token. Skips
  2589. // whitespace and comments, and.
  2590. pp$8.skipSpace = function() {
  2591. var this$1 = this;
  2592. loop: while (this.pos < this.input.length) {
  2593. var ch = this$1.input.charCodeAt(this$1.pos);
  2594. switch (ch) {
  2595. case 32: case 160: // ' '
  2596. ++this$1.pos;
  2597. break
  2598. case 13:
  2599. if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
  2600. ++this$1.pos;
  2601. }
  2602. case 10: case 8232: case 8233:
  2603. ++this$1.pos;
  2604. if (this$1.options.locations) {
  2605. ++this$1.curLine;
  2606. this$1.lineStart = this$1.pos;
  2607. }
  2608. break
  2609. case 47: // '/'
  2610. switch (this$1.input.charCodeAt(this$1.pos + 1)) {
  2611. case 42: // '*'
  2612. this$1.skipBlockComment();
  2613. break
  2614. case 47:
  2615. this$1.skipLineComment(2);
  2616. break
  2617. default:
  2618. break loop
  2619. }
  2620. break
  2621. default:
  2622. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  2623. ++this$1.pos;
  2624. } else {
  2625. break loop
  2626. }
  2627. }
  2628. }
  2629. };
  2630. // Called at the end of every token. Sets `end`, `val`, and
  2631. // maintains `context` and `exprAllowed`, and skips the space after
  2632. // the token, so that the next one's `start` will point at the
  2633. // right position.
  2634. pp$8.finishToken = function(type, val) {
  2635. this.end = this.pos;
  2636. if (this.options.locations) { this.endLoc = this.curPosition(); }
  2637. var prevType = this.type;
  2638. this.type = type;
  2639. this.value = val;
  2640. this.updateContext(prevType);
  2641. };
  2642. // ### Token reading
  2643. // This is the function that is called to fetch the next token. It
  2644. // is somewhat obscure, because it works in character codes rather
  2645. // than characters, and because operator parsing has been inlined
  2646. // into it.
  2647. //
  2648. // All in the name of speed.
  2649. //
  2650. pp$8.readToken_dot = function() {
  2651. var next = this.input.charCodeAt(this.pos + 1);
  2652. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  2653. var next2 = this.input.charCodeAt(this.pos + 2);
  2654. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  2655. this.pos += 3;
  2656. return this.finishToken(types.ellipsis)
  2657. } else {
  2658. ++this.pos;
  2659. return this.finishToken(types.dot)
  2660. }
  2661. };
  2662. pp$8.readToken_slash = function() { // '/'
  2663. var next = this.input.charCodeAt(this.pos + 1);
  2664. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  2665. if (next === 61) { return this.finishOp(types.assign, 2) }
  2666. return this.finishOp(types.slash, 1)
  2667. };
  2668. pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
  2669. var next = this.input.charCodeAt(this.pos + 1);
  2670. var size = 1;
  2671. var tokentype = code === 42 ? types.star : types.modulo;
  2672. // exponentiation operator ** and **=
  2673. if (this.options.ecmaVersion >= 7 && next === 42) {
  2674. ++size;
  2675. tokentype = types.starstar;
  2676. next = this.input.charCodeAt(this.pos + 2);
  2677. }
  2678. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  2679. return this.finishOp(tokentype, size)
  2680. };
  2681. pp$8.readToken_pipe_amp = function(code) { // '|&'
  2682. var next = this.input.charCodeAt(this.pos + 1);
  2683. if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
  2684. if (next === 61) { return this.finishOp(types.assign, 2) }
  2685. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  2686. };
  2687. pp$8.readToken_caret = function() { // '^'
  2688. var next = this.input.charCodeAt(this.pos + 1);
  2689. if (next === 61) { return this.finishOp(types.assign, 2) }
  2690. return this.finishOp(types.bitwiseXOR, 1)
  2691. };
  2692. pp$8.readToken_plus_min = function(code) { // '+-'
  2693. var next = this.input.charCodeAt(this.pos + 1);
  2694. if (next === code) {
  2695. if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 &&
  2696. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  2697. // A `-->` line comment
  2698. this.skipLineComment(3);
  2699. this.skipSpace();
  2700. return this.nextToken()
  2701. }
  2702. return this.finishOp(types.incDec, 2)
  2703. }
  2704. if (next === 61) { return this.finishOp(types.assign, 2) }
  2705. return this.finishOp(types.plusMin, 1)
  2706. };
  2707. pp$8.readToken_lt_gt = function(code) { // '<>'
  2708. var next = this.input.charCodeAt(this.pos + 1);
  2709. var size = 1;
  2710. if (next === code) {
  2711. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  2712. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  2713. return this.finishOp(types.bitShift, size)
  2714. }
  2715. if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 &&
  2716. this.input.charCodeAt(this.pos + 3) == 45) {
  2717. if (this.inModule) { this.unexpected(); }
  2718. // `<!--`, an XML-style comment that should be interpreted as a line comment
  2719. this.skipLineComment(4);
  2720. this.skipSpace();
  2721. return this.nextToken()
  2722. }
  2723. if (next === 61) { size = 2; }
  2724. return this.finishOp(types.relational, size)
  2725. };
  2726. pp$8.readToken_eq_excl = function(code) { // '=!'
  2727. var next = this.input.charCodeAt(this.pos + 1);
  2728. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  2729. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  2730. this.pos += 2;
  2731. return this.finishToken(types.arrow)
  2732. }
  2733. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  2734. };
  2735. pp$8.getTokenFromCode = function(code) {
  2736. switch (code) {
  2737. // The interpretation of a dot depends on whether it is followed
  2738. // by a digit or another two dots.
  2739. case 46: // '.'
  2740. return this.readToken_dot()
  2741. // Punctuation tokens.
  2742. case 40: ++this.pos; return this.finishToken(types.parenL)
  2743. case 41: ++this.pos; return this.finishToken(types.parenR)
  2744. case 59: ++this.pos; return this.finishToken(types.semi)
  2745. case 44: ++this.pos; return this.finishToken(types.comma)
  2746. case 91: ++this.pos; return this.finishToken(types.bracketL)
  2747. case 93: ++this.pos; return this.finishToken(types.bracketR)
  2748. case 123: ++this.pos; return this.finishToken(types.braceL)
  2749. case 125: ++this.pos; return this.finishToken(types.braceR)
  2750. case 58: ++this.pos; return this.finishToken(types.colon)
  2751. case 63: ++this.pos; return this.finishToken(types.question)
  2752. case 96: // '`'
  2753. if (this.options.ecmaVersion < 6) { break }
  2754. ++this.pos;
  2755. return this.finishToken(types.backQuote)
  2756. case 48: // '0'
  2757. var next = this.input.charCodeAt(this.pos + 1);
  2758. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  2759. if (this.options.ecmaVersion >= 6) {
  2760. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  2761. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  2762. }
  2763. // Anything else beginning with a digit is an integer, octal
  2764. // number, or float.
  2765. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  2766. return this.readNumber(false)
  2767. // Quotes produce strings.
  2768. case 34: case 39: // '"', "'"
  2769. return this.readString(code)
  2770. // Operators are parsed inline in tiny state machines. '=' (61) is
  2771. // often referred to. `finishOp` simply skips the amount of
  2772. // characters it is given as second argument, and returns a token
  2773. // of the type given by its first argument.
  2774. case 47: // '/'
  2775. return this.readToken_slash()
  2776. case 37: case 42: // '%*'
  2777. return this.readToken_mult_modulo_exp(code)
  2778. case 124: case 38: // '|&'
  2779. return this.readToken_pipe_amp(code)
  2780. case 94: // '^'
  2781. return this.readToken_caret()
  2782. case 43: case 45: // '+-'
  2783. return this.readToken_plus_min(code)
  2784. case 60: case 62: // '<>'
  2785. return this.readToken_lt_gt(code)
  2786. case 61: case 33: // '=!'
  2787. return this.readToken_eq_excl(code)
  2788. case 126: // '~'
  2789. return this.finishOp(types.prefix, 1)
  2790. }
  2791. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  2792. };
  2793. pp$8.finishOp = function(type, size) {
  2794. var str = this.input.slice(this.pos, this.pos + size);
  2795. this.pos += size;
  2796. return this.finishToken(type, str)
  2797. };
  2798. // Parse a regular expression. Some context-awareness is necessary,
  2799. // since a '/' inside a '[]' set does not end the expression.
  2800. function tryCreateRegexp(src, flags, throwErrorAt, parser) {
  2801. try {
  2802. return new RegExp(src, flags)
  2803. } catch (e) {
  2804. if (throwErrorAt !== undefined) {
  2805. if (e instanceof SyntaxError) { parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message); }
  2806. throw e
  2807. }
  2808. }
  2809. }
  2810. var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
  2811. pp$8.readRegexp = function() {
  2812. var this$1 = this;
  2813. var escaped, inClass, start = this.pos;
  2814. for (;;) {
  2815. if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
  2816. var ch = this$1.input.charAt(this$1.pos);
  2817. if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
  2818. if (!escaped) {
  2819. if (ch === "[") { inClass = true; }
  2820. else if (ch === "]" && inClass) { inClass = false; }
  2821. else if (ch === "/" && !inClass) { break }
  2822. escaped = ch === "\\";
  2823. } else { escaped = false; }
  2824. ++this$1.pos;
  2825. }
  2826. var content = this.input.slice(start, this.pos);
  2827. ++this.pos;
  2828. // Need to use `readWord1` because '\uXXXX' sequences are allowed
  2829. // here (don't ask).
  2830. var mods = this.readWord1();
  2831. var tmp = content, tmpFlags = "";
  2832. if (mods) {
  2833. var validFlags = /^[gim]*$/;
  2834. if (this.options.ecmaVersion >= 6) { validFlags = /^[gimuy]*$/; }
  2835. if (!validFlags.test(mods)) { this.raise(start, "Invalid regular expression flag"); }
  2836. if (mods.indexOf("u") >= 0) {
  2837. if (regexpUnicodeSupport) {
  2838. tmpFlags = "u";
  2839. } else {
  2840. // Replace each astral symbol and every Unicode escape sequence that
  2841. // possibly represents an astral symbol or a paired surrogate with a
  2842. // single ASCII symbol to avoid throwing on regular expressions that
  2843. // are only valid in combination with the `/u` flag.
  2844. // Note: replacing with the ASCII symbol `x` might cause false
  2845. // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
  2846. // perfectly valid pattern that is equivalent to `[a-b]`, but it would
  2847. // be replaced by `[x-b]` which throws an error.
  2848. tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
  2849. code = Number("0x" + code);
  2850. if (code > 0x10FFFF) { this$1.raise(start + offset + 3, "Code point out of bounds"); }
  2851. return "x"
  2852. });
  2853. tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
  2854. tmpFlags = tmpFlags.replace("u", "");
  2855. }
  2856. }
  2857. }
  2858. // Detect invalid regular expressions.
  2859. var value = null;
  2860. // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
  2861. // so don't do detection if we are running under Rhino
  2862. if (!isRhino) {
  2863. tryCreateRegexp(tmp, tmpFlags, start, this);
  2864. // Get a regular expression object for this pattern-flag pair, or `null` in
  2865. // case the current environment doesn't support the flags it uses.
  2866. value = tryCreateRegexp(content, mods);
  2867. }
  2868. return this.finishToken(types.regexp, {pattern: content, flags: mods, value: value})
  2869. };
  2870. // Read an integer in the given radix. Return null if zero digits
  2871. // were read, the integer value otherwise. When `len` is given, this
  2872. // will return `null` unless the integer has exactly `len` digits.
  2873. pp$8.readInt = function(radix, len) {
  2874. var this$1 = this;
  2875. var start = this.pos, total = 0;
  2876. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2877. var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
  2878. if (code >= 97) { val = code - 97 + 10; } // a
  2879. else if (code >= 65) { val = code - 65 + 10; } // A
  2880. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  2881. else { val = Infinity; }
  2882. if (val >= radix) { break }
  2883. ++this$1.pos;
  2884. total = total * radix + val;
  2885. }
  2886. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  2887. return total
  2888. };
  2889. pp$8.readRadixNumber = function(radix) {
  2890. this.pos += 2; // 0x
  2891. var val = this.readInt(radix);
  2892. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  2893. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  2894. return this.finishToken(types.num, val)
  2895. };
  2896. // Read an integer, octal integer, or floating-point number.
  2897. pp$8.readNumber = function(startsWithDot) {
  2898. var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48;
  2899. if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  2900. if (octal && this.pos == start + 1) { octal = false; }
  2901. var next = this.input.charCodeAt(this.pos);
  2902. if (next === 46 && !octal) { // '.'
  2903. ++this.pos;
  2904. this.readInt(10);
  2905. isFloat = true;
  2906. next = this.input.charCodeAt(this.pos);
  2907. }
  2908. if ((next === 69 || next === 101) && !octal) { // 'eE'
  2909. next = this.input.charCodeAt(++this.pos);
  2910. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  2911. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  2912. isFloat = true;
  2913. }
  2914. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  2915. var str = this.input.slice(start, this.pos), val;
  2916. if (isFloat) { val = parseFloat(str); }
  2917. else if (!octal || str.length === 1) { val = parseInt(str, 10); }
  2918. else if (this.strict) { this.raise(start, "Invalid number"); }
  2919. else if (/[89]/.test(str)) { val = parseInt(str, 10); }
  2920. else { val = parseInt(str, 8); }
  2921. return this.finishToken(types.num, val)
  2922. };
  2923. // Read a string value, interpreting backslash-escapes.
  2924. pp$8.readCodePoint = function() {
  2925. var ch = this.input.charCodeAt(this.pos), code;
  2926. if (ch === 123) { // '{'
  2927. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  2928. var codePos = ++this.pos;
  2929. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  2930. ++this.pos;
  2931. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  2932. } else {
  2933. code = this.readHexChar(4);
  2934. }
  2935. return code
  2936. };
  2937. function codePointToString(code) {
  2938. // UTF-16 Decoding
  2939. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  2940. code -= 0x10000;
  2941. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  2942. }
  2943. pp$8.readString = function(quote) {
  2944. var this$1 = this;
  2945. var out = "", chunkStart = ++this.pos;
  2946. for (;;) {
  2947. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
  2948. var ch = this$1.input.charCodeAt(this$1.pos);
  2949. if (ch === quote) { break }
  2950. if (ch === 92) { // '\'
  2951. out += this$1.input.slice(chunkStart, this$1.pos);
  2952. out += this$1.readEscapedChar(false);
  2953. chunkStart = this$1.pos;
  2954. } else {
  2955. if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
  2956. ++this$1.pos;
  2957. }
  2958. }
  2959. out += this.input.slice(chunkStart, this.pos++);
  2960. return this.finishToken(types.string, out)
  2961. };
  2962. // Reads template string tokens.
  2963. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  2964. pp$8.tryReadTemplateToken = function() {
  2965. this.inTemplateElement = true;
  2966. try {
  2967. this.readTmplToken();
  2968. } catch (err) {
  2969. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  2970. this.readInvalidTemplateToken();
  2971. } else {
  2972. throw err
  2973. }
  2974. }
  2975. this.inTemplateElement = false;
  2976. };
  2977. pp$8.invalidStringToken = function(position, message) {
  2978. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  2979. throw INVALID_TEMPLATE_ESCAPE_ERROR
  2980. } else {
  2981. this.raise(position, message);
  2982. }
  2983. };
  2984. pp$8.readTmplToken = function() {
  2985. var this$1 = this;
  2986. var out = "", chunkStart = this.pos;
  2987. for (;;) {
  2988. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
  2989. var ch = this$1.input.charCodeAt(this$1.pos);
  2990. if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
  2991. if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
  2992. if (ch === 36) {
  2993. this$1.pos += 2;
  2994. return this$1.finishToken(types.dollarBraceL)
  2995. } else {
  2996. ++this$1.pos;
  2997. return this$1.finishToken(types.backQuote)
  2998. }
  2999. }
  3000. out += this$1.input.slice(chunkStart, this$1.pos);
  3001. return this$1.finishToken(types.template, out)
  3002. }
  3003. if (ch === 92) { // '\'
  3004. out += this$1.input.slice(chunkStart, this$1.pos);
  3005. out += this$1.readEscapedChar(true);
  3006. chunkStart = this$1.pos;
  3007. } else if (isNewLine(ch)) {
  3008. out += this$1.input.slice(chunkStart, this$1.pos);
  3009. ++this$1.pos;
  3010. switch (ch) {
  3011. case 13:
  3012. if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
  3013. case 10:
  3014. out += "\n";
  3015. break
  3016. default:
  3017. out += String.fromCharCode(ch);
  3018. break
  3019. }
  3020. if (this$1.options.locations) {
  3021. ++this$1.curLine;
  3022. this$1.lineStart = this$1.pos;
  3023. }
  3024. chunkStart = this$1.pos;
  3025. } else {
  3026. ++this$1.pos;
  3027. }
  3028. }
  3029. };
  3030. // Reads a template token to search for the end, without validating any escape sequences
  3031. pp$8.readInvalidTemplateToken = function() {
  3032. var this$1 = this;
  3033. for (; this.pos < this.input.length; this.pos++) {
  3034. switch (this$1.input[this$1.pos]) {
  3035. case "\\":
  3036. ++this$1.pos;
  3037. break
  3038. case "$":
  3039. if (this$1.input[this$1.pos + 1] !== "{") {
  3040. break
  3041. }
  3042. // falls through
  3043. case "`":
  3044. return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
  3045. // no default
  3046. }
  3047. }
  3048. this.raise(this.start, "Unterminated template");
  3049. };
  3050. // Used to read escaped characters
  3051. pp$8.readEscapedChar = function(inTemplate) {
  3052. var ch = this.input.charCodeAt(++this.pos);
  3053. ++this.pos;
  3054. switch (ch) {
  3055. case 110: return "\n" // 'n' -> '\n'
  3056. case 114: return "\r" // 'r' -> '\r'
  3057. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  3058. case 117: return codePointToString(this.readCodePoint()) // 'u'
  3059. case 116: return "\t" // 't' -> '\t'
  3060. case 98: return "\b" // 'b' -> '\b'
  3061. case 118: return "\u000b" // 'v' -> '\u000b'
  3062. case 102: return "\f" // 'f' -> '\f'
  3063. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  3064. case 10: // ' \n'
  3065. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  3066. return ""
  3067. default:
  3068. if (ch >= 48 && ch <= 55) {
  3069. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  3070. var octal = parseInt(octalStr, 8);
  3071. if (octal > 255) {
  3072. octalStr = octalStr.slice(0, -1);
  3073. octal = parseInt(octalStr, 8);
  3074. }
  3075. if (octalStr !== "0" && (this.strict || inTemplate)) {
  3076. this.invalidStringToken(this.pos - 2, "Octal literal in strict mode");
  3077. }
  3078. this.pos += octalStr.length - 1;
  3079. return String.fromCharCode(octal)
  3080. }
  3081. return String.fromCharCode(ch)
  3082. }
  3083. };
  3084. // Used to read character escape sequences ('\x', '\u', '\U').
  3085. pp$8.readHexChar = function(len) {
  3086. var codePos = this.pos;
  3087. var n = this.readInt(16, len);
  3088. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  3089. return n
  3090. };
  3091. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  3092. // to whether the word contained a '\u' escape.
  3093. //
  3094. // Incrementally adds only escaped chars, adding other chunks as-is
  3095. // as a micro-optimization.
  3096. pp$8.readWord1 = function() {
  3097. var this$1 = this;
  3098. this.containsEsc = false;
  3099. var word = "", first = true, chunkStart = this.pos;
  3100. var astral = this.options.ecmaVersion >= 6;
  3101. while (this.pos < this.input.length) {
  3102. var ch = this$1.fullCharCodeAtPos();
  3103. if (isIdentifierChar(ch, astral)) {
  3104. this$1.pos += ch <= 0xffff ? 1 : 2;
  3105. } else if (ch === 92) { // "\"
  3106. this$1.containsEsc = true;
  3107. word += this$1.input.slice(chunkStart, this$1.pos);
  3108. var escStart = this$1.pos;
  3109. if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
  3110. { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  3111. ++this$1.pos;
  3112. var esc = this$1.readCodePoint();
  3113. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  3114. { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
  3115. word += codePointToString(esc);
  3116. chunkStart = this$1.pos;
  3117. } else {
  3118. break
  3119. }
  3120. first = false;
  3121. }
  3122. return word + this.input.slice(chunkStart, this.pos)
  3123. };
  3124. // Read an identifier or keyword token. Will check for reserved
  3125. // words when necessary.
  3126. pp$8.readWord = function() {
  3127. var word = this.readWord1();
  3128. var type = types.name;
  3129. if (this.keywords.test(word)) {
  3130. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
  3131. type = keywords$1[word];
  3132. }
  3133. return this.finishToken(type, word)
  3134. };
  3135. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  3136. //
  3137. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  3138. // various contributors and released under an MIT license.
  3139. //
  3140. // Git repositories for Acorn are available at
  3141. //
  3142. // http://marijnhaverbeke.nl/git/acorn
  3143. // https://github.com/ternjs/acorn.git
  3144. //
  3145. // Please use the [github bug tracker][ghbt] to report issues.
  3146. //
  3147. // [ghbt]: https://github.com/ternjs/acorn/issues
  3148. //
  3149. // This file defines the main parser interface. The library also comes
  3150. // with a [error-tolerant parser][dammit] and an
  3151. // [abstract syntax tree walker][walk], defined in other files.
  3152. //
  3153. // [dammit]: acorn_loose.js
  3154. // [walk]: util/walk.js
  3155. var version = "5.1.1";
  3156. // The main exported interface (under `self.acorn` when in the
  3157. // browser) is a `parse` function that takes a code string and
  3158. // returns an abstract syntax tree as specified by [Mozilla parser
  3159. // API][api].
  3160. //
  3161. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  3162. function parse(input, options) {
  3163. return new Parser(options, input).parse()
  3164. }
  3165. // This function tries to parse a single expression at a given
  3166. // offset in a string. Useful for parsing mixed-language formats
  3167. // that embed JavaScript expressions.
  3168. function parseExpressionAt(input, pos, options) {
  3169. var p = new Parser(options, input, pos);
  3170. p.nextToken();
  3171. return p.parseExpression()
  3172. }
  3173. // Acorn is organized as a tokenizer and a recursive-descent parser.
  3174. // The `tokenizer` export provides an interface to the tokenizer.
  3175. function tokenizer(input, options) {
  3176. return new Parser(options, input)
  3177. }
  3178. // This is a terrible kludge to support the existing, pre-ES6
  3179. // interface where the loose parser module retroactively adds exports
  3180. // to this module.
  3181. // eslint-disable-line camelcase
  3182. function addLooseExports(parse, Parser$$1, plugins$$1) {
  3183. exports.parse_dammit = parse; // eslint-disable-line camelcase
  3184. exports.LooseParser = Parser$$1;
  3185. exports.pluginsLoose = plugins$$1;
  3186. }
  3187. exports.version = version;
  3188. exports.parse = parse;
  3189. exports.parseExpressionAt = parseExpressionAt;
  3190. exports.tokenizer = tokenizer;
  3191. exports.addLooseExports = addLooseExports;
  3192. exports.Parser = Parser;
  3193. exports.plugins = plugins;
  3194. exports.defaultOptions = defaultOptions;
  3195. exports.Position = Position;
  3196. exports.SourceLocation = SourceLocation;
  3197. exports.getLineInfo = getLineInfo;
  3198. exports.Node = Node;
  3199. exports.TokenType = TokenType;
  3200. exports.tokTypes = types;
  3201. exports.keywordTypes = keywords$1;
  3202. exports.TokContext = TokContext;
  3203. exports.tokContexts = types$1;
  3204. exports.isIdentifierChar = isIdentifierChar;
  3205. exports.isIdentifierStart = isIdentifierStart;
  3206. exports.Token = Token;
  3207. exports.isNewLine = isNewLine;
  3208. exports.lineBreak = lineBreak;
  3209. exports.lineBreakG = lineBreakG;
  3210. exports.nonASCIIwhitespace = nonASCIIwhitespace;
  3211. Object.defineProperty(exports, '__esModule', { value: true });
  3212. })));