escallmatch.js 260 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776
  1. /**
  2. * Modules in this bundle
  3. * @license
  4. *
  5. * escallmatch:
  6. * license: MIT (http://opensource.org/licenses/MIT)
  7. * author: Takuto Wada <takuto.wada@gmail.com>
  8. * homepage: https://github.com/twada/escallmatch
  9. * version: 1.5.0
  10. *
  11. * call-matcher:
  12. * license: MIT (http://opensource.org/licenses/MIT)
  13. * author: Takuto Wada <takuto.wada@gmail.com>
  14. * maintainers: twada <takuto.wada@gmail.com>
  15. * homepage: https://github.com/twada/call-matcher
  16. * version: 1.0.0
  17. *
  18. * core-js:
  19. * license: MIT (http://opensource.org/licenses/MIT)
  20. * maintainers: zloirock <zloirock@zloirock.ru>
  21. * homepage: https://github.com/zloirock/core-js#readme
  22. * version: 2.4.1
  23. *
  24. * deep-equal:
  25. * license: MIT (http://opensource.org/licenses/MIT)
  26. * author: James Halliday <mail@substack.net>
  27. * maintainers: substack <mail@substack.net>
  28. * homepage: https://github.com/substack/node-deep-equal#readme
  29. * version: 1.0.1
  30. *
  31. * esprima:
  32. * license: BSD-2-Clause (http://opensource.org/licenses/BSD-2-Clause)
  33. * author: Ariya Hidayat <ariya.hidayat@gmail.com>
  34. * maintainers: ariya <ariya.hidayat@gmail.com>
  35. * homepage: http://esprima.org
  36. * version: 2.7.2
  37. *
  38. * espurify:
  39. * license: MIT (http://opensource.org/licenses/MIT)
  40. * author: Takuto Wada <takuto.wada@gmail.com>
  41. * maintainers: twada <takuto.wada@gmail.com>
  42. * homepage: https://github.com/estools/espurify
  43. * version: 1.6.0
  44. *
  45. * estraverse:
  46. * license: BSD-2-Clause (http://opensource.org/licenses/BSD-2-Clause)
  47. * maintainers: constellation <utatane.tea@gmail.com>, michaelficarra <npm@michael.ficarra.me>, nzakas <nicholas@nczconsulting.com>
  48. * homepage: https://github.com/estools/estraverse
  49. * version: 4.2.0
  50. *
  51. * This header is generated by licensify (https://github.com/twada/licensify)
  52. */
  53. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.escallmatch = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw (f.code="MODULE_NOT_FOUND", f)}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  54. /**
  55. * escallmatch:
  56. * ECMAScript CallExpression matcher made from function/method signature
  57. *
  58. * https://github.com/twada/escallmatch
  59. *
  60. * Copyright (c) 2014-2016 Takuto Wada
  61. * Licensed under the MIT license.
  62. * https://github.com/twada/escallmatch/blob/master/LICENSE
  63. */
  64. 'use strict';
  65. /* jshint -W024 */
  66. var esprima = _dereq_('esprima');
  67. var CallMatcher = _dereq_('call-matcher');
  68. var notCallExprMessage = 'Argument should be in the form of CallExpression';
  69. function createMatcher (signatureStr, options) {
  70. var ast = extractExpressionFrom(esprima.parse(signatureStr));
  71. return new CallMatcher(ast, options || {});
  72. }
  73. function extractExpressionFrom (tree) {
  74. var statement = tree.body[0];
  75. if (statement.type !== 'ExpressionStatement') {
  76. throw new Error(notCallExprMessage);
  77. }
  78. return statement.expression;
  79. }
  80. module.exports = createMatcher;
  81. },{"call-matcher":2,"esprima":64}],2:[function(_dereq_,module,exports){
  82. /**
  83. * call-matcher:
  84. * ECMAScript CallExpression matcher made from function/method signature
  85. *
  86. * https://github.com/twada/call-matcher
  87. *
  88. * Copyright (c) 2015-2016 Takuto Wada
  89. * Licensed under the MIT license.
  90. * https://github.com/twada/call-matcher/blob/master/MIT-LICENSE.txt
  91. */
  92. 'use strict';
  93. /* jshint -W024 */
  94. var estraverse = _dereq_('estraverse');
  95. var espurify = _dereq_('espurify');
  96. var syntax = estraverse.Syntax;
  97. var hasOwn = Object.prototype.hasOwnProperty;
  98. var forEach = _dereq_('core-js/library/fn/array/for-each');
  99. var map = _dereq_('core-js/library/fn/array/map');
  100. var filter = _dereq_('core-js/library/fn/array/filter');
  101. var reduce = _dereq_('core-js/library/fn/array/reduce');
  102. var indexOf = _dereq_('core-js/library/fn/array/index-of');
  103. var deepEqual = _dereq_('deep-equal');
  104. var notCallExprMessage = 'Argument should be in the form of CallExpression';
  105. var duplicatedArgMessage = 'Duplicate argument name: ';
  106. var invalidFormMessage = 'Argument should be in the form of `name` or `[name]`';
  107. function CallMatcher (signatureAst, options) {
  108. validateApiExpression(signatureAst);
  109. this.visitorKeys = options.visitorKeys || estraverse.VisitorKeys;
  110. if (options.astWhiteList) {
  111. this.purifyAst = espurify.cloneWithWhitelist(options.astWhiteList);
  112. } else {
  113. this.purifyAst = espurify;
  114. }
  115. this.signatureAst = signatureAst;
  116. this.signatureCalleeDepth = astDepth(signatureAst.callee, this.visitorKeys);
  117. this.numMaxArgs = this.signatureAst.arguments.length;
  118. this.numMinArgs = filter(this.signatureAst.arguments, identifiers).length;
  119. }
  120. CallMatcher.prototype.test = function (currentNode) {
  121. var calleeMatched = this.isCalleeMatched(currentNode);
  122. var numArgs;
  123. if (calleeMatched) {
  124. numArgs = currentNode.arguments.length;
  125. return this.numMinArgs <= numArgs && numArgs <= this.numMaxArgs;
  126. }
  127. return false;
  128. };
  129. CallMatcher.prototype.matchArgument = function (currentNode, parentNode) {
  130. if (isCalleeOfParent(currentNode, parentNode)) {
  131. return null;
  132. }
  133. if (this.test(parentNode)) {
  134. var indexOfCurrentArg = indexOf(parentNode.arguments, currentNode);
  135. var numOptional = parentNode.arguments.length - this.numMinArgs;
  136. var matchedSignatures = reduce(this.argumentSignatures(), function (accum, argSig) {
  137. if (argSig.kind === 'mandatory') {
  138. accum.push(argSig);
  139. }
  140. if (argSig.kind === 'optional' && 0 < numOptional) {
  141. numOptional -= 1;
  142. accum.push(argSig);
  143. }
  144. return accum;
  145. }, []);
  146. return matchedSignatures[indexOfCurrentArg];
  147. }
  148. return null;
  149. };
  150. CallMatcher.prototype.calleeAst = function () {
  151. return this.purifyAst(this.signatureAst.callee);
  152. };
  153. CallMatcher.prototype.argumentSignatures = function () {
  154. return map(this.signatureAst.arguments, toArgumentSignature);
  155. };
  156. CallMatcher.prototype.isCalleeMatched = function (node) {
  157. if (!isCallExpression(node)) {
  158. return false;
  159. }
  160. if (!this.isSameDepthAsSignatureCallee(node.callee)) {
  161. return false;
  162. }
  163. return deepEqual(this.purifyAst(this.signatureAst.callee), this.purifyAst(node.callee));
  164. };
  165. CallMatcher.prototype.isSameDepthAsSignatureCallee = function (ast) {
  166. var depth = this.signatureCalleeDepth;
  167. var currentDepth = 0;
  168. estraverse.traverse(ast, {
  169. keys: this.visitorKeys,
  170. enter: function (currentNode, parentNode) {
  171. var path = this.path();
  172. var pathDepth = path ? path.length : 0;
  173. if (currentDepth < pathDepth) {
  174. currentDepth = pathDepth;
  175. }
  176. if (depth < currentDepth) {
  177. this['break']();
  178. }
  179. }
  180. });
  181. return (depth === currentDepth);
  182. };
  183. function toArgumentSignature (argSignatureNode) {
  184. switch(argSignatureNode.type) {
  185. case syntax.Identifier:
  186. return {
  187. name: argSignatureNode.name,
  188. kind: 'mandatory'
  189. };
  190. case syntax.ArrayExpression:
  191. return {
  192. name: argSignatureNode.elements[0].name,
  193. kind: 'optional'
  194. };
  195. default:
  196. return null;
  197. }
  198. }
  199. function astDepth (ast, visitorKeys) {
  200. var maxDepth = 0;
  201. estraverse.traverse(ast, {
  202. keys: visitorKeys,
  203. enter: function (currentNode, parentNode) {
  204. var path = this.path();
  205. var pathDepth = path ? path.length : 0;
  206. if (maxDepth < pathDepth) {
  207. maxDepth = pathDepth;
  208. }
  209. }
  210. });
  211. return maxDepth;
  212. }
  213. function isCallExpression (node) {
  214. return node && node.type === syntax.CallExpression;
  215. }
  216. function isCalleeOfParent(currentNode, parentNode) {
  217. return parentNode && currentNode &&
  218. parentNode.type === syntax.CallExpression &&
  219. parentNode.callee === currentNode;
  220. }
  221. function identifiers (node) {
  222. return node.type === syntax.Identifier;
  223. }
  224. function validateApiExpression (callExpression) {
  225. if (!callExpression || !callExpression.type) {
  226. throw new Error(notCallExprMessage);
  227. }
  228. if (callExpression.type !== syntax.CallExpression) {
  229. throw new Error(notCallExprMessage);
  230. }
  231. var names = {};
  232. forEach(callExpression.arguments, function (arg) {
  233. var name = validateArg(arg);
  234. if (hasOwn.call(names, name)) {
  235. throw new Error(duplicatedArgMessage + name);
  236. } else {
  237. names[name] = name;
  238. }
  239. });
  240. }
  241. function validateArg (arg) {
  242. var inner;
  243. switch(arg.type) {
  244. case syntax.Identifier:
  245. return arg.name;
  246. case syntax.ArrayExpression:
  247. if (arg.elements.length !== 1) {
  248. throw new Error(invalidFormMessage);
  249. }
  250. inner = arg.elements[0];
  251. if (inner.type !== syntax.Identifier) {
  252. throw new Error(invalidFormMessage);
  253. }
  254. return inner.name;
  255. default:
  256. throw new Error(invalidFormMessage);
  257. }
  258. }
  259. module.exports = CallMatcher;
  260. },{"core-js/library/fn/array/filter":3,"core-js/library/fn/array/for-each":4,"core-js/library/fn/array/index-of":5,"core-js/library/fn/array/map":7,"core-js/library/fn/array/reduce":8,"deep-equal":61,"espurify":65,"estraverse":69}],3:[function(_dereq_,module,exports){
  261. _dereq_('../../modules/es6.array.filter');
  262. module.exports = _dereq_('../../modules/_core').Array.filter;
  263. },{"../../modules/_core":19,"../../modules/es6.array.filter":53}],4:[function(_dereq_,module,exports){
  264. _dereq_('../../modules/es6.array.for-each');
  265. module.exports = _dereq_('../../modules/_core').Array.forEach;
  266. },{"../../modules/_core":19,"../../modules/es6.array.for-each":54}],5:[function(_dereq_,module,exports){
  267. _dereq_('../../modules/es6.array.index-of');
  268. module.exports = _dereq_('../../modules/_core').Array.indexOf;
  269. },{"../../modules/_core":19,"../../modules/es6.array.index-of":55}],6:[function(_dereq_,module,exports){
  270. _dereq_('../../modules/es6.array.is-array');
  271. module.exports = _dereq_('../../modules/_core').Array.isArray;
  272. },{"../../modules/_core":19,"../../modules/es6.array.is-array":56}],7:[function(_dereq_,module,exports){
  273. _dereq_('../../modules/es6.array.map');
  274. module.exports = _dereq_('../../modules/_core').Array.map;
  275. },{"../../modules/_core":19,"../../modules/es6.array.map":57}],8:[function(_dereq_,module,exports){
  276. _dereq_('../../modules/es6.array.reduce');
  277. module.exports = _dereq_('../../modules/_core').Array.reduce;
  278. },{"../../modules/_core":19,"../../modules/es6.array.reduce":58}],9:[function(_dereq_,module,exports){
  279. _dereq_('../../modules/es6.object.assign');
  280. module.exports = _dereq_('../../modules/_core').Object.assign;
  281. },{"../../modules/_core":19,"../../modules/es6.object.assign":59}],10:[function(_dereq_,module,exports){
  282. _dereq_('../../modules/es6.object.keys');
  283. module.exports = _dereq_('../../modules/_core').Object.keys;
  284. },{"../../modules/_core":19,"../../modules/es6.object.keys":60}],11:[function(_dereq_,module,exports){
  285. module.exports = function(it){
  286. if(typeof it != 'function')throw TypeError(it + ' is not a function!');
  287. return it;
  288. };
  289. },{}],12:[function(_dereq_,module,exports){
  290. var isObject = _dereq_('./_is-object');
  291. module.exports = function(it){
  292. if(!isObject(it))throw TypeError(it + ' is not an object!');
  293. return it;
  294. };
  295. },{"./_is-object":33}],13:[function(_dereq_,module,exports){
  296. // false -> Array#indexOf
  297. // true -> Array#includes
  298. var toIObject = _dereq_('./_to-iobject')
  299. , toLength = _dereq_('./_to-length')
  300. , toIndex = _dereq_('./_to-index');
  301. module.exports = function(IS_INCLUDES){
  302. return function($this, el, fromIndex){
  303. var O = toIObject($this)
  304. , length = toLength(O.length)
  305. , index = toIndex(fromIndex, length)
  306. , value;
  307. // Array#includes uses SameValueZero equality algorithm
  308. if(IS_INCLUDES && el != el)while(length > index){
  309. value = O[index++];
  310. if(value != value)return true;
  311. // Array#toIndex ignores holes, Array#includes - not
  312. } else for(;length > index; index++)if(IS_INCLUDES || index in O){
  313. if(O[index] === el)return IS_INCLUDES || index || 0;
  314. } return !IS_INCLUDES && -1;
  315. };
  316. };
  317. },{"./_to-index":45,"./_to-iobject":47,"./_to-length":48}],14:[function(_dereq_,module,exports){
  318. // 0 -> Array#forEach
  319. // 1 -> Array#map
  320. // 2 -> Array#filter
  321. // 3 -> Array#some
  322. // 4 -> Array#every
  323. // 5 -> Array#find
  324. // 6 -> Array#findIndex
  325. var ctx = _dereq_('./_ctx')
  326. , IObject = _dereq_('./_iobject')
  327. , toObject = _dereq_('./_to-object')
  328. , toLength = _dereq_('./_to-length')
  329. , asc = _dereq_('./_array-species-create');
  330. module.exports = function(TYPE, $create){
  331. var IS_MAP = TYPE == 1
  332. , IS_FILTER = TYPE == 2
  333. , IS_SOME = TYPE == 3
  334. , IS_EVERY = TYPE == 4
  335. , IS_FIND_INDEX = TYPE == 6
  336. , NO_HOLES = TYPE == 5 || IS_FIND_INDEX
  337. , create = $create || asc;
  338. return function($this, callbackfn, that){
  339. var O = toObject($this)
  340. , self = IObject(O)
  341. , f = ctx(callbackfn, that, 3)
  342. , length = toLength(self.length)
  343. , index = 0
  344. , result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined
  345. , val, res;
  346. for(;length > index; index++)if(NO_HOLES || index in self){
  347. val = self[index];
  348. res = f(val, index, O);
  349. if(TYPE){
  350. if(IS_MAP)result[index] = res; // map
  351. else if(res)switch(TYPE){
  352. case 3: return true; // some
  353. case 5: return val; // find
  354. case 6: return index; // findIndex
  355. case 2: result.push(val); // filter
  356. } else if(IS_EVERY)return false; // every
  357. }
  358. }
  359. return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result;
  360. };
  361. };
  362. },{"./_array-species-create":17,"./_ctx":20,"./_iobject":31,"./_to-length":48,"./_to-object":49}],15:[function(_dereq_,module,exports){
  363. var aFunction = _dereq_('./_a-function')
  364. , toObject = _dereq_('./_to-object')
  365. , IObject = _dereq_('./_iobject')
  366. , toLength = _dereq_('./_to-length');
  367. module.exports = function(that, callbackfn, aLen, memo, isRight){
  368. aFunction(callbackfn);
  369. var O = toObject(that)
  370. , self = IObject(O)
  371. , length = toLength(O.length)
  372. , index = isRight ? length - 1 : 0
  373. , i = isRight ? -1 : 1;
  374. if(aLen < 2)for(;;){
  375. if(index in self){
  376. memo = self[index];
  377. index += i;
  378. break;
  379. }
  380. index += i;
  381. if(isRight ? index < 0 : length <= index){
  382. throw TypeError('Reduce of empty array with no initial value');
  383. }
  384. }
  385. for(;isRight ? index >= 0 : length > index; index += i)if(index in self){
  386. memo = callbackfn(memo, self[index], index, O);
  387. }
  388. return memo;
  389. };
  390. },{"./_a-function":11,"./_iobject":31,"./_to-length":48,"./_to-object":49}],16:[function(_dereq_,module,exports){
  391. var isObject = _dereq_('./_is-object')
  392. , isArray = _dereq_('./_is-array')
  393. , SPECIES = _dereq_('./_wks')('species');
  394. module.exports = function(original){
  395. var C;
  396. if(isArray(original)){
  397. C = original.constructor;
  398. // cross-realm fallback
  399. if(typeof C == 'function' && (C === Array || isArray(C.prototype)))C = undefined;
  400. if(isObject(C)){
  401. C = C[SPECIES];
  402. if(C === null)C = undefined;
  403. }
  404. } return C === undefined ? Array : C;
  405. };
  406. },{"./_is-array":32,"./_is-object":33,"./_wks":52}],17:[function(_dereq_,module,exports){
  407. // 9.4.2.3 ArraySpeciesCreate(originalArray, length)
  408. var speciesConstructor = _dereq_('./_array-species-constructor');
  409. module.exports = function(original, length){
  410. return new (speciesConstructor(original))(length);
  411. };
  412. },{"./_array-species-constructor":16}],18:[function(_dereq_,module,exports){
  413. var toString = {}.toString;
  414. module.exports = function(it){
  415. return toString.call(it).slice(8, -1);
  416. };
  417. },{}],19:[function(_dereq_,module,exports){
  418. var core = module.exports = {version: '2.4.0'};
  419. if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef
  420. },{}],20:[function(_dereq_,module,exports){
  421. // optional / simple context binding
  422. var aFunction = _dereq_('./_a-function');
  423. module.exports = function(fn, that, length){
  424. aFunction(fn);
  425. if(that === undefined)return fn;
  426. switch(length){
  427. case 1: return function(a){
  428. return fn.call(that, a);
  429. };
  430. case 2: return function(a, b){
  431. return fn.call(that, a, b);
  432. };
  433. case 3: return function(a, b, c){
  434. return fn.call(that, a, b, c);
  435. };
  436. }
  437. return function(/* ...args */){
  438. return fn.apply(that, arguments);
  439. };
  440. };
  441. },{"./_a-function":11}],21:[function(_dereq_,module,exports){
  442. // 7.2.1 RequireObjectCoercible(argument)
  443. module.exports = function(it){
  444. if(it == undefined)throw TypeError("Can't call method on " + it);
  445. return it;
  446. };
  447. },{}],22:[function(_dereq_,module,exports){
  448. // Thank's IE8 for his funny defineProperty
  449. module.exports = !_dereq_('./_fails')(function(){
  450. return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7;
  451. });
  452. },{"./_fails":26}],23:[function(_dereq_,module,exports){
  453. var isObject = _dereq_('./_is-object')
  454. , document = _dereq_('./_global').document
  455. // in old IE typeof document.createElement is 'object'
  456. , is = isObject(document) && isObject(document.createElement);
  457. module.exports = function(it){
  458. return is ? document.createElement(it) : {};
  459. };
  460. },{"./_global":27,"./_is-object":33}],24:[function(_dereq_,module,exports){
  461. // IE 8- don't enum bug keys
  462. module.exports = (
  463. 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
  464. ).split(',');
  465. },{}],25:[function(_dereq_,module,exports){
  466. var global = _dereq_('./_global')
  467. , core = _dereq_('./_core')
  468. , ctx = _dereq_('./_ctx')
  469. , hide = _dereq_('./_hide')
  470. , PROTOTYPE = 'prototype';
  471. var $export = function(type, name, source){
  472. var IS_FORCED = type & $export.F
  473. , IS_GLOBAL = type & $export.G
  474. , IS_STATIC = type & $export.S
  475. , IS_PROTO = type & $export.P
  476. , IS_BIND = type & $export.B
  477. , IS_WRAP = type & $export.W
  478. , exports = IS_GLOBAL ? core : core[name] || (core[name] = {})
  479. , expProto = exports[PROTOTYPE]
  480. , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE]
  481. , key, own, out;
  482. if(IS_GLOBAL)source = name;
  483. for(key in source){
  484. // contains in native
  485. own = !IS_FORCED && target && target[key] !== undefined;
  486. if(own && key in exports)continue;
  487. // export native or passed
  488. out = own ? target[key] : source[key];
  489. // prevent global pollution for namespaces
  490. exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key]
  491. // bind timers to global for call from export context
  492. : IS_BIND && own ? ctx(out, global)
  493. // wrap global constructors for prevent change them in library
  494. : IS_WRAP && target[key] == out ? (function(C){
  495. var F = function(a, b, c){
  496. if(this instanceof C){
  497. switch(arguments.length){
  498. case 0: return new C;
  499. case 1: return new C(a);
  500. case 2: return new C(a, b);
  501. } return new C(a, b, c);
  502. } return C.apply(this, arguments);
  503. };
  504. F[PROTOTYPE] = C[PROTOTYPE];
  505. return F;
  506. // make static versions for prototype methods
  507. })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
  508. // export proto methods to core.%CONSTRUCTOR%.methods.%NAME%
  509. if(IS_PROTO){
  510. (exports.virtual || (exports.virtual = {}))[key] = out;
  511. // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME%
  512. if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out);
  513. }
  514. }
  515. };
  516. // type bitmap
  517. $export.F = 1; // forced
  518. $export.G = 2; // global
  519. $export.S = 4; // static
  520. $export.P = 8; // proto
  521. $export.B = 16; // bind
  522. $export.W = 32; // wrap
  523. $export.U = 64; // safe
  524. $export.R = 128; // real proto method for `library`
  525. module.exports = $export;
  526. },{"./_core":19,"./_ctx":20,"./_global":27,"./_hide":29}],26:[function(_dereq_,module,exports){
  527. module.exports = function(exec){
  528. try {
  529. return !!exec();
  530. } catch(e){
  531. return true;
  532. }
  533. };
  534. },{}],27:[function(_dereq_,module,exports){
  535. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  536. var global = module.exports = typeof window != 'undefined' && window.Math == Math
  537. ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
  538. if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef
  539. },{}],28:[function(_dereq_,module,exports){
  540. var hasOwnProperty = {}.hasOwnProperty;
  541. module.exports = function(it, key){
  542. return hasOwnProperty.call(it, key);
  543. };
  544. },{}],29:[function(_dereq_,module,exports){
  545. var dP = _dereq_('./_object-dp')
  546. , createDesc = _dereq_('./_property-desc');
  547. module.exports = _dereq_('./_descriptors') ? function(object, key, value){
  548. return dP.f(object, key, createDesc(1, value));
  549. } : function(object, key, value){
  550. object[key] = value;
  551. return object;
  552. };
  553. },{"./_descriptors":22,"./_object-dp":35,"./_property-desc":41}],30:[function(_dereq_,module,exports){
  554. module.exports = !_dereq_('./_descriptors') && !_dereq_('./_fails')(function(){
  555. return Object.defineProperty(_dereq_('./_dom-create')('div'), 'a', {get: function(){ return 7; }}).a != 7;
  556. });
  557. },{"./_descriptors":22,"./_dom-create":23,"./_fails":26}],31:[function(_dereq_,module,exports){
  558. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  559. var cof = _dereq_('./_cof');
  560. module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){
  561. return cof(it) == 'String' ? it.split('') : Object(it);
  562. };
  563. },{"./_cof":18}],32:[function(_dereq_,module,exports){
  564. // 7.2.2 IsArray(argument)
  565. var cof = _dereq_('./_cof');
  566. module.exports = Array.isArray || function isArray(arg){
  567. return cof(arg) == 'Array';
  568. };
  569. },{"./_cof":18}],33:[function(_dereq_,module,exports){
  570. module.exports = function(it){
  571. return typeof it === 'object' ? it !== null : typeof it === 'function';
  572. };
  573. },{}],34:[function(_dereq_,module,exports){
  574. 'use strict';
  575. // 19.1.2.1 Object.assign(target, source, ...)
  576. var getKeys = _dereq_('./_object-keys')
  577. , gOPS = _dereq_('./_object-gops')
  578. , pIE = _dereq_('./_object-pie')
  579. , toObject = _dereq_('./_to-object')
  580. , IObject = _dereq_('./_iobject')
  581. , $assign = Object.assign;
  582. // should work with symbols and should have deterministic property order (V8 bug)
  583. module.exports = !$assign || _dereq_('./_fails')(function(){
  584. var A = {}
  585. , B = {}
  586. , S = Symbol()
  587. , K = 'abcdefghijklmnopqrst';
  588. A[S] = 7;
  589. K.split('').forEach(function(k){ B[k] = k; });
  590. return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
  591. }) ? function assign(target, source){ // eslint-disable-line no-unused-vars
  592. var T = toObject(target)
  593. , aLen = arguments.length
  594. , index = 1
  595. , getSymbols = gOPS.f
  596. , isEnum = pIE.f;
  597. while(aLen > index){
  598. var S = IObject(arguments[index++])
  599. , keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S)
  600. , length = keys.length
  601. , j = 0
  602. , key;
  603. while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key];
  604. } return T;
  605. } : $assign;
  606. },{"./_fails":26,"./_iobject":31,"./_object-gops":36,"./_object-keys":38,"./_object-pie":39,"./_to-object":49}],35:[function(_dereq_,module,exports){
  607. var anObject = _dereq_('./_an-object')
  608. , IE8_DOM_DEFINE = _dereq_('./_ie8-dom-define')
  609. , toPrimitive = _dereq_('./_to-primitive')
  610. , dP = Object.defineProperty;
  611. exports.f = _dereq_('./_descriptors') ? Object.defineProperty : function defineProperty(O, P, Attributes){
  612. anObject(O);
  613. P = toPrimitive(P, true);
  614. anObject(Attributes);
  615. if(IE8_DOM_DEFINE)try {
  616. return dP(O, P, Attributes);
  617. } catch(e){ /* empty */ }
  618. if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!');
  619. if('value' in Attributes)O[P] = Attributes.value;
  620. return O;
  621. };
  622. },{"./_an-object":12,"./_descriptors":22,"./_ie8-dom-define":30,"./_to-primitive":50}],36:[function(_dereq_,module,exports){
  623. exports.f = Object.getOwnPropertySymbols;
  624. },{}],37:[function(_dereq_,module,exports){
  625. var has = _dereq_('./_has')
  626. , toIObject = _dereq_('./_to-iobject')
  627. , arrayIndexOf = _dereq_('./_array-includes')(false)
  628. , IE_PROTO = _dereq_('./_shared-key')('IE_PROTO');
  629. module.exports = function(object, names){
  630. var O = toIObject(object)
  631. , i = 0
  632. , result = []
  633. , key;
  634. for(key in O)if(key != IE_PROTO)has(O, key) && result.push(key);
  635. // Don't enum bug & hidden keys
  636. while(names.length > i)if(has(O, key = names[i++])){
  637. ~arrayIndexOf(result, key) || result.push(key);
  638. }
  639. return result;
  640. };
  641. },{"./_array-includes":13,"./_has":28,"./_shared-key":42,"./_to-iobject":47}],38:[function(_dereq_,module,exports){
  642. // 19.1.2.14 / 15.2.3.14 Object.keys(O)
  643. var $keys = _dereq_('./_object-keys-internal')
  644. , enumBugKeys = _dereq_('./_enum-bug-keys');
  645. module.exports = Object.keys || function keys(O){
  646. return $keys(O, enumBugKeys);
  647. };
  648. },{"./_enum-bug-keys":24,"./_object-keys-internal":37}],39:[function(_dereq_,module,exports){
  649. exports.f = {}.propertyIsEnumerable;
  650. },{}],40:[function(_dereq_,module,exports){
  651. // most Object methods by ES6 should accept primitives
  652. var $export = _dereq_('./_export')
  653. , core = _dereq_('./_core')
  654. , fails = _dereq_('./_fails');
  655. module.exports = function(KEY, exec){
  656. var fn = (core.Object || {})[KEY] || Object[KEY]
  657. , exp = {};
  658. exp[KEY] = exec(fn);
  659. $export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp);
  660. };
  661. },{"./_core":19,"./_export":25,"./_fails":26}],41:[function(_dereq_,module,exports){
  662. module.exports = function(bitmap, value){
  663. return {
  664. enumerable : !(bitmap & 1),
  665. configurable: !(bitmap & 2),
  666. writable : !(bitmap & 4),
  667. value : value
  668. };
  669. };
  670. },{}],42:[function(_dereq_,module,exports){
  671. var shared = _dereq_('./_shared')('keys')
  672. , uid = _dereq_('./_uid');
  673. module.exports = function(key){
  674. return shared[key] || (shared[key] = uid(key));
  675. };
  676. },{"./_shared":43,"./_uid":51}],43:[function(_dereq_,module,exports){
  677. var global = _dereq_('./_global')
  678. , SHARED = '__core-js_shared__'
  679. , store = global[SHARED] || (global[SHARED] = {});
  680. module.exports = function(key){
  681. return store[key] || (store[key] = {});
  682. };
  683. },{"./_global":27}],44:[function(_dereq_,module,exports){
  684. var fails = _dereq_('./_fails');
  685. module.exports = function(method, arg){
  686. return !!method && fails(function(){
  687. arg ? method.call(null, function(){}, 1) : method.call(null);
  688. });
  689. };
  690. },{"./_fails":26}],45:[function(_dereq_,module,exports){
  691. var toInteger = _dereq_('./_to-integer')
  692. , max = Math.max
  693. , min = Math.min;
  694. module.exports = function(index, length){
  695. index = toInteger(index);
  696. return index < 0 ? max(index + length, 0) : min(index, length);
  697. };
  698. },{"./_to-integer":46}],46:[function(_dereq_,module,exports){
  699. // 7.1.4 ToInteger
  700. var ceil = Math.ceil
  701. , floor = Math.floor;
  702. module.exports = function(it){
  703. return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
  704. };
  705. },{}],47:[function(_dereq_,module,exports){
  706. // to indexed object, toObject with fallback for non-array-like ES3 strings
  707. var IObject = _dereq_('./_iobject')
  708. , defined = _dereq_('./_defined');
  709. module.exports = function(it){
  710. return IObject(defined(it));
  711. };
  712. },{"./_defined":21,"./_iobject":31}],48:[function(_dereq_,module,exports){
  713. // 7.1.15 ToLength
  714. var toInteger = _dereq_('./_to-integer')
  715. , min = Math.min;
  716. module.exports = function(it){
  717. return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
  718. };
  719. },{"./_to-integer":46}],49:[function(_dereq_,module,exports){
  720. // 7.1.13 ToObject(argument)
  721. var defined = _dereq_('./_defined');
  722. module.exports = function(it){
  723. return Object(defined(it));
  724. };
  725. },{"./_defined":21}],50:[function(_dereq_,module,exports){
  726. // 7.1.1 ToPrimitive(input [, PreferredType])
  727. var isObject = _dereq_('./_is-object');
  728. // instead of the ES6 spec version, we didn't implement @@toPrimitive case
  729. // and the second argument - flag - preferred type is a string
  730. module.exports = function(it, S){
  731. if(!isObject(it))return it;
  732. var fn, val;
  733. if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val;
  734. if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val;
  735. if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val;
  736. throw TypeError("Can't convert object to primitive value");
  737. };
  738. },{"./_is-object":33}],51:[function(_dereq_,module,exports){
  739. var id = 0
  740. , px = Math.random();
  741. module.exports = function(key){
  742. return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
  743. };
  744. },{}],52:[function(_dereq_,module,exports){
  745. var store = _dereq_('./_shared')('wks')
  746. , uid = _dereq_('./_uid')
  747. , Symbol = _dereq_('./_global').Symbol
  748. , USE_SYMBOL = typeof Symbol == 'function';
  749. var $exports = module.exports = function(name){
  750. return store[name] || (store[name] =
  751. USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : uid)('Symbol.' + name));
  752. };
  753. $exports.store = store;
  754. },{"./_global":27,"./_shared":43,"./_uid":51}],53:[function(_dereq_,module,exports){
  755. 'use strict';
  756. var $export = _dereq_('./_export')
  757. , $filter = _dereq_('./_array-methods')(2);
  758. $export($export.P + $export.F * !_dereq_('./_strict-method')([].filter, true), 'Array', {
  759. // 22.1.3.7 / 15.4.4.20 Array.prototype.filter(callbackfn [, thisArg])
  760. filter: function filter(callbackfn /* , thisArg */){
  761. return $filter(this, callbackfn, arguments[1]);
  762. }
  763. });
  764. },{"./_array-methods":14,"./_export":25,"./_strict-method":44}],54:[function(_dereq_,module,exports){
  765. 'use strict';
  766. var $export = _dereq_('./_export')
  767. , $forEach = _dereq_('./_array-methods')(0)
  768. , STRICT = _dereq_('./_strict-method')([].forEach, true);
  769. $export($export.P + $export.F * !STRICT, 'Array', {
  770. // 22.1.3.10 / 15.4.4.18 Array.prototype.forEach(callbackfn [, thisArg])
  771. forEach: function forEach(callbackfn /* , thisArg */){
  772. return $forEach(this, callbackfn, arguments[1]);
  773. }
  774. });
  775. },{"./_array-methods":14,"./_export":25,"./_strict-method":44}],55:[function(_dereq_,module,exports){
  776. 'use strict';
  777. var $export = _dereq_('./_export')
  778. , $indexOf = _dereq_('./_array-includes')(false)
  779. , $native = [].indexOf
  780. , NEGATIVE_ZERO = !!$native && 1 / [1].indexOf(1, -0) < 0;
  781. $export($export.P + $export.F * (NEGATIVE_ZERO || !_dereq_('./_strict-method')($native)), 'Array', {
  782. // 22.1.3.11 / 15.4.4.14 Array.prototype.indexOf(searchElement [, fromIndex])
  783. indexOf: function indexOf(searchElement /*, fromIndex = 0 */){
  784. return NEGATIVE_ZERO
  785. // convert -0 to +0
  786. ? $native.apply(this, arguments) || 0
  787. : $indexOf(this, searchElement, arguments[1]);
  788. }
  789. });
  790. },{"./_array-includes":13,"./_export":25,"./_strict-method":44}],56:[function(_dereq_,module,exports){
  791. // 22.1.2.2 / 15.4.3.2 Array.isArray(arg)
  792. var $export = _dereq_('./_export');
  793. $export($export.S, 'Array', {isArray: _dereq_('./_is-array')});
  794. },{"./_export":25,"./_is-array":32}],57:[function(_dereq_,module,exports){
  795. 'use strict';
  796. var $export = _dereq_('./_export')
  797. , $map = _dereq_('./_array-methods')(1);
  798. $export($export.P + $export.F * !_dereq_('./_strict-method')([].map, true), 'Array', {
  799. // 22.1.3.15 / 15.4.4.19 Array.prototype.map(callbackfn [, thisArg])
  800. map: function map(callbackfn /* , thisArg */){
  801. return $map(this, callbackfn, arguments[1]);
  802. }
  803. });
  804. },{"./_array-methods":14,"./_export":25,"./_strict-method":44}],58:[function(_dereq_,module,exports){
  805. 'use strict';
  806. var $export = _dereq_('./_export')
  807. , $reduce = _dereq_('./_array-reduce');
  808. $export($export.P + $export.F * !_dereq_('./_strict-method')([].reduce, true), 'Array', {
  809. // 22.1.3.18 / 15.4.4.21 Array.prototype.reduce(callbackfn [, initialValue])
  810. reduce: function reduce(callbackfn /* , initialValue */){
  811. return $reduce(this, callbackfn, arguments.length, arguments[1], false);
  812. }
  813. });
  814. },{"./_array-reduce":15,"./_export":25,"./_strict-method":44}],59:[function(_dereq_,module,exports){
  815. // 19.1.3.1 Object.assign(target, source)
  816. var $export = _dereq_('./_export');
  817. $export($export.S + $export.F, 'Object', {assign: _dereq_('./_object-assign')});
  818. },{"./_export":25,"./_object-assign":34}],60:[function(_dereq_,module,exports){
  819. // 19.1.2.14 Object.keys(O)
  820. var toObject = _dereq_('./_to-object')
  821. , $keys = _dereq_('./_object-keys');
  822. _dereq_('./_object-sap')('keys', function(){
  823. return function keys(it){
  824. return $keys(toObject(it));
  825. };
  826. });
  827. },{"./_object-keys":38,"./_object-sap":40,"./_to-object":49}],61:[function(_dereq_,module,exports){
  828. var pSlice = Array.prototype.slice;
  829. var objectKeys = _dereq_('./lib/keys.js');
  830. var isArguments = _dereq_('./lib/is_arguments.js');
  831. var deepEqual = module.exports = function (actual, expected, opts) {
  832. if (!opts) opts = {};
  833. // 7.1. All identical values are equivalent, as determined by ===.
  834. if (actual === expected) {
  835. return true;
  836. } else if (actual instanceof Date && expected instanceof Date) {
  837. return actual.getTime() === expected.getTime();
  838. // 7.3. Other pairs that do not both pass typeof value == 'object',
  839. // equivalence is determined by ==.
  840. } else if (!actual || !expected || typeof actual != 'object' && typeof expected != 'object') {
  841. return opts.strict ? actual === expected : actual == expected;
  842. // 7.4. For all other Object pairs, including Array objects, equivalence is
  843. // determined by having the same number of owned properties (as verified
  844. // with Object.prototype.hasOwnProperty.call), the same set of keys
  845. // (although not necessarily the same order), equivalent values for every
  846. // corresponding key, and an identical 'prototype' property. Note: this
  847. // accounts for both named and indexed properties on Arrays.
  848. } else {
  849. return objEquiv(actual, expected, opts);
  850. }
  851. }
  852. function isUndefinedOrNull(value) {
  853. return value === null || value === undefined;
  854. }
  855. function isBuffer (x) {
  856. if (!x || typeof x !== 'object' || typeof x.length !== 'number') return false;
  857. if (typeof x.copy !== 'function' || typeof x.slice !== 'function') {
  858. return false;
  859. }
  860. if (x.length > 0 && typeof x[0] !== 'number') return false;
  861. return true;
  862. }
  863. function objEquiv(a, b, opts) {
  864. var i, key;
  865. if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
  866. return false;
  867. // an identical 'prototype' property.
  868. if (a.prototype !== b.prototype) return false;
  869. //~~~I've managed to break Object.keys through screwy arguments passing.
  870. // Converting to array solves the problem.
  871. if (isArguments(a)) {
  872. if (!isArguments(b)) {
  873. return false;
  874. }
  875. a = pSlice.call(a);
  876. b = pSlice.call(b);
  877. return deepEqual(a, b, opts);
  878. }
  879. if (isBuffer(a)) {
  880. if (!isBuffer(b)) {
  881. return false;
  882. }
  883. if (a.length !== b.length) return false;
  884. for (i = 0; i < a.length; i++) {
  885. if (a[i] !== b[i]) return false;
  886. }
  887. return true;
  888. }
  889. try {
  890. var ka = objectKeys(a),
  891. kb = objectKeys(b);
  892. } catch (e) {//happens when one is a string literal and the other isn't
  893. return false;
  894. }
  895. // having the same number of owned properties (keys incorporates
  896. // hasOwnProperty)
  897. if (ka.length != kb.length)
  898. return false;
  899. //the same set of keys (although not necessarily the same order),
  900. ka.sort();
  901. kb.sort();
  902. //~~~cheap key test
  903. for (i = ka.length - 1; i >= 0; i--) {
  904. if (ka[i] != kb[i])
  905. return false;
  906. }
  907. //equivalent values for every corresponding key, and
  908. //~~~possibly expensive deep test
  909. for (i = ka.length - 1; i >= 0; i--) {
  910. key = ka[i];
  911. if (!deepEqual(a[key], b[key], opts)) return false;
  912. }
  913. return typeof a === typeof b;
  914. }
  915. },{"./lib/is_arguments.js":62,"./lib/keys.js":63}],62:[function(_dereq_,module,exports){
  916. var supportsArgumentsClass = (function(){
  917. return Object.prototype.toString.call(arguments)
  918. })() == '[object Arguments]';
  919. exports = module.exports = supportsArgumentsClass ? supported : unsupported;
  920. exports.supported = supported;
  921. function supported(object) {
  922. return Object.prototype.toString.call(object) == '[object Arguments]';
  923. };
  924. exports.unsupported = unsupported;
  925. function unsupported(object){
  926. return object &&
  927. typeof object == 'object' &&
  928. typeof object.length == 'number' &&
  929. Object.prototype.hasOwnProperty.call(object, 'callee') &&
  930. !Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
  931. false;
  932. };
  933. },{}],63:[function(_dereq_,module,exports){
  934. exports = module.exports = typeof Object.keys === 'function'
  935. ? Object.keys : shim;
  936. exports.shim = shim;
  937. function shim (obj) {
  938. var keys = [];
  939. for (var key in obj) keys.push(key);
  940. return keys;
  941. }
  942. },{}],64:[function(_dereq_,module,exports){
  943. /*
  944. Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
  945. Redistribution and use in source and binary forms, with or without
  946. modification, are permitted provided that the following conditions are met:
  947. * Redistributions of source code must retain the above copyright
  948. notice, this list of conditions and the following disclaimer.
  949. * Redistributions in binary form must reproduce the above copyright
  950. notice, this list of conditions and the following disclaimer in the
  951. documentation and/or other materials provided with the distribution.
  952. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  953. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  954. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  955. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  956. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  957. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  958. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  959. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  960. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  961. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  962. */
  963. (function (root, factory) {
  964. 'use strict';
  965. // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
  966. // Rhino, and plain browser loading.
  967. /* istanbul ignore next */
  968. if (typeof define === 'function' && define.amd) {
  969. define(['exports'], factory);
  970. } else if (typeof exports !== 'undefined') {
  971. factory(exports);
  972. } else {
  973. factory((root.esprima = {}));
  974. }
  975. }(this, function (exports) {
  976. 'use strict';
  977. var Token,
  978. TokenName,
  979. FnExprTokens,
  980. Syntax,
  981. PlaceHolders,
  982. Messages,
  983. Regex,
  984. source,
  985. strict,
  986. index,
  987. lineNumber,
  988. lineStart,
  989. hasLineTerminator,
  990. lastIndex,
  991. lastLineNumber,
  992. lastLineStart,
  993. startIndex,
  994. startLineNumber,
  995. startLineStart,
  996. scanning,
  997. length,
  998. lookahead,
  999. state,
  1000. extra,
  1001. isBindingElement,
  1002. isAssignmentTarget,
  1003. firstCoverInitializedNameError;
  1004. Token = {
  1005. BooleanLiteral: 1,
  1006. EOF: 2,
  1007. Identifier: 3,
  1008. Keyword: 4,
  1009. NullLiteral: 5,
  1010. NumericLiteral: 6,
  1011. Punctuator: 7,
  1012. StringLiteral: 8,
  1013. RegularExpression: 9,
  1014. Template: 10
  1015. };
  1016. TokenName = {};
  1017. TokenName[Token.BooleanLiteral] = 'Boolean';
  1018. TokenName[Token.EOF] = '<end>';
  1019. TokenName[Token.Identifier] = 'Identifier';
  1020. TokenName[Token.Keyword] = 'Keyword';
  1021. TokenName[Token.NullLiteral] = 'Null';
  1022. TokenName[Token.NumericLiteral] = 'Numeric';
  1023. TokenName[Token.Punctuator] = 'Punctuator';
  1024. TokenName[Token.StringLiteral] = 'String';
  1025. TokenName[Token.RegularExpression] = 'RegularExpression';
  1026. TokenName[Token.Template] = 'Template';
  1027. // A function following one of those tokens is an expression.
  1028. FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
  1029. 'return', 'case', 'delete', 'throw', 'void',
  1030. // assignment operators
  1031. '=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',
  1032. '&=', '|=', '^=', ',',
  1033. // binary/unary operators
  1034. '+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
  1035. '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
  1036. '<=', '<', '>', '!=', '!=='];
  1037. Syntax = {
  1038. AssignmentExpression: 'AssignmentExpression',
  1039. AssignmentPattern: 'AssignmentPattern',
  1040. ArrayExpression: 'ArrayExpression',
  1041. ArrayPattern: 'ArrayPattern',
  1042. ArrowFunctionExpression: 'ArrowFunctionExpression',
  1043. BlockStatement: 'BlockStatement',
  1044. BinaryExpression: 'BinaryExpression',
  1045. BreakStatement: 'BreakStatement',
  1046. CallExpression: 'CallExpression',
  1047. CatchClause: 'CatchClause',
  1048. ClassBody: 'ClassBody',
  1049. ClassDeclaration: 'ClassDeclaration',
  1050. ClassExpression: 'ClassExpression',
  1051. ConditionalExpression: 'ConditionalExpression',
  1052. ContinueStatement: 'ContinueStatement',
  1053. DoWhileStatement: 'DoWhileStatement',
  1054. DebuggerStatement: 'DebuggerStatement',
  1055. EmptyStatement: 'EmptyStatement',
  1056. ExportAllDeclaration: 'ExportAllDeclaration',
  1057. ExportDefaultDeclaration: 'ExportDefaultDeclaration',
  1058. ExportNamedDeclaration: 'ExportNamedDeclaration',
  1059. ExportSpecifier: 'ExportSpecifier',
  1060. ExpressionStatement: 'ExpressionStatement',
  1061. ForStatement: 'ForStatement',
  1062. ForOfStatement: 'ForOfStatement',
  1063. ForInStatement: 'ForInStatement',
  1064. FunctionDeclaration: 'FunctionDeclaration',
  1065. FunctionExpression: 'FunctionExpression',
  1066. Identifier: 'Identifier',
  1067. IfStatement: 'IfStatement',
  1068. ImportDeclaration: 'ImportDeclaration',
  1069. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  1070. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  1071. ImportSpecifier: 'ImportSpecifier',
  1072. Literal: 'Literal',
  1073. LabeledStatement: 'LabeledStatement',
  1074. LogicalExpression: 'LogicalExpression',
  1075. MemberExpression: 'MemberExpression',
  1076. MetaProperty: 'MetaProperty',
  1077. MethodDefinition: 'MethodDefinition',
  1078. NewExpression: 'NewExpression',
  1079. ObjectExpression: 'ObjectExpression',
  1080. ObjectPattern: 'ObjectPattern',
  1081. Program: 'Program',
  1082. Property: 'Property',
  1083. RestElement: 'RestElement',
  1084. ReturnStatement: 'ReturnStatement',
  1085. SequenceExpression: 'SequenceExpression',
  1086. SpreadElement: 'SpreadElement',
  1087. Super: 'Super',
  1088. SwitchCase: 'SwitchCase',
  1089. SwitchStatement: 'SwitchStatement',
  1090. TaggedTemplateExpression: 'TaggedTemplateExpression',
  1091. TemplateElement: 'TemplateElement',
  1092. TemplateLiteral: 'TemplateLiteral',
  1093. ThisExpression: 'ThisExpression',
  1094. ThrowStatement: 'ThrowStatement',
  1095. TryStatement: 'TryStatement',
  1096. UnaryExpression: 'UnaryExpression',
  1097. UpdateExpression: 'UpdateExpression',
  1098. VariableDeclaration: 'VariableDeclaration',
  1099. VariableDeclarator: 'VariableDeclarator',
  1100. WhileStatement: 'WhileStatement',
  1101. WithStatement: 'WithStatement',
  1102. YieldExpression: 'YieldExpression'
  1103. };
  1104. PlaceHolders = {
  1105. ArrowParameterPlaceHolder: 'ArrowParameterPlaceHolder'
  1106. };
  1107. // Error messages should be identical to V8.
  1108. Messages = {
  1109. UnexpectedToken: 'Unexpected token %0',
  1110. UnexpectedNumber: 'Unexpected number',
  1111. UnexpectedString: 'Unexpected string',
  1112. UnexpectedIdentifier: 'Unexpected identifier',
  1113. UnexpectedReserved: 'Unexpected reserved word',
  1114. UnexpectedTemplate: 'Unexpected quasi %0',
  1115. UnexpectedEOS: 'Unexpected end of input',
  1116. NewlineAfterThrow: 'Illegal newline after throw',
  1117. InvalidRegExp: 'Invalid regular expression',
  1118. UnterminatedRegExp: 'Invalid regular expression: missing /',
  1119. InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
  1120. InvalidLHSInForIn: 'Invalid left-hand side in for-in',
  1121. InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
  1122. MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
  1123. NoCatchOrFinally: 'Missing catch or finally after try',
  1124. UnknownLabel: 'Undefined label \'%0\'',
  1125. Redeclaration: '%0 \'%1\' has already been declared',
  1126. IllegalContinue: 'Illegal continue statement',
  1127. IllegalBreak: 'Illegal break statement',
  1128. IllegalReturn: 'Illegal return statement',
  1129. StrictModeWith: 'Strict mode code may not include a with statement',
  1130. StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
  1131. StrictVarName: 'Variable name may not be eval or arguments in strict mode',
  1132. StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
  1133. StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
  1134. StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
  1135. StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
  1136. StrictDelete: 'Delete of an unqualified identifier in strict mode.',
  1137. StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
  1138. StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
  1139. StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
  1140. StrictReservedWord: 'Use of future reserved word in strict mode',
  1141. TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
  1142. ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
  1143. DefaultRestParameter: 'Unexpected token =',
  1144. ObjectPatternAsRestParameter: 'Unexpected token {',
  1145. DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
  1146. ConstructorSpecialMethod: 'Class constructor may not be an accessor',
  1147. DuplicateConstructor: 'A class may only have one constructor',
  1148. StaticPrototype: 'Classes may not have static property named prototype',
  1149. MissingFromClause: 'Unexpected token',
  1150. NoAsAfterImportNamespace: 'Unexpected token',
  1151. InvalidModuleSpecifier: 'Unexpected token',
  1152. IllegalImportDeclaration: 'Unexpected token',
  1153. IllegalExportDeclaration: 'Unexpected token',
  1154. DuplicateBinding: 'Duplicate binding %0'
  1155. };
  1156. // See also tools/generate-unicode-regex.js.
  1157. Regex = {
  1158. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierStart:
  1159. NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\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\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\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-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\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-\uAB5F\uAB64\uAB65\uABC0-\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]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDE00-\uDE11\uDE13-\uDE2B\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDE00-\uDE2F\uDE44\uDE80-\uDEAA]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF98]|\uD809[\uDC00-\uDC6E]|[\uD80C\uD840-\uD868\uD86A-\uD86C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D]|\uD87E[\uDC00-\uDE1D]/,
  1160. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierPart:
  1161. NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B2\u08E4-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\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\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\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\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\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-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDD0-\uDDDA\uDE00-\uDE11\uDE13-\uDE37\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF01-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF98]|\uD809[\uDC00-\uDC6E]|[\uD80C\uD840-\uD868\uD86A-\uD86C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
  1162. };
  1163. // Ensure the condition is true, otherwise throw an error.
  1164. // This is only to have a better contract semantic, i.e. another safety net
  1165. // to catch a logic error. The condition shall be fulfilled in normal case.
  1166. // Do NOT use this to enforce a certain condition on any user input.
  1167. function assert(condition, message) {
  1168. /* istanbul ignore if */
  1169. if (!condition) {
  1170. throw new Error('ASSERT: ' + message);
  1171. }
  1172. }
  1173. function isDecimalDigit(ch) {
  1174. return (ch >= 0x30 && ch <= 0x39); // 0..9
  1175. }
  1176. function isHexDigit(ch) {
  1177. return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;
  1178. }
  1179. function isOctalDigit(ch) {
  1180. return '01234567'.indexOf(ch) >= 0;
  1181. }
  1182. function octalToDecimal(ch) {
  1183. // \0 is not octal escape sequence
  1184. var octal = (ch !== '0'), code = '01234567'.indexOf(ch);
  1185. if (index < length && isOctalDigit(source[index])) {
  1186. octal = true;
  1187. code = code * 8 + '01234567'.indexOf(source[index++]);
  1188. // 3 digits are only allowed when string starts
  1189. // with 0, 1, 2, 3
  1190. if ('0123'.indexOf(ch) >= 0 &&
  1191. index < length &&
  1192. isOctalDigit(source[index])) {
  1193. code = code * 8 + '01234567'.indexOf(source[index++]);
  1194. }
  1195. }
  1196. return {
  1197. code: code,
  1198. octal: octal
  1199. };
  1200. }
  1201. // ECMA-262 11.2 White Space
  1202. function isWhiteSpace(ch) {
  1203. return (ch === 0x20) || (ch === 0x09) || (ch === 0x0B) || (ch === 0x0C) || (ch === 0xA0) ||
  1204. (ch >= 0x1680 && [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(ch) >= 0);
  1205. }
  1206. // ECMA-262 11.3 Line Terminators
  1207. function isLineTerminator(ch) {
  1208. return (ch === 0x0A) || (ch === 0x0D) || (ch === 0x2028) || (ch === 0x2029);
  1209. }
  1210. // ECMA-262 11.6 Identifier Names and Identifiers
  1211. function fromCodePoint(cp) {
  1212. return (cp < 0x10000) ? String.fromCharCode(cp) :
  1213. String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) +
  1214. String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023));
  1215. }
  1216. function isIdentifierStart(ch) {
  1217. return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)
  1218. (ch >= 0x41 && ch <= 0x5A) || // A..Z
  1219. (ch >= 0x61 && ch <= 0x7A) || // a..z
  1220. (ch === 0x5C) || // \ (backslash)
  1221. ((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch)));
  1222. }
  1223. function isIdentifierPart(ch) {
  1224. return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)
  1225. (ch >= 0x41 && ch <= 0x5A) || // A..Z
  1226. (ch >= 0x61 && ch <= 0x7A) || // a..z
  1227. (ch >= 0x30 && ch <= 0x39) || // 0..9
  1228. (ch === 0x5C) || // \ (backslash)
  1229. ((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch)));
  1230. }
  1231. // ECMA-262 11.6.2.2 Future Reserved Words
  1232. function isFutureReservedWord(id) {
  1233. switch (id) {
  1234. case 'enum':
  1235. case 'export':
  1236. case 'import':
  1237. case 'super':
  1238. return true;
  1239. default:
  1240. return false;
  1241. }
  1242. }
  1243. function isStrictModeReservedWord(id) {
  1244. switch (id) {
  1245. case 'implements':
  1246. case 'interface':
  1247. case 'package':
  1248. case 'private':
  1249. case 'protected':
  1250. case 'public':
  1251. case 'static':
  1252. case 'yield':
  1253. case 'let':
  1254. return true;
  1255. default:
  1256. return false;
  1257. }
  1258. }
  1259. function isRestrictedWord(id) {
  1260. return id === 'eval' || id === 'arguments';
  1261. }
  1262. // ECMA-262 11.6.2.1 Keywords
  1263. function isKeyword(id) {
  1264. switch (id.length) {
  1265. case 2:
  1266. return (id === 'if') || (id === 'in') || (id === 'do');
  1267. case 3:
  1268. return (id === 'var') || (id === 'for') || (id === 'new') ||
  1269. (id === 'try') || (id === 'let');
  1270. case 4:
  1271. return (id === 'this') || (id === 'else') || (id === 'case') ||
  1272. (id === 'void') || (id === 'with') || (id === 'enum');
  1273. case 5:
  1274. return (id === 'while') || (id === 'break') || (id === 'catch') ||
  1275. (id === 'throw') || (id === 'const') || (id === 'yield') ||
  1276. (id === 'class') || (id === 'super');
  1277. case 6:
  1278. return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
  1279. (id === 'switch') || (id === 'export') || (id === 'import');
  1280. case 7:
  1281. return (id === 'default') || (id === 'finally') || (id === 'extends');
  1282. case 8:
  1283. return (id === 'function') || (id === 'continue') || (id === 'debugger');
  1284. case 10:
  1285. return (id === 'instanceof');
  1286. default:
  1287. return false;
  1288. }
  1289. }
  1290. // ECMA-262 11.4 Comments
  1291. function addComment(type, value, start, end, loc) {
  1292. var comment;
  1293. assert(typeof start === 'number', 'Comment must have valid position');
  1294. state.lastCommentStart = start;
  1295. comment = {
  1296. type: type,
  1297. value: value
  1298. };
  1299. if (extra.range) {
  1300. comment.range = [start, end];
  1301. }
  1302. if (extra.loc) {
  1303. comment.loc = loc;
  1304. }
  1305. extra.comments.push(comment);
  1306. if (extra.attachComment) {
  1307. extra.leadingComments.push(comment);
  1308. extra.trailingComments.push(comment);
  1309. }
  1310. if (extra.tokenize) {
  1311. comment.type = comment.type + 'Comment';
  1312. if (extra.delegate) {
  1313. comment = extra.delegate(comment);
  1314. }
  1315. extra.tokens.push(comment);
  1316. }
  1317. }
  1318. function skipSingleLineComment(offset) {
  1319. var start, loc, ch, comment;
  1320. start = index - offset;
  1321. loc = {
  1322. start: {
  1323. line: lineNumber,
  1324. column: index - lineStart - offset
  1325. }
  1326. };
  1327. while (index < length) {
  1328. ch = source.charCodeAt(index);
  1329. ++index;
  1330. if (isLineTerminator(ch)) {
  1331. hasLineTerminator = true;
  1332. if (extra.comments) {
  1333. comment = source.slice(start + offset, index - 1);
  1334. loc.end = {
  1335. line: lineNumber,
  1336. column: index - lineStart - 1
  1337. };
  1338. addComment('Line', comment, start, index - 1, loc);
  1339. }
  1340. if (ch === 13 && source.charCodeAt(index) === 10) {
  1341. ++index;
  1342. }
  1343. ++lineNumber;
  1344. lineStart = index;
  1345. return;
  1346. }
  1347. }
  1348. if (extra.comments) {
  1349. comment = source.slice(start + offset, index);
  1350. loc.end = {
  1351. line: lineNumber,
  1352. column: index - lineStart
  1353. };
  1354. addComment('Line', comment, start, index, loc);
  1355. }
  1356. }
  1357. function skipMultiLineComment() {
  1358. var start, loc, ch, comment;
  1359. if (extra.comments) {
  1360. start = index - 2;
  1361. loc = {
  1362. start: {
  1363. line: lineNumber,
  1364. column: index - lineStart - 2
  1365. }
  1366. };
  1367. }
  1368. while (index < length) {
  1369. ch = source.charCodeAt(index);
  1370. if (isLineTerminator(ch)) {
  1371. if (ch === 0x0D && source.charCodeAt(index + 1) === 0x0A) {
  1372. ++index;
  1373. }
  1374. hasLineTerminator = true;
  1375. ++lineNumber;
  1376. ++index;
  1377. lineStart = index;
  1378. } else if (ch === 0x2A) {
  1379. // Block comment ends with '*/'.
  1380. if (source.charCodeAt(index + 1) === 0x2F) {
  1381. ++index;
  1382. ++index;
  1383. if (extra.comments) {
  1384. comment = source.slice(start + 2, index - 2);
  1385. loc.end = {
  1386. line: lineNumber,
  1387. column: index - lineStart
  1388. };
  1389. addComment('Block', comment, start, index, loc);
  1390. }
  1391. return;
  1392. }
  1393. ++index;
  1394. } else {
  1395. ++index;
  1396. }
  1397. }
  1398. // Ran off the end of the file - the whole thing is a comment
  1399. if (extra.comments) {
  1400. loc.end = {
  1401. line: lineNumber,
  1402. column: index - lineStart
  1403. };
  1404. comment = source.slice(start + 2, index);
  1405. addComment('Block', comment, start, index, loc);
  1406. }
  1407. tolerateUnexpectedToken();
  1408. }
  1409. function skipComment() {
  1410. var ch, start;
  1411. hasLineTerminator = false;
  1412. start = (index === 0);
  1413. while (index < length) {
  1414. ch = source.charCodeAt(index);
  1415. if (isWhiteSpace(ch)) {
  1416. ++index;
  1417. } else if (isLineTerminator(ch)) {
  1418. hasLineTerminator = true;
  1419. ++index;
  1420. if (ch === 0x0D && source.charCodeAt(index) === 0x0A) {
  1421. ++index;
  1422. }
  1423. ++lineNumber;
  1424. lineStart = index;
  1425. start = true;
  1426. } else if (ch === 0x2F) { // U+002F is '/'
  1427. ch = source.charCodeAt(index + 1);
  1428. if (ch === 0x2F) {
  1429. ++index;
  1430. ++index;
  1431. skipSingleLineComment(2);
  1432. start = true;
  1433. } else if (ch === 0x2A) { // U+002A is '*'
  1434. ++index;
  1435. ++index;
  1436. skipMultiLineComment();
  1437. } else {
  1438. break;
  1439. }
  1440. } else if (start && ch === 0x2D) { // U+002D is '-'
  1441. // U+003E is '>'
  1442. if ((source.charCodeAt(index + 1) === 0x2D) && (source.charCodeAt(index + 2) === 0x3E)) {
  1443. // '-->' is a single-line comment
  1444. index += 3;
  1445. skipSingleLineComment(3);
  1446. } else {
  1447. break;
  1448. }
  1449. } else if (ch === 0x3C) { // U+003C is '<'
  1450. if (source.slice(index + 1, index + 4) === '!--') {
  1451. ++index; // `<`
  1452. ++index; // `!`
  1453. ++index; // `-`
  1454. ++index; // `-`
  1455. skipSingleLineComment(4);
  1456. } else {
  1457. break;
  1458. }
  1459. } else {
  1460. break;
  1461. }
  1462. }
  1463. }
  1464. function scanHexEscape(prefix) {
  1465. var i, len, ch, code = 0;
  1466. len = (prefix === 'u') ? 4 : 2;
  1467. for (i = 0; i < len; ++i) {
  1468. if (index < length && isHexDigit(source[index])) {
  1469. ch = source[index++];
  1470. code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
  1471. } else {
  1472. return '';
  1473. }
  1474. }
  1475. return String.fromCharCode(code);
  1476. }
  1477. function scanUnicodeCodePointEscape() {
  1478. var ch, code;
  1479. ch = source[index];
  1480. code = 0;
  1481. // At least, one hex digit is required.
  1482. if (ch === '}') {
  1483. throwUnexpectedToken();
  1484. }
  1485. while (index < length) {
  1486. ch = source[index++];
  1487. if (!isHexDigit(ch)) {
  1488. break;
  1489. }
  1490. code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
  1491. }
  1492. if (code > 0x10FFFF || ch !== '}') {
  1493. throwUnexpectedToken();
  1494. }
  1495. return fromCodePoint(code);
  1496. }
  1497. function codePointAt(i) {
  1498. var cp, first, second;
  1499. cp = source.charCodeAt(i);
  1500. if (cp >= 0xD800 && cp <= 0xDBFF) {
  1501. second = source.charCodeAt(i + 1);
  1502. if (second >= 0xDC00 && second <= 0xDFFF) {
  1503. first = cp;
  1504. cp = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  1505. }
  1506. }
  1507. return cp;
  1508. }
  1509. function getComplexIdentifier() {
  1510. var cp, ch, id;
  1511. cp = codePointAt(index);
  1512. id = fromCodePoint(cp);
  1513. index += id.length;
  1514. // '\u' (U+005C, U+0075) denotes an escaped character.
  1515. if (cp === 0x5C) {
  1516. if (source.charCodeAt(index) !== 0x75) {
  1517. throwUnexpectedToken();
  1518. }
  1519. ++index;
  1520. if (source[index] === '{') {
  1521. ++index;
  1522. ch = scanUnicodeCodePointEscape();
  1523. } else {
  1524. ch = scanHexEscape('u');
  1525. cp = ch.charCodeAt(0);
  1526. if (!ch || ch === '\\' || !isIdentifierStart(cp)) {
  1527. throwUnexpectedToken();
  1528. }
  1529. }
  1530. id = ch;
  1531. }
  1532. while (index < length) {
  1533. cp = codePointAt(index);
  1534. if (!isIdentifierPart(cp)) {
  1535. break;
  1536. }
  1537. ch = fromCodePoint(cp);
  1538. id += ch;
  1539. index += ch.length;
  1540. // '\u' (U+005C, U+0075) denotes an escaped character.
  1541. if (cp === 0x5C) {
  1542. id = id.substr(0, id.length - 1);
  1543. if (source.charCodeAt(index) !== 0x75) {
  1544. throwUnexpectedToken();
  1545. }
  1546. ++index;
  1547. if (source[index] === '{') {
  1548. ++index;
  1549. ch = scanUnicodeCodePointEscape();
  1550. } else {
  1551. ch = scanHexEscape('u');
  1552. cp = ch.charCodeAt(0);
  1553. if (!ch || ch === '\\' || !isIdentifierPart(cp)) {
  1554. throwUnexpectedToken();
  1555. }
  1556. }
  1557. id += ch;
  1558. }
  1559. }
  1560. return id;
  1561. }
  1562. function getIdentifier() {
  1563. var start, ch;
  1564. start = index++;
  1565. while (index < length) {
  1566. ch = source.charCodeAt(index);
  1567. if (ch === 0x5C) {
  1568. // Blackslash (U+005C) marks Unicode escape sequence.
  1569. index = start;
  1570. return getComplexIdentifier();
  1571. } else if (ch >= 0xD800 && ch < 0xDFFF) {
  1572. // Need to handle surrogate pairs.
  1573. index = start;
  1574. return getComplexIdentifier();
  1575. }
  1576. if (isIdentifierPart(ch)) {
  1577. ++index;
  1578. } else {
  1579. break;
  1580. }
  1581. }
  1582. return source.slice(start, index);
  1583. }
  1584. function scanIdentifier() {
  1585. var start, id, type;
  1586. start = index;
  1587. // Backslash (U+005C) starts an escaped character.
  1588. id = (source.charCodeAt(index) === 0x5C) ? getComplexIdentifier() : getIdentifier();
  1589. // There is no keyword or literal with only one character.
  1590. // Thus, it must be an identifier.
  1591. if (id.length === 1) {
  1592. type = Token.Identifier;
  1593. } else if (isKeyword(id)) {
  1594. type = Token.Keyword;
  1595. } else if (id === 'null') {
  1596. type = Token.NullLiteral;
  1597. } else if (id === 'true' || id === 'false') {
  1598. type = Token.BooleanLiteral;
  1599. } else {
  1600. type = Token.Identifier;
  1601. }
  1602. return {
  1603. type: type,
  1604. value: id,
  1605. lineNumber: lineNumber,
  1606. lineStart: lineStart,
  1607. start: start,
  1608. end: index
  1609. };
  1610. }
  1611. // ECMA-262 11.7 Punctuators
  1612. function scanPunctuator() {
  1613. var token, str;
  1614. token = {
  1615. type: Token.Punctuator,
  1616. value: '',
  1617. lineNumber: lineNumber,
  1618. lineStart: lineStart,
  1619. start: index,
  1620. end: index
  1621. };
  1622. // Check for most common single-character punctuators.
  1623. str = source[index];
  1624. switch (str) {
  1625. case '(':
  1626. if (extra.tokenize) {
  1627. extra.openParenToken = extra.tokenValues.length;
  1628. }
  1629. ++index;
  1630. break;
  1631. case '{':
  1632. if (extra.tokenize) {
  1633. extra.openCurlyToken = extra.tokenValues.length;
  1634. }
  1635. state.curlyStack.push('{');
  1636. ++index;
  1637. break;
  1638. case '.':
  1639. ++index;
  1640. if (source[index] === '.' && source[index + 1] === '.') {
  1641. // Spread operator: ...
  1642. index += 2;
  1643. str = '...';
  1644. }
  1645. break;
  1646. case '}':
  1647. ++index;
  1648. state.curlyStack.pop();
  1649. break;
  1650. case ')':
  1651. case ';':
  1652. case ',':
  1653. case '[':
  1654. case ']':
  1655. case ':':
  1656. case '?':
  1657. case '~':
  1658. ++index;
  1659. break;
  1660. default:
  1661. // 4-character punctuator.
  1662. str = source.substr(index, 4);
  1663. if (str === '>>>=') {
  1664. index += 4;
  1665. } else {
  1666. // 3-character punctuators.
  1667. str = str.substr(0, 3);
  1668. if (str === '===' || str === '!==' || str === '>>>' ||
  1669. str === '<<=' || str === '>>=') {
  1670. index += 3;
  1671. } else {
  1672. // 2-character punctuators.
  1673. str = str.substr(0, 2);
  1674. if (str === '&&' || str === '||' || str === '==' || str === '!=' ||
  1675. str === '+=' || str === '-=' || str === '*=' || str === '/=' ||
  1676. str === '++' || str === '--' || str === '<<' || str === '>>' ||
  1677. str === '&=' || str === '|=' || str === '^=' || str === '%=' ||
  1678. str === '<=' || str === '>=' || str === '=>') {
  1679. index += 2;
  1680. } else {
  1681. // 1-character punctuators.
  1682. str = source[index];
  1683. if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {
  1684. ++index;
  1685. }
  1686. }
  1687. }
  1688. }
  1689. }
  1690. if (index === token.start) {
  1691. throwUnexpectedToken();
  1692. }
  1693. token.end = index;
  1694. token.value = str;
  1695. return token;
  1696. }
  1697. // ECMA-262 11.8.3 Numeric Literals
  1698. function scanHexLiteral(start) {
  1699. var number = '';
  1700. while (index < length) {
  1701. if (!isHexDigit(source[index])) {
  1702. break;
  1703. }
  1704. number += source[index++];
  1705. }
  1706. if (number.length === 0) {
  1707. throwUnexpectedToken();
  1708. }
  1709. if (isIdentifierStart(source.charCodeAt(index))) {
  1710. throwUnexpectedToken();
  1711. }
  1712. return {
  1713. type: Token.NumericLiteral,
  1714. value: parseInt('0x' + number, 16),
  1715. lineNumber: lineNumber,
  1716. lineStart: lineStart,
  1717. start: start,
  1718. end: index
  1719. };
  1720. }
  1721. function scanBinaryLiteral(start) {
  1722. var ch, number;
  1723. number = '';
  1724. while (index < length) {
  1725. ch = source[index];
  1726. if (ch !== '0' && ch !== '1') {
  1727. break;
  1728. }
  1729. number += source[index++];
  1730. }
  1731. if (number.length === 0) {
  1732. // only 0b or 0B
  1733. throwUnexpectedToken();
  1734. }
  1735. if (index < length) {
  1736. ch = source.charCodeAt(index);
  1737. /* istanbul ignore else */
  1738. if (isIdentifierStart(ch) || isDecimalDigit(ch)) {
  1739. throwUnexpectedToken();
  1740. }
  1741. }
  1742. return {
  1743. type: Token.NumericLiteral,
  1744. value: parseInt(number, 2),
  1745. lineNumber: lineNumber,
  1746. lineStart: lineStart,
  1747. start: start,
  1748. end: index
  1749. };
  1750. }
  1751. function scanOctalLiteral(prefix, start) {
  1752. var number, octal;
  1753. if (isOctalDigit(prefix)) {
  1754. octal = true;
  1755. number = '0' + source[index++];
  1756. } else {
  1757. octal = false;
  1758. ++index;
  1759. number = '';
  1760. }
  1761. while (index < length) {
  1762. if (!isOctalDigit(source[index])) {
  1763. break;
  1764. }
  1765. number += source[index++];
  1766. }
  1767. if (!octal && number.length === 0) {
  1768. // only 0o or 0O
  1769. throwUnexpectedToken();
  1770. }
  1771. if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {
  1772. throwUnexpectedToken();
  1773. }
  1774. return {
  1775. type: Token.NumericLiteral,
  1776. value: parseInt(number, 8),
  1777. octal: octal,
  1778. lineNumber: lineNumber,
  1779. lineStart: lineStart,
  1780. start: start,
  1781. end: index
  1782. };
  1783. }
  1784. function isImplicitOctalLiteral() {
  1785. var i, ch;
  1786. // Implicit octal, unless there is a non-octal digit.
  1787. // (Annex B.1.1 on Numeric Literals)
  1788. for (i = index + 1; i < length; ++i) {
  1789. ch = source[i];
  1790. if (ch === '8' || ch === '9') {
  1791. return false;
  1792. }
  1793. if (!isOctalDigit(ch)) {
  1794. return true;
  1795. }
  1796. }
  1797. return true;
  1798. }
  1799. function scanNumericLiteral() {
  1800. var number, start, ch;
  1801. ch = source[index];
  1802. assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),
  1803. 'Numeric literal must start with a decimal digit or a decimal point');
  1804. start = index;
  1805. number = '';
  1806. if (ch !== '.') {
  1807. number = source[index++];
  1808. ch = source[index];
  1809. // Hex number starts with '0x'.
  1810. // Octal number starts with '0'.
  1811. // Octal number in ES6 starts with '0o'.
  1812. // Binary number in ES6 starts with '0b'.
  1813. if (number === '0') {
  1814. if (ch === 'x' || ch === 'X') {
  1815. ++index;
  1816. return scanHexLiteral(start);
  1817. }
  1818. if (ch === 'b' || ch === 'B') {
  1819. ++index;
  1820. return scanBinaryLiteral(start);
  1821. }
  1822. if (ch === 'o' || ch === 'O') {
  1823. return scanOctalLiteral(ch, start);
  1824. }
  1825. if (isOctalDigit(ch)) {
  1826. if (isImplicitOctalLiteral()) {
  1827. return scanOctalLiteral(ch, start);
  1828. }
  1829. }
  1830. }
  1831. while (isDecimalDigit(source.charCodeAt(index))) {
  1832. number += source[index++];
  1833. }
  1834. ch = source[index];
  1835. }
  1836. if (ch === '.') {
  1837. number += source[index++];
  1838. while (isDecimalDigit(source.charCodeAt(index))) {
  1839. number += source[index++];
  1840. }
  1841. ch = source[index];
  1842. }
  1843. if (ch === 'e' || ch === 'E') {
  1844. number += source[index++];
  1845. ch = source[index];
  1846. if (ch === '+' || ch === '-') {
  1847. number += source[index++];
  1848. }
  1849. if (isDecimalDigit(source.charCodeAt(index))) {
  1850. while (isDecimalDigit(source.charCodeAt(index))) {
  1851. number += source[index++];
  1852. }
  1853. } else {
  1854. throwUnexpectedToken();
  1855. }
  1856. }
  1857. if (isIdentifierStart(source.charCodeAt(index))) {
  1858. throwUnexpectedToken();
  1859. }
  1860. return {
  1861. type: Token.NumericLiteral,
  1862. value: parseFloat(number),
  1863. lineNumber: lineNumber,
  1864. lineStart: lineStart,
  1865. start: start,
  1866. end: index
  1867. };
  1868. }
  1869. // ECMA-262 11.8.4 String Literals
  1870. function scanStringLiteral() {
  1871. var str = '', quote, start, ch, unescaped, octToDec, octal = false;
  1872. quote = source[index];
  1873. assert((quote === '\'' || quote === '"'),
  1874. 'String literal must starts with a quote');
  1875. start = index;
  1876. ++index;
  1877. while (index < length) {
  1878. ch = source[index++];
  1879. if (ch === quote) {
  1880. quote = '';
  1881. break;
  1882. } else if (ch === '\\') {
  1883. ch = source[index++];
  1884. if (!ch || !isLineTerminator(ch.charCodeAt(0))) {
  1885. switch (ch) {
  1886. case 'u':
  1887. case 'x':
  1888. if (source[index] === '{') {
  1889. ++index;
  1890. str += scanUnicodeCodePointEscape();
  1891. } else {
  1892. unescaped = scanHexEscape(ch);
  1893. if (!unescaped) {
  1894. throw throwUnexpectedToken();
  1895. }
  1896. str += unescaped;
  1897. }
  1898. break;
  1899. case 'n':
  1900. str += '\n';
  1901. break;
  1902. case 'r':
  1903. str += '\r';
  1904. break;
  1905. case 't':
  1906. str += '\t';
  1907. break;
  1908. case 'b':
  1909. str += '\b';
  1910. break;
  1911. case 'f':
  1912. str += '\f';
  1913. break;
  1914. case 'v':
  1915. str += '\x0B';
  1916. break;
  1917. case '8':
  1918. case '9':
  1919. str += ch;
  1920. tolerateUnexpectedToken();
  1921. break;
  1922. default:
  1923. if (isOctalDigit(ch)) {
  1924. octToDec = octalToDecimal(ch);
  1925. octal = octToDec.octal || octal;
  1926. str += String.fromCharCode(octToDec.code);
  1927. } else {
  1928. str += ch;
  1929. }
  1930. break;
  1931. }
  1932. } else {
  1933. ++lineNumber;
  1934. if (ch === '\r' && source[index] === '\n') {
  1935. ++index;
  1936. }
  1937. lineStart = index;
  1938. }
  1939. } else if (isLineTerminator(ch.charCodeAt(0))) {
  1940. break;
  1941. } else {
  1942. str += ch;
  1943. }
  1944. }
  1945. if (quote !== '') {
  1946. index = start;
  1947. throwUnexpectedToken();
  1948. }
  1949. return {
  1950. type: Token.StringLiteral,
  1951. value: str,
  1952. octal: octal,
  1953. lineNumber: startLineNumber,
  1954. lineStart: startLineStart,
  1955. start: start,
  1956. end: index
  1957. };
  1958. }
  1959. // ECMA-262 11.8.6 Template Literal Lexical Components
  1960. function scanTemplate() {
  1961. var cooked = '', ch, start, rawOffset, terminated, head, tail, restore, unescaped;
  1962. terminated = false;
  1963. tail = false;
  1964. start = index;
  1965. head = (source[index] === '`');
  1966. rawOffset = 2;
  1967. ++index;
  1968. while (index < length) {
  1969. ch = source[index++];
  1970. if (ch === '`') {
  1971. rawOffset = 1;
  1972. tail = true;
  1973. terminated = true;
  1974. break;
  1975. } else if (ch === '$') {
  1976. if (source[index] === '{') {
  1977. state.curlyStack.push('${');
  1978. ++index;
  1979. terminated = true;
  1980. break;
  1981. }
  1982. cooked += ch;
  1983. } else if (ch === '\\') {
  1984. ch = source[index++];
  1985. if (!isLineTerminator(ch.charCodeAt(0))) {
  1986. switch (ch) {
  1987. case 'n':
  1988. cooked += '\n';
  1989. break;
  1990. case 'r':
  1991. cooked += '\r';
  1992. break;
  1993. case 't':
  1994. cooked += '\t';
  1995. break;
  1996. case 'u':
  1997. case 'x':
  1998. if (source[index] === '{') {
  1999. ++index;
  2000. cooked += scanUnicodeCodePointEscape();
  2001. } else {
  2002. restore = index;
  2003. unescaped = scanHexEscape(ch);
  2004. if (unescaped) {
  2005. cooked += unescaped;
  2006. } else {
  2007. index = restore;
  2008. cooked += ch;
  2009. }
  2010. }
  2011. break;
  2012. case 'b':
  2013. cooked += '\b';
  2014. break;
  2015. case 'f':
  2016. cooked += '\f';
  2017. break;
  2018. case 'v':
  2019. cooked += '\v';
  2020. break;
  2021. default:
  2022. if (ch === '0') {
  2023. if (isDecimalDigit(source.charCodeAt(index))) {
  2024. // Illegal: \01 \02 and so on
  2025. throwError(Messages.TemplateOctalLiteral);
  2026. }
  2027. cooked += '\0';
  2028. } else if (isOctalDigit(ch)) {
  2029. // Illegal: \1 \2
  2030. throwError(Messages.TemplateOctalLiteral);
  2031. } else {
  2032. cooked += ch;
  2033. }
  2034. break;
  2035. }
  2036. } else {
  2037. ++lineNumber;
  2038. if (ch === '\r' && source[index] === '\n') {
  2039. ++index;
  2040. }
  2041. lineStart = index;
  2042. }
  2043. } else if (isLineTerminator(ch.charCodeAt(0))) {
  2044. ++lineNumber;
  2045. if (ch === '\r' && source[index] === '\n') {
  2046. ++index;
  2047. }
  2048. lineStart = index;
  2049. cooked += '\n';
  2050. } else {
  2051. cooked += ch;
  2052. }
  2053. }
  2054. if (!terminated) {
  2055. throwUnexpectedToken();
  2056. }
  2057. if (!head) {
  2058. state.curlyStack.pop();
  2059. }
  2060. return {
  2061. type: Token.Template,
  2062. value: {
  2063. cooked: cooked,
  2064. raw: source.slice(start + 1, index - rawOffset)
  2065. },
  2066. head: head,
  2067. tail: tail,
  2068. lineNumber: lineNumber,
  2069. lineStart: lineStart,
  2070. start: start,
  2071. end: index
  2072. };
  2073. }
  2074. // ECMA-262 11.8.5 Regular Expression Literals
  2075. function testRegExp(pattern, flags) {
  2076. // The BMP character to use as a replacement for astral symbols when
  2077. // translating an ES6 "u"-flagged pattern to an ES5-compatible
  2078. // approximation.
  2079. // Note: replacing with '\uFFFF' enables false positives in unlikely
  2080. // scenarios. For example, `[\u{1044f}-\u{10440}]` is an invalid
  2081. // pattern that would not be detected by this substitution.
  2082. var astralSubstitute = '\uFFFF',
  2083. tmp = pattern;
  2084. if (flags.indexOf('u') >= 0) {
  2085. tmp = tmp
  2086. // Replace every Unicode escape sequence with the equivalent
  2087. // BMP character or a constant ASCII code point in the case of
  2088. // astral symbols. (See the above note on `astralSubstitute`
  2089. // for more information.)
  2090. .replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, function ($0, $1, $2) {
  2091. var codePoint = parseInt($1 || $2, 16);
  2092. if (codePoint > 0x10FFFF) {
  2093. throwUnexpectedToken(null, Messages.InvalidRegExp);
  2094. }
  2095. if (codePoint <= 0xFFFF) {
  2096. return String.fromCharCode(codePoint);
  2097. }
  2098. return astralSubstitute;
  2099. })
  2100. // Replace each paired surrogate with a single ASCII symbol to
  2101. // avoid throwing on regular expressions that are only valid in
  2102. // combination with the "u" flag.
  2103. .replace(
  2104. /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  2105. astralSubstitute
  2106. );
  2107. }
  2108. // First, detect invalid regular expressions.
  2109. try {
  2110. RegExp(tmp);
  2111. } catch (e) {
  2112. throwUnexpectedToken(null, Messages.InvalidRegExp);
  2113. }
  2114. // Return a regular expression object for this pattern-flag pair, or
  2115. // `null` in case the current environment doesn't support the flags it
  2116. // uses.
  2117. try {
  2118. return new RegExp(pattern, flags);
  2119. } catch (exception) {
  2120. return null;
  2121. }
  2122. }
  2123. function scanRegExpBody() {
  2124. var ch, str, classMarker, terminated, body;
  2125. ch = source[index];
  2126. assert(ch === '/', 'Regular expression literal must start with a slash');
  2127. str = source[index++];
  2128. classMarker = false;
  2129. terminated = false;
  2130. while (index < length) {
  2131. ch = source[index++];
  2132. str += ch;
  2133. if (ch === '\\') {
  2134. ch = source[index++];
  2135. // ECMA-262 7.8.5
  2136. if (isLineTerminator(ch.charCodeAt(0))) {
  2137. throwUnexpectedToken(null, Messages.UnterminatedRegExp);
  2138. }
  2139. str += ch;
  2140. } else if (isLineTerminator(ch.charCodeAt(0))) {
  2141. throwUnexpectedToken(null, Messages.UnterminatedRegExp);
  2142. } else if (classMarker) {
  2143. if (ch === ']') {
  2144. classMarker = false;
  2145. }
  2146. } else {
  2147. if (ch === '/') {
  2148. terminated = true;
  2149. break;
  2150. } else if (ch === '[') {
  2151. classMarker = true;
  2152. }
  2153. }
  2154. }
  2155. if (!terminated) {
  2156. throwUnexpectedToken(null, Messages.UnterminatedRegExp);
  2157. }
  2158. // Exclude leading and trailing slash.
  2159. body = str.substr(1, str.length - 2);
  2160. return {
  2161. value: body,
  2162. literal: str
  2163. };
  2164. }
  2165. function scanRegExpFlags() {
  2166. var ch, str, flags, restore;
  2167. str = '';
  2168. flags = '';
  2169. while (index < length) {
  2170. ch = source[index];
  2171. if (!isIdentifierPart(ch.charCodeAt(0))) {
  2172. break;
  2173. }
  2174. ++index;
  2175. if (ch === '\\' && index < length) {
  2176. ch = source[index];
  2177. if (ch === 'u') {
  2178. ++index;
  2179. restore = index;
  2180. ch = scanHexEscape('u');
  2181. if (ch) {
  2182. flags += ch;
  2183. for (str += '\\u'; restore < index; ++restore) {
  2184. str += source[restore];
  2185. }
  2186. } else {
  2187. index = restore;
  2188. flags += 'u';
  2189. str += '\\u';
  2190. }
  2191. tolerateUnexpectedToken();
  2192. } else {
  2193. str += '\\';
  2194. tolerateUnexpectedToken();
  2195. }
  2196. } else {
  2197. flags += ch;
  2198. str += ch;
  2199. }
  2200. }
  2201. return {
  2202. value: flags,
  2203. literal: str
  2204. };
  2205. }
  2206. function scanRegExp() {
  2207. var start, body, flags, value;
  2208. scanning = true;
  2209. lookahead = null;
  2210. skipComment();
  2211. start = index;
  2212. body = scanRegExpBody();
  2213. flags = scanRegExpFlags();
  2214. value = testRegExp(body.value, flags.value);
  2215. scanning = false;
  2216. if (extra.tokenize) {
  2217. return {
  2218. type: Token.RegularExpression,
  2219. value: value,
  2220. regex: {
  2221. pattern: body.value,
  2222. flags: flags.value
  2223. },
  2224. lineNumber: lineNumber,
  2225. lineStart: lineStart,
  2226. start: start,
  2227. end: index
  2228. };
  2229. }
  2230. return {
  2231. literal: body.literal + flags.literal,
  2232. value: value,
  2233. regex: {
  2234. pattern: body.value,
  2235. flags: flags.value
  2236. },
  2237. start: start,
  2238. end: index
  2239. };
  2240. }
  2241. function collectRegex() {
  2242. var pos, loc, regex, token;
  2243. skipComment();
  2244. pos = index;
  2245. loc = {
  2246. start: {
  2247. line: lineNumber,
  2248. column: index - lineStart
  2249. }
  2250. };
  2251. regex = scanRegExp();
  2252. loc.end = {
  2253. line: lineNumber,
  2254. column: index - lineStart
  2255. };
  2256. /* istanbul ignore next */
  2257. if (!extra.tokenize) {
  2258. // Pop the previous token, which is likely '/' or '/='
  2259. if (extra.tokens.length > 0) {
  2260. token = extra.tokens[extra.tokens.length - 1];
  2261. if (token.range[0] === pos && token.type === 'Punctuator') {
  2262. if (token.value === '/' || token.value === '/=') {
  2263. extra.tokens.pop();
  2264. }
  2265. }
  2266. }
  2267. extra.tokens.push({
  2268. type: 'RegularExpression',
  2269. value: regex.literal,
  2270. regex: regex.regex,
  2271. range: [pos, index],
  2272. loc: loc
  2273. });
  2274. }
  2275. return regex;
  2276. }
  2277. function isIdentifierName(token) {
  2278. return token.type === Token.Identifier ||
  2279. token.type === Token.Keyword ||
  2280. token.type === Token.BooleanLiteral ||
  2281. token.type === Token.NullLiteral;
  2282. }
  2283. // Using the following algorithm:
  2284. // https://github.com/mozilla/sweet.js/wiki/design
  2285. function advanceSlash() {
  2286. var regex, previous, check;
  2287. function testKeyword(value) {
  2288. return value && (value.length > 1) && (value[0] >= 'a') && (value[0] <= 'z');
  2289. }
  2290. previous = extra.tokenValues[extra.tokens.length - 1];
  2291. regex = (previous !== null);
  2292. switch (previous) {
  2293. case 'this':
  2294. case ']':
  2295. regex = false;
  2296. break;
  2297. case ')':
  2298. check = extra.tokenValues[extra.openParenToken - 1];
  2299. regex = (check === 'if' || check === 'while' || check === 'for' || check === 'with');
  2300. break;
  2301. case '}':
  2302. // Dividing a function by anything makes little sense,
  2303. // but we have to check for that.
  2304. regex = false;
  2305. if (testKeyword(extra.tokenValues[extra.openCurlyToken - 3])) {
  2306. // Anonymous function, e.g. function(){} /42
  2307. check = extra.tokenValues[extra.openCurlyToken - 4];
  2308. regex = check ? (FnExprTokens.indexOf(check) < 0) : false;
  2309. } else if (testKeyword(extra.tokenValues[extra.openCurlyToken - 4])) {
  2310. // Named function, e.g. function f(){} /42/
  2311. check = extra.tokenValues[extra.openCurlyToken - 5];
  2312. regex = check ? (FnExprTokens.indexOf(check) < 0) : true;
  2313. }
  2314. }
  2315. return regex ? collectRegex() : scanPunctuator();
  2316. }
  2317. function advance() {
  2318. var cp, token;
  2319. if (index >= length) {
  2320. return {
  2321. type: Token.EOF,
  2322. lineNumber: lineNumber,
  2323. lineStart: lineStart,
  2324. start: index,
  2325. end: index
  2326. };
  2327. }
  2328. cp = source.charCodeAt(index);
  2329. if (isIdentifierStart(cp)) {
  2330. token = scanIdentifier();
  2331. if (strict && isStrictModeReservedWord(token.value)) {
  2332. token.type = Token.Keyword;
  2333. }
  2334. return token;
  2335. }
  2336. // Very common: ( and ) and ;
  2337. if (cp === 0x28 || cp === 0x29 || cp === 0x3B) {
  2338. return scanPunctuator();
  2339. }
  2340. // String literal starts with single quote (U+0027) or double quote (U+0022).
  2341. if (cp === 0x27 || cp === 0x22) {
  2342. return scanStringLiteral();
  2343. }
  2344. // Dot (.) U+002E can also start a floating-point number, hence the need
  2345. // to check the next character.
  2346. if (cp === 0x2E) {
  2347. if (isDecimalDigit(source.charCodeAt(index + 1))) {
  2348. return scanNumericLiteral();
  2349. }
  2350. return scanPunctuator();
  2351. }
  2352. if (isDecimalDigit(cp)) {
  2353. return scanNumericLiteral();
  2354. }
  2355. // Slash (/) U+002F can also start a regex.
  2356. if (extra.tokenize && cp === 0x2F) {
  2357. return advanceSlash();
  2358. }
  2359. // Template literals start with ` (U+0060) for template head
  2360. // or } (U+007D) for template middle or template tail.
  2361. if (cp === 0x60 || (cp === 0x7D && state.curlyStack[state.curlyStack.length - 1] === '${')) {
  2362. return scanTemplate();
  2363. }
  2364. // Possible identifier start in a surrogate pair.
  2365. if (cp >= 0xD800 && cp < 0xDFFF) {
  2366. cp = codePointAt(index);
  2367. if (isIdentifierStart(cp)) {
  2368. return scanIdentifier();
  2369. }
  2370. }
  2371. return scanPunctuator();
  2372. }
  2373. function collectToken() {
  2374. var loc, token, value, entry;
  2375. loc = {
  2376. start: {
  2377. line: lineNumber,
  2378. column: index - lineStart
  2379. }
  2380. };
  2381. token = advance();
  2382. loc.end = {
  2383. line: lineNumber,
  2384. column: index - lineStart
  2385. };
  2386. if (token.type !== Token.EOF) {
  2387. value = source.slice(token.start, token.end);
  2388. entry = {
  2389. type: TokenName[token.type],
  2390. value: value,
  2391. range: [token.start, token.end],
  2392. loc: loc
  2393. };
  2394. if (token.regex) {
  2395. entry.regex = {
  2396. pattern: token.regex.pattern,
  2397. flags: token.regex.flags
  2398. };
  2399. }
  2400. if (extra.tokenValues) {
  2401. extra.tokenValues.push((entry.type === 'Punctuator' || entry.type === 'Keyword') ? entry.value : null);
  2402. }
  2403. if (extra.tokenize) {
  2404. if (!extra.range) {
  2405. delete entry.range;
  2406. }
  2407. if (!extra.loc) {
  2408. delete entry.loc;
  2409. }
  2410. if (extra.delegate) {
  2411. entry = extra.delegate(entry);
  2412. }
  2413. }
  2414. extra.tokens.push(entry);
  2415. }
  2416. return token;
  2417. }
  2418. function lex() {
  2419. var token;
  2420. scanning = true;
  2421. lastIndex = index;
  2422. lastLineNumber = lineNumber;
  2423. lastLineStart = lineStart;
  2424. skipComment();
  2425. token = lookahead;
  2426. startIndex = index;
  2427. startLineNumber = lineNumber;
  2428. startLineStart = lineStart;
  2429. lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();
  2430. scanning = false;
  2431. return token;
  2432. }
  2433. function peek() {
  2434. scanning = true;
  2435. skipComment();
  2436. lastIndex = index;
  2437. lastLineNumber = lineNumber;
  2438. lastLineStart = lineStart;
  2439. startIndex = index;
  2440. startLineNumber = lineNumber;
  2441. startLineStart = lineStart;
  2442. lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();
  2443. scanning = false;
  2444. }
  2445. function Position() {
  2446. this.line = startLineNumber;
  2447. this.column = startIndex - startLineStart;
  2448. }
  2449. function SourceLocation() {
  2450. this.start = new Position();
  2451. this.end = null;
  2452. }
  2453. function WrappingSourceLocation(startToken) {
  2454. this.start = {
  2455. line: startToken.lineNumber,
  2456. column: startToken.start - startToken.lineStart
  2457. };
  2458. this.end = null;
  2459. }
  2460. function Node() {
  2461. if (extra.range) {
  2462. this.range = [startIndex, 0];
  2463. }
  2464. if (extra.loc) {
  2465. this.loc = new SourceLocation();
  2466. }
  2467. }
  2468. function WrappingNode(startToken) {
  2469. if (extra.range) {
  2470. this.range = [startToken.start, 0];
  2471. }
  2472. if (extra.loc) {
  2473. this.loc = new WrappingSourceLocation(startToken);
  2474. }
  2475. }
  2476. WrappingNode.prototype = Node.prototype = {
  2477. processComment: function () {
  2478. var lastChild,
  2479. innerComments,
  2480. leadingComments,
  2481. trailingComments,
  2482. bottomRight = extra.bottomRightStack,
  2483. i,
  2484. comment,
  2485. last = bottomRight[bottomRight.length - 1];
  2486. if (this.type === Syntax.Program) {
  2487. if (this.body.length > 0) {
  2488. return;
  2489. }
  2490. }
  2491. /**
  2492. * patch innnerComments for properties empty block
  2493. * `function a() {/** comments **\/}`
  2494. */
  2495. if (this.type === Syntax.BlockStatement && this.body.length === 0) {
  2496. innerComments = [];
  2497. for (i = extra.leadingComments.length - 1; i >= 0; --i) {
  2498. comment = extra.leadingComments[i];
  2499. if (this.range[1] >= comment.range[1]) {
  2500. innerComments.unshift(comment);
  2501. extra.leadingComments.splice(i, 1);
  2502. extra.trailingComments.splice(i, 1);
  2503. }
  2504. }
  2505. if (innerComments.length) {
  2506. this.innerComments = innerComments;
  2507. //bottomRight.push(this);
  2508. return;
  2509. }
  2510. }
  2511. if (extra.trailingComments.length > 0) {
  2512. trailingComments = [];
  2513. for (i = extra.trailingComments.length - 1; i >= 0; --i) {
  2514. comment = extra.trailingComments[i];
  2515. if (comment.range[0] >= this.range[1]) {
  2516. trailingComments.unshift(comment);
  2517. extra.trailingComments.splice(i, 1);
  2518. }
  2519. }
  2520. extra.trailingComments = [];
  2521. } else {
  2522. if (last && last.trailingComments && last.trailingComments[0].range[0] >= this.range[1]) {
  2523. trailingComments = last.trailingComments;
  2524. delete last.trailingComments;
  2525. }
  2526. }
  2527. // Eating the stack.
  2528. while (last && last.range[0] >= this.range[0]) {
  2529. lastChild = bottomRight.pop();
  2530. last = bottomRight[bottomRight.length - 1];
  2531. }
  2532. if (lastChild) {
  2533. if (lastChild.leadingComments) {
  2534. leadingComments = [];
  2535. for (i = lastChild.leadingComments.length - 1; i >= 0; --i) {
  2536. comment = lastChild.leadingComments[i];
  2537. if (comment.range[1] <= this.range[0]) {
  2538. leadingComments.unshift(comment);
  2539. lastChild.leadingComments.splice(i, 1);
  2540. }
  2541. }
  2542. if (!lastChild.leadingComments.length) {
  2543. lastChild.leadingComments = undefined;
  2544. }
  2545. }
  2546. } else if (extra.leadingComments.length > 0) {
  2547. leadingComments = [];
  2548. for (i = extra.leadingComments.length - 1; i >= 0; --i) {
  2549. comment = extra.leadingComments[i];
  2550. if (comment.range[1] <= this.range[0]) {
  2551. leadingComments.unshift(comment);
  2552. extra.leadingComments.splice(i, 1);
  2553. }
  2554. }
  2555. }
  2556. if (leadingComments && leadingComments.length > 0) {
  2557. this.leadingComments = leadingComments;
  2558. }
  2559. if (trailingComments && trailingComments.length > 0) {
  2560. this.trailingComments = trailingComments;
  2561. }
  2562. bottomRight.push(this);
  2563. },
  2564. finish: function () {
  2565. if (extra.range) {
  2566. this.range[1] = lastIndex;
  2567. }
  2568. if (extra.loc) {
  2569. this.loc.end = {
  2570. line: lastLineNumber,
  2571. column: lastIndex - lastLineStart
  2572. };
  2573. if (extra.source) {
  2574. this.loc.source = extra.source;
  2575. }
  2576. }
  2577. if (extra.attachComment) {
  2578. this.processComment();
  2579. }
  2580. },
  2581. finishArrayExpression: function (elements) {
  2582. this.type = Syntax.ArrayExpression;
  2583. this.elements = elements;
  2584. this.finish();
  2585. return this;
  2586. },
  2587. finishArrayPattern: function (elements) {
  2588. this.type = Syntax.ArrayPattern;
  2589. this.elements = elements;
  2590. this.finish();
  2591. return this;
  2592. },
  2593. finishArrowFunctionExpression: function (params, defaults, body, expression) {
  2594. this.type = Syntax.ArrowFunctionExpression;
  2595. this.id = null;
  2596. this.params = params;
  2597. this.defaults = defaults;
  2598. this.body = body;
  2599. this.generator = false;
  2600. this.expression = expression;
  2601. this.finish();
  2602. return this;
  2603. },
  2604. finishAssignmentExpression: function (operator, left, right) {
  2605. this.type = Syntax.AssignmentExpression;
  2606. this.operator = operator;
  2607. this.left = left;
  2608. this.right = right;
  2609. this.finish();
  2610. return this;
  2611. },
  2612. finishAssignmentPattern: function (left, right) {
  2613. this.type = Syntax.AssignmentPattern;
  2614. this.left = left;
  2615. this.right = right;
  2616. this.finish();
  2617. return this;
  2618. },
  2619. finishBinaryExpression: function (operator, left, right) {
  2620. this.type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression : Syntax.BinaryExpression;
  2621. this.operator = operator;
  2622. this.left = left;
  2623. this.right = right;
  2624. this.finish();
  2625. return this;
  2626. },
  2627. finishBlockStatement: function (body) {
  2628. this.type = Syntax.BlockStatement;
  2629. this.body = body;
  2630. this.finish();
  2631. return this;
  2632. },
  2633. finishBreakStatement: function (label) {
  2634. this.type = Syntax.BreakStatement;
  2635. this.label = label;
  2636. this.finish();
  2637. return this;
  2638. },
  2639. finishCallExpression: function (callee, args) {
  2640. this.type = Syntax.CallExpression;
  2641. this.callee = callee;
  2642. this.arguments = args;
  2643. this.finish();
  2644. return this;
  2645. },
  2646. finishCatchClause: function (param, body) {
  2647. this.type = Syntax.CatchClause;
  2648. this.param = param;
  2649. this.body = body;
  2650. this.finish();
  2651. return this;
  2652. },
  2653. finishClassBody: function (body) {
  2654. this.type = Syntax.ClassBody;
  2655. this.body = body;
  2656. this.finish();
  2657. return this;
  2658. },
  2659. finishClassDeclaration: function (id, superClass, body) {
  2660. this.type = Syntax.ClassDeclaration;
  2661. this.id = id;
  2662. this.superClass = superClass;
  2663. this.body = body;
  2664. this.finish();
  2665. return this;
  2666. },
  2667. finishClassExpression: function (id, superClass, body) {
  2668. this.type = Syntax.ClassExpression;
  2669. this.id = id;
  2670. this.superClass = superClass;
  2671. this.body = body;
  2672. this.finish();
  2673. return this;
  2674. },
  2675. finishConditionalExpression: function (test, consequent, alternate) {
  2676. this.type = Syntax.ConditionalExpression;
  2677. this.test = test;
  2678. this.consequent = consequent;
  2679. this.alternate = alternate;
  2680. this.finish();
  2681. return this;
  2682. },
  2683. finishContinueStatement: function (label) {
  2684. this.type = Syntax.ContinueStatement;
  2685. this.label = label;
  2686. this.finish();
  2687. return this;
  2688. },
  2689. finishDebuggerStatement: function () {
  2690. this.type = Syntax.DebuggerStatement;
  2691. this.finish();
  2692. return this;
  2693. },
  2694. finishDoWhileStatement: function (body, test) {
  2695. this.type = Syntax.DoWhileStatement;
  2696. this.body = body;
  2697. this.test = test;
  2698. this.finish();
  2699. return this;
  2700. },
  2701. finishEmptyStatement: function () {
  2702. this.type = Syntax.EmptyStatement;
  2703. this.finish();
  2704. return this;
  2705. },
  2706. finishExpressionStatement: function (expression) {
  2707. this.type = Syntax.ExpressionStatement;
  2708. this.expression = expression;
  2709. this.finish();
  2710. return this;
  2711. },
  2712. finishForStatement: function (init, test, update, body) {
  2713. this.type = Syntax.ForStatement;
  2714. this.init = init;
  2715. this.test = test;
  2716. this.update = update;
  2717. this.body = body;
  2718. this.finish();
  2719. return this;
  2720. },
  2721. finishForOfStatement: function (left, right, body) {
  2722. this.type = Syntax.ForOfStatement;
  2723. this.left = left;
  2724. this.right = right;
  2725. this.body = body;
  2726. this.finish();
  2727. return this;
  2728. },
  2729. finishForInStatement: function (left, right, body) {
  2730. this.type = Syntax.ForInStatement;
  2731. this.left = left;
  2732. this.right = right;
  2733. this.body = body;
  2734. this.each = false;
  2735. this.finish();
  2736. return this;
  2737. },
  2738. finishFunctionDeclaration: function (id, params, defaults, body, generator) {
  2739. this.type = Syntax.FunctionDeclaration;
  2740. this.id = id;
  2741. this.params = params;
  2742. this.defaults = defaults;
  2743. this.body = body;
  2744. this.generator = generator;
  2745. this.expression = false;
  2746. this.finish();
  2747. return this;
  2748. },
  2749. finishFunctionExpression: function (id, params, defaults, body, generator) {
  2750. this.type = Syntax.FunctionExpression;
  2751. this.id = id;
  2752. this.params = params;
  2753. this.defaults = defaults;
  2754. this.body = body;
  2755. this.generator = generator;
  2756. this.expression = false;
  2757. this.finish();
  2758. return this;
  2759. },
  2760. finishIdentifier: function (name) {
  2761. this.type = Syntax.Identifier;
  2762. this.name = name;
  2763. this.finish();
  2764. return this;
  2765. },
  2766. finishIfStatement: function (test, consequent, alternate) {
  2767. this.type = Syntax.IfStatement;
  2768. this.test = test;
  2769. this.consequent = consequent;
  2770. this.alternate = alternate;
  2771. this.finish();
  2772. return this;
  2773. },
  2774. finishLabeledStatement: function (label, body) {
  2775. this.type = Syntax.LabeledStatement;
  2776. this.label = label;
  2777. this.body = body;
  2778. this.finish();
  2779. return this;
  2780. },
  2781. finishLiteral: function (token) {
  2782. this.type = Syntax.Literal;
  2783. this.value = token.value;
  2784. this.raw = source.slice(token.start, token.end);
  2785. if (token.regex) {
  2786. this.regex = token.regex;
  2787. }
  2788. this.finish();
  2789. return this;
  2790. },
  2791. finishMemberExpression: function (accessor, object, property) {
  2792. this.type = Syntax.MemberExpression;
  2793. this.computed = accessor === '[';
  2794. this.object = object;
  2795. this.property = property;
  2796. this.finish();
  2797. return this;
  2798. },
  2799. finishMetaProperty: function (meta, property) {
  2800. this.type = Syntax.MetaProperty;
  2801. this.meta = meta;
  2802. this.property = property;
  2803. this.finish();
  2804. return this;
  2805. },
  2806. finishNewExpression: function (callee, args) {
  2807. this.type = Syntax.NewExpression;
  2808. this.callee = callee;
  2809. this.arguments = args;
  2810. this.finish();
  2811. return this;
  2812. },
  2813. finishObjectExpression: function (properties) {
  2814. this.type = Syntax.ObjectExpression;
  2815. this.properties = properties;
  2816. this.finish();
  2817. return this;
  2818. },
  2819. finishObjectPattern: function (properties) {
  2820. this.type = Syntax.ObjectPattern;
  2821. this.properties = properties;
  2822. this.finish();
  2823. return this;
  2824. },
  2825. finishPostfixExpression: function (operator, argument) {
  2826. this.type = Syntax.UpdateExpression;
  2827. this.operator = operator;
  2828. this.argument = argument;
  2829. this.prefix = false;
  2830. this.finish();
  2831. return this;
  2832. },
  2833. finishProgram: function (body, sourceType) {
  2834. this.type = Syntax.Program;
  2835. this.body = body;
  2836. this.sourceType = sourceType;
  2837. this.finish();
  2838. return this;
  2839. },
  2840. finishProperty: function (kind, key, computed, value, method, shorthand) {
  2841. this.type = Syntax.Property;
  2842. this.key = key;
  2843. this.computed = computed;
  2844. this.value = value;
  2845. this.kind = kind;
  2846. this.method = method;
  2847. this.shorthand = shorthand;
  2848. this.finish();
  2849. return this;
  2850. },
  2851. finishRestElement: function (argument) {
  2852. this.type = Syntax.RestElement;
  2853. this.argument = argument;
  2854. this.finish();
  2855. return this;
  2856. },
  2857. finishReturnStatement: function (argument) {
  2858. this.type = Syntax.ReturnStatement;
  2859. this.argument = argument;
  2860. this.finish();
  2861. return this;
  2862. },
  2863. finishSequenceExpression: function (expressions) {
  2864. this.type = Syntax.SequenceExpression;
  2865. this.expressions = expressions;
  2866. this.finish();
  2867. return this;
  2868. },
  2869. finishSpreadElement: function (argument) {
  2870. this.type = Syntax.SpreadElement;
  2871. this.argument = argument;
  2872. this.finish();
  2873. return this;
  2874. },
  2875. finishSwitchCase: function (test, consequent) {
  2876. this.type = Syntax.SwitchCase;
  2877. this.test = test;
  2878. this.consequent = consequent;
  2879. this.finish();
  2880. return this;
  2881. },
  2882. finishSuper: function () {
  2883. this.type = Syntax.Super;
  2884. this.finish();
  2885. return this;
  2886. },
  2887. finishSwitchStatement: function (discriminant, cases) {
  2888. this.type = Syntax.SwitchStatement;
  2889. this.discriminant = discriminant;
  2890. this.cases = cases;
  2891. this.finish();
  2892. return this;
  2893. },
  2894. finishTaggedTemplateExpression: function (tag, quasi) {
  2895. this.type = Syntax.TaggedTemplateExpression;
  2896. this.tag = tag;
  2897. this.quasi = quasi;
  2898. this.finish();
  2899. return this;
  2900. },
  2901. finishTemplateElement: function (value, tail) {
  2902. this.type = Syntax.TemplateElement;
  2903. this.value = value;
  2904. this.tail = tail;
  2905. this.finish();
  2906. return this;
  2907. },
  2908. finishTemplateLiteral: function (quasis, expressions) {
  2909. this.type = Syntax.TemplateLiteral;
  2910. this.quasis = quasis;
  2911. this.expressions = expressions;
  2912. this.finish();
  2913. return this;
  2914. },
  2915. finishThisExpression: function () {
  2916. this.type = Syntax.ThisExpression;
  2917. this.finish();
  2918. return this;
  2919. },
  2920. finishThrowStatement: function (argument) {
  2921. this.type = Syntax.ThrowStatement;
  2922. this.argument = argument;
  2923. this.finish();
  2924. return this;
  2925. },
  2926. finishTryStatement: function (block, handler, finalizer) {
  2927. this.type = Syntax.TryStatement;
  2928. this.block = block;
  2929. this.guardedHandlers = [];
  2930. this.handlers = handler ? [handler] : [];
  2931. this.handler = handler;
  2932. this.finalizer = finalizer;
  2933. this.finish();
  2934. return this;
  2935. },
  2936. finishUnaryExpression: function (operator, argument) {
  2937. this.type = (operator === '++' || operator === '--') ? Syntax.UpdateExpression : Syntax.UnaryExpression;
  2938. this.operator = operator;
  2939. this.argument = argument;
  2940. this.prefix = true;
  2941. this.finish();
  2942. return this;
  2943. },
  2944. finishVariableDeclaration: function (declarations) {
  2945. this.type = Syntax.VariableDeclaration;
  2946. this.declarations = declarations;
  2947. this.kind = 'var';
  2948. this.finish();
  2949. return this;
  2950. },
  2951. finishLexicalDeclaration: function (declarations, kind) {
  2952. this.type = Syntax.VariableDeclaration;
  2953. this.declarations = declarations;
  2954. this.kind = kind;
  2955. this.finish();
  2956. return this;
  2957. },
  2958. finishVariableDeclarator: function (id, init) {
  2959. this.type = Syntax.VariableDeclarator;
  2960. this.id = id;
  2961. this.init = init;
  2962. this.finish();
  2963. return this;
  2964. },
  2965. finishWhileStatement: function (test, body) {
  2966. this.type = Syntax.WhileStatement;
  2967. this.test = test;
  2968. this.body = body;
  2969. this.finish();
  2970. return this;
  2971. },
  2972. finishWithStatement: function (object, body) {
  2973. this.type = Syntax.WithStatement;
  2974. this.object = object;
  2975. this.body = body;
  2976. this.finish();
  2977. return this;
  2978. },
  2979. finishExportSpecifier: function (local, exported) {
  2980. this.type = Syntax.ExportSpecifier;
  2981. this.exported = exported || local;
  2982. this.local = local;
  2983. this.finish();
  2984. return this;
  2985. },
  2986. finishImportDefaultSpecifier: function (local) {
  2987. this.type = Syntax.ImportDefaultSpecifier;
  2988. this.local = local;
  2989. this.finish();
  2990. return this;
  2991. },
  2992. finishImportNamespaceSpecifier: function (local) {
  2993. this.type = Syntax.ImportNamespaceSpecifier;
  2994. this.local = local;
  2995. this.finish();
  2996. return this;
  2997. },
  2998. finishExportNamedDeclaration: function (declaration, specifiers, src) {
  2999. this.type = Syntax.ExportNamedDeclaration;
  3000. this.declaration = declaration;
  3001. this.specifiers = specifiers;
  3002. this.source = src;
  3003. this.finish();
  3004. return this;
  3005. },
  3006. finishExportDefaultDeclaration: function (declaration) {
  3007. this.type = Syntax.ExportDefaultDeclaration;
  3008. this.declaration = declaration;
  3009. this.finish();
  3010. return this;
  3011. },
  3012. finishExportAllDeclaration: function (src) {
  3013. this.type = Syntax.ExportAllDeclaration;
  3014. this.source = src;
  3015. this.finish();
  3016. return this;
  3017. },
  3018. finishImportSpecifier: function (local, imported) {
  3019. this.type = Syntax.ImportSpecifier;
  3020. this.local = local || imported;
  3021. this.imported = imported;
  3022. this.finish();
  3023. return this;
  3024. },
  3025. finishImportDeclaration: function (specifiers, src) {
  3026. this.type = Syntax.ImportDeclaration;
  3027. this.specifiers = specifiers;
  3028. this.source = src;
  3029. this.finish();
  3030. return this;
  3031. },
  3032. finishYieldExpression: function (argument, delegate) {
  3033. this.type = Syntax.YieldExpression;
  3034. this.argument = argument;
  3035. this.delegate = delegate;
  3036. this.finish();
  3037. return this;
  3038. }
  3039. };
  3040. function recordError(error) {
  3041. var e, existing;
  3042. for (e = 0; e < extra.errors.length; e++) {
  3043. existing = extra.errors[e];
  3044. // Prevent duplicated error.
  3045. /* istanbul ignore next */
  3046. if (existing.index === error.index && existing.message === error.message) {
  3047. return;
  3048. }
  3049. }
  3050. extra.errors.push(error);
  3051. }
  3052. function constructError(msg, column) {
  3053. var error = new Error(msg);
  3054. try {
  3055. throw error;
  3056. } catch (base) {
  3057. /* istanbul ignore else */
  3058. if (Object.create && Object.defineProperty) {
  3059. error = Object.create(base);
  3060. Object.defineProperty(error, 'column', { value: column });
  3061. }
  3062. } finally {
  3063. return error;
  3064. }
  3065. }
  3066. function createError(line, pos, description) {
  3067. var msg, column, error;
  3068. msg = 'Line ' + line + ': ' + description;
  3069. column = pos - (scanning ? lineStart : lastLineStart) + 1;
  3070. error = constructError(msg, column);
  3071. error.lineNumber = line;
  3072. error.description = description;
  3073. error.index = pos;
  3074. return error;
  3075. }
  3076. // Throw an exception
  3077. function throwError(messageFormat) {
  3078. var args, msg;
  3079. args = Array.prototype.slice.call(arguments, 1);
  3080. msg = messageFormat.replace(/%(\d)/g,
  3081. function (whole, idx) {
  3082. assert(idx < args.length, 'Message reference must be in range');
  3083. return args[idx];
  3084. }
  3085. );
  3086. throw createError(lastLineNumber, lastIndex, msg);
  3087. }
  3088. function tolerateError(messageFormat) {
  3089. var args, msg, error;
  3090. args = Array.prototype.slice.call(arguments, 1);
  3091. /* istanbul ignore next */
  3092. msg = messageFormat.replace(/%(\d)/g,
  3093. function (whole, idx) {
  3094. assert(idx < args.length, 'Message reference must be in range');
  3095. return args[idx];
  3096. }
  3097. );
  3098. error = createError(lineNumber, lastIndex, msg);
  3099. if (extra.errors) {
  3100. recordError(error);
  3101. } else {
  3102. throw error;
  3103. }
  3104. }
  3105. // Throw an exception because of the token.
  3106. function unexpectedTokenError(token, message) {
  3107. var value, msg = message || Messages.UnexpectedToken;
  3108. if (token) {
  3109. if (!message) {
  3110. msg = (token.type === Token.EOF) ? Messages.UnexpectedEOS :
  3111. (token.type === Token.Identifier) ? Messages.UnexpectedIdentifier :
  3112. (token.type === Token.NumericLiteral) ? Messages.UnexpectedNumber :
  3113. (token.type === Token.StringLiteral) ? Messages.UnexpectedString :
  3114. (token.type === Token.Template) ? Messages.UnexpectedTemplate :
  3115. Messages.UnexpectedToken;
  3116. if (token.type === Token.Keyword) {
  3117. if (isFutureReservedWord(token.value)) {
  3118. msg = Messages.UnexpectedReserved;
  3119. } else if (strict && isStrictModeReservedWord(token.value)) {
  3120. msg = Messages.StrictReservedWord;
  3121. }
  3122. }
  3123. }
  3124. value = (token.type === Token.Template) ? token.value.raw : token.value;
  3125. } else {
  3126. value = 'ILLEGAL';
  3127. }
  3128. msg = msg.replace('%0', value);
  3129. return (token && typeof token.lineNumber === 'number') ?
  3130. createError(token.lineNumber, token.start, msg) :
  3131. createError(scanning ? lineNumber : lastLineNumber, scanning ? index : lastIndex, msg);
  3132. }
  3133. function throwUnexpectedToken(token, message) {
  3134. throw unexpectedTokenError(token, message);
  3135. }
  3136. function tolerateUnexpectedToken(token, message) {
  3137. var error = unexpectedTokenError(token, message);
  3138. if (extra.errors) {
  3139. recordError(error);
  3140. } else {
  3141. throw error;
  3142. }
  3143. }
  3144. // Expect the next token to match the specified punctuator.
  3145. // If not, an exception will be thrown.
  3146. function expect(value) {
  3147. var token = lex();
  3148. if (token.type !== Token.Punctuator || token.value !== value) {
  3149. throwUnexpectedToken(token);
  3150. }
  3151. }
  3152. /**
  3153. * @name expectCommaSeparator
  3154. * @description Quietly expect a comma when in tolerant mode, otherwise delegates
  3155. * to <code>expect(value)</code>
  3156. * @since 2.0
  3157. */
  3158. function expectCommaSeparator() {
  3159. var token;
  3160. if (extra.errors) {
  3161. token = lookahead;
  3162. if (token.type === Token.Punctuator && token.value === ',') {
  3163. lex();
  3164. } else if (token.type === Token.Punctuator && token.value === ';') {
  3165. lex();
  3166. tolerateUnexpectedToken(token);
  3167. } else {
  3168. tolerateUnexpectedToken(token, Messages.UnexpectedToken);
  3169. }
  3170. } else {
  3171. expect(',');
  3172. }
  3173. }
  3174. // Expect the next token to match the specified keyword.
  3175. // If not, an exception will be thrown.
  3176. function expectKeyword(keyword) {
  3177. var token = lex();
  3178. if (token.type !== Token.Keyword || token.value !== keyword) {
  3179. throwUnexpectedToken(token);
  3180. }
  3181. }
  3182. // Return true if the next token matches the specified punctuator.
  3183. function match(value) {
  3184. return lookahead.type === Token.Punctuator && lookahead.value === value;
  3185. }
  3186. // Return true if the next token matches the specified keyword
  3187. function matchKeyword(keyword) {
  3188. return lookahead.type === Token.Keyword && lookahead.value === keyword;
  3189. }
  3190. // Return true if the next token matches the specified contextual keyword
  3191. // (where an identifier is sometimes a keyword depending on the context)
  3192. function matchContextualKeyword(keyword) {
  3193. return lookahead.type === Token.Identifier && lookahead.value === keyword;
  3194. }
  3195. // Return true if the next token is an assignment operator
  3196. function matchAssign() {
  3197. var op;
  3198. if (lookahead.type !== Token.Punctuator) {
  3199. return false;
  3200. }
  3201. op = lookahead.value;
  3202. return op === '=' ||
  3203. op === '*=' ||
  3204. op === '/=' ||
  3205. op === '%=' ||
  3206. op === '+=' ||
  3207. op === '-=' ||
  3208. op === '<<=' ||
  3209. op === '>>=' ||
  3210. op === '>>>=' ||
  3211. op === '&=' ||
  3212. op === '^=' ||
  3213. op === '|=';
  3214. }
  3215. function consumeSemicolon() {
  3216. // Catch the very common case first: immediately a semicolon (U+003B).
  3217. if (source.charCodeAt(startIndex) === 0x3B || match(';')) {
  3218. lex();
  3219. return;
  3220. }
  3221. if (hasLineTerminator) {
  3222. return;
  3223. }
  3224. // FIXME(ikarienator): this is seemingly an issue in the previous location info convention.
  3225. lastIndex = startIndex;
  3226. lastLineNumber = startLineNumber;
  3227. lastLineStart = startLineStart;
  3228. if (lookahead.type !== Token.EOF && !match('}')) {
  3229. throwUnexpectedToken(lookahead);
  3230. }
  3231. }
  3232. // Cover grammar support.
  3233. //
  3234. // When an assignment expression position starts with an left parenthesis, the determination of the type
  3235. // of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
  3236. // or the first comma. This situation also defers the determination of all the expressions nested in the pair.
  3237. //
  3238. // There are three productions that can be parsed in a parentheses pair that needs to be determined
  3239. // after the outermost pair is closed. They are:
  3240. //
  3241. // 1. AssignmentExpression
  3242. // 2. BindingElements
  3243. // 3. AssignmentTargets
  3244. //
  3245. // In order to avoid exponential backtracking, we use two flags to denote if the production can be
  3246. // binding element or assignment target.
  3247. //
  3248. // The three productions have the relationship:
  3249. //
  3250. // BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
  3251. //
  3252. // with a single exception that CoverInitializedName when used directly in an Expression, generates
  3253. // an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
  3254. // first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
  3255. //
  3256. // isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
  3257. // effect the current flags. This means the production the parser parses is only used as an expression. Therefore
  3258. // the CoverInitializedName check is conducted.
  3259. //
  3260. // inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
  3261. // the flags outside of the parser. This means the production the parser parses is used as a part of a potential
  3262. // pattern. The CoverInitializedName check is deferred.
  3263. function isolateCoverGrammar(parser) {
  3264. var oldIsBindingElement = isBindingElement,
  3265. oldIsAssignmentTarget = isAssignmentTarget,
  3266. oldFirstCoverInitializedNameError = firstCoverInitializedNameError,
  3267. result;
  3268. isBindingElement = true;
  3269. isAssignmentTarget = true;
  3270. firstCoverInitializedNameError = null;
  3271. result = parser();
  3272. if (firstCoverInitializedNameError !== null) {
  3273. throwUnexpectedToken(firstCoverInitializedNameError);
  3274. }
  3275. isBindingElement = oldIsBindingElement;
  3276. isAssignmentTarget = oldIsAssignmentTarget;
  3277. firstCoverInitializedNameError = oldFirstCoverInitializedNameError;
  3278. return result;
  3279. }
  3280. function inheritCoverGrammar(parser) {
  3281. var oldIsBindingElement = isBindingElement,
  3282. oldIsAssignmentTarget = isAssignmentTarget,
  3283. oldFirstCoverInitializedNameError = firstCoverInitializedNameError,
  3284. result;
  3285. isBindingElement = true;
  3286. isAssignmentTarget = true;
  3287. firstCoverInitializedNameError = null;
  3288. result = parser();
  3289. isBindingElement = isBindingElement && oldIsBindingElement;
  3290. isAssignmentTarget = isAssignmentTarget && oldIsAssignmentTarget;
  3291. firstCoverInitializedNameError = oldFirstCoverInitializedNameError || firstCoverInitializedNameError;
  3292. return result;
  3293. }
  3294. // ECMA-262 13.3.3 Destructuring Binding Patterns
  3295. function parseArrayPattern(params, kind) {
  3296. var node = new Node(), elements = [], rest, restNode;
  3297. expect('[');
  3298. while (!match(']')) {
  3299. if (match(',')) {
  3300. lex();
  3301. elements.push(null);
  3302. } else {
  3303. if (match('...')) {
  3304. restNode = new Node();
  3305. lex();
  3306. params.push(lookahead);
  3307. rest = parseVariableIdentifier(kind);
  3308. elements.push(restNode.finishRestElement(rest));
  3309. break;
  3310. } else {
  3311. elements.push(parsePatternWithDefault(params, kind));
  3312. }
  3313. if (!match(']')) {
  3314. expect(',');
  3315. }
  3316. }
  3317. }
  3318. expect(']');
  3319. return node.finishArrayPattern(elements);
  3320. }
  3321. function parsePropertyPattern(params, kind) {
  3322. var node = new Node(), key, keyToken, computed = match('['), init;
  3323. if (lookahead.type === Token.Identifier) {
  3324. keyToken = lookahead;
  3325. key = parseVariableIdentifier();
  3326. if (match('=')) {
  3327. params.push(keyToken);
  3328. lex();
  3329. init = parseAssignmentExpression();
  3330. return node.finishProperty(
  3331. 'init', key, false,
  3332. new WrappingNode(keyToken).finishAssignmentPattern(key, init), false, true);
  3333. } else if (!match(':')) {
  3334. params.push(keyToken);
  3335. return node.finishProperty('init', key, false, key, false, true);
  3336. }
  3337. } else {
  3338. key = parseObjectPropertyKey();
  3339. }
  3340. expect(':');
  3341. init = parsePatternWithDefault(params, kind);
  3342. return node.finishProperty('init', key, computed, init, false, false);
  3343. }
  3344. function parseObjectPattern(params, kind) {
  3345. var node = new Node(), properties = [];
  3346. expect('{');
  3347. while (!match('}')) {
  3348. properties.push(parsePropertyPattern(params, kind));
  3349. if (!match('}')) {
  3350. expect(',');
  3351. }
  3352. }
  3353. lex();
  3354. return node.finishObjectPattern(properties);
  3355. }
  3356. function parsePattern(params, kind) {
  3357. if (match('[')) {
  3358. return parseArrayPattern(params, kind);
  3359. } else if (match('{')) {
  3360. return parseObjectPattern(params, kind);
  3361. } else if (matchKeyword('let')) {
  3362. if (kind === 'const' || kind === 'let') {
  3363. tolerateUnexpectedToken(lookahead, Messages.UnexpectedToken);
  3364. }
  3365. }
  3366. params.push(lookahead);
  3367. return parseVariableIdentifier(kind);
  3368. }
  3369. function parsePatternWithDefault(params, kind) {
  3370. var startToken = lookahead, pattern, previousAllowYield, right;
  3371. pattern = parsePattern(params, kind);
  3372. if (match('=')) {
  3373. lex();
  3374. previousAllowYield = state.allowYield;
  3375. state.allowYield = true;
  3376. right = isolateCoverGrammar(parseAssignmentExpression);
  3377. state.allowYield = previousAllowYield;
  3378. pattern = new WrappingNode(startToken).finishAssignmentPattern(pattern, right);
  3379. }
  3380. return pattern;
  3381. }
  3382. // ECMA-262 12.2.5 Array Initializer
  3383. function parseArrayInitializer() {
  3384. var elements = [], node = new Node(), restSpread;
  3385. expect('[');
  3386. while (!match(']')) {
  3387. if (match(',')) {
  3388. lex();
  3389. elements.push(null);
  3390. } else if (match('...')) {
  3391. restSpread = new Node();
  3392. lex();
  3393. restSpread.finishSpreadElement(inheritCoverGrammar(parseAssignmentExpression));
  3394. if (!match(']')) {
  3395. isAssignmentTarget = isBindingElement = false;
  3396. expect(',');
  3397. }
  3398. elements.push(restSpread);
  3399. } else {
  3400. elements.push(inheritCoverGrammar(parseAssignmentExpression));
  3401. if (!match(']')) {
  3402. expect(',');
  3403. }
  3404. }
  3405. }
  3406. lex();
  3407. return node.finishArrayExpression(elements);
  3408. }
  3409. // ECMA-262 12.2.6 Object Initializer
  3410. function parsePropertyFunction(node, paramInfo, isGenerator) {
  3411. var previousStrict, body;
  3412. isAssignmentTarget = isBindingElement = false;
  3413. previousStrict = strict;
  3414. body = isolateCoverGrammar(parseFunctionSourceElements);
  3415. if (strict && paramInfo.firstRestricted) {
  3416. tolerateUnexpectedToken(paramInfo.firstRestricted, paramInfo.message);
  3417. }
  3418. if (strict && paramInfo.stricted) {
  3419. tolerateUnexpectedToken(paramInfo.stricted, paramInfo.message);
  3420. }
  3421. strict = previousStrict;
  3422. return node.finishFunctionExpression(null, paramInfo.params, paramInfo.defaults, body, isGenerator);
  3423. }
  3424. function parsePropertyMethodFunction() {
  3425. var params, method, node = new Node(),
  3426. previousAllowYield = state.allowYield;
  3427. state.allowYield = false;
  3428. params = parseParams();
  3429. state.allowYield = previousAllowYield;
  3430. state.allowYield = false;
  3431. method = parsePropertyFunction(node, params, false);
  3432. state.allowYield = previousAllowYield;
  3433. return method;
  3434. }
  3435. function parseObjectPropertyKey() {
  3436. var token, node = new Node(), expr;
  3437. token = lex();
  3438. // Note: This function is called only from parseObjectProperty(), where
  3439. // EOF and Punctuator tokens are already filtered out.
  3440. switch (token.type) {
  3441. case Token.StringLiteral:
  3442. case Token.NumericLiteral:
  3443. if (strict && token.octal) {
  3444. tolerateUnexpectedToken(token, Messages.StrictOctalLiteral);
  3445. }
  3446. return node.finishLiteral(token);
  3447. case Token.Identifier:
  3448. case Token.BooleanLiteral:
  3449. case Token.NullLiteral:
  3450. case Token.Keyword:
  3451. return node.finishIdentifier(token.value);
  3452. case Token.Punctuator:
  3453. if (token.value === '[') {
  3454. expr = isolateCoverGrammar(parseAssignmentExpression);
  3455. expect(']');
  3456. return expr;
  3457. }
  3458. break;
  3459. }
  3460. throwUnexpectedToken(token);
  3461. }
  3462. function lookaheadPropertyName() {
  3463. switch (lookahead.type) {
  3464. case Token.Identifier:
  3465. case Token.StringLiteral:
  3466. case Token.BooleanLiteral:
  3467. case Token.NullLiteral:
  3468. case Token.NumericLiteral:
  3469. case Token.Keyword:
  3470. return true;
  3471. case Token.Punctuator:
  3472. return lookahead.value === '[';
  3473. }
  3474. return false;
  3475. }
  3476. // This function is to try to parse a MethodDefinition as defined in 14.3. But in the case of object literals,
  3477. // it might be called at a position where there is in fact a short hand identifier pattern or a data property.
  3478. // This can only be determined after we consumed up to the left parentheses.
  3479. //
  3480. // In order to avoid back tracking, it returns `null` if the position is not a MethodDefinition and the caller
  3481. // is responsible to visit other options.
  3482. function tryParseMethodDefinition(token, key, computed, node) {
  3483. var value, options, methodNode, params,
  3484. previousAllowYield = state.allowYield;
  3485. if (token.type === Token.Identifier) {
  3486. // check for `get` and `set`;
  3487. if (token.value === 'get' && lookaheadPropertyName()) {
  3488. computed = match('[');
  3489. key = parseObjectPropertyKey();
  3490. methodNode = new Node();
  3491. expect('(');
  3492. expect(')');
  3493. state.allowYield = false;
  3494. value = parsePropertyFunction(methodNode, {
  3495. params: [],
  3496. defaults: [],
  3497. stricted: null,
  3498. firstRestricted: null,
  3499. message: null
  3500. }, false);
  3501. state.allowYield = previousAllowYield;
  3502. return node.finishProperty('get', key, computed, value, false, false);
  3503. } else if (token.value === 'set' && lookaheadPropertyName()) {
  3504. computed = match('[');
  3505. key = parseObjectPropertyKey();
  3506. methodNode = new Node();
  3507. expect('(');
  3508. options = {
  3509. params: [],
  3510. defaultCount: 0,
  3511. defaults: [],
  3512. firstRestricted: null,
  3513. paramSet: {}
  3514. };
  3515. if (match(')')) {
  3516. tolerateUnexpectedToken(lookahead);
  3517. } else {
  3518. state.allowYield = false;
  3519. parseParam(options);
  3520. state.allowYield = previousAllowYield;
  3521. if (options.defaultCount === 0) {
  3522. options.defaults = [];
  3523. }
  3524. }
  3525. expect(')');
  3526. state.allowYield = false;
  3527. value = parsePropertyFunction(methodNode, options, false);
  3528. state.allowYield = previousAllowYield;
  3529. return node.finishProperty('set', key, computed, value, false, false);
  3530. }
  3531. } else if (token.type === Token.Punctuator && token.value === '*' && lookaheadPropertyName()) {
  3532. computed = match('[');
  3533. key = parseObjectPropertyKey();
  3534. methodNode = new Node();
  3535. state.allowYield = true;
  3536. params = parseParams();
  3537. state.allowYield = previousAllowYield;
  3538. state.allowYield = false;
  3539. value = parsePropertyFunction(methodNode, params, true);
  3540. state.allowYield = previousAllowYield;
  3541. return node.finishProperty('init', key, computed, value, true, false);
  3542. }
  3543. if (key && match('(')) {
  3544. value = parsePropertyMethodFunction();
  3545. return node.finishProperty('init', key, computed, value, true, false);
  3546. }
  3547. // Not a MethodDefinition.
  3548. return null;
  3549. }
  3550. function parseObjectProperty(hasProto) {
  3551. var token = lookahead, node = new Node(), computed, key, maybeMethod, proto, value;
  3552. computed = match('[');
  3553. if (match('*')) {
  3554. lex();
  3555. } else {
  3556. key = parseObjectPropertyKey();
  3557. }
  3558. maybeMethod = tryParseMethodDefinition(token, key, computed, node);
  3559. if (maybeMethod) {
  3560. return maybeMethod;
  3561. }
  3562. if (!key) {
  3563. throwUnexpectedToken(lookahead);
  3564. }
  3565. // Check for duplicated __proto__
  3566. if (!computed) {
  3567. proto = (key.type === Syntax.Identifier && key.name === '__proto__') ||
  3568. (key.type === Syntax.Literal && key.value === '__proto__');
  3569. if (hasProto.value && proto) {
  3570. tolerateError(Messages.DuplicateProtoProperty);
  3571. }
  3572. hasProto.value |= proto;
  3573. }
  3574. if (match(':')) {
  3575. lex();
  3576. value = inheritCoverGrammar(parseAssignmentExpression);
  3577. return node.finishProperty('init', key, computed, value, false, false);
  3578. }
  3579. if (token.type === Token.Identifier) {
  3580. if (match('=')) {
  3581. firstCoverInitializedNameError = lookahead;
  3582. lex();
  3583. value = isolateCoverGrammar(parseAssignmentExpression);
  3584. return node.finishProperty('init', key, computed,
  3585. new WrappingNode(token).finishAssignmentPattern(key, value), false, true);
  3586. }
  3587. return node.finishProperty('init', key, computed, key, false, true);
  3588. }
  3589. throwUnexpectedToken(lookahead);
  3590. }
  3591. function parseObjectInitializer() {
  3592. var properties = [], hasProto = {value: false}, node = new Node();
  3593. expect('{');
  3594. while (!match('}')) {
  3595. properties.push(parseObjectProperty(hasProto));
  3596. if (!match('}')) {
  3597. expectCommaSeparator();
  3598. }
  3599. }
  3600. expect('}');
  3601. return node.finishObjectExpression(properties);
  3602. }
  3603. function reinterpretExpressionAsPattern(expr) {
  3604. var i;
  3605. switch (expr.type) {
  3606. case Syntax.Identifier:
  3607. case Syntax.MemberExpression:
  3608. case Syntax.RestElement:
  3609. case Syntax.AssignmentPattern:
  3610. break;
  3611. case Syntax.SpreadElement:
  3612. expr.type = Syntax.RestElement;
  3613. reinterpretExpressionAsPattern(expr.argument);
  3614. break;
  3615. case Syntax.ArrayExpression:
  3616. expr.type = Syntax.ArrayPattern;
  3617. for (i = 0; i < expr.elements.length; i++) {
  3618. if (expr.elements[i] !== null) {
  3619. reinterpretExpressionAsPattern(expr.elements[i]);
  3620. }
  3621. }
  3622. break;
  3623. case Syntax.ObjectExpression:
  3624. expr.type = Syntax.ObjectPattern;
  3625. for (i = 0; i < expr.properties.length; i++) {
  3626. reinterpretExpressionAsPattern(expr.properties[i].value);
  3627. }
  3628. break;
  3629. case Syntax.AssignmentExpression:
  3630. expr.type = Syntax.AssignmentPattern;
  3631. reinterpretExpressionAsPattern(expr.left);
  3632. break;
  3633. default:
  3634. // Allow other node type for tolerant parsing.
  3635. break;
  3636. }
  3637. }
  3638. // ECMA-262 12.2.9 Template Literals
  3639. function parseTemplateElement(option) {
  3640. var node, token;
  3641. if (lookahead.type !== Token.Template || (option.head && !lookahead.head)) {
  3642. throwUnexpectedToken();
  3643. }
  3644. node = new Node();
  3645. token = lex();
  3646. return node.finishTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail);
  3647. }
  3648. function parseTemplateLiteral() {
  3649. var quasi, quasis, expressions, node = new Node();
  3650. quasi = parseTemplateElement({ head: true });
  3651. quasis = [quasi];
  3652. expressions = [];
  3653. while (!quasi.tail) {
  3654. expressions.push(parseExpression());
  3655. quasi = parseTemplateElement({ head: false });
  3656. quasis.push(quasi);
  3657. }
  3658. return node.finishTemplateLiteral(quasis, expressions);
  3659. }
  3660. // ECMA-262 12.2.10 The Grouping Operator
  3661. function parseGroupExpression() {
  3662. var expr, expressions, startToken, i, params = [];
  3663. expect('(');
  3664. if (match(')')) {
  3665. lex();
  3666. if (!match('=>')) {
  3667. expect('=>');
  3668. }
  3669. return {
  3670. type: PlaceHolders.ArrowParameterPlaceHolder,
  3671. params: [],
  3672. rawParams: []
  3673. };
  3674. }
  3675. startToken = lookahead;
  3676. if (match('...')) {
  3677. expr = parseRestElement(params);
  3678. expect(')');
  3679. if (!match('=>')) {
  3680. expect('=>');
  3681. }
  3682. return {
  3683. type: PlaceHolders.ArrowParameterPlaceHolder,
  3684. params: [expr]
  3685. };
  3686. }
  3687. isBindingElement = true;
  3688. expr = inheritCoverGrammar(parseAssignmentExpression);
  3689. if (match(',')) {
  3690. isAssignmentTarget = false;
  3691. expressions = [expr];
  3692. while (startIndex < length) {
  3693. if (!match(',')) {
  3694. break;
  3695. }
  3696. lex();
  3697. if (match('...')) {
  3698. if (!isBindingElement) {
  3699. throwUnexpectedToken(lookahead);
  3700. }
  3701. expressions.push(parseRestElement(params));
  3702. expect(')');
  3703. if (!match('=>')) {
  3704. expect('=>');
  3705. }
  3706. isBindingElement = false;
  3707. for (i = 0; i < expressions.length; i++) {
  3708. reinterpretExpressionAsPattern(expressions[i]);
  3709. }
  3710. return {
  3711. type: PlaceHolders.ArrowParameterPlaceHolder,
  3712. params: expressions
  3713. };
  3714. }
  3715. expressions.push(inheritCoverGrammar(parseAssignmentExpression));
  3716. }
  3717. expr = new WrappingNode(startToken).finishSequenceExpression(expressions);
  3718. }
  3719. expect(')');
  3720. if (match('=>')) {
  3721. if (expr.type === Syntax.Identifier && expr.name === 'yield') {
  3722. return {
  3723. type: PlaceHolders.ArrowParameterPlaceHolder,
  3724. params: [expr]
  3725. };
  3726. }
  3727. if (!isBindingElement) {
  3728. throwUnexpectedToken(lookahead);
  3729. }
  3730. if (expr.type === Syntax.SequenceExpression) {
  3731. for (i = 0; i < expr.expressions.length; i++) {
  3732. reinterpretExpressionAsPattern(expr.expressions[i]);
  3733. }
  3734. } else {
  3735. reinterpretExpressionAsPattern(expr);
  3736. }
  3737. expr = {
  3738. type: PlaceHolders.ArrowParameterPlaceHolder,
  3739. params: expr.type === Syntax.SequenceExpression ? expr.expressions : [expr]
  3740. };
  3741. }
  3742. isBindingElement = false;
  3743. return expr;
  3744. }
  3745. // ECMA-262 12.2 Primary Expressions
  3746. function parsePrimaryExpression() {
  3747. var type, token, expr, node;
  3748. if (match('(')) {
  3749. isBindingElement = false;
  3750. return inheritCoverGrammar(parseGroupExpression);
  3751. }
  3752. if (match('[')) {
  3753. return inheritCoverGrammar(parseArrayInitializer);
  3754. }
  3755. if (match('{')) {
  3756. return inheritCoverGrammar(parseObjectInitializer);
  3757. }
  3758. type = lookahead.type;
  3759. node = new Node();
  3760. if (type === Token.Identifier) {
  3761. if (state.sourceType === 'module' && lookahead.value === 'await') {
  3762. tolerateUnexpectedToken(lookahead);
  3763. }
  3764. expr = node.finishIdentifier(lex().value);
  3765. } else if (type === Token.StringLiteral || type === Token.NumericLiteral) {
  3766. isAssignmentTarget = isBindingElement = false;
  3767. if (strict && lookahead.octal) {
  3768. tolerateUnexpectedToken(lookahead, Messages.StrictOctalLiteral);
  3769. }
  3770. expr = node.finishLiteral(lex());
  3771. } else if (type === Token.Keyword) {
  3772. if (!strict && state.allowYield && matchKeyword('yield')) {
  3773. return parseNonComputedProperty();
  3774. }
  3775. if (!strict && matchKeyword('let')) {
  3776. return node.finishIdentifier(lex().value);
  3777. }
  3778. isAssignmentTarget = isBindingElement = false;
  3779. if (matchKeyword('function')) {
  3780. return parseFunctionExpression();
  3781. }
  3782. if (matchKeyword('this')) {
  3783. lex();
  3784. return node.finishThisExpression();
  3785. }
  3786. if (matchKeyword('class')) {
  3787. return parseClassExpression();
  3788. }
  3789. throwUnexpectedToken(lex());
  3790. } else if (type === Token.BooleanLiteral) {
  3791. isAssignmentTarget = isBindingElement = false;
  3792. token = lex();
  3793. token.value = (token.value === 'true');
  3794. expr = node.finishLiteral(token);
  3795. } else if (type === Token.NullLiteral) {
  3796. isAssignmentTarget = isBindingElement = false;
  3797. token = lex();
  3798. token.value = null;
  3799. expr = node.finishLiteral(token);
  3800. } else if (match('/') || match('/=')) {
  3801. isAssignmentTarget = isBindingElement = false;
  3802. index = startIndex;
  3803. if (typeof extra.tokens !== 'undefined') {
  3804. token = collectRegex();
  3805. } else {
  3806. token = scanRegExp();
  3807. }
  3808. lex();
  3809. expr = node.finishLiteral(token);
  3810. } else if (type === Token.Template) {
  3811. expr = parseTemplateLiteral();
  3812. } else {
  3813. throwUnexpectedToken(lex());
  3814. }
  3815. return expr;
  3816. }
  3817. // ECMA-262 12.3 Left-Hand-Side Expressions
  3818. function parseArguments() {
  3819. var args = [], expr;
  3820. expect('(');
  3821. if (!match(')')) {
  3822. while (startIndex < length) {
  3823. if (match('...')) {
  3824. expr = new Node();
  3825. lex();
  3826. expr.finishSpreadElement(isolateCoverGrammar(parseAssignmentExpression));
  3827. } else {
  3828. expr = isolateCoverGrammar(parseAssignmentExpression);
  3829. }
  3830. args.push(expr);
  3831. if (match(')')) {
  3832. break;
  3833. }
  3834. expectCommaSeparator();
  3835. }
  3836. }
  3837. expect(')');
  3838. return args;
  3839. }
  3840. function parseNonComputedProperty() {
  3841. var token, node = new Node();
  3842. token = lex();
  3843. if (!isIdentifierName(token)) {
  3844. throwUnexpectedToken(token);
  3845. }
  3846. return node.finishIdentifier(token.value);
  3847. }
  3848. function parseNonComputedMember() {
  3849. expect('.');
  3850. return parseNonComputedProperty();
  3851. }
  3852. function parseComputedMember() {
  3853. var expr;
  3854. expect('[');
  3855. expr = isolateCoverGrammar(parseExpression);
  3856. expect(']');
  3857. return expr;
  3858. }
  3859. // ECMA-262 12.3.3 The new Operator
  3860. function parseNewExpression() {
  3861. var callee, args, node = new Node();
  3862. expectKeyword('new');
  3863. if (match('.')) {
  3864. lex();
  3865. if (lookahead.type === Token.Identifier && lookahead.value === 'target') {
  3866. if (state.inFunctionBody) {
  3867. lex();
  3868. return node.finishMetaProperty('new', 'target');
  3869. }
  3870. }
  3871. throwUnexpectedToken(lookahead);
  3872. }
  3873. callee = isolateCoverGrammar(parseLeftHandSideExpression);
  3874. args = match('(') ? parseArguments() : [];
  3875. isAssignmentTarget = isBindingElement = false;
  3876. return node.finishNewExpression(callee, args);
  3877. }
  3878. // ECMA-262 12.3.4 Function Calls
  3879. function parseLeftHandSideExpressionAllowCall() {
  3880. var quasi, expr, args, property, startToken, previousAllowIn = state.allowIn;
  3881. startToken = lookahead;
  3882. state.allowIn = true;
  3883. if (matchKeyword('super') && state.inFunctionBody) {
  3884. expr = new Node();
  3885. lex();
  3886. expr = expr.finishSuper();
  3887. if (!match('(') && !match('.') && !match('[')) {
  3888. throwUnexpectedToken(lookahead);
  3889. }
  3890. } else {
  3891. expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);
  3892. }
  3893. for (;;) {
  3894. if (match('.')) {
  3895. isBindingElement = false;
  3896. isAssignmentTarget = true;
  3897. property = parseNonComputedMember();
  3898. expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);
  3899. } else if (match('(')) {
  3900. isBindingElement = false;
  3901. isAssignmentTarget = false;
  3902. args = parseArguments();
  3903. expr = new WrappingNode(startToken).finishCallExpression(expr, args);
  3904. } else if (match('[')) {
  3905. isBindingElement = false;
  3906. isAssignmentTarget = true;
  3907. property = parseComputedMember();
  3908. expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);
  3909. } else if (lookahead.type === Token.Template && lookahead.head) {
  3910. quasi = parseTemplateLiteral();
  3911. expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);
  3912. } else {
  3913. break;
  3914. }
  3915. }
  3916. state.allowIn = previousAllowIn;
  3917. return expr;
  3918. }
  3919. // ECMA-262 12.3 Left-Hand-Side Expressions
  3920. function parseLeftHandSideExpression() {
  3921. var quasi, expr, property, startToken;
  3922. assert(state.allowIn, 'callee of new expression always allow in keyword.');
  3923. startToken = lookahead;
  3924. if (matchKeyword('super') && state.inFunctionBody) {
  3925. expr = new Node();
  3926. lex();
  3927. expr = expr.finishSuper();
  3928. if (!match('[') && !match('.')) {
  3929. throwUnexpectedToken(lookahead);
  3930. }
  3931. } else {
  3932. expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);
  3933. }
  3934. for (;;) {
  3935. if (match('[')) {
  3936. isBindingElement = false;
  3937. isAssignmentTarget = true;
  3938. property = parseComputedMember();
  3939. expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);
  3940. } else if (match('.')) {
  3941. isBindingElement = false;
  3942. isAssignmentTarget = true;
  3943. property = parseNonComputedMember();
  3944. expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);
  3945. } else if (lookahead.type === Token.Template && lookahead.head) {
  3946. quasi = parseTemplateLiteral();
  3947. expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);
  3948. } else {
  3949. break;
  3950. }
  3951. }
  3952. return expr;
  3953. }
  3954. // ECMA-262 12.4 Postfix Expressions
  3955. function parsePostfixExpression() {
  3956. var expr, token, startToken = lookahead;
  3957. expr = inheritCoverGrammar(parseLeftHandSideExpressionAllowCall);
  3958. if (!hasLineTerminator && lookahead.type === Token.Punctuator) {
  3959. if (match('++') || match('--')) {
  3960. // ECMA-262 11.3.1, 11.3.2
  3961. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  3962. tolerateError(Messages.StrictLHSPostfix);
  3963. }
  3964. if (!isAssignmentTarget) {
  3965. tolerateError(Messages.InvalidLHSInAssignment);
  3966. }
  3967. isAssignmentTarget = isBindingElement = false;
  3968. token = lex();
  3969. expr = new WrappingNode(startToken).finishPostfixExpression(token.value, expr);
  3970. }
  3971. }
  3972. return expr;
  3973. }
  3974. // ECMA-262 12.5 Unary Operators
  3975. function parseUnaryExpression() {
  3976. var token, expr, startToken;
  3977. if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {
  3978. expr = parsePostfixExpression();
  3979. } else if (match('++') || match('--')) {
  3980. startToken = lookahead;
  3981. token = lex();
  3982. expr = inheritCoverGrammar(parseUnaryExpression);
  3983. // ECMA-262 11.4.4, 11.4.5
  3984. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  3985. tolerateError(Messages.StrictLHSPrefix);
  3986. }
  3987. if (!isAssignmentTarget) {
  3988. tolerateError(Messages.InvalidLHSInAssignment);
  3989. }
  3990. expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
  3991. isAssignmentTarget = isBindingElement = false;
  3992. } else if (match('+') || match('-') || match('~') || match('!')) {
  3993. startToken = lookahead;
  3994. token = lex();
  3995. expr = inheritCoverGrammar(parseUnaryExpression);
  3996. expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
  3997. isAssignmentTarget = isBindingElement = false;
  3998. } else if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {
  3999. startToken = lookahead;
  4000. token = lex();
  4001. expr = inheritCoverGrammar(parseUnaryExpression);
  4002. expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
  4003. if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {
  4004. tolerateError(Messages.StrictDelete);
  4005. }
  4006. isAssignmentTarget = isBindingElement = false;
  4007. } else {
  4008. expr = parsePostfixExpression();
  4009. }
  4010. return expr;
  4011. }
  4012. function binaryPrecedence(token, allowIn) {
  4013. var prec = 0;
  4014. if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {
  4015. return 0;
  4016. }
  4017. switch (token.value) {
  4018. case '||':
  4019. prec = 1;
  4020. break;
  4021. case '&&':
  4022. prec = 2;
  4023. break;
  4024. case '|':
  4025. prec = 3;
  4026. break;
  4027. case '^':
  4028. prec = 4;
  4029. break;
  4030. case '&':
  4031. prec = 5;
  4032. break;
  4033. case '==':
  4034. case '!=':
  4035. case '===':
  4036. case '!==':
  4037. prec = 6;
  4038. break;
  4039. case '<':
  4040. case '>':
  4041. case '<=':
  4042. case '>=':
  4043. case 'instanceof':
  4044. prec = 7;
  4045. break;
  4046. case 'in':
  4047. prec = allowIn ? 7 : 0;
  4048. break;
  4049. case '<<':
  4050. case '>>':
  4051. case '>>>':
  4052. prec = 8;
  4053. break;
  4054. case '+':
  4055. case '-':
  4056. prec = 9;
  4057. break;
  4058. case '*':
  4059. case '/':
  4060. case '%':
  4061. prec = 11;
  4062. break;
  4063. default:
  4064. break;
  4065. }
  4066. return prec;
  4067. }
  4068. // ECMA-262 12.6 Multiplicative Operators
  4069. // ECMA-262 12.7 Additive Operators
  4070. // ECMA-262 12.8 Bitwise Shift Operators
  4071. // ECMA-262 12.9 Relational Operators
  4072. // ECMA-262 12.10 Equality Operators
  4073. // ECMA-262 12.11 Binary Bitwise Operators
  4074. // ECMA-262 12.12 Binary Logical Operators
  4075. function parseBinaryExpression() {
  4076. var marker, markers, expr, token, prec, stack, right, operator, left, i;
  4077. marker = lookahead;
  4078. left = inheritCoverGrammar(parseUnaryExpression);
  4079. token = lookahead;
  4080. prec = binaryPrecedence(token, state.allowIn);
  4081. if (prec === 0) {
  4082. return left;
  4083. }
  4084. isAssignmentTarget = isBindingElement = false;
  4085. token.prec = prec;
  4086. lex();
  4087. markers = [marker, lookahead];
  4088. right = isolateCoverGrammar(parseUnaryExpression);
  4089. stack = [left, token, right];
  4090. while ((prec = binaryPrecedence(lookahead, state.allowIn)) > 0) {
  4091. // Reduce: make a binary expression from the three topmost entries.
  4092. while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
  4093. right = stack.pop();
  4094. operator = stack.pop().value;
  4095. left = stack.pop();
  4096. markers.pop();
  4097. expr = new WrappingNode(markers[markers.length - 1]).finishBinaryExpression(operator, left, right);
  4098. stack.push(expr);
  4099. }
  4100. // Shift.
  4101. token = lex();
  4102. token.prec = prec;
  4103. stack.push(token);
  4104. markers.push(lookahead);
  4105. expr = isolateCoverGrammar(parseUnaryExpression);
  4106. stack.push(expr);
  4107. }
  4108. // Final reduce to clean-up the stack.
  4109. i = stack.length - 1;
  4110. expr = stack[i];
  4111. markers.pop();
  4112. while (i > 1) {
  4113. expr = new WrappingNode(markers.pop()).finishBinaryExpression(stack[i - 1].value, stack[i - 2], expr);
  4114. i -= 2;
  4115. }
  4116. return expr;
  4117. }
  4118. // ECMA-262 12.13 Conditional Operator
  4119. function parseConditionalExpression() {
  4120. var expr, previousAllowIn, consequent, alternate, startToken;
  4121. startToken = lookahead;
  4122. expr = inheritCoverGrammar(parseBinaryExpression);
  4123. if (match('?')) {
  4124. lex();
  4125. previousAllowIn = state.allowIn;
  4126. state.allowIn = true;
  4127. consequent = isolateCoverGrammar(parseAssignmentExpression);
  4128. state.allowIn = previousAllowIn;
  4129. expect(':');
  4130. alternate = isolateCoverGrammar(parseAssignmentExpression);
  4131. expr = new WrappingNode(startToken).finishConditionalExpression(expr, consequent, alternate);
  4132. isAssignmentTarget = isBindingElement = false;
  4133. }
  4134. return expr;
  4135. }
  4136. // ECMA-262 14.2 Arrow Function Definitions
  4137. function parseConciseBody() {
  4138. if (match('{')) {
  4139. return parseFunctionSourceElements();
  4140. }
  4141. return isolateCoverGrammar(parseAssignmentExpression);
  4142. }
  4143. function checkPatternParam(options, param) {
  4144. var i;
  4145. switch (param.type) {
  4146. case Syntax.Identifier:
  4147. validateParam(options, param, param.name);
  4148. break;
  4149. case Syntax.RestElement:
  4150. checkPatternParam(options, param.argument);
  4151. break;
  4152. case Syntax.AssignmentPattern:
  4153. checkPatternParam(options, param.left);
  4154. break;
  4155. case Syntax.ArrayPattern:
  4156. for (i = 0; i < param.elements.length; i++) {
  4157. if (param.elements[i] !== null) {
  4158. checkPatternParam(options, param.elements[i]);
  4159. }
  4160. }
  4161. break;
  4162. case Syntax.YieldExpression:
  4163. break;
  4164. default:
  4165. assert(param.type === Syntax.ObjectPattern, 'Invalid type');
  4166. for (i = 0; i < param.properties.length; i++) {
  4167. checkPatternParam(options, param.properties[i].value);
  4168. }
  4169. break;
  4170. }
  4171. }
  4172. function reinterpretAsCoverFormalsList(expr) {
  4173. var i, len, param, params, defaults, defaultCount, options, token;
  4174. defaults = [];
  4175. defaultCount = 0;
  4176. params = [expr];
  4177. switch (expr.type) {
  4178. case Syntax.Identifier:
  4179. break;
  4180. case PlaceHolders.ArrowParameterPlaceHolder:
  4181. params = expr.params;
  4182. break;
  4183. default:
  4184. return null;
  4185. }
  4186. options = {
  4187. paramSet: {}
  4188. };
  4189. for (i = 0, len = params.length; i < len; i += 1) {
  4190. param = params[i];
  4191. switch (param.type) {
  4192. case Syntax.AssignmentPattern:
  4193. params[i] = param.left;
  4194. if (param.right.type === Syntax.YieldExpression) {
  4195. if (param.right.argument) {
  4196. throwUnexpectedToken(lookahead);
  4197. }
  4198. param.right.type = Syntax.Identifier;
  4199. param.right.name = 'yield';
  4200. delete param.right.argument;
  4201. delete param.right.delegate;
  4202. }
  4203. defaults.push(param.right);
  4204. ++defaultCount;
  4205. checkPatternParam(options, param.left);
  4206. break;
  4207. default:
  4208. checkPatternParam(options, param);
  4209. params[i] = param;
  4210. defaults.push(null);
  4211. break;
  4212. }
  4213. }
  4214. if (strict || !state.allowYield) {
  4215. for (i = 0, len = params.length; i < len; i += 1) {
  4216. param = params[i];
  4217. if (param.type === Syntax.YieldExpression) {
  4218. throwUnexpectedToken(lookahead);
  4219. }
  4220. }
  4221. }
  4222. if (options.message === Messages.StrictParamDupe) {
  4223. token = strict ? options.stricted : options.firstRestricted;
  4224. throwUnexpectedToken(token, options.message);
  4225. }
  4226. if (defaultCount === 0) {
  4227. defaults = [];
  4228. }
  4229. return {
  4230. params: params,
  4231. defaults: defaults,
  4232. stricted: options.stricted,
  4233. firstRestricted: options.firstRestricted,
  4234. message: options.message
  4235. };
  4236. }
  4237. function parseArrowFunctionExpression(options, node) {
  4238. var previousStrict, previousAllowYield, body;
  4239. if (hasLineTerminator) {
  4240. tolerateUnexpectedToken(lookahead);
  4241. }
  4242. expect('=>');
  4243. previousStrict = strict;
  4244. previousAllowYield = state.allowYield;
  4245. state.allowYield = true;
  4246. body = parseConciseBody();
  4247. if (strict && options.firstRestricted) {
  4248. throwUnexpectedToken(options.firstRestricted, options.message);
  4249. }
  4250. if (strict && options.stricted) {
  4251. tolerateUnexpectedToken(options.stricted, options.message);
  4252. }
  4253. strict = previousStrict;
  4254. state.allowYield = previousAllowYield;
  4255. return node.finishArrowFunctionExpression(options.params, options.defaults, body, body.type !== Syntax.BlockStatement);
  4256. }
  4257. // ECMA-262 14.4 Yield expression
  4258. function parseYieldExpression() {
  4259. var argument, expr, delegate, previousAllowYield;
  4260. argument = null;
  4261. expr = new Node();
  4262. delegate = false;
  4263. expectKeyword('yield');
  4264. if (!hasLineTerminator) {
  4265. previousAllowYield = state.allowYield;
  4266. state.allowYield = false;
  4267. delegate = match('*');
  4268. if (delegate) {
  4269. lex();
  4270. argument = parseAssignmentExpression();
  4271. } else {
  4272. if (!match(';') && !match('}') && !match(')') && lookahead.type !== Token.EOF) {
  4273. argument = parseAssignmentExpression();
  4274. }
  4275. }
  4276. state.allowYield = previousAllowYield;
  4277. }
  4278. return expr.finishYieldExpression(argument, delegate);
  4279. }
  4280. // ECMA-262 12.14 Assignment Operators
  4281. function parseAssignmentExpression() {
  4282. var token, expr, right, list, startToken;
  4283. startToken = lookahead;
  4284. token = lookahead;
  4285. if (!state.allowYield && matchKeyword('yield')) {
  4286. return parseYieldExpression();
  4287. }
  4288. expr = parseConditionalExpression();
  4289. if (expr.type === PlaceHolders.ArrowParameterPlaceHolder || match('=>')) {
  4290. isAssignmentTarget = isBindingElement = false;
  4291. list = reinterpretAsCoverFormalsList(expr);
  4292. if (list) {
  4293. firstCoverInitializedNameError = null;
  4294. return parseArrowFunctionExpression(list, new WrappingNode(startToken));
  4295. }
  4296. return expr;
  4297. }
  4298. if (matchAssign()) {
  4299. if (!isAssignmentTarget) {
  4300. tolerateError(Messages.InvalidLHSInAssignment);
  4301. }
  4302. // ECMA-262 12.1.1
  4303. if (strict && expr.type === Syntax.Identifier) {
  4304. if (isRestrictedWord(expr.name)) {
  4305. tolerateUnexpectedToken(token, Messages.StrictLHSAssignment);
  4306. }
  4307. if (isStrictModeReservedWord(expr.name)) {
  4308. tolerateUnexpectedToken(token, Messages.StrictReservedWord);
  4309. }
  4310. }
  4311. if (!match('=')) {
  4312. isAssignmentTarget = isBindingElement = false;
  4313. } else {
  4314. reinterpretExpressionAsPattern(expr);
  4315. }
  4316. token = lex();
  4317. right = isolateCoverGrammar(parseAssignmentExpression);
  4318. expr = new WrappingNode(startToken).finishAssignmentExpression(token.value, expr, right);
  4319. firstCoverInitializedNameError = null;
  4320. }
  4321. return expr;
  4322. }
  4323. // ECMA-262 12.15 Comma Operator
  4324. function parseExpression() {
  4325. var expr, startToken = lookahead, expressions;
  4326. expr = isolateCoverGrammar(parseAssignmentExpression);
  4327. if (match(',')) {
  4328. expressions = [expr];
  4329. while (startIndex < length) {
  4330. if (!match(',')) {
  4331. break;
  4332. }
  4333. lex();
  4334. expressions.push(isolateCoverGrammar(parseAssignmentExpression));
  4335. }
  4336. expr = new WrappingNode(startToken).finishSequenceExpression(expressions);
  4337. }
  4338. return expr;
  4339. }
  4340. // ECMA-262 13.2 Block
  4341. function parseStatementListItem() {
  4342. if (lookahead.type === Token.Keyword) {
  4343. switch (lookahead.value) {
  4344. case 'export':
  4345. if (state.sourceType !== 'module') {
  4346. tolerateUnexpectedToken(lookahead, Messages.IllegalExportDeclaration);
  4347. }
  4348. return parseExportDeclaration();
  4349. case 'import':
  4350. if (state.sourceType !== 'module') {
  4351. tolerateUnexpectedToken(lookahead, Messages.IllegalImportDeclaration);
  4352. }
  4353. return parseImportDeclaration();
  4354. case 'const':
  4355. return parseLexicalDeclaration({inFor: false});
  4356. case 'function':
  4357. return parseFunctionDeclaration(new Node());
  4358. case 'class':
  4359. return parseClassDeclaration();
  4360. }
  4361. }
  4362. if (matchKeyword('let') && isLexicalDeclaration()) {
  4363. return parseLexicalDeclaration({inFor: false});
  4364. }
  4365. return parseStatement();
  4366. }
  4367. function parseStatementList() {
  4368. var list = [];
  4369. while (startIndex < length) {
  4370. if (match('}')) {
  4371. break;
  4372. }
  4373. list.push(parseStatementListItem());
  4374. }
  4375. return list;
  4376. }
  4377. function parseBlock() {
  4378. var block, node = new Node();
  4379. expect('{');
  4380. block = parseStatementList();
  4381. expect('}');
  4382. return node.finishBlockStatement(block);
  4383. }
  4384. // ECMA-262 13.3.2 Variable Statement
  4385. function parseVariableIdentifier(kind) {
  4386. var token, node = new Node();
  4387. token = lex();
  4388. if (token.type === Token.Keyword && token.value === 'yield') {
  4389. if (strict) {
  4390. tolerateUnexpectedToken(token, Messages.StrictReservedWord);
  4391. } if (!state.allowYield) {
  4392. throwUnexpectedToken(token);
  4393. }
  4394. } else if (token.type !== Token.Identifier) {
  4395. if (strict && token.type === Token.Keyword && isStrictModeReservedWord(token.value)) {
  4396. tolerateUnexpectedToken(token, Messages.StrictReservedWord);
  4397. } else {
  4398. if (strict || token.value !== 'let' || kind !== 'var') {
  4399. throwUnexpectedToken(token);
  4400. }
  4401. }
  4402. } else if (state.sourceType === 'module' && token.type === Token.Identifier && token.value === 'await') {
  4403. tolerateUnexpectedToken(token);
  4404. }
  4405. return node.finishIdentifier(token.value);
  4406. }
  4407. function parseVariableDeclaration(options) {
  4408. var init = null, id, node = new Node(), params = [];
  4409. id = parsePattern(params, 'var');
  4410. // ECMA-262 12.2.1
  4411. if (strict && isRestrictedWord(id.name)) {
  4412. tolerateError(Messages.StrictVarName);
  4413. }
  4414. if (match('=')) {
  4415. lex();
  4416. init = isolateCoverGrammar(parseAssignmentExpression);
  4417. } else if (id.type !== Syntax.Identifier && !options.inFor) {
  4418. expect('=');
  4419. }
  4420. return node.finishVariableDeclarator(id, init);
  4421. }
  4422. function parseVariableDeclarationList(options) {
  4423. var opt, list;
  4424. opt = { inFor: options.inFor };
  4425. list = [parseVariableDeclaration(opt)];
  4426. while (match(',')) {
  4427. lex();
  4428. list.push(parseVariableDeclaration(opt));
  4429. }
  4430. return list;
  4431. }
  4432. function parseVariableStatement(node) {
  4433. var declarations;
  4434. expectKeyword('var');
  4435. declarations = parseVariableDeclarationList({ inFor: false });
  4436. consumeSemicolon();
  4437. return node.finishVariableDeclaration(declarations);
  4438. }
  4439. // ECMA-262 13.3.1 Let and Const Declarations
  4440. function parseLexicalBinding(kind, options) {
  4441. var init = null, id, node = new Node(), params = [];
  4442. id = parsePattern(params, kind);
  4443. // ECMA-262 12.2.1
  4444. if (strict && id.type === Syntax.Identifier && isRestrictedWord(id.name)) {
  4445. tolerateError(Messages.StrictVarName);
  4446. }
  4447. if (kind === 'const') {
  4448. if (!matchKeyword('in') && !matchContextualKeyword('of')) {
  4449. expect('=');
  4450. init = isolateCoverGrammar(parseAssignmentExpression);
  4451. }
  4452. } else if ((!options.inFor && id.type !== Syntax.Identifier) || match('=')) {
  4453. expect('=');
  4454. init = isolateCoverGrammar(parseAssignmentExpression);
  4455. }
  4456. return node.finishVariableDeclarator(id, init);
  4457. }
  4458. function parseBindingList(kind, options) {
  4459. var list = [parseLexicalBinding(kind, options)];
  4460. while (match(',')) {
  4461. lex();
  4462. list.push(parseLexicalBinding(kind, options));
  4463. }
  4464. return list;
  4465. }
  4466. function tokenizerState() {
  4467. return {
  4468. index: index,
  4469. lineNumber: lineNumber,
  4470. lineStart: lineStart,
  4471. hasLineTerminator: hasLineTerminator,
  4472. lastIndex: lastIndex,
  4473. lastLineNumber: lastLineNumber,
  4474. lastLineStart: lastLineStart,
  4475. startIndex: startIndex,
  4476. startLineNumber: startLineNumber,
  4477. startLineStart: startLineStart,
  4478. lookahead: lookahead,
  4479. tokenCount: extra.tokens ? extra.tokens.length : 0
  4480. };
  4481. }
  4482. function resetTokenizerState(ts) {
  4483. index = ts.index;
  4484. lineNumber = ts.lineNumber;
  4485. lineStart = ts.lineStart;
  4486. hasLineTerminator = ts.hasLineTerminator;
  4487. lastIndex = ts.lastIndex;
  4488. lastLineNumber = ts.lastLineNumber;
  4489. lastLineStart = ts.lastLineStart;
  4490. startIndex = ts.startIndex;
  4491. startLineNumber = ts.startLineNumber;
  4492. startLineStart = ts.startLineStart;
  4493. lookahead = ts.lookahead;
  4494. if (extra.tokens) {
  4495. extra.tokens.splice(ts.tokenCount, extra.tokens.length);
  4496. }
  4497. }
  4498. function isLexicalDeclaration() {
  4499. var lexical, ts;
  4500. ts = tokenizerState();
  4501. lex();
  4502. lexical = (lookahead.type === Token.Identifier) || match('[') || match('{') ||
  4503. matchKeyword('let') || matchKeyword('yield');
  4504. resetTokenizerState(ts);
  4505. return lexical;
  4506. }
  4507. function parseLexicalDeclaration(options) {
  4508. var kind, declarations, node = new Node();
  4509. kind = lex().value;
  4510. assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');
  4511. declarations = parseBindingList(kind, options);
  4512. consumeSemicolon();
  4513. return node.finishLexicalDeclaration(declarations, kind);
  4514. }
  4515. function parseRestElement(params) {
  4516. var param, node = new Node();
  4517. lex();
  4518. if (match('{')) {
  4519. throwError(Messages.ObjectPatternAsRestParameter);
  4520. }
  4521. params.push(lookahead);
  4522. param = parseVariableIdentifier();
  4523. if (match('=')) {
  4524. throwError(Messages.DefaultRestParameter);
  4525. }
  4526. if (!match(')')) {
  4527. throwError(Messages.ParameterAfterRestParameter);
  4528. }
  4529. return node.finishRestElement(param);
  4530. }
  4531. // ECMA-262 13.4 Empty Statement
  4532. function parseEmptyStatement(node) {
  4533. expect(';');
  4534. return node.finishEmptyStatement();
  4535. }
  4536. // ECMA-262 12.4 Expression Statement
  4537. function parseExpressionStatement(node) {
  4538. var expr = parseExpression();
  4539. consumeSemicolon();
  4540. return node.finishExpressionStatement(expr);
  4541. }
  4542. // ECMA-262 13.6 If statement
  4543. function parseIfStatement(node) {
  4544. var test, consequent, alternate;
  4545. expectKeyword('if');
  4546. expect('(');
  4547. test = parseExpression();
  4548. expect(')');
  4549. consequent = parseStatement();
  4550. if (matchKeyword('else')) {
  4551. lex();
  4552. alternate = parseStatement();
  4553. } else {
  4554. alternate = null;
  4555. }
  4556. return node.finishIfStatement(test, consequent, alternate);
  4557. }
  4558. // ECMA-262 13.7 Iteration Statements
  4559. function parseDoWhileStatement(node) {
  4560. var body, test, oldInIteration;
  4561. expectKeyword('do');
  4562. oldInIteration = state.inIteration;
  4563. state.inIteration = true;
  4564. body = parseStatement();
  4565. state.inIteration = oldInIteration;
  4566. expectKeyword('while');
  4567. expect('(');
  4568. test = parseExpression();
  4569. expect(')');
  4570. if (match(';')) {
  4571. lex();
  4572. }
  4573. return node.finishDoWhileStatement(body, test);
  4574. }
  4575. function parseWhileStatement(node) {
  4576. var test, body, oldInIteration;
  4577. expectKeyword('while');
  4578. expect('(');
  4579. test = parseExpression();
  4580. expect(')');
  4581. oldInIteration = state.inIteration;
  4582. state.inIteration = true;
  4583. body = parseStatement();
  4584. state.inIteration = oldInIteration;
  4585. return node.finishWhileStatement(test, body);
  4586. }
  4587. function parseForStatement(node) {
  4588. var init, forIn, initSeq, initStartToken, test, update, left, right, kind, declarations,
  4589. body, oldInIteration, previousAllowIn = state.allowIn;
  4590. init = test = update = null;
  4591. forIn = true;
  4592. expectKeyword('for');
  4593. expect('(');
  4594. if (match(';')) {
  4595. lex();
  4596. } else {
  4597. if (matchKeyword('var')) {
  4598. init = new Node();
  4599. lex();
  4600. state.allowIn = false;
  4601. declarations = parseVariableDeclarationList({ inFor: true });
  4602. state.allowIn = previousAllowIn;
  4603. if (declarations.length === 1 && matchKeyword('in')) {
  4604. init = init.finishVariableDeclaration(declarations);
  4605. lex();
  4606. left = init;
  4607. right = parseExpression();
  4608. init = null;
  4609. } else if (declarations.length === 1 && declarations[0].init === null && matchContextualKeyword('of')) {
  4610. init = init.finishVariableDeclaration(declarations);
  4611. lex();
  4612. left = init;
  4613. right = parseAssignmentExpression();
  4614. init = null;
  4615. forIn = false;
  4616. } else {
  4617. init = init.finishVariableDeclaration(declarations);
  4618. expect(';');
  4619. }
  4620. } else if (matchKeyword('const') || matchKeyword('let')) {
  4621. init = new Node();
  4622. kind = lex().value;
  4623. if (!strict && lookahead.value === 'in') {
  4624. init = init.finishIdentifier(kind);
  4625. lex();
  4626. left = init;
  4627. right = parseExpression();
  4628. init = null;
  4629. } else {
  4630. state.allowIn = false;
  4631. declarations = parseBindingList(kind, {inFor: true});
  4632. state.allowIn = previousAllowIn;
  4633. if (declarations.length === 1 && declarations[0].init === null && matchKeyword('in')) {
  4634. init = init.finishLexicalDeclaration(declarations, kind);
  4635. lex();
  4636. left = init;
  4637. right = parseExpression();
  4638. init = null;
  4639. } else if (declarations.length === 1 && declarations[0].init === null && matchContextualKeyword('of')) {
  4640. init = init.finishLexicalDeclaration(declarations, kind);
  4641. lex();
  4642. left = init;
  4643. right = parseAssignmentExpression();
  4644. init = null;
  4645. forIn = false;
  4646. } else {
  4647. consumeSemicolon();
  4648. init = init.finishLexicalDeclaration(declarations, kind);
  4649. }
  4650. }
  4651. } else {
  4652. initStartToken = lookahead;
  4653. state.allowIn = false;
  4654. init = inheritCoverGrammar(parseAssignmentExpression);
  4655. state.allowIn = previousAllowIn;
  4656. if (matchKeyword('in')) {
  4657. if (!isAssignmentTarget) {
  4658. tolerateError(Messages.InvalidLHSInForIn);
  4659. }
  4660. lex();
  4661. reinterpretExpressionAsPattern(init);
  4662. left = init;
  4663. right = parseExpression();
  4664. init = null;
  4665. } else if (matchContextualKeyword('of')) {
  4666. if (!isAssignmentTarget) {
  4667. tolerateError(Messages.InvalidLHSInForLoop);
  4668. }
  4669. lex();
  4670. reinterpretExpressionAsPattern(init);
  4671. left = init;
  4672. right = parseAssignmentExpression();
  4673. init = null;
  4674. forIn = false;
  4675. } else {
  4676. if (match(',')) {
  4677. initSeq = [init];
  4678. while (match(',')) {
  4679. lex();
  4680. initSeq.push(isolateCoverGrammar(parseAssignmentExpression));
  4681. }
  4682. init = new WrappingNode(initStartToken).finishSequenceExpression(initSeq);
  4683. }
  4684. expect(';');
  4685. }
  4686. }
  4687. }
  4688. if (typeof left === 'undefined') {
  4689. if (!match(';')) {
  4690. test = parseExpression();
  4691. }
  4692. expect(';');
  4693. if (!match(')')) {
  4694. update = parseExpression();
  4695. }
  4696. }
  4697. expect(')');
  4698. oldInIteration = state.inIteration;
  4699. state.inIteration = true;
  4700. body = isolateCoverGrammar(parseStatement);
  4701. state.inIteration = oldInIteration;
  4702. return (typeof left === 'undefined') ?
  4703. node.finishForStatement(init, test, update, body) :
  4704. forIn ? node.finishForInStatement(left, right, body) :
  4705. node.finishForOfStatement(left, right, body);
  4706. }
  4707. // ECMA-262 13.8 The continue statement
  4708. function parseContinueStatement(node) {
  4709. var label = null, key;
  4710. expectKeyword('continue');
  4711. // Optimize the most common form: 'continue;'.
  4712. if (source.charCodeAt(startIndex) === 0x3B) {
  4713. lex();
  4714. if (!state.inIteration) {
  4715. throwError(Messages.IllegalContinue);
  4716. }
  4717. return node.finishContinueStatement(null);
  4718. }
  4719. if (hasLineTerminator) {
  4720. if (!state.inIteration) {
  4721. throwError(Messages.IllegalContinue);
  4722. }
  4723. return node.finishContinueStatement(null);
  4724. }
  4725. if (lookahead.type === Token.Identifier) {
  4726. label = parseVariableIdentifier();
  4727. key = '$' + label.name;
  4728. if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
  4729. throwError(Messages.UnknownLabel, label.name);
  4730. }
  4731. }
  4732. consumeSemicolon();
  4733. if (label === null && !state.inIteration) {
  4734. throwError(Messages.IllegalContinue);
  4735. }
  4736. return node.finishContinueStatement(label);
  4737. }
  4738. // ECMA-262 13.9 The break statement
  4739. function parseBreakStatement(node) {
  4740. var label = null, key;
  4741. expectKeyword('break');
  4742. // Catch the very common case first: immediately a semicolon (U+003B).
  4743. if (source.charCodeAt(lastIndex) === 0x3B) {
  4744. lex();
  4745. if (!(state.inIteration || state.inSwitch)) {
  4746. throwError(Messages.IllegalBreak);
  4747. }
  4748. return node.finishBreakStatement(null);
  4749. }
  4750. if (hasLineTerminator) {
  4751. if (!(state.inIteration || state.inSwitch)) {
  4752. throwError(Messages.IllegalBreak);
  4753. }
  4754. } else if (lookahead.type === Token.Identifier) {
  4755. label = parseVariableIdentifier();
  4756. key = '$' + label.name;
  4757. if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
  4758. throwError(Messages.UnknownLabel, label.name);
  4759. }
  4760. }
  4761. consumeSemicolon();
  4762. if (label === null && !(state.inIteration || state.inSwitch)) {
  4763. throwError(Messages.IllegalBreak);
  4764. }
  4765. return node.finishBreakStatement(label);
  4766. }
  4767. // ECMA-262 13.10 The return statement
  4768. function parseReturnStatement(node) {
  4769. var argument = null;
  4770. expectKeyword('return');
  4771. if (!state.inFunctionBody) {
  4772. tolerateError(Messages.IllegalReturn);
  4773. }
  4774. // 'return' followed by a space and an identifier is very common.
  4775. if (source.charCodeAt(lastIndex) === 0x20) {
  4776. if (isIdentifierStart(source.charCodeAt(lastIndex + 1))) {
  4777. argument = parseExpression();
  4778. consumeSemicolon();
  4779. return node.finishReturnStatement(argument);
  4780. }
  4781. }
  4782. if (hasLineTerminator) {
  4783. // HACK
  4784. return node.finishReturnStatement(null);
  4785. }
  4786. if (!match(';')) {
  4787. if (!match('}') && lookahead.type !== Token.EOF) {
  4788. argument = parseExpression();
  4789. }
  4790. }
  4791. consumeSemicolon();
  4792. return node.finishReturnStatement(argument);
  4793. }
  4794. // ECMA-262 13.11 The with statement
  4795. function parseWithStatement(node) {
  4796. var object, body;
  4797. if (strict) {
  4798. tolerateError(Messages.StrictModeWith);
  4799. }
  4800. expectKeyword('with');
  4801. expect('(');
  4802. object = parseExpression();
  4803. expect(')');
  4804. body = parseStatement();
  4805. return node.finishWithStatement(object, body);
  4806. }
  4807. // ECMA-262 13.12 The switch statement
  4808. function parseSwitchCase() {
  4809. var test, consequent = [], statement, node = new Node();
  4810. if (matchKeyword('default')) {
  4811. lex();
  4812. test = null;
  4813. } else {
  4814. expectKeyword('case');
  4815. test = parseExpression();
  4816. }
  4817. expect(':');
  4818. while (startIndex < length) {
  4819. if (match('}') || matchKeyword('default') || matchKeyword('case')) {
  4820. break;
  4821. }
  4822. statement = parseStatementListItem();
  4823. consequent.push(statement);
  4824. }
  4825. return node.finishSwitchCase(test, consequent);
  4826. }
  4827. function parseSwitchStatement(node) {
  4828. var discriminant, cases, clause, oldInSwitch, defaultFound;
  4829. expectKeyword('switch');
  4830. expect('(');
  4831. discriminant = parseExpression();
  4832. expect(')');
  4833. expect('{');
  4834. cases = [];
  4835. if (match('}')) {
  4836. lex();
  4837. return node.finishSwitchStatement(discriminant, cases);
  4838. }
  4839. oldInSwitch = state.inSwitch;
  4840. state.inSwitch = true;
  4841. defaultFound = false;
  4842. while (startIndex < length) {
  4843. if (match('}')) {
  4844. break;
  4845. }
  4846. clause = parseSwitchCase();
  4847. if (clause.test === null) {
  4848. if (defaultFound) {
  4849. throwError(Messages.MultipleDefaultsInSwitch);
  4850. }
  4851. defaultFound = true;
  4852. }
  4853. cases.push(clause);
  4854. }
  4855. state.inSwitch = oldInSwitch;
  4856. expect('}');
  4857. return node.finishSwitchStatement(discriminant, cases);
  4858. }
  4859. // ECMA-262 13.14 The throw statement
  4860. function parseThrowStatement(node) {
  4861. var argument;
  4862. expectKeyword('throw');
  4863. if (hasLineTerminator) {
  4864. throwError(Messages.NewlineAfterThrow);
  4865. }
  4866. argument = parseExpression();
  4867. consumeSemicolon();
  4868. return node.finishThrowStatement(argument);
  4869. }
  4870. // ECMA-262 13.15 The try statement
  4871. function parseCatchClause() {
  4872. var param, params = [], paramMap = {}, key, i, body, node = new Node();
  4873. expectKeyword('catch');
  4874. expect('(');
  4875. if (match(')')) {
  4876. throwUnexpectedToken(lookahead);
  4877. }
  4878. param = parsePattern(params);
  4879. for (i = 0; i < params.length; i++) {
  4880. key = '$' + params[i].value;
  4881. if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
  4882. tolerateError(Messages.DuplicateBinding, params[i].value);
  4883. }
  4884. paramMap[key] = true;
  4885. }
  4886. // ECMA-262 12.14.1
  4887. if (strict && isRestrictedWord(param.name)) {
  4888. tolerateError(Messages.StrictCatchVariable);
  4889. }
  4890. expect(')');
  4891. body = parseBlock();
  4892. return node.finishCatchClause(param, body);
  4893. }
  4894. function parseTryStatement(node) {
  4895. var block, handler = null, finalizer = null;
  4896. expectKeyword('try');
  4897. block = parseBlock();
  4898. if (matchKeyword('catch')) {
  4899. handler = parseCatchClause();
  4900. }
  4901. if (matchKeyword('finally')) {
  4902. lex();
  4903. finalizer = parseBlock();
  4904. }
  4905. if (!handler && !finalizer) {
  4906. throwError(Messages.NoCatchOrFinally);
  4907. }
  4908. return node.finishTryStatement(block, handler, finalizer);
  4909. }
  4910. // ECMA-262 13.16 The debugger statement
  4911. function parseDebuggerStatement(node) {
  4912. expectKeyword('debugger');
  4913. consumeSemicolon();
  4914. return node.finishDebuggerStatement();
  4915. }
  4916. // 13 Statements
  4917. function parseStatement() {
  4918. var type = lookahead.type,
  4919. expr,
  4920. labeledBody,
  4921. key,
  4922. node;
  4923. if (type === Token.EOF) {
  4924. throwUnexpectedToken(lookahead);
  4925. }
  4926. if (type === Token.Punctuator && lookahead.value === '{') {
  4927. return parseBlock();
  4928. }
  4929. isAssignmentTarget = isBindingElement = true;
  4930. node = new Node();
  4931. if (type === Token.Punctuator) {
  4932. switch (lookahead.value) {
  4933. case ';':
  4934. return parseEmptyStatement(node);
  4935. case '(':
  4936. return parseExpressionStatement(node);
  4937. default:
  4938. break;
  4939. }
  4940. } else if (type === Token.Keyword) {
  4941. switch (lookahead.value) {
  4942. case 'break':
  4943. return parseBreakStatement(node);
  4944. case 'continue':
  4945. return parseContinueStatement(node);
  4946. case 'debugger':
  4947. return parseDebuggerStatement(node);
  4948. case 'do':
  4949. return parseDoWhileStatement(node);
  4950. case 'for':
  4951. return parseForStatement(node);
  4952. case 'function':
  4953. return parseFunctionDeclaration(node);
  4954. case 'if':
  4955. return parseIfStatement(node);
  4956. case 'return':
  4957. return parseReturnStatement(node);
  4958. case 'switch':
  4959. return parseSwitchStatement(node);
  4960. case 'throw':
  4961. return parseThrowStatement(node);
  4962. case 'try':
  4963. return parseTryStatement(node);
  4964. case 'var':
  4965. return parseVariableStatement(node);
  4966. case 'while':
  4967. return parseWhileStatement(node);
  4968. case 'with':
  4969. return parseWithStatement(node);
  4970. default:
  4971. break;
  4972. }
  4973. }
  4974. expr = parseExpression();
  4975. // ECMA-262 12.12 Labelled Statements
  4976. if ((expr.type === Syntax.Identifier) && match(':')) {
  4977. lex();
  4978. key = '$' + expr.name;
  4979. if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
  4980. throwError(Messages.Redeclaration, 'Label', expr.name);
  4981. }
  4982. state.labelSet[key] = true;
  4983. labeledBody = parseStatement();
  4984. delete state.labelSet[key];
  4985. return node.finishLabeledStatement(expr, labeledBody);
  4986. }
  4987. consumeSemicolon();
  4988. return node.finishExpressionStatement(expr);
  4989. }
  4990. // ECMA-262 14.1 Function Definition
  4991. function parseFunctionSourceElements() {
  4992. var statement, body = [], token, directive, firstRestricted,
  4993. oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody,
  4994. node = new Node();
  4995. expect('{');
  4996. while (startIndex < length) {
  4997. if (lookahead.type !== Token.StringLiteral) {
  4998. break;
  4999. }
  5000. token = lookahead;
  5001. statement = parseStatementListItem();
  5002. body.push(statement);
  5003. if (statement.expression.type !== Syntax.Literal) {
  5004. // this is not directive
  5005. break;
  5006. }
  5007. directive = source.slice(token.start + 1, token.end - 1);
  5008. if (directive === 'use strict') {
  5009. strict = true;
  5010. if (firstRestricted) {
  5011. tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);
  5012. }
  5013. } else {
  5014. if (!firstRestricted && token.octal) {
  5015. firstRestricted = token;
  5016. }
  5017. }
  5018. }
  5019. oldLabelSet = state.labelSet;
  5020. oldInIteration = state.inIteration;
  5021. oldInSwitch = state.inSwitch;
  5022. oldInFunctionBody = state.inFunctionBody;
  5023. state.labelSet = {};
  5024. state.inIteration = false;
  5025. state.inSwitch = false;
  5026. state.inFunctionBody = true;
  5027. while (startIndex < length) {
  5028. if (match('}')) {
  5029. break;
  5030. }
  5031. body.push(parseStatementListItem());
  5032. }
  5033. expect('}');
  5034. state.labelSet = oldLabelSet;
  5035. state.inIteration = oldInIteration;
  5036. state.inSwitch = oldInSwitch;
  5037. state.inFunctionBody = oldInFunctionBody;
  5038. return node.finishBlockStatement(body);
  5039. }
  5040. function validateParam(options, param, name) {
  5041. var key = '$' + name;
  5042. if (strict) {
  5043. if (isRestrictedWord(name)) {
  5044. options.stricted = param;
  5045. options.message = Messages.StrictParamName;
  5046. }
  5047. if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  5048. options.stricted = param;
  5049. options.message = Messages.StrictParamDupe;
  5050. }
  5051. } else if (!options.firstRestricted) {
  5052. if (isRestrictedWord(name)) {
  5053. options.firstRestricted = param;
  5054. options.message = Messages.StrictParamName;
  5055. } else if (isStrictModeReservedWord(name)) {
  5056. options.firstRestricted = param;
  5057. options.message = Messages.StrictReservedWord;
  5058. } else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  5059. options.stricted = param;
  5060. options.message = Messages.StrictParamDupe;
  5061. }
  5062. }
  5063. options.paramSet[key] = true;
  5064. }
  5065. function parseParam(options) {
  5066. var token, param, params = [], i, def;
  5067. token = lookahead;
  5068. if (token.value === '...') {
  5069. param = parseRestElement(params);
  5070. validateParam(options, param.argument, param.argument.name);
  5071. options.params.push(param);
  5072. options.defaults.push(null);
  5073. return false;
  5074. }
  5075. param = parsePatternWithDefault(params);
  5076. for (i = 0; i < params.length; i++) {
  5077. validateParam(options, params[i], params[i].value);
  5078. }
  5079. if (param.type === Syntax.AssignmentPattern) {
  5080. def = param.right;
  5081. param = param.left;
  5082. ++options.defaultCount;
  5083. }
  5084. options.params.push(param);
  5085. options.defaults.push(def);
  5086. return !match(')');
  5087. }
  5088. function parseParams(firstRestricted) {
  5089. var options;
  5090. options = {
  5091. params: [],
  5092. defaultCount: 0,
  5093. defaults: [],
  5094. firstRestricted: firstRestricted
  5095. };
  5096. expect('(');
  5097. if (!match(')')) {
  5098. options.paramSet = {};
  5099. while (startIndex < length) {
  5100. if (!parseParam(options)) {
  5101. break;
  5102. }
  5103. expect(',');
  5104. }
  5105. }
  5106. expect(')');
  5107. if (options.defaultCount === 0) {
  5108. options.defaults = [];
  5109. }
  5110. return {
  5111. params: options.params,
  5112. defaults: options.defaults,
  5113. stricted: options.stricted,
  5114. firstRestricted: options.firstRestricted,
  5115. message: options.message
  5116. };
  5117. }
  5118. function parseFunctionDeclaration(node, identifierIsOptional) {
  5119. var id = null, params = [], defaults = [], body, token, stricted, tmp, firstRestricted, message, previousStrict,
  5120. isGenerator, previousAllowYield;
  5121. previousAllowYield = state.allowYield;
  5122. expectKeyword('function');
  5123. isGenerator = match('*');
  5124. if (isGenerator) {
  5125. lex();
  5126. }
  5127. if (!identifierIsOptional || !match('(')) {
  5128. token = lookahead;
  5129. id = parseVariableIdentifier();
  5130. if (strict) {
  5131. if (isRestrictedWord(token.value)) {
  5132. tolerateUnexpectedToken(token, Messages.StrictFunctionName);
  5133. }
  5134. } else {
  5135. if (isRestrictedWord(token.value)) {
  5136. firstRestricted = token;
  5137. message = Messages.StrictFunctionName;
  5138. } else if (isStrictModeReservedWord(token.value)) {
  5139. firstRestricted = token;
  5140. message = Messages.StrictReservedWord;
  5141. }
  5142. }
  5143. }
  5144. state.allowYield = !isGenerator;
  5145. tmp = parseParams(firstRestricted);
  5146. params = tmp.params;
  5147. defaults = tmp.defaults;
  5148. stricted = tmp.stricted;
  5149. firstRestricted = tmp.firstRestricted;
  5150. if (tmp.message) {
  5151. message = tmp.message;
  5152. }
  5153. previousStrict = strict;
  5154. body = parseFunctionSourceElements();
  5155. if (strict && firstRestricted) {
  5156. throwUnexpectedToken(firstRestricted, message);
  5157. }
  5158. if (strict && stricted) {
  5159. tolerateUnexpectedToken(stricted, message);
  5160. }
  5161. strict = previousStrict;
  5162. state.allowYield = previousAllowYield;
  5163. return node.finishFunctionDeclaration(id, params, defaults, body, isGenerator);
  5164. }
  5165. function parseFunctionExpression() {
  5166. var token, id = null, stricted, firstRestricted, message, tmp,
  5167. params = [], defaults = [], body, previousStrict, node = new Node(),
  5168. isGenerator, previousAllowYield;
  5169. previousAllowYield = state.allowYield;
  5170. expectKeyword('function');
  5171. isGenerator = match('*');
  5172. if (isGenerator) {
  5173. lex();
  5174. }
  5175. state.allowYield = !isGenerator;
  5176. if (!match('(')) {
  5177. token = lookahead;
  5178. id = (!strict && !isGenerator && matchKeyword('yield')) ? parseNonComputedProperty() : parseVariableIdentifier();
  5179. if (strict) {
  5180. if (isRestrictedWord(token.value)) {
  5181. tolerateUnexpectedToken(token, Messages.StrictFunctionName);
  5182. }
  5183. } else {
  5184. if (isRestrictedWord(token.value)) {
  5185. firstRestricted = token;
  5186. message = Messages.StrictFunctionName;
  5187. } else if (isStrictModeReservedWord(token.value)) {
  5188. firstRestricted = token;
  5189. message = Messages.StrictReservedWord;
  5190. }
  5191. }
  5192. }
  5193. tmp = parseParams(firstRestricted);
  5194. params = tmp.params;
  5195. defaults = tmp.defaults;
  5196. stricted = tmp.stricted;
  5197. firstRestricted = tmp.firstRestricted;
  5198. if (tmp.message) {
  5199. message = tmp.message;
  5200. }
  5201. previousStrict = strict;
  5202. body = parseFunctionSourceElements();
  5203. if (strict && firstRestricted) {
  5204. throwUnexpectedToken(firstRestricted, message);
  5205. }
  5206. if (strict && stricted) {
  5207. tolerateUnexpectedToken(stricted, message);
  5208. }
  5209. strict = previousStrict;
  5210. state.allowYield = previousAllowYield;
  5211. return node.finishFunctionExpression(id, params, defaults, body, isGenerator);
  5212. }
  5213. // ECMA-262 14.5 Class Definitions
  5214. function parseClassBody() {
  5215. var classBody, token, isStatic, hasConstructor = false, body, method, computed, key;
  5216. classBody = new Node();
  5217. expect('{');
  5218. body = [];
  5219. while (!match('}')) {
  5220. if (match(';')) {
  5221. lex();
  5222. } else {
  5223. method = new Node();
  5224. token = lookahead;
  5225. isStatic = false;
  5226. computed = match('[');
  5227. if (match('*')) {
  5228. lex();
  5229. } else {
  5230. key = parseObjectPropertyKey();
  5231. if (key.name === 'static' && (lookaheadPropertyName() || match('*'))) {
  5232. token = lookahead;
  5233. isStatic = true;
  5234. computed = match('[');
  5235. if (match('*')) {
  5236. lex();
  5237. } else {
  5238. key = parseObjectPropertyKey();
  5239. }
  5240. }
  5241. }
  5242. method = tryParseMethodDefinition(token, key, computed, method);
  5243. if (method) {
  5244. method['static'] = isStatic; // jscs:ignore requireDotNotation
  5245. if (method.kind === 'init') {
  5246. method.kind = 'method';
  5247. }
  5248. if (!isStatic) {
  5249. if (!method.computed && (method.key.name || method.key.value.toString()) === 'constructor') {
  5250. if (method.kind !== 'method' || !method.method || method.value.generator) {
  5251. throwUnexpectedToken(token, Messages.ConstructorSpecialMethod);
  5252. }
  5253. if (hasConstructor) {
  5254. throwUnexpectedToken(token, Messages.DuplicateConstructor);
  5255. } else {
  5256. hasConstructor = true;
  5257. }
  5258. method.kind = 'constructor';
  5259. }
  5260. } else {
  5261. if (!method.computed && (method.key.name || method.key.value.toString()) === 'prototype') {
  5262. throwUnexpectedToken(token, Messages.StaticPrototype);
  5263. }
  5264. }
  5265. method.type = Syntax.MethodDefinition;
  5266. delete method.method;
  5267. delete method.shorthand;
  5268. body.push(method);
  5269. } else {
  5270. throwUnexpectedToken(lookahead);
  5271. }
  5272. }
  5273. }
  5274. lex();
  5275. return classBody.finishClassBody(body);
  5276. }
  5277. function parseClassDeclaration(identifierIsOptional) {
  5278. var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;
  5279. strict = true;
  5280. expectKeyword('class');
  5281. if (!identifierIsOptional || lookahead.type === Token.Identifier) {
  5282. id = parseVariableIdentifier();
  5283. }
  5284. if (matchKeyword('extends')) {
  5285. lex();
  5286. superClass = isolateCoverGrammar(parseLeftHandSideExpressionAllowCall);
  5287. }
  5288. classBody = parseClassBody();
  5289. strict = previousStrict;
  5290. return classNode.finishClassDeclaration(id, superClass, classBody);
  5291. }
  5292. function parseClassExpression() {
  5293. var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;
  5294. strict = true;
  5295. expectKeyword('class');
  5296. if (lookahead.type === Token.Identifier) {
  5297. id = parseVariableIdentifier();
  5298. }
  5299. if (matchKeyword('extends')) {
  5300. lex();
  5301. superClass = isolateCoverGrammar(parseLeftHandSideExpressionAllowCall);
  5302. }
  5303. classBody = parseClassBody();
  5304. strict = previousStrict;
  5305. return classNode.finishClassExpression(id, superClass, classBody);
  5306. }
  5307. // ECMA-262 15.2 Modules
  5308. function parseModuleSpecifier() {
  5309. var node = new Node();
  5310. if (lookahead.type !== Token.StringLiteral) {
  5311. throwError(Messages.InvalidModuleSpecifier);
  5312. }
  5313. return node.finishLiteral(lex());
  5314. }
  5315. // ECMA-262 15.2.3 Exports
  5316. function parseExportSpecifier() {
  5317. var exported, local, node = new Node(), def;
  5318. if (matchKeyword('default')) {
  5319. // export {default} from 'something';
  5320. def = new Node();
  5321. lex();
  5322. local = def.finishIdentifier('default');
  5323. } else {
  5324. local = parseVariableIdentifier();
  5325. }
  5326. if (matchContextualKeyword('as')) {
  5327. lex();
  5328. exported = parseNonComputedProperty();
  5329. }
  5330. return node.finishExportSpecifier(local, exported);
  5331. }
  5332. function parseExportNamedDeclaration(node) {
  5333. var declaration = null,
  5334. isExportFromIdentifier,
  5335. src = null, specifiers = [];
  5336. // non-default export
  5337. if (lookahead.type === Token.Keyword) {
  5338. // covers:
  5339. // export var f = 1;
  5340. switch (lookahead.value) {
  5341. case 'let':
  5342. case 'const':
  5343. declaration = parseLexicalDeclaration({inFor: false});
  5344. return node.finishExportNamedDeclaration(declaration, specifiers, null);
  5345. case 'var':
  5346. case 'class':
  5347. case 'function':
  5348. declaration = parseStatementListItem();
  5349. return node.finishExportNamedDeclaration(declaration, specifiers, null);
  5350. }
  5351. }
  5352. expect('{');
  5353. while (!match('}')) {
  5354. isExportFromIdentifier = isExportFromIdentifier || matchKeyword('default');
  5355. specifiers.push(parseExportSpecifier());
  5356. if (!match('}')) {
  5357. expect(',');
  5358. if (match('}')) {
  5359. break;
  5360. }
  5361. }
  5362. }
  5363. expect('}');
  5364. if (matchContextualKeyword('from')) {
  5365. // covering:
  5366. // export {default} from 'foo';
  5367. // export {foo} from 'foo';
  5368. lex();
  5369. src = parseModuleSpecifier();
  5370. consumeSemicolon();
  5371. } else if (isExportFromIdentifier) {
  5372. // covering:
  5373. // export {default}; // missing fromClause
  5374. throwError(lookahead.value ?
  5375. Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
  5376. } else {
  5377. // cover
  5378. // export {foo};
  5379. consumeSemicolon();
  5380. }
  5381. return node.finishExportNamedDeclaration(declaration, specifiers, src);
  5382. }
  5383. function parseExportDefaultDeclaration(node) {
  5384. var declaration = null,
  5385. expression = null;
  5386. // covers:
  5387. // export default ...
  5388. expectKeyword('default');
  5389. if (matchKeyword('function')) {
  5390. // covers:
  5391. // export default function foo () {}
  5392. // export default function () {}
  5393. declaration = parseFunctionDeclaration(new Node(), true);
  5394. return node.finishExportDefaultDeclaration(declaration);
  5395. }
  5396. if (matchKeyword('class')) {
  5397. declaration = parseClassDeclaration(true);
  5398. return node.finishExportDefaultDeclaration(declaration);
  5399. }
  5400. if (matchContextualKeyword('from')) {
  5401. throwError(Messages.UnexpectedToken, lookahead.value);
  5402. }
  5403. // covers:
  5404. // export default {};
  5405. // export default [];
  5406. // export default (1 + 2);
  5407. if (match('{')) {
  5408. expression = parseObjectInitializer();
  5409. } else if (match('[')) {
  5410. expression = parseArrayInitializer();
  5411. } else {
  5412. expression = parseAssignmentExpression();
  5413. }
  5414. consumeSemicolon();
  5415. return node.finishExportDefaultDeclaration(expression);
  5416. }
  5417. function parseExportAllDeclaration(node) {
  5418. var src;
  5419. // covers:
  5420. // export * from 'foo';
  5421. expect('*');
  5422. if (!matchContextualKeyword('from')) {
  5423. throwError(lookahead.value ?
  5424. Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
  5425. }
  5426. lex();
  5427. src = parseModuleSpecifier();
  5428. consumeSemicolon();
  5429. return node.finishExportAllDeclaration(src);
  5430. }
  5431. function parseExportDeclaration() {
  5432. var node = new Node();
  5433. if (state.inFunctionBody) {
  5434. throwError(Messages.IllegalExportDeclaration);
  5435. }
  5436. expectKeyword('export');
  5437. if (matchKeyword('default')) {
  5438. return parseExportDefaultDeclaration(node);
  5439. }
  5440. if (match('*')) {
  5441. return parseExportAllDeclaration(node);
  5442. }
  5443. return parseExportNamedDeclaration(node);
  5444. }
  5445. // ECMA-262 15.2.2 Imports
  5446. function parseImportSpecifier() {
  5447. // import {<foo as bar>} ...;
  5448. var local, imported, node = new Node();
  5449. imported = parseNonComputedProperty();
  5450. if (matchContextualKeyword('as')) {
  5451. lex();
  5452. local = parseVariableIdentifier();
  5453. }
  5454. return node.finishImportSpecifier(local, imported);
  5455. }
  5456. function parseNamedImports() {
  5457. var specifiers = [];
  5458. // {foo, bar as bas}
  5459. expect('{');
  5460. while (!match('}')) {
  5461. specifiers.push(parseImportSpecifier());
  5462. if (!match('}')) {
  5463. expect(',');
  5464. if (match('}')) {
  5465. break;
  5466. }
  5467. }
  5468. }
  5469. expect('}');
  5470. return specifiers;
  5471. }
  5472. function parseImportDefaultSpecifier() {
  5473. // import <foo> ...;
  5474. var local, node = new Node();
  5475. local = parseNonComputedProperty();
  5476. return node.finishImportDefaultSpecifier(local);
  5477. }
  5478. function parseImportNamespaceSpecifier() {
  5479. // import <* as foo> ...;
  5480. var local, node = new Node();
  5481. expect('*');
  5482. if (!matchContextualKeyword('as')) {
  5483. throwError(Messages.NoAsAfterImportNamespace);
  5484. }
  5485. lex();
  5486. local = parseNonComputedProperty();
  5487. return node.finishImportNamespaceSpecifier(local);
  5488. }
  5489. function parseImportDeclaration() {
  5490. var specifiers = [], src, node = new Node();
  5491. if (state.inFunctionBody) {
  5492. throwError(Messages.IllegalImportDeclaration);
  5493. }
  5494. expectKeyword('import');
  5495. if (lookahead.type === Token.StringLiteral) {
  5496. // import 'foo';
  5497. src = parseModuleSpecifier();
  5498. } else {
  5499. if (match('{')) {
  5500. // import {bar}
  5501. specifiers = specifiers.concat(parseNamedImports());
  5502. } else if (match('*')) {
  5503. // import * as foo
  5504. specifiers.push(parseImportNamespaceSpecifier());
  5505. } else if (isIdentifierName(lookahead) && !matchKeyword('default')) {
  5506. // import foo
  5507. specifiers.push(parseImportDefaultSpecifier());
  5508. if (match(',')) {
  5509. lex();
  5510. if (match('*')) {
  5511. // import foo, * as foo
  5512. specifiers.push(parseImportNamespaceSpecifier());
  5513. } else if (match('{')) {
  5514. // import foo, {bar}
  5515. specifiers = specifiers.concat(parseNamedImports());
  5516. } else {
  5517. throwUnexpectedToken(lookahead);
  5518. }
  5519. }
  5520. } else {
  5521. throwUnexpectedToken(lex());
  5522. }
  5523. if (!matchContextualKeyword('from')) {
  5524. throwError(lookahead.value ?
  5525. Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
  5526. }
  5527. lex();
  5528. src = parseModuleSpecifier();
  5529. }
  5530. consumeSemicolon();
  5531. return node.finishImportDeclaration(specifiers, src);
  5532. }
  5533. // ECMA-262 15.1 Scripts
  5534. function parseScriptBody() {
  5535. var statement, body = [], token, directive, firstRestricted;
  5536. while (startIndex < length) {
  5537. token = lookahead;
  5538. if (token.type !== Token.StringLiteral) {
  5539. break;
  5540. }
  5541. statement = parseStatementListItem();
  5542. body.push(statement);
  5543. if (statement.expression.type !== Syntax.Literal) {
  5544. // this is not directive
  5545. break;
  5546. }
  5547. directive = source.slice(token.start + 1, token.end - 1);
  5548. if (directive === 'use strict') {
  5549. strict = true;
  5550. if (firstRestricted) {
  5551. tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);
  5552. }
  5553. } else {
  5554. if (!firstRestricted && token.octal) {
  5555. firstRestricted = token;
  5556. }
  5557. }
  5558. }
  5559. while (startIndex < length) {
  5560. statement = parseStatementListItem();
  5561. /* istanbul ignore if */
  5562. if (typeof statement === 'undefined') {
  5563. break;
  5564. }
  5565. body.push(statement);
  5566. }
  5567. return body;
  5568. }
  5569. function parseProgram() {
  5570. var body, node;
  5571. peek();
  5572. node = new Node();
  5573. body = parseScriptBody();
  5574. return node.finishProgram(body, state.sourceType);
  5575. }
  5576. function filterTokenLocation() {
  5577. var i, entry, token, tokens = [];
  5578. for (i = 0; i < extra.tokens.length; ++i) {
  5579. entry = extra.tokens[i];
  5580. token = {
  5581. type: entry.type,
  5582. value: entry.value
  5583. };
  5584. if (entry.regex) {
  5585. token.regex = {
  5586. pattern: entry.regex.pattern,
  5587. flags: entry.regex.flags
  5588. };
  5589. }
  5590. if (extra.range) {
  5591. token.range = entry.range;
  5592. }
  5593. if (extra.loc) {
  5594. token.loc = entry.loc;
  5595. }
  5596. tokens.push(token);
  5597. }
  5598. extra.tokens = tokens;
  5599. }
  5600. function tokenize(code, options, delegate) {
  5601. var toString,
  5602. tokens;
  5603. toString = String;
  5604. if (typeof code !== 'string' && !(code instanceof String)) {
  5605. code = toString(code);
  5606. }
  5607. source = code;
  5608. index = 0;
  5609. lineNumber = (source.length > 0) ? 1 : 0;
  5610. lineStart = 0;
  5611. startIndex = index;
  5612. startLineNumber = lineNumber;
  5613. startLineStart = lineStart;
  5614. length = source.length;
  5615. lookahead = null;
  5616. state = {
  5617. allowIn: true,
  5618. allowYield: true,
  5619. labelSet: {},
  5620. inFunctionBody: false,
  5621. inIteration: false,
  5622. inSwitch: false,
  5623. lastCommentStart: -1,
  5624. curlyStack: []
  5625. };
  5626. extra = {};
  5627. // Options matching.
  5628. options = options || {};
  5629. // Of course we collect tokens here.
  5630. options.tokens = true;
  5631. extra.tokens = [];
  5632. extra.tokenValues = [];
  5633. extra.tokenize = true;
  5634. extra.delegate = delegate;
  5635. // The following two fields are necessary to compute the Regex tokens.
  5636. extra.openParenToken = -1;
  5637. extra.openCurlyToken = -1;
  5638. extra.range = (typeof options.range === 'boolean') && options.range;
  5639. extra.loc = (typeof options.loc === 'boolean') && options.loc;
  5640. if (typeof options.comment === 'boolean' && options.comment) {
  5641. extra.comments = [];
  5642. }
  5643. if (typeof options.tolerant === 'boolean' && options.tolerant) {
  5644. extra.errors = [];
  5645. }
  5646. try {
  5647. peek();
  5648. if (lookahead.type === Token.EOF) {
  5649. return extra.tokens;
  5650. }
  5651. lex();
  5652. while (lookahead.type !== Token.EOF) {
  5653. try {
  5654. lex();
  5655. } catch (lexError) {
  5656. if (extra.errors) {
  5657. recordError(lexError);
  5658. // We have to break on the first error
  5659. // to avoid infinite loops.
  5660. break;
  5661. } else {
  5662. throw lexError;
  5663. }
  5664. }
  5665. }
  5666. tokens = extra.tokens;
  5667. if (typeof extra.errors !== 'undefined') {
  5668. tokens.errors = extra.errors;
  5669. }
  5670. } catch (e) {
  5671. throw e;
  5672. } finally {
  5673. extra = {};
  5674. }
  5675. return tokens;
  5676. }
  5677. function parse(code, options) {
  5678. var program, toString;
  5679. toString = String;
  5680. if (typeof code !== 'string' && !(code instanceof String)) {
  5681. code = toString(code);
  5682. }
  5683. source = code;
  5684. index = 0;
  5685. lineNumber = (source.length > 0) ? 1 : 0;
  5686. lineStart = 0;
  5687. startIndex = index;
  5688. startLineNumber = lineNumber;
  5689. startLineStart = lineStart;
  5690. length = source.length;
  5691. lookahead = null;
  5692. state = {
  5693. allowIn: true,
  5694. allowYield: true,
  5695. labelSet: {},
  5696. inFunctionBody: false,
  5697. inIteration: false,
  5698. inSwitch: false,
  5699. lastCommentStart: -1,
  5700. curlyStack: [],
  5701. sourceType: 'script'
  5702. };
  5703. strict = false;
  5704. extra = {};
  5705. if (typeof options !== 'undefined') {
  5706. extra.range = (typeof options.range === 'boolean') && options.range;
  5707. extra.loc = (typeof options.loc === 'boolean') && options.loc;
  5708. extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;
  5709. if (extra.loc && options.source !== null && options.source !== undefined) {
  5710. extra.source = toString(options.source);
  5711. }
  5712. if (typeof options.tokens === 'boolean' && options.tokens) {
  5713. extra.tokens = [];
  5714. }
  5715. if (typeof options.comment === 'boolean' && options.comment) {
  5716. extra.comments = [];
  5717. }
  5718. if (typeof options.tolerant === 'boolean' && options.tolerant) {
  5719. extra.errors = [];
  5720. }
  5721. if (extra.attachComment) {
  5722. extra.range = true;
  5723. extra.comments = [];
  5724. extra.bottomRightStack = [];
  5725. extra.trailingComments = [];
  5726. extra.leadingComments = [];
  5727. }
  5728. if (options.sourceType === 'module') {
  5729. // very restrictive condition for now
  5730. state.sourceType = options.sourceType;
  5731. strict = true;
  5732. }
  5733. }
  5734. try {
  5735. program = parseProgram();
  5736. if (typeof extra.comments !== 'undefined') {
  5737. program.comments = extra.comments;
  5738. }
  5739. if (typeof extra.tokens !== 'undefined') {
  5740. filterTokenLocation();
  5741. program.tokens = extra.tokens;
  5742. }
  5743. if (typeof extra.errors !== 'undefined') {
  5744. program.errors = extra.errors;
  5745. }
  5746. } catch (e) {
  5747. throw e;
  5748. } finally {
  5749. extra = {};
  5750. }
  5751. return program;
  5752. }
  5753. // Sync with *.json manifests.
  5754. exports.version = '2.7.2';
  5755. exports.tokenize = tokenize;
  5756. exports.parse = parse;
  5757. // Deep copy.
  5758. /* istanbul ignore next */
  5759. exports.Syntax = (function () {
  5760. var name, types = {};
  5761. if (typeof Object.create === 'function') {
  5762. types = Object.create(null);
  5763. }
  5764. for (name in Syntax) {
  5765. if (Syntax.hasOwnProperty(name)) {
  5766. types[name] = Syntax[name];
  5767. }
  5768. }
  5769. if (typeof Object.freeze === 'function') {
  5770. Object.freeze(types);
  5771. }
  5772. return types;
  5773. }());
  5774. }));
  5775. /* vim: set sw=4 ts=4 et tw=80 : */
  5776. },{}],65:[function(_dereq_,module,exports){
  5777. /**
  5778. * espurify - Clone new AST without extra properties
  5779. *
  5780. * https://github.com/estools/espurify
  5781. *
  5782. * Copyright (c) 2014-2016 Takuto Wada
  5783. * Licensed under the MIT license.
  5784. * https://github.com/estools/espurify/blob/master/MIT-LICENSE.txt
  5785. */
  5786. 'use strict';
  5787. var createWhitelist = _dereq_('./lib/create-whitelist');
  5788. var cloneWithWhitelist = _dereq_('./lib/clone-ast');
  5789. function createCloneFunction (options) {
  5790. return cloneWithWhitelist(createWhitelist(options));
  5791. }
  5792. var espurify = createCloneFunction();
  5793. espurify.customize = createCloneFunction;
  5794. espurify.cloneWithWhitelist = cloneWithWhitelist;
  5795. module.exports = espurify;
  5796. },{"./lib/clone-ast":67,"./lib/create-whitelist":68}],66:[function(_dereq_,module,exports){
  5797. module.exports = {
  5798. ArrayExpression: ['type', 'elements'],
  5799. ArrayPattern: ['type', 'elements'],
  5800. ArrowFunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'expression'],
  5801. AssignmentExpression: ['type', 'operator', 'left', 'right'],
  5802. AssignmentPattern: ['type', 'left', 'right'],
  5803. BinaryExpression: ['type', 'operator', 'left', 'right'],
  5804. BlockStatement: ['type', 'body'],
  5805. BreakStatement: ['type', 'label'],
  5806. CallExpression: ['type', 'callee', 'arguments'],
  5807. CatchClause: ['type', 'param', 'guard', 'body'],
  5808. ClassBody: ['type', 'body'],
  5809. ClassDeclaration: ['type', 'id', 'superClass', 'body'],
  5810. ClassExpression: ['type', 'id', 'superClass', 'body'],
  5811. ConditionalExpression: ['type', 'test', 'alternate', 'consequent'],
  5812. ContinueStatement: ['type', 'label'],
  5813. DebuggerStatement: ['type'],
  5814. DoWhileStatement: ['type', 'body', 'test'],
  5815. EmptyStatement: ['type'],
  5816. ExportAllDeclaration: ['type', 'source'],
  5817. ExportDefaultDeclaration: ['type', 'declaration'],
  5818. ExportNamedDeclaration: ['type', 'declaration', 'specifiers', 'source'],
  5819. ExportSpecifier: ['type', 'exported', 'local'],
  5820. ExpressionStatement: ['type', 'expression'],
  5821. ForInStatement: ['type', 'left', 'right', 'body'],
  5822. ForOfStatement: ['type', 'left', 'right', 'body'],
  5823. ForStatement: ['type', 'init', 'test', 'update', 'body'],
  5824. FunctionDeclaration: ['type', 'id', 'params', 'body', 'generator'],
  5825. FunctionExpression: ['type', 'id', 'params', 'body', 'generator'],
  5826. Identifier: ['type', 'name'],
  5827. IfStatement: ['type', 'test', 'consequent', 'alternate'],
  5828. ImportDeclaration: ['type', 'specifiers', 'source'],
  5829. ImportDefaultSpecifier: ['type', 'local'],
  5830. ImportNamespaceSpecifier: ['type', 'local'],
  5831. ImportSpecifier: ['type', 'imported', 'local'],
  5832. LabeledStatement: ['type', 'label', 'body'],
  5833. Literal: ['type', 'value', 'regex'],
  5834. LogicalExpression: ['type', 'operator', 'left', 'right'],
  5835. MemberExpression: ['type', 'object', 'property', 'computed'],
  5836. MetaProperty: ['type', 'meta', 'property'],
  5837. MethodDefinition: ['type', 'key', 'value', 'kind', 'computed', 'static'],
  5838. NewExpression: ['type', 'callee', 'arguments'],
  5839. ObjectExpression: ['type', 'properties'],
  5840. ObjectPattern: ['type', 'properties'],
  5841. Program: ['type', 'body', 'sourceType'],
  5842. Property: ['type', 'key', 'value', 'kind', 'method', 'shorthand', 'computed'],
  5843. RestElement: ['type', 'argument'],
  5844. ReturnStatement: ['type', 'argument'],
  5845. SequenceExpression: ['type', 'expressions'],
  5846. SpreadElement: ['type', 'argument'],
  5847. Super: ['type'],
  5848. SwitchCase: ['type', 'test', 'consequent'],
  5849. SwitchStatement: ['type', 'discriminant', 'cases', 'lexical'],
  5850. TaggedTemplateExpression: ['type', 'tag', 'quasi'],
  5851. TemplateElement: ['type', 'tail', 'value'],
  5852. TemplateLiteral: ['type', 'quasis', 'expressions'],
  5853. ThisExpression: ['type'],
  5854. ThrowStatement: ['type', 'argument'],
  5855. TryStatement: ['type', 'block', 'handler', 'finalizer'],
  5856. UnaryExpression: ['type', 'operator', 'prefix', 'argument'],
  5857. UpdateExpression: ['type', 'operator', 'argument', 'prefix'],
  5858. VariableDeclaration: ['type', 'declarations', 'kind'],
  5859. VariableDeclarator: ['type', 'id', 'init'],
  5860. WhileStatement: ['type', 'test', 'body'],
  5861. WithStatement: ['type', 'object', 'body'],
  5862. YieldExpression: ['type', 'argument', 'delegate']
  5863. };
  5864. },{}],67:[function(_dereq_,module,exports){
  5865. 'use strict';
  5866. var isArray = _dereq_('core-js/library/fn/array/is-array');
  5867. var objectKeys = _dereq_('core-js/library/fn/object/keys');
  5868. var indexOf = _dereq_('core-js/library/fn/array/index-of');
  5869. var reduce = _dereq_('core-js/library/fn/array/reduce');
  5870. module.exports = function cloneWithWhitelist (astWhiteList) {
  5871. var whitelist = reduce(objectKeys(astWhiteList), function (props, key) {
  5872. var propNames = astWhiteList[key];
  5873. var prepend = (indexOf(propNames, 'type') === -1) ? ['type'] : [];
  5874. props[key] = prepend.concat(propNames);
  5875. return props;
  5876. }, {});
  5877. function cloneNodeOrObject (obj) {
  5878. var props = obj.type ? whitelist[obj.type] : null;
  5879. if (props) {
  5880. return cloneNode(obj, props);
  5881. } else {
  5882. return cloneObject(obj);
  5883. }
  5884. }
  5885. function cloneArray (ary) {
  5886. var i = ary.length, clone = [];
  5887. while (i--) {
  5888. clone[i] = cloneOf(ary[i]);
  5889. }
  5890. return clone;
  5891. }
  5892. function cloneNode (node, props) {
  5893. var i, len, key, clone = {};
  5894. for (i = 0, len = props.length; i < len; i += 1) {
  5895. key = props[i];
  5896. if (node.hasOwnProperty(key)) {
  5897. clone[key] = cloneOf(node[key]);
  5898. }
  5899. }
  5900. return clone;
  5901. }
  5902. function cloneObject (obj) {
  5903. var props = objectKeys(obj);
  5904. var i, len, key, clone = {};
  5905. for (i = 0, len = props.length; i < len; i += 1) {
  5906. key = props[i];
  5907. clone[key] = cloneOf(obj[key]);
  5908. }
  5909. return clone;
  5910. }
  5911. function cloneOf (val) {
  5912. if (typeof val === 'object' && val !== null) {
  5913. if (val instanceof RegExp) {
  5914. return new RegExp(val);
  5915. } else if (isArray(val)) {
  5916. return cloneArray(val);
  5917. } else {
  5918. return cloneNodeOrObject(val);
  5919. }
  5920. } else {
  5921. return val;
  5922. }
  5923. }
  5924. return cloneNodeOrObject;
  5925. };
  5926. },{"core-js/library/fn/array/index-of":5,"core-js/library/fn/array/is-array":6,"core-js/library/fn/array/reduce":8,"core-js/library/fn/object/keys":10}],68:[function(_dereq_,module,exports){
  5927. 'use strict';
  5928. var defaultProps = _dereq_('./ast-properties');
  5929. var objectKeys = _dereq_('core-js/library/fn/object/keys');
  5930. var assign = _dereq_('core-js/library/fn/object/assign');
  5931. module.exports = function createWhitelist (options) {
  5932. var opts = assign({}, options);
  5933. var typeName, i, len;
  5934. var keys = objectKeys(defaultProps);
  5935. var result = {};
  5936. for (i = 0, len = keys.length; i < len; i += 1) {
  5937. typeName = keys[i];
  5938. result[typeName] = defaultProps[typeName].concat(opts.extra);
  5939. }
  5940. return result;
  5941. };
  5942. },{"./ast-properties":66,"core-js/library/fn/object/assign":9,"core-js/library/fn/object/keys":10}],69:[function(_dereq_,module,exports){
  5943. /*
  5944. Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
  5945. Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
  5946. Redistribution and use in source and binary forms, with or without
  5947. modification, are permitted provided that the following conditions are met:
  5948. * Redistributions of source code must retain the above copyright
  5949. notice, this list of conditions and the following disclaimer.
  5950. * Redistributions in binary form must reproduce the above copyright
  5951. notice, this list of conditions and the following disclaimer in the
  5952. documentation and/or other materials provided with the distribution.
  5953. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  5954. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  5955. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  5956. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  5957. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5958. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5959. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5960. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5961. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  5962. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5963. */
  5964. /*jslint vars:false, bitwise:true*/
  5965. /*jshint indent:4*/
  5966. /*global exports:true*/
  5967. (function clone(exports) {
  5968. 'use strict';
  5969. var Syntax,
  5970. isArray,
  5971. VisitorOption,
  5972. VisitorKeys,
  5973. objectCreate,
  5974. objectKeys,
  5975. BREAK,
  5976. SKIP,
  5977. REMOVE;
  5978. function ignoreJSHintError() { }
  5979. isArray = Array.isArray;
  5980. if (!isArray) {
  5981. isArray = function isArray(array) {
  5982. return Object.prototype.toString.call(array) === '[object Array]';
  5983. };
  5984. }
  5985. function deepCopy(obj) {
  5986. var ret = {}, key, val;
  5987. for (key in obj) {
  5988. if (obj.hasOwnProperty(key)) {
  5989. val = obj[key];
  5990. if (typeof val === 'object' && val !== null) {
  5991. ret[key] = deepCopy(val);
  5992. } else {
  5993. ret[key] = val;
  5994. }
  5995. }
  5996. }
  5997. return ret;
  5998. }
  5999. function shallowCopy(obj) {
  6000. var ret = {}, key;
  6001. for (key in obj) {
  6002. if (obj.hasOwnProperty(key)) {
  6003. ret[key] = obj[key];
  6004. }
  6005. }
  6006. return ret;
  6007. }
  6008. ignoreJSHintError(shallowCopy);
  6009. // based on LLVM libc++ upper_bound / lower_bound
  6010. // MIT License
  6011. function upperBound(array, func) {
  6012. var diff, len, i, current;
  6013. len = array.length;
  6014. i = 0;
  6015. while (len) {
  6016. diff = len >>> 1;
  6017. current = i + diff;
  6018. if (func(array[current])) {
  6019. len = diff;
  6020. } else {
  6021. i = current + 1;
  6022. len -= diff + 1;
  6023. }
  6024. }
  6025. return i;
  6026. }
  6027. function lowerBound(array, func) {
  6028. var diff, len, i, current;
  6029. len = array.length;
  6030. i = 0;
  6031. while (len) {
  6032. diff = len >>> 1;
  6033. current = i + diff;
  6034. if (func(array[current])) {
  6035. i = current + 1;
  6036. len -= diff + 1;
  6037. } else {
  6038. len = diff;
  6039. }
  6040. }
  6041. return i;
  6042. }
  6043. ignoreJSHintError(lowerBound);
  6044. objectCreate = Object.create || (function () {
  6045. function F() { }
  6046. return function (o) {
  6047. F.prototype = o;
  6048. return new F();
  6049. };
  6050. })();
  6051. objectKeys = Object.keys || function (o) {
  6052. var keys = [], key;
  6053. for (key in o) {
  6054. keys.push(key);
  6055. }
  6056. return keys;
  6057. };
  6058. function extend(to, from) {
  6059. var keys = objectKeys(from), key, i, len;
  6060. for (i = 0, len = keys.length; i < len; i += 1) {
  6061. key = keys[i];
  6062. to[key] = from[key];
  6063. }
  6064. return to;
  6065. }
  6066. Syntax = {
  6067. AssignmentExpression: 'AssignmentExpression',
  6068. AssignmentPattern: 'AssignmentPattern',
  6069. ArrayExpression: 'ArrayExpression',
  6070. ArrayPattern: 'ArrayPattern',
  6071. ArrowFunctionExpression: 'ArrowFunctionExpression',
  6072. AwaitExpression: 'AwaitExpression', // CAUTION: It's deferred to ES7.
  6073. BlockStatement: 'BlockStatement',
  6074. BinaryExpression: 'BinaryExpression',
  6075. BreakStatement: 'BreakStatement',
  6076. CallExpression: 'CallExpression',
  6077. CatchClause: 'CatchClause',
  6078. ClassBody: 'ClassBody',
  6079. ClassDeclaration: 'ClassDeclaration',
  6080. ClassExpression: 'ClassExpression',
  6081. ComprehensionBlock: 'ComprehensionBlock', // CAUTION: It's deferred to ES7.
  6082. ComprehensionExpression: 'ComprehensionExpression', // CAUTION: It's deferred to ES7.
  6083. ConditionalExpression: 'ConditionalExpression',
  6084. ContinueStatement: 'ContinueStatement',
  6085. DebuggerStatement: 'DebuggerStatement',
  6086. DirectiveStatement: 'DirectiveStatement',
  6087. DoWhileStatement: 'DoWhileStatement',
  6088. EmptyStatement: 'EmptyStatement',
  6089. ExportAllDeclaration: 'ExportAllDeclaration',
  6090. ExportDefaultDeclaration: 'ExportDefaultDeclaration',
  6091. ExportNamedDeclaration: 'ExportNamedDeclaration',
  6092. ExportSpecifier: 'ExportSpecifier',
  6093. ExpressionStatement: 'ExpressionStatement',
  6094. ForStatement: 'ForStatement',
  6095. ForInStatement: 'ForInStatement',
  6096. ForOfStatement: 'ForOfStatement',
  6097. FunctionDeclaration: 'FunctionDeclaration',
  6098. FunctionExpression: 'FunctionExpression',
  6099. GeneratorExpression: 'GeneratorExpression', // CAUTION: It's deferred to ES7.
  6100. Identifier: 'Identifier',
  6101. IfStatement: 'IfStatement',
  6102. ImportDeclaration: 'ImportDeclaration',
  6103. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  6104. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  6105. ImportSpecifier: 'ImportSpecifier',
  6106. Literal: 'Literal',
  6107. LabeledStatement: 'LabeledStatement',
  6108. LogicalExpression: 'LogicalExpression',
  6109. MemberExpression: 'MemberExpression',
  6110. MetaProperty: 'MetaProperty',
  6111. MethodDefinition: 'MethodDefinition',
  6112. ModuleSpecifier: 'ModuleSpecifier',
  6113. NewExpression: 'NewExpression',
  6114. ObjectExpression: 'ObjectExpression',
  6115. ObjectPattern: 'ObjectPattern',
  6116. Program: 'Program',
  6117. Property: 'Property',
  6118. RestElement: 'RestElement',
  6119. ReturnStatement: 'ReturnStatement',
  6120. SequenceExpression: 'SequenceExpression',
  6121. SpreadElement: 'SpreadElement',
  6122. Super: 'Super',
  6123. SwitchStatement: 'SwitchStatement',
  6124. SwitchCase: 'SwitchCase',
  6125. TaggedTemplateExpression: 'TaggedTemplateExpression',
  6126. TemplateElement: 'TemplateElement',
  6127. TemplateLiteral: 'TemplateLiteral',
  6128. ThisExpression: 'ThisExpression',
  6129. ThrowStatement: 'ThrowStatement',
  6130. TryStatement: 'TryStatement',
  6131. UnaryExpression: 'UnaryExpression',
  6132. UpdateExpression: 'UpdateExpression',
  6133. VariableDeclaration: 'VariableDeclaration',
  6134. VariableDeclarator: 'VariableDeclarator',
  6135. WhileStatement: 'WhileStatement',
  6136. WithStatement: 'WithStatement',
  6137. YieldExpression: 'YieldExpression'
  6138. };
  6139. VisitorKeys = {
  6140. AssignmentExpression: ['left', 'right'],
  6141. AssignmentPattern: ['left', 'right'],
  6142. ArrayExpression: ['elements'],
  6143. ArrayPattern: ['elements'],
  6144. ArrowFunctionExpression: ['params', 'body'],
  6145. AwaitExpression: ['argument'], // CAUTION: It's deferred to ES7.
  6146. BlockStatement: ['body'],
  6147. BinaryExpression: ['left', 'right'],
  6148. BreakStatement: ['label'],
  6149. CallExpression: ['callee', 'arguments'],
  6150. CatchClause: ['param', 'body'],
  6151. ClassBody: ['body'],
  6152. ClassDeclaration: ['id', 'superClass', 'body'],
  6153. ClassExpression: ['id', 'superClass', 'body'],
  6154. ComprehensionBlock: ['left', 'right'], // CAUTION: It's deferred to ES7.
  6155. ComprehensionExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
  6156. ConditionalExpression: ['test', 'consequent', 'alternate'],
  6157. ContinueStatement: ['label'],
  6158. DebuggerStatement: [],
  6159. DirectiveStatement: [],
  6160. DoWhileStatement: ['body', 'test'],
  6161. EmptyStatement: [],
  6162. ExportAllDeclaration: ['source'],
  6163. ExportDefaultDeclaration: ['declaration'],
  6164. ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
  6165. ExportSpecifier: ['exported', 'local'],
  6166. ExpressionStatement: ['expression'],
  6167. ForStatement: ['init', 'test', 'update', 'body'],
  6168. ForInStatement: ['left', 'right', 'body'],
  6169. ForOfStatement: ['left', 'right', 'body'],
  6170. FunctionDeclaration: ['id', 'params', 'body'],
  6171. FunctionExpression: ['id', 'params', 'body'],
  6172. GeneratorExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
  6173. Identifier: [],
  6174. IfStatement: ['test', 'consequent', 'alternate'],
  6175. ImportDeclaration: ['specifiers', 'source'],
  6176. ImportDefaultSpecifier: ['local'],
  6177. ImportNamespaceSpecifier: ['local'],
  6178. ImportSpecifier: ['imported', 'local'],
  6179. Literal: [],
  6180. LabeledStatement: ['label', 'body'],
  6181. LogicalExpression: ['left', 'right'],
  6182. MemberExpression: ['object', 'property'],
  6183. MetaProperty: ['meta', 'property'],
  6184. MethodDefinition: ['key', 'value'],
  6185. ModuleSpecifier: [],
  6186. NewExpression: ['callee', 'arguments'],
  6187. ObjectExpression: ['properties'],
  6188. ObjectPattern: ['properties'],
  6189. Program: ['body'],
  6190. Property: ['key', 'value'],
  6191. RestElement: [ 'argument' ],
  6192. ReturnStatement: ['argument'],
  6193. SequenceExpression: ['expressions'],
  6194. SpreadElement: ['argument'],
  6195. Super: [],
  6196. SwitchStatement: ['discriminant', 'cases'],
  6197. SwitchCase: ['test', 'consequent'],
  6198. TaggedTemplateExpression: ['tag', 'quasi'],
  6199. TemplateElement: [],
  6200. TemplateLiteral: ['quasis', 'expressions'],
  6201. ThisExpression: [],
  6202. ThrowStatement: ['argument'],
  6203. TryStatement: ['block', 'handler', 'finalizer'],
  6204. UnaryExpression: ['argument'],
  6205. UpdateExpression: ['argument'],
  6206. VariableDeclaration: ['declarations'],
  6207. VariableDeclarator: ['id', 'init'],
  6208. WhileStatement: ['test', 'body'],
  6209. WithStatement: ['object', 'body'],
  6210. YieldExpression: ['argument']
  6211. };
  6212. // unique id
  6213. BREAK = {};
  6214. SKIP = {};
  6215. REMOVE = {};
  6216. VisitorOption = {
  6217. Break: BREAK,
  6218. Skip: SKIP,
  6219. Remove: REMOVE
  6220. };
  6221. function Reference(parent, key) {
  6222. this.parent = parent;
  6223. this.key = key;
  6224. }
  6225. Reference.prototype.replace = function replace(node) {
  6226. this.parent[this.key] = node;
  6227. };
  6228. Reference.prototype.remove = function remove() {
  6229. if (isArray(this.parent)) {
  6230. this.parent.splice(this.key, 1);
  6231. return true;
  6232. } else {
  6233. this.replace(null);
  6234. return false;
  6235. }
  6236. };
  6237. function Element(node, path, wrap, ref) {
  6238. this.node = node;
  6239. this.path = path;
  6240. this.wrap = wrap;
  6241. this.ref = ref;
  6242. }
  6243. function Controller() { }
  6244. // API:
  6245. // return property path array from root to current node
  6246. Controller.prototype.path = function path() {
  6247. var i, iz, j, jz, result, element;
  6248. function addToPath(result, path) {
  6249. if (isArray(path)) {
  6250. for (j = 0, jz = path.length; j < jz; ++j) {
  6251. result.push(path[j]);
  6252. }
  6253. } else {
  6254. result.push(path);
  6255. }
  6256. }
  6257. // root node
  6258. if (!this.__current.path) {
  6259. return null;
  6260. }
  6261. // first node is sentinel, second node is root element
  6262. result = [];
  6263. for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
  6264. element = this.__leavelist[i];
  6265. addToPath(result, element.path);
  6266. }
  6267. addToPath(result, this.__current.path);
  6268. return result;
  6269. };
  6270. // API:
  6271. // return type of current node
  6272. Controller.prototype.type = function () {
  6273. var node = this.current();
  6274. return node.type || this.__current.wrap;
  6275. };
  6276. // API:
  6277. // return array of parent elements
  6278. Controller.prototype.parents = function parents() {
  6279. var i, iz, result;
  6280. // first node is sentinel
  6281. result = [];
  6282. for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
  6283. result.push(this.__leavelist[i].node);
  6284. }
  6285. return result;
  6286. };
  6287. // API:
  6288. // return current node
  6289. Controller.prototype.current = function current() {
  6290. return this.__current.node;
  6291. };
  6292. Controller.prototype.__execute = function __execute(callback, element) {
  6293. var previous, result;
  6294. result = undefined;
  6295. previous = this.__current;
  6296. this.__current = element;
  6297. this.__state = null;
  6298. if (callback) {
  6299. result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
  6300. }
  6301. this.__current = previous;
  6302. return result;
  6303. };
  6304. // API:
  6305. // notify control skip / break
  6306. Controller.prototype.notify = function notify(flag) {
  6307. this.__state = flag;
  6308. };
  6309. // API:
  6310. // skip child nodes of current node
  6311. Controller.prototype.skip = function () {
  6312. this.notify(SKIP);
  6313. };
  6314. // API:
  6315. // break traversals
  6316. Controller.prototype['break'] = function () {
  6317. this.notify(BREAK);
  6318. };
  6319. // API:
  6320. // remove node
  6321. Controller.prototype.remove = function () {
  6322. this.notify(REMOVE);
  6323. };
  6324. Controller.prototype.__initialize = function(root, visitor) {
  6325. this.visitor = visitor;
  6326. this.root = root;
  6327. this.__worklist = [];
  6328. this.__leavelist = [];
  6329. this.__current = null;
  6330. this.__state = null;
  6331. this.__fallback = null;
  6332. if (visitor.fallback === 'iteration') {
  6333. this.__fallback = objectKeys;
  6334. } else if (typeof visitor.fallback === 'function') {
  6335. this.__fallback = visitor.fallback;
  6336. }
  6337. this.__keys = VisitorKeys;
  6338. if (visitor.keys) {
  6339. this.__keys = extend(objectCreate(this.__keys), visitor.keys);
  6340. }
  6341. };
  6342. function isNode(node) {
  6343. if (node == null) {
  6344. return false;
  6345. }
  6346. return typeof node === 'object' && typeof node.type === 'string';
  6347. }
  6348. function isProperty(nodeType, key) {
  6349. return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && 'properties' === key;
  6350. }
  6351. Controller.prototype.traverse = function traverse(root, visitor) {
  6352. var worklist,
  6353. leavelist,
  6354. element,
  6355. node,
  6356. nodeType,
  6357. ret,
  6358. key,
  6359. current,
  6360. current2,
  6361. candidates,
  6362. candidate,
  6363. sentinel;
  6364. this.__initialize(root, visitor);
  6365. sentinel = {};
  6366. // reference
  6367. worklist = this.__worklist;
  6368. leavelist = this.__leavelist;
  6369. // initialize
  6370. worklist.push(new Element(root, null, null, null));
  6371. leavelist.push(new Element(null, null, null, null));
  6372. while (worklist.length) {
  6373. element = worklist.pop();
  6374. if (element === sentinel) {
  6375. element = leavelist.pop();
  6376. ret = this.__execute(visitor.leave, element);
  6377. if (this.__state === BREAK || ret === BREAK) {
  6378. return;
  6379. }
  6380. continue;
  6381. }
  6382. if (element.node) {
  6383. ret = this.__execute(visitor.enter, element);
  6384. if (this.__state === BREAK || ret === BREAK) {
  6385. return;
  6386. }
  6387. worklist.push(sentinel);
  6388. leavelist.push(element);
  6389. if (this.__state === SKIP || ret === SKIP) {
  6390. continue;
  6391. }
  6392. node = element.node;
  6393. nodeType = node.type || element.wrap;
  6394. candidates = this.__keys[nodeType];
  6395. if (!candidates) {
  6396. if (this.__fallback) {
  6397. candidates = this.__fallback(node);
  6398. } else {
  6399. throw new Error('Unknown node type ' + nodeType + '.');
  6400. }
  6401. }
  6402. current = candidates.length;
  6403. while ((current -= 1) >= 0) {
  6404. key = candidates[current];
  6405. candidate = node[key];
  6406. if (!candidate) {
  6407. continue;
  6408. }
  6409. if (isArray(candidate)) {
  6410. current2 = candidate.length;
  6411. while ((current2 -= 1) >= 0) {
  6412. if (!candidate[current2]) {
  6413. continue;
  6414. }
  6415. if (isProperty(nodeType, candidates[current])) {
  6416. element = new Element(candidate[current2], [key, current2], 'Property', null);
  6417. } else if (isNode(candidate[current2])) {
  6418. element = new Element(candidate[current2], [key, current2], null, null);
  6419. } else {
  6420. continue;
  6421. }
  6422. worklist.push(element);
  6423. }
  6424. } else if (isNode(candidate)) {
  6425. worklist.push(new Element(candidate, key, null, null));
  6426. }
  6427. }
  6428. }
  6429. }
  6430. };
  6431. Controller.prototype.replace = function replace(root, visitor) {
  6432. var worklist,
  6433. leavelist,
  6434. node,
  6435. nodeType,
  6436. target,
  6437. element,
  6438. current,
  6439. current2,
  6440. candidates,
  6441. candidate,
  6442. sentinel,
  6443. outer,
  6444. key;
  6445. function removeElem(element) {
  6446. var i,
  6447. key,
  6448. nextElem,
  6449. parent;
  6450. if (element.ref.remove()) {
  6451. // When the reference is an element of an array.
  6452. key = element.ref.key;
  6453. parent = element.ref.parent;
  6454. // If removed from array, then decrease following items' keys.
  6455. i = worklist.length;
  6456. while (i--) {
  6457. nextElem = worklist[i];
  6458. if (nextElem.ref && nextElem.ref.parent === parent) {
  6459. if (nextElem.ref.key < key) {
  6460. break;
  6461. }
  6462. --nextElem.ref.key;
  6463. }
  6464. }
  6465. }
  6466. }
  6467. this.__initialize(root, visitor);
  6468. sentinel = {};
  6469. // reference
  6470. worklist = this.__worklist;
  6471. leavelist = this.__leavelist;
  6472. // initialize
  6473. outer = {
  6474. root: root
  6475. };
  6476. element = new Element(root, null, null, new Reference(outer, 'root'));
  6477. worklist.push(element);
  6478. leavelist.push(element);
  6479. while (worklist.length) {
  6480. element = worklist.pop();
  6481. if (element === sentinel) {
  6482. element = leavelist.pop();
  6483. target = this.__execute(visitor.leave, element);
  6484. // node may be replaced with null,
  6485. // so distinguish between undefined and null in this place
  6486. if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
  6487. // replace
  6488. element.ref.replace(target);
  6489. }
  6490. if (this.__state === REMOVE || target === REMOVE) {
  6491. removeElem(element);
  6492. }
  6493. if (this.__state === BREAK || target === BREAK) {
  6494. return outer.root;
  6495. }
  6496. continue;
  6497. }
  6498. target = this.__execute(visitor.enter, element);
  6499. // node may be replaced with null,
  6500. // so distinguish between undefined and null in this place
  6501. if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
  6502. // replace
  6503. element.ref.replace(target);
  6504. element.node = target;
  6505. }
  6506. if (this.__state === REMOVE || target === REMOVE) {
  6507. removeElem(element);
  6508. element.node = null;
  6509. }
  6510. if (this.__state === BREAK || target === BREAK) {
  6511. return outer.root;
  6512. }
  6513. // node may be null
  6514. node = element.node;
  6515. if (!node) {
  6516. continue;
  6517. }
  6518. worklist.push(sentinel);
  6519. leavelist.push(element);
  6520. if (this.__state === SKIP || target === SKIP) {
  6521. continue;
  6522. }
  6523. nodeType = node.type || element.wrap;
  6524. candidates = this.__keys[nodeType];
  6525. if (!candidates) {
  6526. if (this.__fallback) {
  6527. candidates = this.__fallback(node);
  6528. } else {
  6529. throw new Error('Unknown node type ' + nodeType + '.');
  6530. }
  6531. }
  6532. current = candidates.length;
  6533. while ((current -= 1) >= 0) {
  6534. key = candidates[current];
  6535. candidate = node[key];
  6536. if (!candidate) {
  6537. continue;
  6538. }
  6539. if (isArray(candidate)) {
  6540. current2 = candidate.length;
  6541. while ((current2 -= 1) >= 0) {
  6542. if (!candidate[current2]) {
  6543. continue;
  6544. }
  6545. if (isProperty(nodeType, candidates[current])) {
  6546. element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2));
  6547. } else if (isNode(candidate[current2])) {
  6548. element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
  6549. } else {
  6550. continue;
  6551. }
  6552. worklist.push(element);
  6553. }
  6554. } else if (isNode(candidate)) {
  6555. worklist.push(new Element(candidate, key, null, new Reference(node, key)));
  6556. }
  6557. }
  6558. }
  6559. return outer.root;
  6560. };
  6561. function traverse(root, visitor) {
  6562. var controller = new Controller();
  6563. return controller.traverse(root, visitor);
  6564. }
  6565. function replace(root, visitor) {
  6566. var controller = new Controller();
  6567. return controller.replace(root, visitor);
  6568. }
  6569. function extendCommentRange(comment, tokens) {
  6570. var target;
  6571. target = upperBound(tokens, function search(token) {
  6572. return token.range[0] > comment.range[0];
  6573. });
  6574. comment.extendedRange = [comment.range[0], comment.range[1]];
  6575. if (target !== tokens.length) {
  6576. comment.extendedRange[1] = tokens[target].range[0];
  6577. }
  6578. target -= 1;
  6579. if (target >= 0) {
  6580. comment.extendedRange[0] = tokens[target].range[1];
  6581. }
  6582. return comment;
  6583. }
  6584. function attachComments(tree, providedComments, tokens) {
  6585. // At first, we should calculate extended comment ranges.
  6586. var comments = [], comment, len, i, cursor;
  6587. if (!tree.range) {
  6588. throw new Error('attachComments needs range information');
  6589. }
  6590. // tokens array is empty, we attach comments to tree as 'leadingComments'
  6591. if (!tokens.length) {
  6592. if (providedComments.length) {
  6593. for (i = 0, len = providedComments.length; i < len; i += 1) {
  6594. comment = deepCopy(providedComments[i]);
  6595. comment.extendedRange = [0, tree.range[0]];
  6596. comments.push(comment);
  6597. }
  6598. tree.leadingComments = comments;
  6599. }
  6600. return tree;
  6601. }
  6602. for (i = 0, len = providedComments.length; i < len; i += 1) {
  6603. comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
  6604. }
  6605. // This is based on John Freeman's implementation.
  6606. cursor = 0;
  6607. traverse(tree, {
  6608. enter: function (node) {
  6609. var comment;
  6610. while (cursor < comments.length) {
  6611. comment = comments[cursor];
  6612. if (comment.extendedRange[1] > node.range[0]) {
  6613. break;
  6614. }
  6615. if (comment.extendedRange[1] === node.range[0]) {
  6616. if (!node.leadingComments) {
  6617. node.leadingComments = [];
  6618. }
  6619. node.leadingComments.push(comment);
  6620. comments.splice(cursor, 1);
  6621. } else {
  6622. cursor += 1;
  6623. }
  6624. }
  6625. // already out of owned node
  6626. if (cursor === comments.length) {
  6627. return VisitorOption.Break;
  6628. }
  6629. if (comments[cursor].extendedRange[0] > node.range[1]) {
  6630. return VisitorOption.Skip;
  6631. }
  6632. }
  6633. });
  6634. cursor = 0;
  6635. traverse(tree, {
  6636. leave: function (node) {
  6637. var comment;
  6638. while (cursor < comments.length) {
  6639. comment = comments[cursor];
  6640. if (node.range[1] < comment.extendedRange[0]) {
  6641. break;
  6642. }
  6643. if (node.range[1] === comment.extendedRange[0]) {
  6644. if (!node.trailingComments) {
  6645. node.trailingComments = [];
  6646. }
  6647. node.trailingComments.push(comment);
  6648. comments.splice(cursor, 1);
  6649. } else {
  6650. cursor += 1;
  6651. }
  6652. }
  6653. // already out of owned node
  6654. if (cursor === comments.length) {
  6655. return VisitorOption.Break;
  6656. }
  6657. if (comments[cursor].extendedRange[0] > node.range[1]) {
  6658. return VisitorOption.Skip;
  6659. }
  6660. }
  6661. });
  6662. return tree;
  6663. }
  6664. exports.version = _dereq_('./package.json').version;
  6665. exports.Syntax = Syntax;
  6666. exports.traverse = traverse;
  6667. exports.replace = replace;
  6668. exports.attachComments = attachComments;
  6669. exports.VisitorKeys = VisitorKeys;
  6670. exports.VisitorOption = VisitorOption;
  6671. exports.Controller = Controller;
  6672. exports.cloneEnvironment = function () { return clone({}); };
  6673. return exports;
  6674. }(exports));
  6675. /* vim: set sw=4 ts=4 et tw=80 : */
  6676. },{"./package.json":70}],70:[function(_dereq_,module,exports){
  6677. module.exports={"version":"4.2.0"}
  6678. },{}]},{},[1])(1)
  6679. });