acorn.js 195 KB

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