acorn.es.js 174 KB

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