Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

acorn.mjs 175KB

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